Search in sources :

Example 1 with ModularUI

use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.

the class NetworkHandler method init.

public static void init() {
    channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(GTValues.MODID);
    channel.register(new NetworkHandler());
    PacketEncoder<PacketUIWidgetUpdate> widgetUpdateEncoder = (packet, buf) -> {
        buf.writeVarInt(packet.updateData.readableBytes());
        buf.writeBytes(packet.updateData);
        buf.writeVarInt(packet.windowId);
        buf.writeVarInt(packet.widgetId);
    };
    PacketDecoder<PacketUIWidgetUpdate> widgetUpdateDecoder = (buf) -> {
        ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
        ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
        directSliceBuffer.release();
        return new PacketUIWidgetUpdate(buf.readVarInt(), buf.readVarInt(), new PacketBuffer(copiedDataBuffer));
    };
    registerPacket(1, PacketUIOpen.class, new PacketCodec<>((packet, buf) -> {
        buf.writeVarInt(packet.serializedHolder.readableBytes());
        buf.writeBytes(packet.serializedHolder);
        buf.writeVarInt(packet.uiFactoryId);
        buf.writeVarInt(packet.windowId);
        buf.writeVarInt(packet.initialWidgetUpdates.size());
        for (PacketUIWidgetUpdate widgetUpdate : packet.initialWidgetUpdates) {
            widgetUpdateEncoder.encode(widgetUpdate, buf);
        }
    }, (buf) -> {
        ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
        ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
        directSliceBuffer.release();
        int uiFactoryId = buf.readVarInt();
        int windowId = buf.readVarInt();
        ArrayList<PacketUIWidgetUpdate> initialWidgetUpdates = new ArrayList<>();
        int initialWidgetUpdatesCount = buf.readVarInt();
        for (int i = 0; i < initialWidgetUpdatesCount; i++) {
            initialWidgetUpdates.add(widgetUpdateDecoder.decode(buf));
        }
        return new PacketUIOpen(uiFactoryId, new PacketBuffer(copiedDataBuffer), windowId, initialWidgetUpdates);
    }));
    registerPacket(2, PacketUIWidgetUpdate.class, new PacketCodec<>((packet, buf) -> {
        buf.writeVarInt(packet.updateData.readableBytes());
        buf.writeBytes(packet.updateData);
        buf.writeVarInt(packet.windowId);
        buf.writeVarInt(packet.widgetId);
    }, (buf) -> {
        ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
        ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
        directSliceBuffer.release();
        return new PacketUIWidgetUpdate(buf.readVarInt(), buf.readVarInt(), new PacketBuffer(copiedDataBuffer));
    }));
    registerPacket(3, PacketUIClientAction.class, new PacketCodec<>((packet, buf) -> {
        buf.writeVarInt(packet.updateData.readableBytes());
        buf.writeBytes(packet.updateData);
        buf.writeVarInt(packet.windowId);
        buf.writeVarInt(packet.widgetId);
    }, (buf) -> {
        ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
        ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
        directSliceBuffer.release();
        return new PacketUIClientAction(buf.readVarInt(), buf.readVarInt(), new PacketBuffer(copiedDataBuffer));
    }));
    registerPacket(4, PacketBlockParticle.class, new PacketCodec<>((packet, buf) -> {
        buf.writeBlockPos(packet.blockPos);
        buf.writeFloat((float) packet.entityPos.x);
        buf.writeFloat((float) packet.entityPos.y);
        buf.writeFloat((float) packet.entityPos.z);
        buf.writeVarInt(packet.particlesAmount);
    }, (buf) -> new PacketBlockParticle(buf.readBlockPos(), new Vector3(buf.readFloat(), buf.readFloat(), buf.readFloat()), buf.readVarInt())));
    registerPacket(5, PacketClipboard.class, new PacketCodec<>((packet, buf) -> {
        buf.writeString(packet.text);
    }, (buf) -> new PacketClipboard(buf.readString(32767))));
    registerServerExecutor(PacketUIClientAction.class, (packet, handler) -> {
        Container openContainer = handler.player.openContainer;
        if (openContainer instanceof ModularUIContainer && openContainer.windowId == packet.windowId) {
            ModularUI modularUI = ((ModularUIContainer) openContainer).getModularUI();
            PacketBuffer buffer = packet.updateData;
            modularUI.guiWidgets.get(packet.widgetId).handleClientAction(buffer.readVarInt(), buffer);
        }
    });
    if (FMLCommonHandler.instance().getSide().isClient()) {
        initClient();
    }
}
Also used : FMLNetworkEvent(net.minecraftforge.fml.common.network.FMLNetworkEvent) Vector3(codechicken.lib.vec.Vector3) ModularUIGui(gregtech.api.gui.impl.ModularUIGui) FMLEventChannel(net.minecraftforge.fml.common.network.FMLEventChannel) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) HashMap(java.util.HashMap) IntIdentityHashBiMap(net.minecraft.util.IntIdentityHashBiMap) ICustomParticleBlock(gregtech.api.block.ICustomParticleBlock) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) IThreadListener(net.minecraft.util.IThreadListener) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ModularUIContainer(gregtech.api.gui.impl.ModularUIContainer) GTLog(gregtech.api.util.GTLog) World(net.minecraft.world.World) INetHandler(net.minecraft.network.INetHandler) BlockPos(net.minecraft.util.math.BlockPos) ClipboardUtil(gregtech.api.util.ClipboardUtil) IBlockState(net.minecraft.block.state.IBlockState) GuiScreen(net.minecraft.client.gui.GuiScreen) GTValues(gregtech.api.GTValues) ParticleManager(net.minecraft.client.particle.ParticleManager) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) NetHandlerPlayClient(net.minecraft.client.network.NetHandlerPlayClient) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ModularUI(gregtech.api.gui.ModularUI) PacketBuffer(net.minecraft.network.PacketBuffer) UIFactory(gregtech.api.gui.UIFactory) Container(net.minecraft.inventory.Container) ArrayList(java.util.ArrayList) Vector3(codechicken.lib.vec.Vector3) ByteBuf(io.netty.buffer.ByteBuf) ModularUIContainer(gregtech.api.gui.impl.ModularUIContainer) Container(net.minecraft.inventory.Container) ModularUIContainer(gregtech.api.gui.impl.ModularUIContainer) ModularUI(gregtech.api.gui.ModularUI) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 2 with ModularUI

