diff options
4 files changed, 163 insertions, 12 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_Slot_Holo_ME.java b/src/main/java/gregtech/api/gui/GT_Slot_Holo_ME.java new file mode 100644 index 0000000000..08a11d29f4 --- /dev/null +++ b/src/main/java/gregtech/api/gui/GT_Slot_Holo_ME.java @@ -0,0 +1,9 @@ +package gregtech.api.gui; + +import net.minecraft.inventory.IInventory; + +public class GT_Slot_Holo_ME extends GT_Slot_Holo { + public GT_Slot_Holo_ME(IInventory inventory, int slotIndex, int xPos, int yPos, boolean aCanInsertItem, boolean aCanStackItem) { + super(inventory, slotIndex, xPos, yPos, aCanInsertItem, aCanStackItem, Integer.MAX_VALUE); + } +} 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 index ae018657c4..c164d06695 100644 --- a/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java +++ b/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java @@ -10,9 +10,11 @@ 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_Holo_ME; import gregtech.api.gui.GT_Slot_Render; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_InputBus_ME; public class GT_Container_InputBus_ME extends GT_ContainerMetaTile_Machine { private static final int LEFT_OFFSET = 8; @@ -26,12 +28,26 @@ public class GT_Container_InputBus_ME extends GT_ContainerMetaTile_Machine { } @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)); + for (int y = 0; y < 4; ++y) + for (int x = 0; x < 4; ++x) + addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, x + y * 4, + LEFT_OFFSET + x * SLOT_SIZE, TOP_OFFSET + y * SLOT_SIZE, false, true, 1)); + for (int y = 0; y < 4; ++y) + for (int x = 0; x < 4; ++x) { + GT_Slot_Holo_ME slot = new GT_Slot_Holo_ME(this.mTileEntity, x + y * 4 + 16, + LEFT_OFFSET + x * SLOT_SIZE + 90, TOP_OFFSET + y * SLOT_SIZE, false, true); + addSlotToContainer(slot); + } + addSlotToContainer(slotCircuit = new GT_Slot_Render(mTileEntity, CIRCUIT_SLOT, 80, 63)); + } + + private boolean containsSuchStack(ItemStack tStack) { + for (int i = 0; i < 16; ++i) { + Slot tSlot = (Slot) this.inventorySlots.get(i); + if (tSlot != null && GT_Utility.areStacksEqual(tSlot.getStack(), tStack, false)) + return true; + } + return false; } @Override @@ -46,8 +62,15 @@ public class GT_Container_InputBus_ME extends GT_ContainerMetaTile_Machine { tSlot.putStack(null); } else { + if (containsSuchStack(tStack)) + return null; tSlot.putStack(GT_Utility.copyAmount(1L, new Object[] {tStack})); } + if (mTileEntity.isServerSide()) { + ItemStack newInfo = ((GT_MetaTileEntity_Hatch_InputBus_ME) mTileEntity.getMetaTileEntity()).updateInformationSlot(aSlotIndex, tStack); + ((Slot) this.inventorySlots.get(aSlotIndex + 16)).putStack(newInfo); + detectAndSendChanges(); + } return null; } } 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 index 5aefb98e55..08801d1473 100644 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java +++ b/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java @@ -2,20 +2,34 @@ package gregtech.common.gui; import java.util.List; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; +import appeng.client.render.AppEngRenderItem; +import appeng.core.AELog; +import appeng.integration.IntegrationRegistry; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.INEI; +import appeng.util.Platform; +import cpw.mods.fml.common.Optional; 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.gui.GT_Slot_Holo; +import gregtech.api.gui.GT_Slot_Holo_ME; 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 { + private final AppEngRenderItem aeRenderItem = new AppEngRenderItem(); + 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); @@ -50,4 +64,62 @@ public class GT_GUIContainer_InputBus_ME extends GT_GUIContainerMetaTile_Machin GT_Utility.findMatchingStackInList(circuits, mContainer.mTileEntity.getStackInSlot(GT_Container_InputBus_ME.CIRCUIT_SLOT)))); } + + // base method is made public by AE2 ASM + public void func_146977_a( final Slot s ) + { + this.drawSlot( s ); + } + + + @Optional.Method(modid = "appliedenergistics2") + private RenderItem setItemRender( final RenderItem item ) + { + if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.NEI ) ) + { + return ( (INEI) IntegrationRegistry.INSTANCE.getInstance( IntegrationType.NEI ) ).setItemRender( item ); + } + else + { + final RenderItem ri = itemRender; + itemRender = item; + return ri; + } + } + + @Optional.Method(modid = "appliedenergistics2") + private void drawSlot( final Slot s ) + { + if (s instanceof GT_Slot_Holo_ME) { + final RenderItem pIR = this.setItemRender( this.aeRenderItem ); + try + { + this.zLevel = 0.0F; + itemRender.zLevel = 0.0F; + + this.aeRenderItem.setAeStack( Platform.getAEStackInSlot( s ) ); + + this.safeDrawSlot( s ); + } + catch( final Exception err ) + { + AELog.warn( "[AppEng] AE prevented crash while drawing slot: " + err.toString() ); + } + this.setItemRender( pIR ); + return; + } + safeDrawSlot(s); + } + + @Optional.Method(modid = "appliedenergistics2") + private void safeDrawSlot( final Slot s ) + { + try + { + GuiContainer.class.getDeclaredMethod( "func_146977_a_original", Slot.class ).invoke( this, s ); + } + catch( final Exception err ) + { + } + } } 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 index bb3655ddfe..62c01b7b73 100644 --- 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 @@ -4,10 +4,12 @@ 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.nbt.NBTTagIntArray; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; import appeng.api.networking.GridFlags; import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.IActionHost; @@ -121,6 +123,10 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); + int[] sizes = new int[16]; + for (int i = 0; i < 16; ++i) + sizes[i] = mInventory[i + 16] == null ? 0 : mInventory[i + 16].stackSize; + aNBT.setIntArray("sizes", sizes); if (GregTech_API.mAE2) { gridProxy.writeToNBT(aNBT); } @@ -129,6 +135,18 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); + if (aNBT.hasKey("sizes")) { + int[] sizes = aNBT.getIntArray("sizes"); + if (sizes.length == 16) { + for (int i = 0; i < 16; ++i) { + if (sizes[i] != 0 && mInventory[i] != null) { + ItemStack s = mInventory[i].copy(); + s.stackSize = sizes[i]; + mInventory[i + 16] = s; + } + } + } + } if (GregTech_API.mAE2) { getProxy().readFromNBT(aNBT); } @@ -191,10 +209,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch 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()})); + this.setInventorySlotContents(aIndex + SLOT_COUNT, this.shadowInventory[aIndex]); return this.shadowInventory[aIndex]; } else { //Request failed @@ -235,13 +250,16 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch 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]) { + ItemStack oldStack = shadowInventory[i]; + if (oldStack == null || oldStack.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); + request.setStackSize(savedStackSizes[i] - (oldStack == null ? 0 : oldStack.stackSize)); sg.extractItems(request, Actionable.MODULATE, getRequestSource()); + proxy.getEnergy().extractAEPower(request.getStackSize(), Actionable.MODULATE, PowerMultiplier.CONFIG); + setInventorySlotContents(i + SLOT_COUNT, oldStack); } catch (final GridAccessException ignored) { } @@ -254,6 +272,35 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch processingRecipe = false; } + public ItemStack updateInformationSlot(int aIndex, ItemStack aStack) { + if (GregTech_API.mAE2 && aIndex >= 0 && aIndex < SLOT_COUNT) { + if (aStack == null) { + super.setInventorySlotContents(aIndex + SLOT_COUNT, null); + return null; + } + else { + AENetworkProxy proxy = getProxy(); + if (!proxy.isActive()) { + super.setInventorySlotContents(aIndex + SLOT_COUNT, 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()); + ItemStack s = (result != null) ? result.getItemStack() : null; + setInventorySlotContents(aIndex + SLOT_COUNT, s); + return s; + } + catch (final GridAccessException ignored) { + } + return null; + } + } + return null; + } + @Override public boolean isValidSlot(int aIndex) { return false; |