From a6046ddfad81dca9b1c63d5f171b9ccd137f7288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Sun, 2 Jul 2017 00:09:48 +0200 Subject: [PATCH 1/3] 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. --- src/main/java/gregtech/GT_Mod.java | 3 +- .../metatileentity/BaseMetaTileEntity.java | 54 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index debca654..84c9c5fa 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -60,7 +60,8 @@ import java.util.regex.Pattern; @Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false, dependencies = "required-after:IC2; after:Forestry; after:PFAAGeologica; after:Thaumcraft; after:Railcraft; after:appliedenergistics2; after:ThermalExpansion; after:TwilightForest; after:harvestcraft; after:magicalcrops; after:BuildCraft|Transport; after:BuildCraft|Silicon; after:BuildCraft|Factory; after:BuildCraft|Energy; after:BuildCraft|Core; after:BuildCraft|Builders; after:GalacticraftCore; after:GalacticraftMars; after:GalacticraftPlanets; after:ThermalExpansion|Transport; after:ThermalExpansion|Energy; after:ThermalExpansion|Factory; after:RedPowerCore; after:RedPowerBase; after:RedPowerMachine; after:RedPowerCompat; after:RedPowerWiring; after:RedPowerLogic; after:RedPowerLighting; after:RedPowerWorld; after:RedPowerControl; after:UndergroundBiomes;") public class GT_Mod implements IGT_Mod { - public static final int VERSION = 509; + public static final int VERSION = 509, SUBVERSION = 31; + public static final int TOTAL_VERSION = 1000 * VERSION + SUBVERSION; public static final int REQUIRED_IC2 = 624; @Mod.Instance("gregtech") public static GT_Mod instance; diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 6a64c802..09cf8e2f 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; + } } From 5d8bcb0af35e57da789fc6b2126cb6931c092c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Sun, 2 Jul 2017 01:02:55 +0200 Subject: [PATCH 2/3] Added a method for calculating total version ID --- src/main/java/gregtech/GT_Mod.java | 9 ++++++++- .../gregtech/api/metatileentity/BaseMetaTileEntity.java | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 84c9c5fa..a08cbb8e 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -61,7 +61,7 @@ import java.util.regex.Pattern; @Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false, dependencies = "required-after:IC2; after:Forestry; after:PFAAGeologica; after:Thaumcraft; after:Railcraft; after:appliedenergistics2; after:ThermalExpansion; after:TwilightForest; after:harvestcraft; after:magicalcrops; after:BuildCraft|Transport; after:BuildCraft|Silicon; after:BuildCraft|Factory; after:BuildCraft|Energy; after:BuildCraft|Core; after:BuildCraft|Builders; after:GalacticraftCore; after:GalacticraftMars; after:GalacticraftPlanets; after:ThermalExpansion|Transport; after:ThermalExpansion|Energy; after:ThermalExpansion|Factory; after:RedPowerCore; after:RedPowerBase; after:RedPowerMachine; after:RedPowerCompat; after:RedPowerWiring; after:RedPowerLogic; after:RedPowerLighting; after:RedPowerWorld; after:RedPowerControl; after:UndergroundBiomes;") public class GT_Mod implements IGT_Mod { public static final int VERSION = 509, SUBVERSION = 31; - public static final int TOTAL_VERSION = 1000 * VERSION + SUBVERSION; + public static final int TOTAL_VERSION = calculateTotalGTVersion(VERSION, SUBVERSION); public static final int REQUIRED_IC2 = 624; @Mod.Instance("gregtech") public static GT_Mod instance; @@ -1163,4 +1163,11 @@ public class GT_Mod implements IGT_Mod { } } + public static int calculateTotalGTVersion(int minorVersion){ + return calculateTotalGTVersion(VERSION, minorVersion); + } + + public static int calculateTotalGTVersion(int majorVersion, int minorVersion){ + return majorVersion * 1000 + minorVersion; + } } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 09cf8e2f..6792e501 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1917,8 +1917,9 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE */ private int shiftInventoryIndex(int slotIndex, int nbtVersion){ int oldInputSize, newInputSize, oldOutputSize, newOutputSize; + int chemistryUpdateVersion = GT_Mod.calculateTotalGTVersion(509, 31); if (mID >= 211 && mID <= 218) {//Assembler - if (nbtVersion < 509031) { + if (nbtVersion < chemistryUpdateVersion) { oldInputSize = 2; oldOutputSize = 1; } else { @@ -1927,7 +1928,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE newInputSize = 6; newOutputSize = 1; } else if (mID >= 421 && mID <= 428){//Chemical Reactor - if (nbtVersion < 509031) { + if (nbtVersion < chemistryUpdateVersion) { oldInputSize = 2; oldOutputSize = 1; } else { @@ -1936,7 +1937,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE newInputSize = 2; newOutputSize = 2; } else if (mID >= 531 && mID <= 538) {//Distillery - if (nbtVersion < 509031) { + if (nbtVersion < chemistryUpdateVersion) { oldInputSize = 1; oldOutputSize = 0; } else { From 7d074d985f1f24a12354ed1d605eba92620bbc03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Sun, 2 Jul 2017 17:12:30 +0200 Subject: [PATCH 3/3] Accounted for misc slots when shifting machine inventory contents --- .../java/gregtech/api/metatileentity/BaseMetaTileEntity.java | 5 +++-- .../implementations/GT_MetaTileEntity_BasicMachine.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 6792e501..177810f9 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1911,6 +1911,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE /** * 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. + * Currently this method only works for GT_MetaTileEntity_BasicMachine * @param slotIndex The original Inventory index * @param nbtVersion The GregTech version in which the original Inventory Index was saved. * @return The corrected Inventory index @@ -1949,10 +1950,10 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return slotIndex; } int indexShift = 0; - if (slotIndex >= oldInputSize) { + if (slotIndex >= GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT + oldInputSize) { indexShift += newInputSize - oldInputSize; } - if (slotIndex >= oldInputSize + oldOutputSize) { + if (slotIndex >= GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT + oldInputSize + oldOutputSize) { indexShift += newOutputSize - oldOutputSize; } return slotIndex + indexShift; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 9114780b..fe8c22c7 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -43,7 +43,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B DID_NOT_FIND_RECIPE = 0, FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS = 1, FOUND_AND_SUCCESSFULLY_USED_RECIPE = 2; - private static final int OTHER_SLOT_COUNT = 4; + public static final int OTHER_SLOT_COUNT = 4; public final ItemStack[] mOutputItems; public final int mInputSlotCount, mAmperage; public boolean mAllowInputFromOutputSide = false, mFluidTransfer = false, mItemTransfer = false, mHasBeenUpdated = false, mStuttering = false, mCharge = false, mDecharge = false;