Search in sources :

Example 1 with IFF

use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.

the class OpenIFFScreenPacket method openIFFScreen.

@Environment(EnvType.CLIENT)
private static void openIFFScreen(int id, CompoundTag tag, PlayerEntity player) {
    Entity entity = player.world.getEntityById(id);
    if (!(entity instanceof HasIFF)) {
        return;
    }
    ListTag list = tag.getList("IFFs", 10);
    List<IFF> iffs = list.stream().map(t -> (CompoundTag) t).map(t -> IFFTypeManager.getINSTANCE().loadIFF(t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    MinecraftClient.getInstance().openScreen(new IFFScreen(entity, iffs));
}
Also used : PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) Environment(net.fabricmc.api.Environment) PacketByteBuf(net.minecraft.network.PacketByteBuf) Unpooled(io.netty.buffer.Unpooled) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) IFFTypeManager(net.sistr.littlemaidrebirth.entity.iff.IFFTypeManager) MinecraftServer(net.minecraft.server.MinecraftServer) EnvType(net.fabricmc.api.EnvType) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Entity(net.minecraft.entity.Entity) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) IFF(net.sistr.littlemaidrebirth.entity.iff.IFF) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IFFScreen(net.sistr.littlemaidrebirth.client.IFFScreen) Collectors(java.util.stream.Collectors) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LittleMaidReBirthMod(net.sistr.littlemaidrebirth.LittleMaidReBirthMod) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) Identifier(net.minecraft.util.Identifier) Optional(java.util.Optional) MinecraftClient(net.minecraft.client.MinecraftClient) TameableEntity(net.minecraft.entity.passive.TameableEntity) ListTag(net.minecraft.nbt.ListTag) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) IFFScreen(net.sistr.littlemaidrebirth.client.IFFScreen) Optional(java.util.Optional) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) IFF(net.sistr.littlemaidrebirth.entity.iff.IFF) ListTag(net.minecraft.nbt.ListTag) Environment(net.fabricmc.api.Environment)

Example 2 with IFF

use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.

the class SyncIFFPacket method applyIFFServer.

private static void applyIFFServer(int id, CompoundTag tag, PlayerEntity player) {
    Entity entity = player.world.getEntityById(id);
    if (!(entity instanceof HasIFF)) {
        return;
    }
    if (entity instanceof TameableEntity && !player.getUuid().equals(((TameableEntity) entity).getOwnerUuid())) {
        return;
    }
    ListTag list = tag.getList("IFFs", 10);
    List<IFF> iffs = list.stream().map(t -> (CompoundTag) t).map(t -> IFFTypeManager.getINSTANCE().loadIFF(t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    ((HasIFF) entity).setIFFs(iffs);
}
Also used : Entity(net.minecraft.entity.Entity) PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) IFF(net.sistr.littlemaidrebirth.entity.iff.IFF) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Environment(net.fabricmc.api.Environment) PacketByteBuf(net.minecraft.network.PacketByteBuf) Collectors(java.util.stream.Collectors) Unpooled(io.netty.buffer.Unpooled) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) IFFTypeManager(net.sistr.littlemaidrebirth.entity.iff.IFFTypeManager) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LittleMaidReBirthMod(net.sistr.littlemaidrebirth.LittleMaidReBirthMod) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) Optional(java.util.Optional) TameableEntity(net.minecraft.entity.passive.TameableEntity) ListTag(net.minecraft.nbt.ListTag) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) Optional(java.util.Optional) TameableEntity(net.minecraft.entity.passive.TameableEntity) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) IFF(net.sistr.littlemaidrebirth.entity.iff.IFF) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) ListTag(net.minecraft.nbt.ListTag)

Example 3 with IFF

use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.

the class IFFScreen method renderAllMobs.

public void renderAllMobs(MatrixStack matrices, int mouseX, int mouseY) {
    int count = -1;
    int x = width / 2 - width / 4 + layerSize;
    int y = scrollAmount;
    for (IFF iff : iffs) {
        count++;
        if (y++ < 0)
            continue;
        if (height < y * layerSize)
            break;
        iff.getIFFType().render(matrices, x, y * layerSize, -mouseX + x, -mouseY + y * layerSize);
        if (count == selectLine)
            fill(matrices, width / 4, y * layerSize, width - width / 4, (y - 1) * layerSize, 0x40FFFFFF);
        int color;
        switch(iff.getIFFTag()) {
            case FRIEND:
                color = 0x40FF40;
                break;
            case ENEMY:
                color = 0xFF4040;
                break;
            default:
                color = 0xFFFF40;
        }
        drawStringWithShadow(matrices, textRenderer, iff.getIFFTag().getName(), x + layerSize * 2, y * layerSize - layerSize / 2, color);
    }
}
Also used : IFF(net.sistr.littlemaidrebirth.entity.iff.IFF)

Example 4 with IFF

use of net.sistr.littlemaidrebirth.entity.iff.IFF in project LittleMaidReBirth-Fabric by SistrScarlet.

the class IFFScreen method mouseClicked.

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
    Optional<Float> optional = scrollBar.click(mouseX, mouseY);
    if (optional.isPresent()) {
        scrollAmount = (int) ((-iffs.size() + 2) * optional.get());
        return false;
    }
    if (width / 4F < mouseX && mouseX < width - width / 4F) {
        this.selectLine = -scrollAmount + (int) (mouseY / layerSize);
        if (this.selectLine < 0 || iffs.size() <= selectLine) {
            return false;
        }
        if (Util.getMeasuringTimeMs() - this.time < 250L) {
            IFF iff = iffs.get(selectLine);
            IFFTag tag = iff.getIFFTag();
            switch(tag) {
                case FRIEND:
                    iff.setTag(IFFTag.ENEMY);
                    break;
                case ENEMY:
                    iff.setTag(IFFTag.UNKNOWN);
                    break;
                default:
                    iff.setTag(IFFTag.FRIEND);
            }
            MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
            return true;
        }
    }
    this.time = Util.getMeasuringTimeMs();
    return super.mouseClicked(mouseX, mouseY, button);
}
Also used : IFF(net.sistr.littlemaidrebirth.entity.iff.IFF) IFFTag(net.sistr.littlemaidrebirth.entity.iff.IFFTag)

Aggregations

IFF (net.sistr.littlemaidrebirth.entity.iff.IFF)4 Unpooled (io.netty.buffer.Unpooled)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 EnvType (net.fabricmc.api.EnvType)2 Environment (net.fabricmc.api.Environment)2 ClientPlayNetworking (net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking)2 PacketSender (net.fabricmc.fabric.api.networking.v1.PacketSender)2 Entity (net.minecraft.entity.Entity)2 TameableEntity (net.minecraft.entity.passive.TameableEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 PacketByteBuf (net.minecraft.network.PacketByteBuf)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 ServerPlayNetworkHandler (net.minecraft.server.network.ServerPlayNetworkHandler)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 Identifier (net.minecraft.util.Identifier)2 LittleMaidReBirthMod (net.sistr.littlemaidrebirth.LittleMaidReBirthMod)2