From 8dab80ff200998cdee40144c9855443cd17f366d Mon Sep 17 00:00:00 2001 From: kekzdealer Date: Sat, 12 Oct 2019 00:51:41 +0200 Subject: Made working UI base for nuclear reactor --- .../container/Container_ModularNuclearReactor.java | 77 +++++++++++++--------- .../GUIContainer_ModularNuclearReactor.java | 70 +++++++++----------- 2 files changed, 77 insertions(+), 70 deletions(-) (limited to 'src/main/java/container') diff --git a/src/main/java/container/Container_ModularNuclearReactor.java b/src/main/java/container/Container_ModularNuclearReactor.java index a8fdd5f25a..ec6270d705 100644 --- a/src/main/java/container/Container_ModularNuclearReactor.java +++ b/src/main/java/container/Container_ModularNuclearReactor.java @@ -1,19 +1,14 @@ package container; -import gregtech.api.gui.GT_Container_MultiMachine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import reactor.ButtonSlot; -import tileentities.GTMTE_ModularNuclearReactor; -public class Container_ModularNuclearReactor extends GT_Container_MultiMachine { +public class Container_ModularNuclearReactor extends Container { - private final GTMTE_ModularNuclearReactor REACTOR_TILE; - private final IInventory PLAYER_INVENTORY; - private int nextSlotID = 0; private final Slot[] REACTOR_SLOTS = new Slot[54]; private final Slot SLOT_CONFIGURATION; @@ -24,28 +19,23 @@ public class Container_ModularNuclearReactor extends GT_Container_MultiMachine { private final Slot BUTTON_RESET; - public Container_ModularNuclearReactor(InventoryPlayer inventoryPlayer, IGregTechTileEntity reactorTile) { - - super(inventoryPlayer, reactorTile); - - this.REACTOR_TILE = (GTMTE_ModularNuclearReactor) reactorTile; - this.PLAYER_INVENTORY = inventoryPlayer; - + public Container_ModularNuclearReactor(IGregTechTileEntity te, EntityPlayer player) { + // Add the reactor chamber for(int x = 0; x < 9; x++) { for(int y = 0; y < 6; y++){ - REACTOR_SLOTS[nextSlotID] = super.addSlotToContainer(new Slot(PLAYER_INVENTORY, getNextSlotID(), (16 + 67 * x), (16 + 67 * y))); + REACTOR_SLOTS[nextSlotID] = super.addSlotToContainer(new Slot(te, getNextSlotID(), (16 + 67 * x), (16 + 67 * y))); } } // Add the configuration slot - SLOT_CONFIGURATION = super.addSlotToContainer(new Slot(PLAYER_INVENTORY, getNextSlotID(), 0, 0)); + SLOT_CONFIGURATION = super.addSlotToContainer(new Slot(te, getNextSlotID(), 0, 0)); // Add buttons (they're also slots) - BUTTON_EU_MODE = super.addSlotToContainer(new ButtonSlot(PLAYER_INVENTORY, getNextSlotID(), 0, 0)); - BUTTON_FLUID_MODE = super.addSlotToContainer(new ButtonSlot(PLAYER_INVENTORY, getNextSlotID(), 0, 0)); - BUTTON_CONDITION = super.addSlotToContainer(new ButtonSlot(PLAYER_INVENTORY, getNextSlotID(), 0, 0)); - BUTTON_CONFIGURE = super.addSlotToContainer(new ButtonSlot(PLAYER_INVENTORY, getNextSlotID(), 0, 0)); - BUTTON_RESET = super.addSlotToContainer(new ButtonSlot(PLAYER_INVENTORY, getNextSlotID(), 0, 0)); + BUTTON_EU_MODE = super.addSlotToContainer(new ButtonSlot(te, getNextSlotID(), 0, 0)); + BUTTON_FLUID_MODE = super.addSlotToContainer(new ButtonSlot(te, getNextSlotID(), 0, 0)); + BUTTON_CONDITION = super.addSlotToContainer(new ButtonSlot(te, getNextSlotID(), 0, 0)); + BUTTON_CONFIGURE = super.addSlotToContainer(new ButtonSlot(te, getNextSlotID(), 0, 0)); + BUTTON_RESET = super.addSlotToContainer(new ButtonSlot(te, getNextSlotID(), 0, 0)); } @@ -54,17 +44,44 @@ public class Container_ModularNuclearReactor extends GT_Container_MultiMachine { return nextSlotID - 1; } + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotRaw) + { + ItemStack stack = null; + Slot slot = (Slot)inventorySlots.get(slotRaw); + + if (slot != null && slot.getHasStack()) + { + ItemStack stackInSlot = slot.getStack(); + stack = stackInSlot.copy(); + + if (slotRaw < 3 * 9) + { + if (!mergeItemStack(stackInSlot, 3 * 9, inventorySlots.size(), true)) + { + return null; + } + } + else if (!mergeItemStack(stackInSlot, 0, 3 * 9, false)) + { + return null; + } + + if (stackInSlot.stackSize == 0) + { + slot.putStack((ItemStack)null); + } + else + { + slot.onSlotChanged(); + } + } + return stack; + } + @Override public boolean canInteractWith(EntityPlayer p_75145_1_) { return true; } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if (REACTOR_TILE.getBaseMetaTileEntity().isServerSide() == false) { - return; - } - } } diff --git a/src/main/java/container/GUIContainer_ModularNuclearReactor.java b/src/main/java/container/GUIContainer_ModularNuclearReactor.java index 9bea52badc..1333799a78 100644 --- a/src/main/java/container/GUIContainer_ModularNuclearReactor.java +++ b/src/main/java/container/GUIContainer_ModularNuclearReactor.java @@ -2,52 +2,42 @@ package container; import org.lwjgl.opengl.GL11; -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import kekztech.KekzCore; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; -public class GUIContainer_ModularNuclearReactor extends GT_GUIContainerMetaTile_Machine { +public class GUIContainer_ModularNuclearReactor extends GuiContainer { - private final String resourceName; - private final ResourceLocation texture; - - public GUIContainer_ModularNuclearReactor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, - String aName, String aTextureFile) { - - super(new Container_ModularNuclearReactor(aInventoryPlayer, aTileEntity), aTextureFile); - - this.resourceName = aTextureFile; - this.texture = new ResourceLocation(KekzCore.MODID, "textures/gui/" + resourceName); - } - - @SuppressWarnings("unchecked") - @Override - public void initGui() { - super.initGui(); - - // The parameters of GuiButton are (id, x, y, width, height, text) - super.buttonList.add(new GuiButton(1, 100, 200, 100, 20, "Hello")); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { - - Minecraft.getMinecraft().renderEngine.bindTexture(texture); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - final int x = (super.width - super.xSize); - final int y = (super.height - super.ySize); - - super.drawTexturedModalRect(x, y, 0, 0, super.xSize, super.ySize); - } - - @Override - protected void drawGuiContainerForegroundLayer(int par1, int par2) { - - } + private ResourceLocation texture = new ResourceLocation(KekzCore.MODID, "textures/gui/ReaktorGUI_background.png"); + + private InventoryPlayer inventory; + private IGregTechTileEntity te; + + public GUIContainer_ModularNuclearReactor(IGregTechTileEntity te, EntityPlayer player) + { + super(new Container_ModularNuclearReactor(te, player)); + inventory = player.inventory; + this.te = te; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) + { + Minecraft.getMinecraft().renderEngine.bindTexture(texture); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + drawTexturedModalRect(100, 100, 0, 0, 300, 200); + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) + { + + } } -- cgit