use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.

the class MetaTileEntityChest method createUI.

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
    Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, Math.max(176, 14 + rowSize * 18), 18 + 18 * amountOfRows + 94).label(5, 5, getMetaFullName());
    builder.widget(new SortingButtonWidget(111, 4, 60, 10, "gregtech.gui.sort", (info) -> sortInventorySlotContents(inventory)));
    for (int y = 0; y < amountOfRows; y++) {
        for (int x = 0; x < rowSize; x++) {
            int index = y * rowSize + x;
            builder.slot(inventory, index, 7 + x * 18, 18 + y * 18, GuiTextures.SLOT);
        }
    }
    int startX = (Math.max(176, 14 + rowSize * 18) - 162) / 2;
    builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, startX, 18 + 18 * amountOfRows + 12);
    if (!getWorld().isRemote) {
        builder.bindOpenListener(() -> onContainerOpen(entityPlayer));
        builder.bindCloseListener(() -> onContainerClose(entityPlayer));
    }
    return builder.build(getHolder(), entityPlayer);
}
Also used : Matrix4(codechicken.lib.vec.Matrix4) ModHandler(gregtech.api.recipes.ModHandler) Textures(gregtech.api.render.Textures) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) SolidMaterial(gregtech.api.unification.material.type.SolidMaterial) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) SortingButtonWidget(gregtech.api.gui.widgets.SortingButtonWidget) ArrayList(java.util.ArrayList) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Pair(org.apache.commons.lang3.tuple.Pair) Side(net.minecraftforge.fml.relauncher.Side) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) NonNullList(net.minecraft.util.NonNullList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) SoundCategory(net.minecraft.util.SoundCategory) Nullable(javax.annotation.Nullable) ColourRGBA(codechicken.lib.colour.ColourRGBA) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CCRenderState(codechicken.lib.render.CCRenderState) SoundEvents(net.minecraft.init.SoundEvents) World(net.minecraft.world.World) GTUtility.convertOpaqueRGBA_CLtoRGB(gregtech.api.util.GTUtility.convertOpaqueRGBA_CLtoRGB) BlockPos(net.minecraft.util.math.BlockPos) GuiTextures(gregtech.api.gui.GuiTextures) List(java.util.List) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) ModularUI(gregtech.api.gui.ModularUI) Builder(gregtech.api.gui.ModularUI.Builder) GTUtility(gregtech.api.util.GTUtility) ColourMultiplier(codechicken.lib.render.pipeline.ColourMultiplier) PacketBuffer(net.minecraft.network.PacketBuffer) IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) Cuboid6(codechicken.lib.vec.Cuboid6) Builder(gregtech.api.gui.ModularUI.Builder) SortingButtonWidget(gregtech.api.gui.widgets.SortingButtonWidget)

