From 7dd90331d6af2a13e6aa7771d2fff6e8e8cd8a79 Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:05:23 +1000 Subject: [PATCH] Remove Modlist in Fixes + Patch Capacitor Fixing --- build.gradle | 4 +- .../java/com/nomiceu/nomilabs/LabsValues.java | 6 --- .../nomilabs/remap/datafixer/DataFix.java | 19 +++---- .../remap/datafixer/DataFixerHandler.java | 53 ++++++++---------- .../nomilabs/remap/datafixer/LabsFixes.java | 27 ---------- .../remap/datafixer/LabsWorldFixData.java | 20 ++++--- .../remap/datafixer/fixes/BlockFixer.java | 5 +- .../remap/datafixer/fixes/ItemFixer.java | 5 +- .../datafixer/fixes/TileEntityFixer.java | 5 +- .../datafixer/walker/BlockEntityWalker.java | 3 +- .../remap/datafixer/walker/ChunkWalker.java | 3 +- .../datafixer/walker/ItemStackWalker.java | 3 +- .../nomilabs/util/LabsVersionUtil.java | 54 ------------------- 13 files changed, 51 insertions(+), 156 deletions(-) delete mode 100644 src/main/java/com/nomiceu/nomilabs/util/LabsVersionUtil.java diff --git a/build.gradle b/build.gradle index 6436692e..a99d4771 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1720106721 +//version: 1720840170 /* * DO NOT CHANGE THIS FILE! * Also, you may replace this file at any time if there is an update available. @@ -1252,7 +1252,7 @@ if (cfApiKey.isPresent() || deploymentDebug.toBoolean()) { def fileId = artifact.getCurseFileId() def fileName = artifact.getArtifact().getSingleFile().name println("Uploaded File ${fileName}, With File ID: ${fileId}") - summary = summary + "\n- File: ${fileName} | File ID: ${fileId}" + summary = summary + "\n - File: ${fileName} | File ID: ${fileId}" } println(summary) def stepSummary = providers.environmentVariable("GITHUB_STEP_SUMMARY") diff --git a/src/main/java/com/nomiceu/nomilabs/LabsValues.java b/src/main/java/com/nomiceu/nomilabs/LabsValues.java index b551d370..82d6c2f9 100644 --- a/src/main/java/com/nomiceu/nomilabs/LabsValues.java +++ b/src/main/java/com/nomiceu/nomilabs/LabsValues.java @@ -1,7 +1,5 @@ package com.nomiceu.nomilabs; -import com.nomiceu.nomilabs.util.LabsVersionUtil; - @SuppressWarnings("unused") public class LabsValues { @@ -42,9 +40,5 @@ public class LabsValues { public static final String FTB_UTILS_MODID = "ftbutilities"; public static final String TOP_ADDONS_MODID = "topaddons"; public static final String PACK_MODE_MODID = "packmode"; - - /* AE2 Stuff Compat */ public static final String AE2_STUFF_MODID = "ae2stuff"; - public static final LabsVersionUtil.LabsVersion AE2_STUFF_UNOFFICIAL_SEPARATOR = LabsVersionUtil - .getVersionFromString("0.8"); } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFix.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFix.java index 15447e0f..1a4632f1 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFix.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFix.java @@ -1,6 +1,5 @@ package com.nomiceu.nomilabs.remap.datafixer; -import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; @@ -17,18 +16,15 @@ public abstract class DataFix { public final String description; public final boolean needsMode; public final Function validVersion; - public final Function, Boolean> validModList; public final Function validEntry; public final Consumer transform; public DataFix(String name, String description, boolean needsMode, Function validVersion, - Function, Boolean> validModList, Function validEntry, - Consumer transform) { + Function validEntry, Consumer transform) { this.name = name; this.description = description; this.needsMode = needsMode; this.validVersion = validVersion; - this.validModList = validModList; this.validEntry = validEntry; this.transform = transform; } @@ -36,9 +32,8 @@ public DataFix(String name, String description, boolean needsMode, Function { public ItemFix(String name, String description, boolean needsMode, Function validVersion, - Function, Boolean> validModList, Function validEntry, - Consumer transform) { - super(name, description, needsMode, validVersion, validModList, validEntry, transform); + Function validEntry, Consumer transform) { + super(name, description, needsMode, validVersion, validEntry, transform); } } @@ -49,11 +44,10 @@ public static class BlockFix extends DataFix { public final Function secondaryValidEntry; public BlockFix(String name, String description, boolean needsMode, Function validVersion, - Function, Boolean> validModList, boolean teNeeded, - Function validEntry, + boolean teNeeded, Function validEntry, @Nullable Function secondaryValidEntry, Consumer blockTransform) { - super(name, description, needsMode, validVersion, validModList, validEntry, blockTransform); + super(name, description, needsMode, validVersion, validEntry, blockTransform); this.secondaryValidEntry = secondaryValidEntry; this.teNeeded = teNeeded; } @@ -63,9 +57,8 @@ public static class TileEntityFix extends DataFix { public TileEntityFix(String name, String description, boolean needsMode, Function validVersion, - Function, Boolean> validModList, Function validEntry, Consumer transform) { - super(name, description, needsMode, validVersion, validModList, validEntry, transform); + super(name, description, needsMode, validVersion, validEntry, transform); } } } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java index 027033bd..fc0c5220 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java @@ -6,7 +6,6 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -57,16 +56,16 @@ public class DataFixerHandler { public static LabsWorldFixData worldSavedData = null; public static boolean checked = false; - /* Fixes that should be applied */ - public static Map>> neededFixes; - /* Fixes that should be logged */ public static Map>> neededNewFixes; /* Whether Mode is needed for New Fixes */ public static boolean modeNeeded = false; - private static Map mods; + /* Whether fix is available */ + private static boolean fixAvailable = false; + + private static String savedLabsVersion; /* Must be split up so that idToBlockMap is the old one (so we can use not registered resource locations) */ private static NBTTagList oldBlockRegistry; @@ -95,28 +94,19 @@ public static void preInit() { public static void onWorldLoad(SaveHandler save) { checked = false; modeNeeded = false; - neededFixes = null; neededNewFixes = null; - NomiLabs.LOGGER.info("Checking Data Fixers..."); + savedLabsVersion = null; + fixAvailable = true; // Clear Block Helper Maps, the ids can be different for each save idToBlockMap = null; blockToIdMap = null; oldBlockRegistry = null; + NomiLabs.LOGGER.info("Checking Data Fixers..."); getInfoFromSave(save); - if (mods.isEmpty()) return; LabsFixes.init(); - neededFixes = new Object2ObjectOpenHashMap<>(); - for (var fixType : LabsFixes.fixes.keySet()) { - for (var fix : LabsFixes.fixes.get(fixType)) { - if (fix.validModList.apply(mods)) { - if (!neededFixes.containsKey(fixType)) neededFixes.put(fixType, new ObjectArrayList<>()); - neededFixes.get(fixType).add(fix); - } - } - } var mapFile = save.getMapFileFromName(LabsFixes.DATA_NAME); @@ -124,7 +114,7 @@ public static void onWorldLoad(SaveHandler save) { DataFixerHandler.worldSavedData = LabsWorldFixData.load(mapFile); // Shortcut: If saved version == Current Version, Exit - if (DataFixerHandler.worldSavedData.savedVersion == LabsFixes.CURRENT) { + if (DataFixerHandler.worldSavedData.savedFixVersion == LabsFixes.CURRENT) { DataFixerHandler.worldSavedData = null; NomiLabs.LOGGER.info("This world's data version is up to date."); return; @@ -168,8 +158,6 @@ public static void onWorldLoad(SaveHandler save) { } private static void getInfoFromSave(SaveHandler save) { - mods = new HashMap<>(); - File levelDat = new File(save.getWorldDirectory(), "level.dat"); // If level.dat file does not exist, return. @@ -179,20 +167,23 @@ private static void getInfoFromSave(SaveHandler save) { if (!levelDat.exists()) return; - NBTTagList modList; try { NBTTagCompound nbt = CompressedStreamTools.readCompressed(new FileInputStream(levelDat)); if (!nbt.hasKey("FML", Constants.NBT.TAG_COMPOUND)) return; NBTTagCompound fml = nbt.getCompoundTag("FML"); if (fml.hasKey("ModList", Constants.NBT.TAG_LIST)) { - modList = fml.getTagList("ModList", Constants.NBT.TAG_COMPOUND); + NBTTagList modList = fml.getTagList("ModList", Constants.NBT.TAG_COMPOUND); for (var mod : modList) { if (!(mod instanceof NBTTagCompound compound)) continue; if (!compound.hasKey("ModId", Constants.NBT.TAG_STRING) || !compound.hasKey("ModVersion", Constants.NBT.TAG_STRING)) continue; - mods.put(compound.getString("ModId"), compound.getString("ModVersion")); + if (!LabsValues.LABS_MODID.equals(compound.getString("ModId"))) + continue; + + savedLabsVersion = compound.getString("ModVersion"); + break; } } @@ -212,24 +203,21 @@ private static void getInfoFromSave(SaveHandler save) { private static void determineNeededFixesAndLog() { neededNewFixes = new Object2ObjectOpenHashMap<>(); - if (mods.isEmpty()) return; - // If Nomi Labs Version is same as current version, exit. // This normally means it is a new world. // Sometimes the level.dat file is created first, but usually this runs after it is created. // If the level.dat file is created first, its mod list is equal to the current one. - if (mods.containsKey(LabsValues.LABS_MODID) && mods.get(LabsValues.LABS_MODID).equals(LabsValues.LABS_VERSION)) + if (LabsValues.LABS_VERSION.equals(savedLabsVersion)) return; - DataFixerHandler.worldSavedData.processModList(mods); + DataFixerHandler.worldSavedData.processSavedLabsVersion(savedLabsVersion); NomiLabs.LOGGER.info("NEEDED DATA FIXES: ----------------------------------------"); for (var fixType : LabsFixes.fixes.keySet()) { NomiLabs.LOGGER.info("SECTION: {} -------------------------------------------", fixType); var fixes = LabsFixes.fixes.get(fixType); for (var fix : fixes) { - if (fix.validVersion.apply(DataFixerHandler.worldSavedData.savedVersion) && - fix.validModList.apply(mods)) { + if (fix.validVersion.apply(DataFixerHandler.worldSavedData.savedFixVersion)) { neededNewFixes.computeIfAbsent(fixType, (key) -> new ObjectArrayList<>()).add(fix); if (fix.needsMode) modeNeeded = true; NomiLabs.LOGGER.info("- {}: {}", fix.name, fix.description); @@ -313,13 +301,16 @@ public static boolean hasNoNewFixes() { } public static boolean fixNotAvailable() { - return neededFixes == null || neededFixes.isEmpty(); + return !fixAvailable; } public static void close() { worldSavedData = null; checked = false; - neededFixes = null; + fixAvailable = false; neededNewFixes = null; + idToBlockMap = null; + blockToIdMap = null; + oldBlockRegistry = null; } } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java index bf76b08e..999b18b1 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java @@ -2,10 +2,8 @@ import static com.nomiceu.nomilabs.LabsValues.*; import static com.nomiceu.nomilabs.util.LabsNames.makeLabsName; -import static com.nomiceu.nomilabs.util.LabsVersionUtil.getVersionFromString; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; import net.minecraft.item.ItemStack; @@ -129,7 +127,6 @@ public class LabsFixes { public static Set specialMetaItemsRemap; public static Set materialNames; public static Map capacitorSpecificationRemap; - public static Function, Boolean> requiresAe2StuffRemap; public static void init() { helpersInit(); @@ -183,7 +180,6 @@ public static void init() { "Correctly remaps Content Tweaker Dark Red Coal to XU2 Red Coal.", false, (version) -> version <= DEFAULT, - (modList) -> true, (stack) -> stack.rl.equals(new ResourceLocation(CONTENTTWEAKER_MODID, "dark_red_coal")), (stack) -> stack.setRl(new ResourceLocation(XU2_MODID, "ingredients")) .setMeta((short) 4)) // Red Coal @@ -195,7 +191,6 @@ public static void init() { "Removes NBT from Custom Capacitors.", false, (version) -> version <= PRE_CAPACITOR_REMAPPING, - (modList) -> true, (stack) -> (stack.rl.getNamespace().equals(LABS_MODID) || stack.rl.getNamespace().equals(CONTENTTWEAKER_MODID)) && capacitorSpecificationRemap.containsKey(stack.rl.getPath()) && @@ -208,7 +203,6 @@ public static void init() { "Remaps Deprecated Items to their Modern Counterparts.", false, (version) -> version <= DEFAULT, - (modList) -> true, (stack) -> LabsRemappers.deprecatedRemapper.shouldRemap(stack.rl), (stack) -> stack.setRl(LabsRemappers.deprecatedRemapper.remapRl(stack.rl)))); @@ -217,7 +211,6 @@ public static void init() { "Remaps Content Tweaker Items to their counterparts.", false, (version) -> version <= DEFAULT, - (modList) -> true, (stack) -> LabsRemappers.ctRemapper.shouldRemap(stack.rl), (stack) -> stack.setRl(LabsRemappers.ctRemapper.remapRl(stack.rl)))); @@ -226,7 +219,6 @@ public static void init() { "Remaps Perfect Gems to their counterparts.", false, (version) -> version <= DEFAULT, - (modList) -> true, (stack) -> LabsRemappers.perfectGemRemapper.shouldRemap(stack.rl), (stack) -> stack.setRl(LabsRemappers.perfectGemRemapper.remapRl(stack.rl)))); @@ -236,7 +228,6 @@ public static void init() { "Removes Frequency from XU2 Ingredients.", false, (version) -> version <= DEFAULT || version == NEW, - (modList) -> modList.containsKey(XU2_MODID), (stack) -> stack.rl.equals(new ResourceLocation(XU2_MODID, "ingredients")) && stack.tag != null && stack.tag.hasKey("Freq"), (stack) -> { @@ -250,7 +241,6 @@ public static void init() { "Remaps old Multiblock Metadata to the new format.", true, (version) -> version <= DEFAULT_NOMI_CEU, - (modList) -> true, (stack) -> stack.rl.equals(new ResourceLocation(GREGTECH_MODID, "machine")) && multiblockMetaRemap.containsKey(stack.meta), (stack) -> stack.setMeta(multiblockMetaRemap.get(stack.meta)))); @@ -260,7 +250,6 @@ public static void init() { "Remaps old Meta Items, from Custom Materials, to the new format and registry.", false, (version) -> version <= PRE_MATERIAL_REWORK, - (modList) -> true, (stack) -> stack.rl.getNamespace().equals(GREGTECH_MODID) && LabsRemapHelper.META_ITEM_MATCHER.matcher(stack.rl.getPath()).matches() && !LabsRemapHelper.META_BLOCK_MATCHER.matcher(stack.rl.getPath()).matches() && @@ -273,7 +262,6 @@ public static void init() { "Remaps old Meta Blocks' Item Forms, from Custom Materials, to the new format and registry.", false, (version) -> version <= PRE_MATERIAL_REWORK, - (modList) -> true, (stack) -> LabsRemappers.metaBlockRemapper.shouldRemap(stack.rl), (stack) -> stack.setRl(LabsRemappers.metaBlockRemapper.remapRl(stack.rl)))); @@ -282,7 +270,6 @@ public static void init() { "Remaps old special placeable Meta Items, from Custom Materials, to the new format and registry.", false, (version) -> version <= PRE_MATERIAL_REWORK, - (modList) -> true, (stack) -> specialMetaItemsRemap.contains(stack.rl) && stack.meta >= LabsRemapHelper.MIN_META_ITEM_BASE_ID, (stack) -> stack.setMeta((short) (stack.meta - LabsRemapHelper.MIN_META_ITEM_BASE_ID)) @@ -294,7 +281,6 @@ public static void init() { "Remaps AE2 Stuff Pattern Encoders, which were removed in AE2 Stuff Unofficial, to AE2 Interfaces.", false, (version) -> version <= PRE_AE2_STUFF_REMAP || version == NEW, - requiresAe2StuffRemap, (stack) -> stack.rl.getNamespace().equals(AE2_STUFF_MODID) && stack.rl.getPath().equals("encoder"), (stack) -> stack.setRl(new ResourceLocation(AE2_MODID, "interface")))); @@ -349,7 +335,6 @@ public static void init() { "Remaps old special placeable Meta Blocks, from Custom Materials, to the new format and registry.", false, (version) -> version <= PRE_MATERIAL_REWORK, - (modList) -> true, true, (state) -> specialMetaItemsRemap.contains(state.rl), (state) -> state.tileEntityTag != null && @@ -372,7 +357,6 @@ public static void init() { "Remaps AE2 Stuff Pattern Encoders, which were removed in AE2 Stuff Unofficial, to AE2 Interfaces.", false, (version) -> version <= PRE_AE2_STUFF_REMAP || version == NEW, - requiresAe2StuffRemap, true, (state) -> state.rl.getNamespace().equals(AE2_STUFF_MODID) && state.rl.getPath().equals("encoder"), @@ -501,7 +485,6 @@ public static void init() { "Remaps old Multiblock Tile Entity Names to the new format.", false, (version) -> version <= DEFAULT_NOMI_CEU, - (modList) -> true, (compound) -> compound.hasKey("MetaId", Constants.NBT.TAG_STRING) && compound.hasKey("id", Constants.NBT.TAG_STRING) && compound.getString("id").equals( @@ -603,16 +586,6 @@ private static void helpersInit() { "Can be inserted into EnderIO machines.", "Level: 9.001", "Just kidding, it's only 5.")); - - // If AE2 Stuff is loaded before and now, and if old version was before 0.8, and if current version is equal to - // or after 0.8 - requiresAe2StuffRemap = (modlist) -> modlist.containsKey(AE2_STUFF_MODID) && - getVersionFromString(modlist.get(AE2_STUFF_MODID)) - .compareTo(AE2_STUFF_UNOFFICIAL_SEPARATOR) < 0 && - getVersionFromString( - Loader.instance().getIndexedModList().get(AE2_STUFF_MODID).getVersion()) - .compareTo(AE2_STUFF_UNOFFICIAL_SEPARATOR) >= - 0; } public static class OldCapacitorSpecification { diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java index 88c6156c..85588a2f 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java @@ -4,7 +4,6 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Map; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -13,14 +12,13 @@ import org.jetbrains.annotations.NotNull; -import com.nomiceu.nomilabs.LabsValues; import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.config.LabsConfig; public class LabsWorldFixData extends WorldSavedData { // Fix Version stored in this world. - public int savedVersion; + public int savedFixVersion; // Base Data Key public static final String BASE_DATA_KEY = "data"; @@ -30,24 +28,24 @@ public class LabsWorldFixData extends WorldSavedData { public LabsWorldFixData() { super(LabsFixes.DATA_NAME); - if (LabsConfig.advanced.enableNomiCEuDataFixes) savedVersion = LabsFixes.DEFAULT_NOMI_CEU; - else savedVersion = LabsFixes.DEFAULT; + if (LabsConfig.advanced.enableNomiCEuDataFixes) savedFixVersion = LabsFixes.DEFAULT_NOMI_CEU; + else savedFixVersion = LabsFixes.DEFAULT; } - public void processModList(Map mods) { - if (!mods.containsKey(LabsValues.LABS_MODID) && savedVersion == LabsFixes.DEFAULT) - savedVersion = LabsFixes.NEW; + public void processSavedLabsVersion(String savedLabsVersion) { + if (savedLabsVersion == null && savedFixVersion == LabsFixes.DEFAULT) + savedFixVersion = LabsFixes.NEW; } @Override public void readFromNBT(NBTTagCompound nbt) { if (nbt.hasKey(VERSION_KEY, Constants.NBT.TAG_ANY_NUMERIC)) { - savedVersion = nbt.getInteger(VERSION_KEY); - NomiLabs.LOGGER.info("This world was previously loaded with Fix Version {}.", savedVersion); + savedFixVersion = nbt.getInteger(VERSION_KEY); + NomiLabs.LOGGER.info("This world was previously loaded with Fix Version {}.", savedFixVersion); } else NomiLabs.LOGGER.info( "This world was previously loaded without a saved Fix Version, possibly due to corruption, defaulting to {}.", - savedVersion); + savedFixVersion); } @Override diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java index 4a18423d..506c4348 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java @@ -8,7 +8,6 @@ import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.remap.LabsRemapHelper; import com.nomiceu.nomilabs.remap.datafixer.DataFix; -import com.nomiceu.nomilabs.remap.datafixer.DataFixerHandler; import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.types.LabsFixTypes; @@ -21,7 +20,7 @@ public int getFixVersion() { @Override public @NotNull NBTTagCompound fixTagCompound(@NotNull NBTTagCompound compound) { - var blockFixes = DataFixerHandler.neededFixes.get(LabsFixTypes.FixerTypes.CHUNK); + var blockFixes = LabsFixes.fixes.get(LabsFixTypes.FixerTypes.CHUNK); LabsRemapHelper.rewriteBlocks(compound, (state) -> { for (var fix : blockFixes) { if (!(fix instanceof DataFix.BlockFix blockFix)) continue; @@ -36,7 +35,7 @@ public int getFixVersion() { if (blockFix.teNeeded) NomiLabs.LOGGER.debug("[Data Fixer] Changed Tile Entity With Above Block: {} to {}.", oldState.tileEntityTag, state.tileEntityTag); - return state; + // Don't return, allow other block fixes to apply } return state; }); diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java index 32dbec8e..dd71daa7 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java @@ -7,7 +7,6 @@ import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.remap.datafixer.DataFix; -import com.nomiceu.nomilabs.remap.datafixer.DataFixerHandler; import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.storage.ItemStackLike; import com.nomiceu.nomilabs.remap.datafixer.types.LabsFixTypes; @@ -22,13 +21,13 @@ public int getFixVersion() { @Override public @NotNull NBTTagCompound fixTagCompound(@NotNull NBTTagCompound compound) { var stack = new ItemStackLike(compound); - for (var fix : DataFixerHandler.neededFixes.get(LabsFixTypes.FixerTypes.ITEM)) { + for (var fix : LabsFixes.fixes.get(LabsFixTypes.FixerTypes.ITEM)) { if (!(fix instanceof DataFix.ItemFix itemFix)) continue; if (!itemFix.validEntry.apply(stack)) continue; itemFix.transform.accept(stack); var oldCompound = compound.copy(); NomiLabs.LOGGER.debug("[Data Fixer] Changed Stack: {} to {}", oldCompound, stack.changeCompound(compound)); - return compound; + // Don't return, allow other item fixes to apply } return compound; } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java index e8e52ba3..0f5ec782 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java @@ -7,7 +7,6 @@ import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.remap.datafixer.DataFix; -import com.nomiceu.nomilabs.remap.datafixer.DataFixerHandler; import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.types.LabsFixTypes; @@ -21,13 +20,13 @@ public int getFixVersion() { @Override @NotNull public NBTTagCompound fixTagCompound(@NotNull NBTTagCompound compound) { - for (var fix : DataFixerHandler.neededFixes.get(LabsFixTypes.FixerTypes.TILE_ENTITY)) { + for (var fix : LabsFixes.fixes.get(LabsFixTypes.FixerTypes.TILE_ENTITY)) { if (!(fix instanceof DataFix.TileEntityFix teFix)) continue; if (!teFix.validEntry.apply(compound)) continue; var oldCompound = compound.copy(); teFix.transform.accept(compound); NomiLabs.LOGGER.debug("[Data Fixer] Changed Block Entity Tag from {} to {}", oldCompound, compound); - return compound; + // Don't return, allow other tile entity fixes to apply } return compound; } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/BlockEntityWalker.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/BlockEntityWalker.java index 21aba56f..c86f432a 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/BlockEntityWalker.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/BlockEntityWalker.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; import com.nomiceu.nomilabs.remap.datafixer.DataFixerHandler; +import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.types.LabsFixTypes; public class BlockEntityWalker implements IDataWalker { @@ -23,7 +24,7 @@ public NBTTagCompound process(@NotNull IDataFixer fixer, @NotNull NBTTagCompound if (DataFixerHandler.fixNotAvailable()) return compound; itemWalker.process(fixer, compound, versionIn); - if (!DataFixerHandler.neededFixes.containsKey(LabsFixTypes.FixerTypes.TILE_ENTITY)) return compound; + if (!LabsFixes.fixes.containsKey(LabsFixTypes.FixerTypes.TILE_ENTITY)) return compound; return fixer.process(LabsFixTypes.FixerTypes.TILE_ENTITY, compound, versionIn); } } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ChunkWalker.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ChunkWalker.java index 2a26277b..8c1876eb 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ChunkWalker.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ChunkWalker.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; import com.nomiceu.nomilabs.remap.datafixer.DataFixerHandler; +import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.types.LabsFixTypes; public class ChunkWalker implements IDataWalker { @@ -14,7 +15,7 @@ public class ChunkWalker implements IDataWalker { @Override public @NotNull NBTTagCompound process(@NotNull IDataFixer fixer, @NotNull NBTTagCompound compound, int versionIn) { if (DataFixerHandler.fixNotAvailable() || - !DataFixerHandler.neededFixes.containsKey(LabsFixTypes.FixerTypes.CHUNK)) + !LabsFixes.fixes.containsKey(LabsFixTypes.FixerTypes.CHUNK)) return compound; return fixer.process(LabsFixTypes.FixerTypes.CHUNK, compound, versionIn); diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ItemStackWalker.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ItemStackWalker.java index 48db340f..8b73aec8 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ItemStackWalker.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/walker/ItemStackWalker.java @@ -8,6 +8,7 @@ import com.nomiceu.nomilabs.remap.LabsRemapHelper; import com.nomiceu.nomilabs.remap.datafixer.DataFixerHandler; +import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.types.LabsFixTypes; public class ItemStackWalker implements IDataWalker { @@ -16,7 +17,7 @@ public class ItemStackWalker implements IDataWalker { @NotNull public NBTTagCompound process(@NotNull IDataFixer fixer, @NotNull NBTTagCompound compound, int versionIn) { if (DataFixerHandler.fixNotAvailable() || - !DataFixerHandler.neededFixes.containsKey(LabsFixTypes.FixerTypes.ITEM)) + !LabsFixes.fixes.containsKey(LabsFixTypes.FixerTypes.ITEM)) return compound; LabsRemapHelper.rewriteCompoundTags(compound, tag -> { diff --git a/src/main/java/com/nomiceu/nomilabs/util/LabsVersionUtil.java b/src/main/java/com/nomiceu/nomilabs/util/LabsVersionUtil.java deleted file mode 100644 index 79c73afb..00000000 --- a/src/main/java/com/nomiceu/nomilabs/util/LabsVersionUtil.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.nomiceu.nomilabs.util; - -import java.util.ArrayList; -import java.util.List; - -import org.jetbrains.annotations.NotNull; - -import com.google.common.base.CharMatcher; - -public class LabsVersionUtil { - - public static LabsVersion getVersionFromString(String version) { - var splitVersion = version.split("\\."); - - List versionParts = new ArrayList<>(); - for (String part : splitVersion) { - String extracted = CharMatcher.digit().retainFrom(part); - if (extracted.isEmpty()) continue; - - versionParts.add(Integer.parseInt(extracted)); - } - return new LabsVersion(versionParts); - } - - /** - * Labs Version object, used for comparing versions of mods. - *

- * Note that all text in the version is ignored! - */ - public static class LabsVersion implements Comparable { - - private final List versionParts; - - public LabsVersion(List versionParts) { - this.versionParts = versionParts; - } - - @Override - public int compareTo(@NotNull LabsVersion o) { - if (versionParts.isEmpty() || o.versionParts.isEmpty()) return 0; - - int result = 0; - for (int i = 0; i < Math.min(versionParts.size(), o.versionParts.size()); i++) { - result = Integer.compare(versionParts.get(i), o.versionParts.get(i)); - if (result != 0) break; - } - if (result == 0) { - result = Integer.compare(versionParts.size(), o.versionParts.size()); - } - - return result; - } - } -}