diff options
author | Jason Mitchell <mitchej@gmail.com> | 2023-01-20 00:30:50 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 09:30:50 +0100 |
commit | 7ed516e30ba224b4b8e3fad9c836c22ca00bfcdb (patch) | |
tree | bea33f6637b929427e9abbe733e19606f8bf9032 /src/main/java/gregtech/api/multitileentity/machine | |
parent | 750a4070af4756e3708e2b2555b9874864bf3cfb (diff) | |
download | GT5-Unofficial-7ed516e30ba224b4b8e3fad9c836c22ca00bfcdb.tar.gz GT5-Unofficial-7ed516e30ba224b4b8e3fad9c836c22ca00bfcdb.tar.bz2 GT5-Unofficial-7ed516e30ba224b4b8e3fad9c836c22ca00bfcdb.zip |
MTE Inventory updates (#1496)
* MTE Inventory updates
* Separate Input/Output inventory
* Use a LinkedHashMap to ensure inventory orders are deterministic
* Input/Output work on either Input/Output inventories
* MTE Inventory
* Add GT_Packet_MultiTileEntity
* More dyanmic packet with packetFeatures
* Add IMTE_HasModes for MultiBlockPart
* Help with MTE Inventory (#1613)
* convert inventory to use ItemStackHandler
* Update MUI
* inventories
* move Iteminventory to its own method
Co-authored-by: miozune <miozune@gmail.com>
* Update MUI
* Update MUI
* Add IMultiBlockPart
* Mte fluid inventory (#1639)
* first work on fluid inventory
* make gui work with numbers not dividable by 4
* use math.min
* add outputfluids saving
* actually working
* Update MUI
Co-authored-by: miozune <miozune@gmail.com>
* Ticking Covers!
* Parts now register covers with the controller
* Controllers now tick covers on parts
* Break cover ticking out into `tickCoverAtSide`
Fix some inventory methods on MultiBlockController
* Filter on tickable covers
* Improve GUIs for MTEs (#1650)
* working controller GUI
* locked inventory selection work
* input and output locking of inventories
Co-authored-by: miozune <miozune@gmail.com>
* spotless
* CoverInfo refactor (#1654)
* Add `CoverInfo` and deprecate the old fields to hold cover information
* Disable MTE registration
* Fix NPE - Return EMPTY_INFO for SIDE_UNKNOWN
Temporarily add back old NBT saving in case of a revert so covers aren't lost.
* Actually save the old NBT data, instead of empty
Co-authored-by: BlueWeabo <76872108+BlueWeabo@users.noreply.github.com>
Co-authored-by: miozune <miozune@gmail.com>
Diffstat (limited to 'src/main/java/gregtech/api/multitileentity/machine')
-rw-r--r-- | src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java | 112 |
1 files changed, 72 insertions, 40 deletions
diff --git a/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java b/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java index 767026b286..17bf44c386 100644 --- a/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java +++ b/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java @@ -3,6 +3,8 @@ package gregtech.api.multitileentity.machine; import static com.google.common.primitives.Ints.saturatedCast; import static gregtech.api.enums.GT_Values.emptyIconContainerArray; +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import gregtech.api.enums.GT_Values; import gregtech.api.enums.GT_Values.NBT; import gregtech.api.enums.Textures; @@ -32,10 +34,11 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { protected boolean mActive = false; protected long mStoredEnergy = 0; protected FluidTankGT[] mTanksInput = GT_Values.emptyFluidTankGT, mTanksOutput = GT_Values.emptyFluidTankGT; - protected ItemStack[] mOutputItems = GT_Values.emptyItemStackArray; protected FluidStack[] mOutputFluids = GT_Values.emptyFluidStack; - protected ItemStack[] mInventory = GT_Values.emptyItemStackArray; + protected final IItemHandlerModifiable mInputInventory = new ItemStackHandler(17); + protected final IItemHandlerModifiable mOutputInventory = new ItemStackHandler(15); + protected boolean mOutputInventoryChanged = false; @Override public String getTileEntityName() { @@ -47,6 +50,43 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { super.writeMultiTileNBT(aNBT); if (mParallel > 0) aNBT.setInteger(NBT.PARALLEL, mParallel); if (mActive) aNBT.setBoolean(NBT.ACTIVE, mActive); + if (mInputInventory != null && mInputInventory.getSlots() > 0) + writeInventory(aNBT, mInputInventory, NBT.INV_INPUT_LIST); + if (mOutputInventory != null && mOutputInventory.getSlots() > 0) + writeInventory(aNBT, mOutputInventory, NBT.INV_OUTPUT_LIST); + for (int i = 0; i < mTanksInput.length; i++) mTanksInput[i].writeToNBT(aNBT, NBT.TANK_IN + i); + for (int i = 0; i < mTanksOutput.length; i++) mTanksOutput[i].writeToNBT(aNBT, NBT.TANK_OUT + i); + if (mOutputFluids != null && mOutputFluids.length > 0) writeFluids(aNBT, mOutputFluids, NBT.FLUID_OUT); + } + + protected void writeFluids(NBTTagCompound aNBT, FluidStack[] fluids, String fluidListTag) { + if (fluids != null && fluids.length > 0) { + final NBTTagList tList = new NBTTagList(); + for (final FluidStack tFluid : fluids) { + if (tFluid != null) { + final NBTTagCompound tag = new NBTTagCompound(); + tFluid.writeToNBT(tag); + tList.appendTag(tag); + } + } + aNBT.setTag(fluidListTag, tList); + } + } + + protected void writeInventory(NBTTagCompound aNBT, IItemHandlerModifiable inv, String invListTag) { + if (inv != null && inv.getSlots() > 0) { + final NBTTagList tList = new NBTTagList(); + for (int tSlot = 0; tSlot < inv.getSlots(); tSlot++) { + final ItemStack tStack = inv.getStackInSlot(tSlot); + if (tStack != null) { + final NBTTagCompound tag = new NBTTagCompound(); + tag.setByte("s", (byte) tSlot); + tStack.writeToNBT(tag); + tList.appendTag(tag); + } + } + aNBT.setTag(invListTag, tList); + } } @Override @@ -55,15 +95,10 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { if (aNBT.hasKey(NBT.PARALLEL)) mParallel = Math.max(1, aNBT.getInteger(NBT.PARALLEL)); if (aNBT.hasKey(NBT.ACTIVE)) mActive = aNBT.getBoolean(NBT.ACTIVE); - mInventory = getDefaultInventory(aNBT); - if (mInventory != null) { - final NBTTagList tList = aNBT.getTagList(NBT.INV_LIST, 10); - for (int i = 0; i < tList.tagCount(); i++) { - final NBTTagCompound tNBT = tList.getCompoundTagAt(i); - final int tSlot = tNBT.getShort("s"); - if (tSlot >= 0 && tSlot < mInventory.length) mInventory[tSlot] = GT_Utility.loadItem(tNBT); - } - } + /* Inventories */ + loadInventory(aNBT, NBT.INV_INPUT_SIZE, NBT.INV_INPUT_LIST); + loadInventory(aNBT, NBT.INV_OUTPUT_SIZE, NBT.INV_OUTPUT_LIST); + /* Tanks */ long tCapacity = 1000; if (aNBT.hasKey(NBT.TANK_CAPACITY)) tCapacity = saturatedCast(aNBT.getLong(NBT.TANK_CAPACITY)); @@ -71,7 +106,6 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { mTanksInput = new FluidTankGT[getFluidInputCount()]; mTanksOutput = new FluidTankGT[getFluidOutputCount()]; mOutputFluids = new FluidStack[getFluidOutputCount()]; - mOutputItems = new ItemStack[getItemOutputCount()]; // TODO: See if we need the adjustable map here `.setCapacity(mRecipes, mParallel * 2L)` in place of the // `setCapacityMultiplier` @@ -83,8 +117,18 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { mTanksOutput[i] = new FluidTankGT().readFromNBT(aNBT, NBT.TANK_OUT + i); for (int i = 0; i < mOutputFluids.length; i++) mOutputFluids[i] = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag(NBT.FLUID_OUT + "." + i)); - for (int i = 0; i < mOutputItems.length; i++) - mOutputItems[i] = ItemStack.loadItemStackFromNBT(aNBT.getCompoundTag(NBT.INV_OUT + "." + i)); + } + + protected void loadInventory(NBTTagCompound aNBT, String sizeTag, String invListTag) { + final IItemHandlerModifiable inv = mInputInventory; + if (inv != null) { + final NBTTagList tList = aNBT.getTagList(invListTag, 10); + for (int i = 0; i < tList.tagCount(); i++) { + final NBTTagCompound tNBT = tList.getCompoundTagAt(i); + final int tSlot = tNBT.getShort("s"); + if (tSlot >= 0 && tSlot < inv.getSlots()) inv.setStackInSlot(tSlot, GT_Utility.loadItem(tNBT)); + } + } } @Override @@ -148,19 +192,14 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { * The number of fluid (input) slots available for this machine */ public int getFluidInputCount() { - return 2; + return 7; } /** * The number of fluid (output) slots available for this machine */ public int getFluidOutputCount() { - return 2; - } - - public ItemStack[] getDefaultInventory(NBTTagCompound aNBT) { - final int tSize = Math.max(0, aNBT.getShort(NBT.INV_SIZE)); - return tSize > 0 ? new ItemStack[tSize] : GT_Values.emptyItemStackArray; + return 3; } @Override @@ -292,8 +331,7 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { if (aSide == GT_Values.SIDE_UNKNOWN) return true; if (aSide >= 0 && aSide < 6) { if (isInvalid()) return false; - if (!getCoverBehaviorAtSideNew(aSide) - .letsEnergyIn(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) return false; + if (!getCoverInfoAtSide(aSide).letsEnergyIn()) return false; if (isEnetInput()) return isEnergyInputSide(aSide); } return false; @@ -304,9 +342,7 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { if (aSide == GT_Values.SIDE_UNKNOWN) return true; if (aSide >= 0 && aSide < 6) { if (isInvalid()) return false; - if (!getCoverBehaviorAtSideNew(aSide) - .letsEnergyOut(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) - return false; + if (!getCoverInfoAtSide(aSide).letsEnergyOut()) return false; if (isEnetOutput()) return isEnergyOutputSide(aSide); } return false; @@ -318,9 +354,19 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { @Override public boolean hasInventoryBeenModified() { + // True if the input inventory has changed return mInventoryChanged; } + public void markOutputInventoryBeenModified() { + mOutputInventoryChanged = true; + } + + public boolean hasOutputInventoryBeenModified() { + // True if the output inventory has changed + return mOutputInventoryChanged; + } + @Override public boolean isItemValidForSlot(int aSlot, ItemStack aStack) { return false; @@ -330,18 +376,4 @@ public class MultiTileBasicMachine extends BaseTickableMultiTileEntity { public int getInventoryStackLimit() { return 64; } - - /** - * The number of item (input) slots available for this machine - */ - public int getItemInputCount() { - return 2; - } - - /** - * The number of item (output) slots available for this machine - */ - public int getItemOutputCount() { - return 2; - } } |