Example 3 with ModularUI

use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.

the class MetaTileEntityLockedSafe method createUI.

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
    DoubleSupplier supplier = () -> 0.2 + (unlockProgress / (MAX_UNLOCK_PROGRESS * 1.0)) * 0.8;
    ModularUI.Builder builder = ModularUI.defaultBuilder().widget(new ProgressWidget(supplier, 5, 5, 166, 74, GuiTextures.PROGRESS_BAR_UNLOCK, MoveType.VERTICAL_INVERTED)).bindPlayerInventory(entityPlayer.inventory);
    ServerWidgetGroup lockedGroup = new ServerWidgetGroup(() -> !isSafeUnlocked && unlockProgress < 0);
    lockedGroup.addWidget(new LabelWidget(5, 20, "gregtech.machine.locked_safe.malfunctioning"));
    lockedGroup.addWidget(new LabelWidget(5, 30, "gregtech.machine.locked_safe.requirements"));
    lockedGroup.addWidget(new SlotWidget(unlockInventory, 0, 70, 40, false, true).setBackgroundTexture(GuiTextures.SLOT));
    lockedGroup.addWidget(new SlotWidget(unlockInventory, 1, 70 + 18, 40, false, true).setBackgroundTexture(GuiTextures.SLOT));
    lockedGroup.addWidget(new SlotWidget(unlockComponents, 0, 70, 58, false, false));
    lockedGroup.addWidget(new SlotWidget(unlockComponents, 1, 70 + 18, 58, false, false));
    ServerWidgetGroup unlockedGroup = new ServerWidgetGroup(() -> isSafeUnlocked);
    for (int row = 0; row < 3; row++) {
        for (int col = 0; col < 9; col++) {
            unlockedGroup.addWidget(new SlotWidget(safeLootInventory, col + row * 9, 8 + col * 18, 15 + row * 18, true, false));
        }
    }
    return builder.widget(unlockedGroup).widget(lockedGroup).build(getHolder(), entityPlayer);
}
Also used : SlotWidget(gregtech.api.gui.widgets.SlotWidget) ModularUI(gregtech.api.gui.ModularUI) DoubleSupplier(java.util.function.DoubleSupplier) ProgressWidget(gregtech.api.gui.widgets.ProgressWidget) ServerWidgetGroup(gregtech.api.gui.widgets.ServerWidgetGroup) LabelWidget(gregtech.api.gui.widgets.LabelWidget)

Example 4 with ModularUI

use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.

the class GTUtility method findPlayersUsing.

public static List<EntityPlayerMP> findPlayersUsing(MetaTileEntity metaTileEntity, double radius) {
    ArrayList<EntityPlayerMP> result = new ArrayList<>();
    AxisAlignedBB box = new AxisAlignedBB(metaTileEntity.getPos()).expand(radius, radius, radius).expand(-radius, -radius, -radius);
    List<EntityPlayerMP> entities = metaTileEntity.getWorld().getEntitiesWithinAABB(EntityPlayerMP.class, box);
    for (EntityPlayerMP player : entities) {
        if (player.openContainer instanceof ModularUIContainer) {
            ModularUI modularUI = ((ModularUIContainer) player.openContainer).getModularUI();
            if (modularUI.holder instanceof MetaTileEntityHolder && ((MetaTileEntityHolder) modularUI.holder).getMetaTileEntity() == metaTileEntity) {
                result.add(player);
            }
        }
    }
    return result;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) ModularUIContainer(gregtech.api.gui.impl.ModularUIContainer) ModularUI(gregtech.api.gui.ModularUI) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 5 with ModularUI

