diff --git a/dependencies.gradle b/dependencies.gradle index fa86c7bb..c3044b25 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -3,7 +3,7 @@ dependencies { implementation("com.github.GTNewHorizons:NotEnoughItems:2.7.15-GTNH:dev") implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.1:dev") - implementation("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-518-GTNH:dev") + implementation("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-523-GTNH:dev") implementation("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") implementation("curse.maven:thaumcraft-nei-plugin-225095:2241913") { transitive = false } diff --git a/src/main/java/thaumicenergistics/client/gui/GuiEssentiaCellWorkbench.java b/src/main/java/thaumicenergistics/client/gui/GuiEssentiaCellWorkbench.java index 987e14e1..e4a895e7 100644 --- a/src/main/java/thaumicenergistics/client/gui/GuiEssentiaCellWorkbench.java +++ b/src/main/java/thaumicenergistics/client/gui/GuiEssentiaCellWorkbench.java @@ -5,10 +5,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; +import appeng.parts.automation.UpgradeInventory; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import thaumcraft.api.aspects.Aspect; @@ -49,7 +52,7 @@ public void mouseClicked(final Aspect withAspect) { /** * Gui size. */ - private static final int GUI_WIDTH = 176, GUI_HEIGHT = 251; + private static final int GUI_WIDTH = 212, GUI_HEIGHT = 251; /** * Title position. @@ -145,7 +148,13 @@ protected void drawGuiContainerBackgroundLayer(final float alpha, final int mous Minecraft.getMinecraft().renderEngine.bindTexture(GuiTextureManager.CELL_WORKBENCH.getTexture()); // Draw the gui texture - this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, this.ySize); + if (this.workbench.hasEssentiaCell()) { + this.drawTexturedModalRect(this.guiLeft + 177, this.guiTop, 177, 0, 35, 7 + 5 * 18); + this.drawTexturedModalRect(this.guiLeft + 177, this.guiTop + (7 + 5 * 18), 177, 151, 35, 7); + this.showUpgradeSlots(); + super.drawAEToolAndUpgradeSlots(alpha, mouseX, mouseY); + } // Bind the AE states texture Minecraft.getMinecraft().renderEngine.bindTexture(AEStateIconsEnum.AE_STATES_TEXTURE); @@ -301,4 +310,31 @@ public void updateAspects(final List aspectList) { this.partitionWidgets[index].setAspect(null); } } + + public void hideUpgradeSlots() { + for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) { + Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i); + if (slot.inventory instanceof UpgradeInventory) { + slot.xDisplayPosition = 1000; + } + } + } + + public void showUpgradeSlots() { + for (int i = 0; i < this.inventorySlots.inventorySlots.size(); i++) { + Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i); + if (slot.inventory instanceof UpgradeInventory) { + slot.xDisplayPosition = 187; + } + } + } + + public void updateSlots(final ItemStack stack, int slot) { + if (stack == null) { + hideUpgradeSlots(); + } else { + showUpgradeSlots(); + } + ((Slot) this.inventorySlots.inventorySlots.get(slot)).putStack(stack); + } } diff --git a/src/main/java/thaumicenergistics/common/container/ContainerEssentiaCellWorkbench.java b/src/main/java/thaumicenergistics/common/container/ContainerEssentiaCellWorkbench.java index e916d835..e6378ae6 100644 --- a/src/main/java/thaumicenergistics/common/container/ContainerEssentiaCellWorkbench.java +++ b/src/main/java/thaumicenergistics/common/container/ContainerEssentiaCellWorkbench.java @@ -1,6 +1,7 @@ package thaumicenergistics.common.container; import java.util.ArrayList; +import java.util.List; import javax.annotation.Nonnull; @@ -9,6 +10,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import appeng.items.contents.CellUpgrades; +import appeng.parts.automation.UpgradeInventory; import thaumcraft.api.aspects.Aspect; import thaumicenergistics.common.container.slot.SlotRestrictive; import thaumicenergistics.common.integration.tc.EssentiaItemContainerHelper; @@ -22,7 +25,7 @@ * @author Nividica * */ -public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory { +public class ContainerEssentiaCellWorkbench extends ContainerWithNetworkTool { /** * Y position for the player inventory @@ -48,6 +51,7 @@ public class ContainerEssentiaCellWorkbench extends ContainerWithPlayerInventory * The cell slot. */ private final Slot cellSlot; + private final List upgradeSlots = new ArrayList<>(); public ContainerEssentiaCellWorkbench(final EntityPlayer player, final World world, final int x, final int y, final int z) { @@ -64,13 +68,20 @@ public ContainerEssentiaCellWorkbench(final EntityPlayer player, final World wor ContainerEssentiaCellWorkbench.CELL_SLOT_X, ContainerEssentiaCellWorkbench.CELL_SLOT_Y); this.addSlotToContainer(this.cellSlot); - // Bind to the player's inventory this.bindPlayerInventory( this.player.inventory, ContainerEssentiaCellWorkbench.PLAYER_INV_POSITION_Y, ContainerEssentiaCellWorkbench.HOTBAR_INV_POSITION_Y); + addUpgradeSlots(new CellUpgrades(this.workbench.fakeECell, 5), 5, 1000, 8); + for (Object inventorySlot : this.inventorySlots) { + Slot slot = (Slot) inventorySlot; + if (slot.inventory instanceof UpgradeInventory) { + upgradeSlots.add(slot); + } + } + // Register with the workbench if (EffectiveSide.isServerSide()) { this.workbench.registerListener(this); @@ -86,6 +97,18 @@ public boolean canInteractWith(final EntityPlayer player) { return false; } + public void wipeSlots() { + for (Slot slot : upgradeSlots) { + slot.putStack(null); + Packet_C_AspectSlot.setUpgradeSlots(slot, this.player); + } + } + + public void updateUpgradeSlots(ItemStack stack, int index) { + upgradeSlots.get(index).putStack(stack); + Packet_C_AspectSlot.setUpgradeSlots(upgradeSlots.get(index), this.player); + } + /** * Called when a client has requested the full list. */ diff --git a/src/main/java/thaumicenergistics/common/integration/IntegrationCore.java b/src/main/java/thaumicenergistics/common/integration/IntegrationCore.java index 43dcd691..c572c94e 100644 --- a/src/main/java/thaumicenergistics/common/integration/IntegrationCore.java +++ b/src/main/java/thaumicenergistics/common/integration/IntegrationCore.java @@ -58,6 +58,23 @@ public static void init() { Upgrades.SPEED.registerItem( ThEApi.instance().blocks().ArcaneAssembler.getStack(), BlockArcaneAssembler.MAX_SPEED_UPGRADES); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_1k.getStack(), 1); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_4k.getStack(), 1); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_16k.getStack(), 1); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_64k.getStack(), 1); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_256k.getStack(), 1); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_1024k.getStack(), 1); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_4096k.getStack(), 1); + Upgrades.VOID_OVERFLOW.registerItem(ThEApi.instance().items().EssentiaCell_16384k.getStack(), 1); + + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_1k.getStack(), 1); + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_4k.getStack(), 1); + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_16k.getStack(), 1); + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_64k.getStack(), 1); + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_256k.getStack(), 1); + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_1024k.getStack(), 1); + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_4096k.getStack(), 1); + Upgrades.DISTRIBUTION.registerItem(ThEApi.instance().items().EssentiaCell_16384k.getStack(), 1); ThELog.endSection("Integration", startTime); } diff --git a/src/main/java/thaumicenergistics/common/inventory/HandlerItemEssentiaCell.java b/src/main/java/thaumicenergistics/common/inventory/HandlerItemEssentiaCell.java index 4d9c14f2..029144bb 100644 --- a/src/main/java/thaumicenergistics/common/inventory/HandlerItemEssentiaCell.java +++ b/src/main/java/thaumicenergistics/common/inventory/HandlerItemEssentiaCell.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -9,7 +10,9 @@ import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; +import appeng.api.config.Upgrades; import appeng.api.config.ViewItems; +import appeng.api.implementations.items.IUpgradeModule; import appeng.api.networking.security.BaseActionSource; import appeng.api.storage.ICellCacheRegistry; import appeng.api.storage.IMEInventoryHandler; @@ -107,6 +110,9 @@ public class HandlerItemEssentiaCell implements IMEInventoryHandler partitionAspects = new ArrayList(); + private boolean hasVoidOverflow = false; + private boolean hasDistribution = false; + public HandlerItemEssentiaCell(final ItemStack storageStack, final ISaveProvider saveProvider) { // Ensure we have a NBT tag if (!storageStack.hasTagCompound()) { @@ -143,18 +149,40 @@ public HandlerItemEssentiaCell(final ItemStack storageStack, final ISaveProvider * @return Amount not stored */ private long addEssentiaToCell(final Aspect aspect, final long amount, final Actionable mode) { - // Calculate amount to store - long amountToStore = Math.min(amount, this.totalEssentiaStorage - this.usedEssentiaStorage); + long amountToStore; + // Get the slot for this aspect + int slotIndex = this.getSlotFor(aspect); + // Get the slot + IAspectStack stackToAddTo = this.storedEssentia[slotIndex]; + if (hasDistribution) { + int types; + if (this.isPartitioned()) { + types = this.partitionAspects.size(); + } else { + types = this.storedEssentia.length; + } + if (stackToAddTo == null) { + amountToStore = Math.min(amount, this.totalEssentiaStorage / types); + } else { + amountToStore = Math.min( + amount, + (this.totalEssentiaStorage / types) - this.storedEssentia[slotIndex].getStackSize()); + } + } else { + amountToStore = Math.min(amount, this.totalEssentiaStorage - this.usedEssentiaStorage); + } // Ensure we can store any if (amountToStore == 0) { + if (hasVoidOverflow) { + if (stackToAddTo != null) { + return 0; + } + } // Cell is full return amount; } - // Get the slot for this aspect - int slotIndex = this.getSlotFor(aspect); - // Ensure there is somewhere to put the essentia if (slotIndex == -1) { return amount; @@ -162,8 +190,6 @@ private long addEssentiaToCell(final Aspect aspect, final long amount, final Act // Are we modulating? if (mode == Actionable.MODULATE) { - // Get the slot - IAspectStack stackToAddTo = this.storedEssentia[slotIndex]; // Is the slot null? if (stackToAddTo == null) { @@ -329,6 +355,26 @@ private void readCellData() { } } } + + if (this.cellData.hasKey("upgrades")) { + NBTTagCompound upgrades = this.cellData.getCompoundTag("upgrades"); + for (int i = 0; i < 5; i++) { + NBTTagCompound upgrade = upgrades.getCompoundTag("#" + i); + if (!Objects.equals(upgrade.toString(), "{}")) { + ItemStack is = ItemStack.loadItemStackFromNBT(upgrade); + if (is != null && is.getItem() instanceof IUpgradeModule) { + final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is); + if (u != null) { + switch (u) { + case VOID_OVERFLOW -> hasVoidOverflow = true; + case DISTRIBUTION -> hasDistribution = true; + default -> {} + } + } + } + } + } + } } /** diff --git a/src/main/java/thaumicenergistics/common/network/packet/client/Packet_C_AspectSlot.java b/src/main/java/thaumicenergistics/common/network/packet/client/Packet_C_AspectSlot.java index 9a2027f0..0dbaf19e 100644 --- a/src/main/java/thaumicenergistics/common/network/packet/client/Packet_C_AspectSlot.java +++ b/src/main/java/thaumicenergistics/common/network/packet/client/Packet_C_AspectSlot.java @@ -6,12 +6,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import thaumcraft.api.aspects.Aspect; import thaumicenergistics.api.gui.IAspectSlotGui; +import thaumicenergistics.client.gui.GuiEssentiaCellWorkbench; import thaumicenergistics.common.network.NetworkHandler; import thaumicenergistics.common.network.ThEBasePacket; @@ -27,6 +30,12 @@ public class Packet_C_AspectSlot extends ThEClientPacket { private List filterAspects; + private static final byte MODE_SLOTS_UPDATE = 1; + + private ItemStack slotStack; + + private int slotIndex; + public static void setFilterList(final List filterAspects, final EntityPlayer player) { Packet_C_AspectSlot packet = new Packet_C_AspectSlot(); @@ -46,6 +55,23 @@ public static void setFilterList(final List filterAspects, final EntityP NetworkHandler.sendPacketToClient(packet); } + public static void setUpgradeSlots(final Slot slot, final EntityPlayer player) { + Packet_C_AspectSlot packet = new Packet_C_AspectSlot(); + + // Set the player + packet.player = player; + + // Set the mode + packet.mode = Packet_C_AspectSlot.MODE_SLOTS_UPDATE; + + packet.slotStack = slot.getStack(); + + packet.slotIndex = slot.slotNumber; + + // Send it + NetworkHandler.sendPacketToClient(packet); + } + @SideOnly(Side.CLIENT) @Override protected void wrappedExecute() { @@ -61,6 +87,9 @@ protected void wrappedExecute() { case Packet_C_AspectSlot.MODE_LIST_UPDATE: ((IAspectSlotGui) gui).updateAspects(this.filterAspects); break; + case Packet_C_AspectSlot.MODE_SLOTS_UPDATE: + ((GuiEssentiaCellWorkbench) gui).updateSlots(this.slotStack, this.slotIndex); + break; } } @@ -79,6 +108,10 @@ public void readData(final ByteBuf stream) { this.filterAspects.add(ThEBasePacket.readAspect(stream)); } break; + case Packet_C_AspectSlot.MODE_SLOTS_UPDATE: + this.slotIndex = stream.readInt(); + this.slotStack = ThEBasePacket.readItemstack(stream); + break; } } @@ -94,6 +127,13 @@ public void writeData(final ByteBuf stream) { ThEBasePacket.writeAspect(this.filterAspects.get(index), stream); } break; + case Packet_C_AspectSlot.MODE_SLOTS_UPDATE: + // Write the size of the list + stream.writeInt(this.slotIndex); + + // Write each aspect + ThEBasePacket.writeItemstack(this.slotStack, stream); + break; } } } diff --git a/src/main/java/thaumicenergistics/common/tiles/TileEssentiaCellWorkbench.java b/src/main/java/thaumicenergistics/common/tiles/TileEssentiaCellWorkbench.java index 0e6b789e..0996a894 100644 --- a/src/main/java/thaumicenergistics/common/tiles/TileEssentiaCellWorkbench.java +++ b/src/main/java/thaumicenergistics/common/tiles/TileEssentiaCellWorkbench.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -12,6 +13,7 @@ import appeng.api.storage.IMEInventory; import appeng.api.storage.ISaveProvider; import thaumcraft.api.aspects.Aspect; +import thaumicenergistics.api.ThEApi; import thaumicenergistics.common.ThaumicEnergistics; import thaumicenergistics.common.container.ContainerEssentiaCellWorkbench; import thaumicenergistics.common.inventory.HandlerItemEssentiaCell; @@ -37,6 +39,8 @@ public class TileEssentiaCellWorkbench extends TileEntity implements IInventory, */ private ItemStack eCell = null; + public ItemStack fakeECell = ThEApi.instance().items().EssentiaCell_64k.getStack(); + /** * Cell handler */ @@ -296,14 +300,29 @@ public void setInventorySlotContents(final int slotIndex, final ItemStack stack) if (this.isItemValidForSlot(slotIndex, stack)) { // Set the cell this.eCell = stack; - if (EffectiveSide.isServerSide()) { if (stack == null) { // Null the handler + this.fakeECell.setTagCompound(new NBTTagCompound()); this.eCellHandler = null; + for (ContainerEssentiaCellWorkbench container : this.listeners) { + container.wipeSlots(); + } } else { // Get the handler + this.fakeECell.setTagCompound(stack.getTagCompound()); this.eCellHandler = new HandlerItemEssentiaCell(stack, this); + if (stack.getTagCompound().hasKey("upgrades")) { + NBTTagCompound upgrades = stack.getTagCompound().getCompoundTag("upgrades"); + for (int i = 0; i < 5; i++) { + NBTTagCompound upgrade = upgrades.getCompoundTag("#" + i); + if (!Objects.equals(upgrade.toString(), "{}")) { + for (ContainerEssentiaCellWorkbench container : this.listeners) { + container.updateUpgradeSlots(ItemStack.loadItemStackFromNBT(upgrade), i); + } + } + } + } } // Update containers diff --git a/src/main/resources/assets/thaumicenergistics/textures/gui/essentia.cell.workbench.png b/src/main/resources/assets/thaumicenergistics/textures/gui/essentia.cell.workbench.png index f8b05eb8..99ac5184 100644 Binary files a/src/main/resources/assets/thaumicenergistics/textures/gui/essentia.cell.workbench.png and b/src/main/resources/assets/thaumicenergistics/textures/gui/essentia.cell.workbench.png differ