diff options
author | repo-alt <wvk17@yandex.ru> | 2022-08-19 19:22:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-19 18:22:17 +0200 |
commit | 77f5016dd0e198724a31a77e334ca069199eacdb (patch) | |
tree | 96a09fa4da882b04bffa504d63dea98f7a20bcc6 /src/main/java/gregtech/common/gui | |
parent | 976c03c765e679cec496597255b1b5dd0fcd6a3e (diff) | |
download | GT5-Unofficial-77f5016dd0e198724a31a77e334ca069199eacdb.tar.gz GT5-Unofficial-77f5016dd0e198724a31a77e334ca069199eacdb.tar.bz2 GT5-Unofficial-77f5016dd0e198724a31a77e334ca069199eacdb.zip |
ME input bus, gives the multiblock direct access to the 16 selected item types (#1271)
* ME input bus, gives the multiblock direct access to the 16 selected item types
* Reworked GUI to match the normal interface
* Don't need to duplicate shadow slots
Sync can (better) be done in `endRecipeProcessing`, in case some multi doesn't call `updateSlots` or does it at the wrong time
* Clarify name, to distinguish from the (future) Buffering and Crafting buses
* Make the GUI 4x4 again
* Make the 4x4 GUI actually work
* Make ghost item show item amount
* Remove unimplemented code remnants
Co-authored-by: Sampsa <sampo.vanninen@aalto.fi>
Diffstat (limited to 'src/main/java/gregtech/common/gui')
-rw-r--r-- | src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java | 92 | ||||
-rw-r--r-- | src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java | 53 |
2 files changed, 145 insertions, 0 deletions
diff --git a/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java b/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java new file mode 100644 index 0000000000..ae018657c4 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java @@ -0,0 +1,92 @@ +package gregtech.common.gui; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import gregtech.api.GregTech_API; +import gregtech.api.gui.GT_ContainerMetaTile_Machine; +import gregtech.api.gui.GT_Slot_Holo; +import gregtech.api.gui.GT_Slot_Render; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_Utility; + +public class GT_Container_InputBus_ME extends GT_ContainerMetaTile_Machine { + private static final int LEFT_OFFSET = 8; + private static final int TOP_OFFSET = 10; + private static final int SLOT_SIZE = 18; + public static final int CIRCUIT_SLOT = 32; + private Runnable circuitSlotClickCallback; + GT_Slot_Render slotCircuit; + public GT_Container_InputBus_ME(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(aInventoryPlayer, aTileEntity); + } + @Override + public void addSlots(InventoryPlayer aInventoryPlayer) { + for (int z = 0; z < 2; ++z) + for (int y = 0; y < 4; ++y) + for (int x = 0; x < 4; ++x) + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, x + y * 4 + z * 16, + LEFT_OFFSET + x * SLOT_SIZE + z * 90, TOP_OFFSET + y * SLOT_SIZE, false, true, 1)); + addSlotToContainer(slotCircuit = new GT_Slot_Render(mTileEntity, CIRCUIT_SLOT, 153, 63)); + } + + @Override + public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (aSlotIndex >= 0 && aSlotIndex < 16) { + Slot tSlot = (Slot) this.inventorySlots.get(aSlotIndex); + if (tSlot != null) { + if (this.mTileEntity.getMetaTileEntity() == null) + return null; + ItemStack tStack = aPlayer.inventory.getItemStack(); + if (tStack == null) { + tSlot.putStack(null); + } + else { + tSlot.putStack(GT_Utility.copyAmount(1L, new Object[] {tStack})); + } + return null; + } + } + + else if (aSlotIndex == CIRCUIT_SLOT && aMouseclick < 2) { + ItemStack newCircuit; + if (aShifthold == 1) { + if (aMouseclick == 0) { + if (circuitSlotClickCallback != null) + circuitSlotClickCallback.run(); + return null; + } else { + // clear + newCircuit = null; + } + } else { + ItemStack cursorStack = aPlayer.inventory.getItemStack(); + List<ItemStack> tCircuits = GregTech_API.getConfigurationCircuitList(1); + int index = GT_Utility.findMatchingStackInList(tCircuits, cursorStack); + if (index < 0) { + int curIndex = GT_Utility.findMatchingStackInList(tCircuits, mTileEntity.getStackInSlot(CIRCUIT_SLOT)) + 1; + if (aMouseclick == 0) { + curIndex += 1; + } else { + curIndex -= 1; + } + curIndex = Math.floorMod(curIndex, tCircuits.size() + 1) - 1; + newCircuit = curIndex < 0 ? null : tCircuits.get(curIndex); + } else { + // set to whatever it is + newCircuit = tCircuits.get(index); + } + } + mTileEntity.setInventorySlotContents(CIRCUIT_SLOT, newCircuit); + return newCircuit; + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + public void setCircuitSlotClickCallback(Runnable circuitSlotClickCallback) { + this.circuitSlotClickCallback = circuitSlotClickCallback; + } +} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java new file mode 100644 index 0000000000..5aefb98e55 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java @@ -0,0 +1,53 @@ +package gregtech.common.gui; + +import java.util.List; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; +import gregtech.api.gui.GT_GUIDialogSelectItem; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.net.GT_Packet_SetConfigurationCircuit_Bus; +import gregtech.api.util.GT_Utility; + +public class GT_GUIContainer_InputBus_ME extends GT_GUIContainerMetaTile_Machine { + + public GT_GUIContainer_InputBus_ME(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(new GT_Container_InputBus_ME(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/InputBusME.png"); + getContainer().setCircuitSlotClickCallback(this::openSelectCircuitDialog); + } + + private GT_Container_InputBus_ME getContainer() { + return (GT_Container_InputBus_ME) mContainer; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); + int x = (this.width - this.xSize) / 2; + int y = (this.height - this.ySize) / 2; + drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + private void onCircuitSelected(ItemStack selected) { + GT_Values.NW.sendToServer(new GT_Packet_SetConfigurationCircuit_Bus(mContainer.mTileEntity, selected)); + // we will not do any validation on client side + // it doesn't get to actually decide what inventory contains anyway + mContainer.mTileEntity.setInventorySlotContents(GT_Container_InputBus_ME.CIRCUIT_SLOT, selected); + } + private void openSelectCircuitDialog() { + List<ItemStack> circuits = GregTech_API.getConfigurationCircuitList(1); + mc.displayGuiScreen(new GT_GUIDialogSelectItem( + StatCollector.translateToLocal("GT5U.machines.select_circuit"), + mContainer.mTileEntity.getMetaTileEntity().getStackForm(0), + this, + this::onCircuitSelected, + circuits, + GT_Utility.findMatchingStackInList(circuits, + mContainer.mTileEntity.getStackInSlot(GT_Container_InputBus_ME.CIRCUIT_SLOT)))); + } +} |