From a6046ddfad81dca9b1c63d5f171b9ccd137f7288 Mon Sep 17 00:00:00 2001 From: Johannes Gäßler Date: Sun, 2 Jul 2017 00:09:48 +0200 Subject: Fixed inventory misalignment when updating 5.09.30 -> 5.09.31 I added a new method to BaseMetaTileEntity that shifts the Inventory index according to the change in Input/Output slots. Instrumentally I have added a new version ID that considers the GT subversion. --- .../api/metatileentity/BaseMetaTileEntity.java | 54 +++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java') diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 6a64c802bd..09cf8e2f2b 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -119,6 +119,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aNBT.setBoolean("mInputDisabled", mInputDisabled); aNBT.setBoolean("mOutputDisabled", mOutputDisabled); aNBT.setTag("GT.CraftingComponents", mRecipeStuff); + aNBT.setInteger("nbtVersion", GT_Mod.TOTAL_VERSION); } catch (Throwable e) { GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); @@ -187,7 +188,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mCoverData = aNBT.getIntArray("mCoverData"); mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); mRecipeStuff = aNBT.getCompoundTag("GT.CraftingComponents"); - + int nbtVersion = aNBT.getInteger("nbtVersion"); + if (mCoverData.length != 6) mCoverData = new int[]{0, 0, 0, 0, 0, 0}; if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; if (mSidedRedstone.length != 6) @@ -202,6 +204,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE for (int i = 0; i < tItemList.tagCount(); i++) { NBTTagCompound tTag = tItemList.getCompoundTagAt(i); int tSlot = tTag.getInteger("IntSlot"); + tSlot = shiftInventoryIndex(tSlot, nbtVersion); if (tSlot >= 0 && tSlot < mMetaTileEntity.getRealInventory().length) { mMetaTileEntity.getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); } @@ -1904,4 +1907,53 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public void onEntityCollidedWithBlock(World aWorld, int aX, int aY, int aZ, Entity collider) { mMetaTileEntity.onEntityCollidedWithBlock(aWorld, aX, aY, aZ, collider); } + + /** + * Shifts the machine Inventory index according to the change in Input/Output Slots. + * This is NOT done automatically. If you want to change slot count for a machine this method needs to be adapted. + * @param slotIndex The original Inventory index + * @param nbtVersion The GregTech version in which the original Inventory Index was saved. + * @return The corrected Inventory index + */ + private int shiftInventoryIndex(int slotIndex, int nbtVersion){ + int oldInputSize, newInputSize, oldOutputSize, newOutputSize; + if (mID >= 211 && mID <= 218) {//Assembler + if (nbtVersion < 509031) { + oldInputSize = 2; + oldOutputSize = 1; + } else { + return slotIndex; + } + newInputSize = 6; + newOutputSize = 1; + } else if (mID >= 421 && mID <= 428){//Chemical Reactor + if (nbtVersion < 509031) { + oldInputSize = 2; + oldOutputSize = 1; + } else { + return slotIndex; + } + newInputSize = 2; + newOutputSize = 2; + } else if (mID >= 531 && mID <= 538) {//Distillery + if (nbtVersion < 509031) { + oldInputSize = 1; + oldOutputSize = 0; + } else { + return slotIndex; + } + newInputSize = 1; + newOutputSize = 1; + } else { + return slotIndex; + } + int indexShift = 0; + if (slotIndex >= oldInputSize) { + indexShift += newInputSize - oldInputSize; + } + if (slotIndex >= oldInputSize + oldOutputSize) { + indexShift += newOutputSize - oldOutputSize; + } + return slotIndex + indexShift; + } } -- cgit