diff options
Diffstat (limited to 'src/main/java/gregtech/common')
6 files changed, 417 insertions, 5 deletions
diff --git a/src/main/java/gregtech/common/GT_Network.java b/src/main/java/gregtech/common/GT_Network.java index 8db38d86f7..3dfc7b8f84 100644 --- a/src/main/java/gregtech/common/GT_Network.java +++ b/src/main/java/gregtech/common/GT_Network.java @@ -53,7 +53,8 @@ public class GT_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet> new GT_Packet_SetLockedFluid(), new GT_Packet_GtTileEntityGuiRequest(), new GT_Packet_SendCoverData(), - new GT_Packet_RequestCoverData() + new GT_Packet_RequestCoverData(), + new GT_Packet_SetConfigurationCircuit_Bus() ); } 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)))); + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java new file mode 100644 index 0000000000..bb3655ddfe --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java @@ -0,0 +1,261 @@ +package gregtech.common.tileentities.machines; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; + +import appeng.api.config.Actionable; +import appeng.api.networking.GridFlags; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.IActionHost; +import appeng.api.networking.security.MachineSource; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.util.AECableType; +import appeng.me.GridAccessException; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.IGridProxyable; +import appeng.util.Platform; +import appeng.util.item.AEItemStack; +import cpw.mods.fml.common.Optional; +import gregtech.api.GregTech_API; +import gregtech.api.enums.ItemList; +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.render.TextureFactory; +import gregtech.common.gui.GT_Container_InputBus_ME; +import gregtech.common.gui.GT_GUIContainer_InputBus_ME; +import gregtech.api.util.GT_Utility; + +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_HATCH; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_INPUT_HATCH_ACTIVE; + +public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch_InputBus { + private static final int SLOT_COUNT = 16; + private BaseActionSource requestSource = null; + private AENetworkProxy gridProxy = null; + private ItemStack[] shadowInventory = new ItemStack[SLOT_COUNT]; + private int[] savedStackSizes = new int[SLOT_COUNT]; + private boolean processingRecipe = false; + public GT_MetaTileEntity_Hatch_InputBus_ME(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 1, SLOT_COUNT * 2 + 1, new String[] { + "Advanced item input for Multiblocks", + "Retrieves directly from ME", + "Keeps 16 item types in stock" + }); + disableSort = true; + } + + public GT_MetaTileEntity_Hatch_InputBus_ME(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, SLOT_COUNT * 2 + 1, aDescription, aTextures); + disableSort = true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Hatch_InputBus_ME(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_ME_INPUT_HATCH_ACTIVE)}; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_ME_INPUT_HATCH)}; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_InputBus_ME(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_InputBus_ME(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + getProxy().onReady(); + } + + @Override + @Optional.Method(modid = "appliedenergistics2") + public AECableType getCableConnectionType(ForgeDirection forgeDirection) { + return isOutputFacing((byte) forgeDirection.ordinal()) ? AECableType.SMART : AECableType.NONE; + } + + + @Override + @Optional.Method(modid = "appliedenergistics2") + public AENetworkProxy getProxy() { + if (gridProxy == null) { + if (getBaseMetaTileEntity() instanceof IGridProxyable) { + gridProxy = new AENetworkProxy((IGridProxyable) getBaseMetaTileEntity(), "proxy", ItemList.Hatch_Output_Bus_ME.get(1), true); + gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL); + if (getBaseMetaTileEntity().getWorld() != null) + gridProxy.setOwner(getBaseMetaTileEntity().getWorld().getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName())); + } + } + return this.gridProxy; + } + + @Override + @Optional.Method(modid = "appliedenergistics2") + public void gridChanged() { + if (getBaseMetaTileEntity() != null && getBaseMetaTileEntity().getTimer() > 1) { + gridProxy = null; + getProxy(); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) + { + super.saveNBTData(aNBT); + if (GregTech_API.mAE2) { + gridProxy.writeToNBT(aNBT); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (GregTech_API.mAE2) { + getProxy().readFromNBT(aNBT); + } + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public String[] getInfoData() { + return new String[]{ + "The bus is " + ((getProxy() != null && getProxy().isActive()) ? + EnumChatFormatting.GREEN + "online" : EnumChatFormatting.RED + "offline") + + EnumChatFormatting.RESET}; + } + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + } + + @Override + public void updateSlots() { + } + + @Override + public int getCircuitSlot() { return SLOT_COUNT * 2; } + + @Override + public ItemStack getStackInSlot(int aIndex) { + if (!processingRecipe) + return super.getStackInSlot(aIndex); + if (aIndex < 0 && aIndex > mInventory.length) + return null; + if (aIndex >= SLOT_COUNT && aIndex < SLOT_COUNT * 2) + //Display slots + return null; + if (aIndex == getCircuitSlot()) + return mInventory[aIndex]; + if (GregTech_API.mAE2 && mInventory[aIndex] != null) { + AENetworkProxy proxy = getProxy(); + if (proxy == null) { + return null; + } + try { + IMEMonitor<IAEItemStack> sg = proxy.getStorage().getItemInventory(); + IAEItemStack request = AEItemStack.create(mInventory[aIndex]); + request.setStackSize(Integer.MAX_VALUE); + IAEItemStack result = sg.extractItems(request, Actionable.SIMULATE, getRequestSource()); + if (result != null) { + this.shadowInventory[aIndex] = result.getItemStack(); + this.savedStackSizes[aIndex] = this.shadowInventory[aIndex].stackSize; + //Show that the request was successful + this.setInventorySlotContents(aIndex + SLOT_COUNT, GT_Utility.copyAmount( + this.shadowInventory[aIndex].stackSize > 64 ? 64 : this.shadowInventory[aIndex].stackSize, + new Object[] {result.getItemStack()})); + return this.shadowInventory[aIndex]; + } else { + //Request failed + this.setInventorySlotContents(aIndex + SLOT_COUNT, null); + return null; + } + } + catch( final GridAccessException ignored ) + { + } + return null; + } else { + //AE available but no items requested + this.setInventorySlotContents(aIndex + SLOT_COUNT, null); + } + return mInventory[aIndex]; + } + + @Optional.Method(modid = "appliedenergistics2") + private BaseActionSource getRequestSource() { + if (requestSource == null) + requestSource = new MachineSource((IActionHost)getBaseMetaTileEntity()); + return requestSource; + } + + @Override + public void onExplosion() { + for (int i = 0; i < SLOT_COUNT; i++) { + mInventory[i] = null; + } + } + + public void startRecipeProcessing() { + processingRecipe = true; + } + + public void endRecipeProcessing() { + if (GregTech_API.mAE2) { + for (int i = 0; i < SLOT_COUNT; ++i) { + if (savedStackSizes[i] != 0) { + if (shadowInventory[i] == null || shadowInventory[i].stackSize < savedStackSizes[i]) { + AENetworkProxy proxy = getProxy(); + try { + IMEMonitor<IAEItemStack> sg = proxy.getStorage().getItemInventory(); + IAEItemStack request = AEItemStack.create(mInventory[i]); + request.setStackSize(savedStackSizes[i] - shadowInventory[i].stackSize); + sg.extractItems(request, Actionable.MODULATE, getRequestSource()); + } + catch (final GridAccessException ignored) { + } + } + savedStackSizes[i] = 0; + shadowInventory[i] = null; + } + } + } + processingRecipe = false; + } + + @Override + public boolean isValidSlot(int aIndex) { + return false; + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java index d149f19565..f9b902e27a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java @@ -38,6 +38,7 @@ import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_HATCH; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_HATCH_ACTIVE; public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatch_OutputBus { private BaseActionSource requestSource = null; @@ -67,7 +68,7 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_ME_HATCH)}; + return new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_ME_HATCH_ACTIVE)}; } @Override @@ -146,6 +147,10 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc @Override @Optional.Method(modid = "appliedenergistics2") public void gridChanged() { + if (getBaseMetaTileEntity() != null && getBaseMetaTileEntity().getTimer() > 1) { + gridProxy = null; + getProxy(); + } } @Optional.Method(modid = "appliedenergistics2") diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java index 34a9b81012..30f8ff8746 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java @@ -358,7 +358,7 @@ public abstract class GT_MetaTileEntity_FusionComputer extends GT_MetaTileEntity mEfficiency = 0; if (mRunningOnLoad && checkMachine(aBaseMetaTileEntity, mInventory[1])) { this.mEUStore = aBaseMetaTileEntity.getStoredEU(); - checkRecipe(mInventory[1]); + checkRecipe(); } if (mUpdated) { mUpdate = 50; @@ -403,14 +403,14 @@ public abstract class GT_MetaTileEntity_FusionComputer extends GT_MetaTileEntity } this.mEUStore = aBaseMetaTileEntity.getStoredEU(); if (aBaseMetaTileEntity.isAllowedToWork()) - checkRecipe(mInventory[1]); + checkRecipe(); } } else { if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified()) { turnCasingActive(mMaxProgresstime > 0); if (aBaseMetaTileEntity.isAllowedToWork()) { this.mEUStore = aBaseMetaTileEntity.getStoredEU(); - if (checkRecipe(mInventory[1])) { + if (checkRecipe()) { if (this.mEUStore < this.mLastRecipe.mSpecialValue - this.mEUt) { criticalStopMachine(); } |