use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.

the class MetaTileEntityItemCollector method createUI.

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
    int rowSize = (int) Math.sqrt(exportItems.getSlots());
    Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 45 + rowSize * 18 + 105 + 82).label(10, 5, getMetaFullName());
    builder.widget(new ClickButtonWidget(10, 20, 20, 20, "-1", data -> adjustSuckingRange(-1)));
    builder.widget(new ClickButtonWidget(146, 20, 20, 20, "+1", data -> adjustSuckingRange(+1)));
    builder.widget(new ImageWidget(30, 20, 116, 20, GuiTextures.DISPLAY));
    builder.widget(new SimpleTextWidget(88, 30, "gregtech.machine.item_collector.gui.collect_range", 0xFFFFFF, () -> Integer.toString(itemSuckingRange)));
    for (int y = 0; y < rowSize; y++) {
        for (int x = 0; x < rowSize; x++) {
            int index = y * rowSize + x;
            builder.widget(new SlotWidget(exportItems, index, 89 - rowSize * 9 + x * 18, 45 + y * 18, true, false).setBackgroundTexture(GuiTextures.SLOT));
        }
    }
    this.itemFilter.initUI(45 + rowSize * 18 + 5, builder::widget);
    builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 7, 45 + rowSize * 18 + 105);
    return builder.build(getHolder(), entityPlayer);
}
Also used : ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) Matrix4(codechicken.lib.vec.Matrix4) SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget) Textures(gregtech.api.render.Textures) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) ClickButtonWidget(gregtech.api.gui.widgets.ClickButtonWidget) ImageWidget(gregtech.api.gui.widgets.ImageWidget) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Side(net.minecraftforge.fml.relauncher.Side) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) SlotWidget(gregtech.api.gui.widgets.SlotWidget) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CCRenderState(codechicken.lib.render.CCRenderState) World(net.minecraft.world.World) ItemFilterContainer(gregtech.common.covers.filter.ItemFilterContainer) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) GuiTextures(gregtech.api.gui.GuiTextures) Capability(net.minecraftforge.common.capabilities.Capability) SimpleOverlayRenderer(gregtech.api.render.SimpleOverlayRenderer) List(java.util.List) GTValues(gregtech.api.GTValues) TieredMetaTileEntity(gregtech.api.metatileentity.TieredMetaTileEntity) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) ModularUI(gregtech.api.gui.ModularUI) Builder(gregtech.api.gui.ModularUI.Builder) PacketBuffer(net.minecraft.network.PacketBuffer) SlotWidget(gregtech.api.gui.widgets.SlotWidget) Builder(gregtech.api.gui.ModularUI.Builder) ImageWidget(gregtech.api.gui.widgets.ImageWidget) SimpleTextWidget(gregtech.api.gui.widgets.SimpleTextWidget)

Aggregations

ModularUI (gregtech.api.gui.ModularUI)7 CCRenderState (codechicken.lib.render.CCRenderState)4 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)4 Matrix4 (codechicken.lib.vec.Matrix4)4 GuiTextures (gregtech.api.gui.GuiTextures)4 Cuboid6 (codechicken.lib.vec.Cuboid6)3 LabelWidget (gregtech.api.gui.widgets.LabelWidget)3 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)3 SimpleOverlayRenderer (gregtech.api.render.SimpleOverlayRenderer)3 GTUtility (gregtech.api.util.GTUtility)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EnumFacing (net.minecraft.util.EnumFacing)3 Capability (net.minecraftforge.common.capabilities.Capability)3 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)2 GTValues (gregtech.api.GTValues)2 CoverBehavior (gregtech.api.cover.CoverBehavior)2 CoverWithUI (gregtech.api.cover.CoverWithUI)2 ICoverable (gregtech.api.cover.ICoverable)2 Builder (gregtech.api.gui.ModularUI.Builder)2