diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-09-16 19:24:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-16 19:24:29 +0200 |
commit | 3227499d75e680fca9f6d7a45a3c0f6ee2b10c0d (patch) | |
tree | e570310ba27acd971d296ccfb1eb954b2804a0f6 /src | |
parent | 766a3de661244a39d918a50ef43e7a1fdf334b01 (diff) | |
download | GT5-Unofficial-3227499d75e680fca9f6d7a45a3c0f6ee2b10c0d.tar.gz GT5-Unofficial-3227499d75e680fca9f6d7a45a3c0f6ee2b10c0d.tar.bz2 GT5-Unofficial-3227499d75e680fca9f6d7a45a3c0f6ee2b10c0d.zip |
Add circuit slot support to super input bus (#349)
* Add circuit slot support to super input bus
* Client side only
* Fix server crash
* Diffrent action
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java index f144076131..345af422f7 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SuperBus_Input.java @@ -1,26 +1,33 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations; -import gregtech.api.enums.Textures.BlockIcons; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUIDialogSelectItem; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; -import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.net.GT_Packet_SetConfigurationCircuit; +import gregtech.api.util.GT_Utility; import gregtech.api.util.extensions.ArrayExt; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; +import java.util.List; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_InputBus { public GT_MetaTileEntity_SuperBus_Input(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier)); + super(aID, aName, aNameRegional, aTier, getSlots(aTier) + 1); } public GT_MetaTileEntity_SuperBus_Input(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, getSlots(aTier), aDescription, aTextures); + super(aName, aTier, getSlots(aTier) + 1, aDescription, aTextures); } /** @@ -33,64 +40,59 @@ public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_In return (1 + aTier) * 16; } - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[] {aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; - } - - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[] {aBaseTexture, new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE_IN)}; - } - - public boolean isSimpleMachine() { - return true; - } - - public boolean isFacingValid(byte aFacing) { - return true; - } - - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; - } - - public boolean isValidSlot(int aIndex) { - return true; - } - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_SuperBus_Input( this.mName, this.mTier, ArrayExt.of(this.mDescription), this.mTextures); } + @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return null; } + @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return null; } - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aSide == this.getBaseMetaTileEntity().getFrontFacing(); - } - @Override public String[] getDescription() { - String[] aDesc = new String[] { + return new String[] { "Item Input for Multiblocks", "This bus has no GUI, but can have items extracted", - "" + getSlots(this.mTier) + " Slots", + "" + (getSlots(this.mTier) + 1) + " Slots", + "To set circuit slot, left click with empty hand", CORE.GT_Tooltip }; - return aDesc; } @Override - public boolean onRightclick( - IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { - return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide() && aPlayer.getCurrentEquippedItem() == null) openCircuitSelector(); + } + + @SideOnly(Side.CLIENT) + private void openCircuitSelector() { + List<ItemStack> circuits = getConfigurationCircuits(); + Minecraft.getMinecraft() + .displayGuiScreen(new GT_GUIDialogSelectItem( + StatCollector.translateToLocal("GT5U.machines.select_circuit"), + getStackForm(0), + null, + this::onCircuitSelected, + circuits, + GT_Utility.findMatchingStackInList(circuits, getStackInSlot(getCircuitSlot())))); } + @SideOnly(Side.CLIENT) + private void onCircuitSelected(ItemStack selected) { + GT_Values.NW.sendToServer(new GT_Packet_SetConfigurationCircuit(getBaseMetaTileEntity(), selected)); + // we will not do any validation on client side + // it doesn't get to actually decide what inventory contains anyway + setInventorySlotContents(getCircuitSlot(), selected); + } + + @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { if (aBaseMetaTileEntity.isClientSide()) { return true; @@ -103,7 +105,7 @@ public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_In public void displayBusContents(EntityPlayer aPlayer) { String STRIP = "Item Array: "; - String aNameString = ItemUtils.getArrayStackNames(getRealInventory()); + String aNameString = ItemUtils.getArrayStackNames(mInventory); aNameString = aNameString.replace(STRIP, ""); String[] aNames; @@ -113,12 +115,12 @@ public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_In aNames = aNameString.split(","); } - if (aNames == null || aNames.length <= 0) { - PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) is Empty. Total Slots: " + getSlots(this.mTier)); + if (aNames == null || aNames.length == 0) { + PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) is Empty. Total Slots: " + mInventory.length); return; } - PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) contains: [" + getRealInventory().length + "]"); + PlayerUtils.messagePlayer(aPlayer, "This Super Bus (I) contains: [" + mInventory.length + "]"); if (aNames.length <= 12) { for (String s : aNames) { @@ -130,15 +132,20 @@ public class GT_MetaTileEntity_SuperBus_Input extends GT_MetaTileEntity_Hatch_In } } else { - String superString = ""; + StringBuilder superString = new StringBuilder(); for (String s : aNames) { if (s.startsWith(" ")) { s = s.substring(1); } - superString += (s + ", "); + superString.append(s).append(", "); } - PlayerUtils.messagePlayer(aPlayer, superString); + PlayerUtils.messagePlayer(aPlayer, superString.toString()); } } + + @Override + public int getCircuitSlot() { + return getSlots(mTier); + } } |