diff --git a/src/main/java/gregtech/common/asm/SaveFormatOldLoadVisitor.java b/src/main/java/gregtech/common/asm/SaveFormatOldLoadVisitor.java index 0f21dd5965..843e632473 100644 --- a/src/main/java/gregtech/common/asm/SaveFormatOldLoadVisitor.java +++ b/src/main/java/gregtech/common/asm/SaveFormatOldLoadVisitor.java @@ -1,4 +1,3 @@ - package gregtech.common.asm; import gregtech.common.asm.util.ObfMapping; diff --git a/src/main/java/gregtech/common/blocks/MetaBlocks.java b/src/main/java/gregtech/common/blocks/MetaBlocks.java index 12cca275b8..cb8d5e8964 100644 --- a/src/main/java/gregtech/common/blocks/MetaBlocks.java +++ b/src/main/java/gregtech/common/blocks/MetaBlocks.java @@ -237,44 +237,6 @@ protected static void createGeneratedBlock(Predicate materialPredicate blocksToGenerate.forEach((key, value) -> blockGenerator.accept(value, key)); } - /** - * Old generation code for initializing BlockCompressed and BlockSurfaceRockDeprecated. - * - * Needed for accurately reproducing the deprecated MetaBlock packing behavior for determining what the old blocks - * are so we can remap them to the correct replacements. - * - * @param materialPredicate a filter for determining if a Material qualifies for generation in the category. - * @param blockGenerator a function which accepts a Materials set to pack into a MetaBlock, and the ordinal this - * MetaBlock should have within its category. - * @return the number of blocks generated by this request - */ - @Deprecated - protected static int createGeneratedBlockDeprecated(Predicate materialPredicate, - BiConsumer blockGenerator) { - Material[] materialBuffer = new Material[16]; - Arrays.fill(materialBuffer, Materials._NULL); - int currentGenerationIndex = 0; - for (Material material : Material.MATERIAL_REGISTRY) { - if (materialPredicate.test(material)) { - if (currentGenerationIndex > 0 && currentGenerationIndex % 16 == 0) { - blockGenerator.accept(materialBuffer, currentGenerationIndex / 16 - 1); - Arrays.fill(materialBuffer, Materials._NULL); - } - materialBuffer[currentGenerationIndex % 16] = material; - currentGenerationIndex++; - } - } - if (materialBuffer[0] != Materials._NULL) { - blockGenerator.accept(materialBuffer, currentGenerationIndex / 16); - } - return (currentGenerationIndex / 16) + 1; - } - - private static BiConsumer generateInto(TIntObjectMap dest) { - return (materials, index) -> dest.put( - index, Arrays.stream(materials).mapToInt(Material.MATERIAL_REGISTRY::getIDForObject).toArray()); - } - private static void createSurfaceRockBlock(Material[] materials, int index) { BlockSurfaceRockDeprecated block = new BlockSurfaceRockDeprecated(materials); block.setRegistryName("meta_block_surface_rock_" + index); diff --git a/src/main/java/gregtech/common/datafix/GregTechDataFixers.java b/src/main/java/gregtech/common/datafix/GregTechDataFixers.java index be429fa8b6..41ec506ab4 100644 --- a/src/main/java/gregtech/common/datafix/GregTechDataFixers.java +++ b/src/main/java/gregtech/common/datafix/GregTechDataFixers.java @@ -36,6 +36,12 @@ public class GregTechDataFixers { */ public static final int DATA_VERSION = V1_META_BLOCK_ID_REWORK; + /** + * Constants used for fixing NBT data. + */ + public static final String COMPOUND_ID = "id"; + public static final String COMPOUND_META = "Damage"; + public static void init() { CompoundDataFixer fmlFixer = FMLCommonHandler.instance().getDataFixer(); IDataWalker walkItemStackLike = new WalkItemStackLike(); diff --git a/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShift.java b/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShift.java index 8a88682269..fb559c5249 100644 --- a/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShift.java +++ b/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShift.java @@ -1,5 +1,6 @@ package gregtech.common.datafix.fixes; +import gregtech.common.datafix.GregTechDataFixers; import gregtech.common.datafix.fixes.metablockid.MetaBlockIdFixHelper; import gregtech.common.datafix.fixes.metablockid.PreGraniteMetaBlockIdFixer; import gregtech.common.datafix.fixes.metablockid.WorldDataHooks; @@ -16,17 +17,17 @@ public int getFixVersion() { @Override public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (!WorldDataHooks.isFixerAvailable()) { + if (WorldDataHooks.isFixerUnavailable()) { return compound; } - int index = MetaBlockIdFixHelper.getCompressedIndexFromResLoc(compound.getString("id")); + int index = MetaBlockIdFixHelper.getCompressedIndexFromResLoc(compound.getString(GregTechDataFixers.COMPOUND_ID)); if (index != -1) { RemappedBlock remapped = ((PreGraniteMetaBlockIdFixer) WorldDataHooks.getMetaBlockIdFixer()) - .remapCompressedPreGraniteToPost(index, compound.getShort("Damage")); + .remapCompressedPreGraniteToPost(index, compound.getShort(GregTechDataFixers.COMPOUND_META)); if (remapped != null) { - compound.setString("id", MetaBlockIdFixHelper.COMP_RESLOC_PREF + remapped.id); - compound.setShort("Damage", remapped.data); + compound.setString(GregTechDataFixers.COMPOUND_ID, MetaBlockIdFixHelper.COMP_RESLOC_PREF + remapped.id); + compound.setShort(GregTechDataFixers.COMPOUND_META, remapped.data); } } return compound; diff --git a/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShiftInWorld.java b/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShiftInWorld.java index e8eee13f00..74d946f202 100644 --- a/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShiftInWorld.java +++ b/src/main/java/gregtech/common/datafix/fixes/Fix0PostGraniteMetaBlockShiftInWorld.java @@ -16,7 +16,7 @@ public int getFixVersion() { @Override public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (!WorldDataHooks.isFixerAvailable()) { + if (WorldDataHooks.isFixerUnavailable()) { return compound; } diff --git a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystem.java b/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystem.java index 038c74cdd3..cc3244d303 100644 --- a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystem.java +++ b/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystem.java @@ -1,5 +1,6 @@ package gregtech.common.datafix.fixes; +import gregtech.common.datafix.GregTechDataFixers; import gregtech.common.datafix.fixes.metablockid.MetaBlockIdFixHelper; import gregtech.common.datafix.fixes.metablockid.PostGraniteMetaBlockIdFixer; import gregtech.common.datafix.fixes.metablockid.WorldDataHooks; @@ -25,26 +26,26 @@ public int getFixVersion() { @Override public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (!WorldDataHooks.isFixerAvailable()) { + if (WorldDataHooks.isFixerUnavailable()) { return compound; } - String blockResLoc = compound.getString("id"); + String blockResLoc = compound.getString(GregTechDataFixers.COMPOUND_ID); int index = MetaBlockIdFixHelper.getCompressedIndexFromResLoc(blockResLoc); if (index != -1) { RemappedBlock remapped = ((PostGraniteMetaBlockIdFixer) WorldDataHooks.getMetaBlockIdFixer()) - .remapCompressedPostGraniteToNew(index, compound.getShort("Damage")); - compound.setString("id", MetaBlockIdFixHelper.COMP_RESLOC_PREF_NEW + remapped.id); - compound.setShort("Damage", remapped.data); + .remapCompressedPostGraniteToNew(index, compound.getShort(GregTechDataFixers.COMPOUND_META)); + compound.setString(GregTechDataFixers.COMPOUND_ID, MetaBlockIdFixHelper.COMP_RESLOC_PREF_NEW + remapped.id); + compound.setShort(GregTechDataFixers.COMPOUND_META, remapped.data); return compound; } index = MetaBlockIdFixHelper.getSurfRockIndexFromResLoc(blockResLoc); if (index != -1) { RemappedBlock remapped = ((PostGraniteMetaBlockIdFixer) WorldDataHooks.getMetaBlockIdFixer()) - .remapSurfRockToNew(index, compound.getShort("Damage")); - compound.setString("id", MetaBlockIdFixHelper.SURF_ROCK_RESLOC_PREF_NEW + remapped.id); - compound.setShort("Damage", remapped.data); + .remapSurfRockToNew(index, compound.getShort(GregTechDataFixers.COMPOUND_META)); + compound.setString(GregTechDataFixers.COMPOUND_ID, MetaBlockIdFixHelper.SURF_ROCK_RESLOC_PREF_NEW + remapped.id); + compound.setShort(GregTechDataFixers.COMPOUND_META, remapped.data); } return compound; } diff --git a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystemInWorld.java b/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystemInWorld.java index a25d1f7aed..5e3b52d204 100644 --- a/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystemInWorld.java +++ b/src/main/java/gregtech/common/datafix/fixes/Fix1MetaBlockIdSystemInWorld.java @@ -17,7 +17,7 @@ public int getFixVersion() { @Override public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (!WorldDataHooks.isFixerAvailable()) { + if (WorldDataHooks.isFixerUnavailable()) { return compound; } diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdRemapCache.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdRemapCache.java index 175d675736..bcf051db7a 100644 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdRemapCache.java +++ b/src/main/java/gregtech/common/datafix/fixes/metablockid/MetaBlockIdRemapCache.java @@ -44,8 +44,10 @@ public int getNewId(int index) { if (id != -1) { return id; } - return newIdCache[index] = Block.getIdFromBlock(Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue( + newIdCache[index] = Block.getIdFromBlock(Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue( new ResourceLocation(GTValues.MODID, newNamePrefix + index)))); + + return newIdCache[index]; } public NBTTagCompound serialize() { diff --git a/src/main/java/gregtech/common/datafix/fixes/metablockid/WorldDataHooks.java b/src/main/java/gregtech/common/datafix/fixes/metablockid/WorldDataHooks.java index 101d1b0a7b..9e371cd8cf 100644 --- a/src/main/java/gregtech/common/datafix/fixes/metablockid/WorldDataHooks.java +++ b/src/main/java/gregtech/common/datafix/fixes/metablockid/WorldDataHooks.java @@ -31,8 +31,11 @@ public class WorldDataHooks { @Nullable private static MetaBlockIdFixer metaBlockIdFixer = null; - public static boolean isFixerAvailable() { - return metaBlockIdFixer != null; + private WorldDataHooks() { + } + + public static boolean isFixerUnavailable() { + return metaBlockIdFixer == null; } public static MetaBlockIdFixer getMetaBlockIdFixer() { diff --git a/src/test/java/gregtech/common/blocks/MetaBlocksTest.java b/src/test/java/gregtech/common/blocks/MetaBlocksTest.java index 14ffb34b12..4e1960f9e3 100644 --- a/src/test/java/gregtech/common/blocks/MetaBlocksTest.java +++ b/src/test/java/gregtech/common/blocks/MetaBlocksTest.java @@ -52,7 +52,7 @@ private static BiConsumer generateMappingSet(Predicate results = new TreeSet<>(); - MetaBlocks.createGeneratedBlockDeprecated( + createGeneratedBlockDeprecated( material -> material instanceof IngotMaterial && material.hasFlag(DustMaterial.MatFlags.GENERATE_ORE), generateMappingSet(m -> m instanceof IngotMaterial, results)); @@ -106,7 +106,7 @@ private static void printDiffMappings(Set mappings, Set mappin private static Set simulateOldCompressedBlockMapping(final Set toIgnore) { final Set oldMappings = new TreeSet<>(); - MetaBlocks.createGeneratedBlockDeprecated( + createGeneratedBlockDeprecated( material -> !toIgnore.contains(material) && material instanceof DustMaterial && !OrePrefix.block.isIgnored(material), @@ -127,4 +127,37 @@ public void simulateNewBlockMappings() { System.out.println("--- New Compressed Block Mappings ---"); results.forEach(blockPrint); } -} \ No newline at end of file + + /** + * Old generation code for initializing BlockCompressed and BlockSurfaceRockDeprecated. + * + * Needed for accurately reproducing the deprecated MetaBlock packing behavior for determining what the old blocks + * are so we can remap them to the correct replacements. + * + * @param materialPredicate a filter for determining if a Material qualifies for generation in the category. + * @param blockGenerator a function which accepts a Materials set to pack into a MetaBlock, and the ordinal this + * MetaBlock should have within its category. + * @return the number of blocks generated by this request + */ + @Deprecated + protected static int createGeneratedBlockDeprecated(Predicate materialPredicate, + BiConsumer blockGenerator) { + Material[] materialBuffer = new Material[16]; + Arrays.fill(materialBuffer, Materials._NULL); + int currentGenerationIndex = 0; + for (Material material : Material.MATERIAL_REGISTRY) { + if (materialPredicate.test(material)) { + if (currentGenerationIndex > 0 && currentGenerationIndex % 16 == 0) { + blockGenerator.accept(materialBuffer, currentGenerationIndex / 16 - 1); + Arrays.fill(materialBuffer, Materials._NULL); + } + materialBuffer[currentGenerationIndex % 16] = material; + currentGenerationIndex++; + } + } + if (materialBuffer[0] != Materials._NULL) { + blockGenerator.accept(materialBuffer, currentGenerationIndex / 16); + } + return (currentGenerationIndex / 16) + 1; + } +}