Skip to content

Commit

Permalink
Refactor Data Fixes Into Mandatory and Nomi-CEu Specific
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 12, 2024
1 parent 523b77a commit 48d338f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@ public static class Advanced {
@Config.LangKey("config.nomilabs.advanced.disable_xp_scaling")
public boolean disableXpScaling = false;

@Config.Comment({"Whether to enable data fixes.",
@Config.Comment({"Whether to enable Nomi-CEu data fixes.",
"This is used for Nomi-CEu, for players coming from before core-mod.",
"If this mod is being used in other scenarios, leave this at false, as this may break worlds!",
"If this is in a Nomi-CEu environment, make sure it is true, and do not change it, or items/blocks may be lost!",
"This may be used in the future as well, and your world will not be fixed if it is up-to-date.",
"[default: false]"})
@Config.LangKey("config.nomilabs.advanced.enable_data_fixes")
@Config.LangKey("config.nomilabs.advanced.enable_nomi_ceu_data_fixes")
@Config.RequiresMcRestart
public boolean enableDataFixes = false;
public boolean enableNomiCEuDataFixes = false;

@Config.Comment({"List of Regex Patterns to ignore if they are included in the ITEM missing registry list.",
"Do not change unless you know what you are doing!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.nomiceu.nomilabs.LabsValues;
import com.nomiceu.nomilabs.NomiLabs;
import com.nomiceu.nomilabs.config.LabsConfig;
import com.nomiceu.nomilabs.remap.LabsRemapHelper;
import com.nomiceu.nomilabs.remap.datafixer.fixes.BlockFixer;
import com.nomiceu.nomilabs.remap.datafixer.fixes.TileEntityFixer;
Expand Down Expand Up @@ -53,8 +52,6 @@ public class DataFixerHandler {
public static Map<Integer, ResourceLocation> blockIdToRlMap;

public static void preInit() {
if (!LabsConfig.advanced.enableDataFixes) return;

CompoundDataFixer fmlFixer = FMLCommonHandler.instance().getDataFixer();

var itemWalker = new ItemStackWalker();
Expand All @@ -74,13 +71,6 @@ public static void preInit() {
}

public static void onWorldLoad(SaveHandler save) {
if (!LabsConfig.advanced.enableDataFixes) {
checked = true;
modeNeeded = false;
worldSavedData = null;
NomiLabs.LOGGER.info("Skipping Data Fixers, due to config...");
return;
}
checked = false;
modeNeeded = false;
NomiLabs.LOGGER.info("Checking Data Fixers...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ public class LabsFixes {
public static final int PRE_MATERIAL_REWORK_VERSION = 1;

/**
* Default version, used if save doesn't have a fix version, or if something goes wrong
* Default version, used if save doesn't have a fix version, or if something goes wrong.
*/
public static final int DEFAULT_VERSION = 0;

/**
* Default Nomi-CEu version, used if save doesn't have a fix version, or if something goes wrong, and Nomi-CEu Specific Data Fixes are enabled.
*/
public static final int DEFAULT_NOMI_CEU_VERSION = -1;

public static List<DataFix.ItemFix> itemFixes;

Expand Down Expand Up @@ -139,7 +143,7 @@ public static void init() {
new DataFix.ItemFix("Old Multiblock Metadata Remap",
"Remaps old Multiblock Metadata to the new format.",
true,
(version) -> version <= DEFAULT_VERSION,
(version) -> version <= DEFAULT_NOMI_CEU_VERSION,
(modList) -> true,
(stack) -> stack.rl.equals(new ResourceLocation(GREGTECH_MODID,"machine")) && multiblockMetaRemap.containsKey(stack.meta),
(stack) -> stack.setMeta(multiblockMetaRemap.get(stack.meta)))
Expand Down Expand Up @@ -246,7 +250,7 @@ public static void init() {
new DataFix.TileEntityFix("Multiblock Tile Entity MetaId Remap",
"Remaps old Multiblock Tile Entity Names to the new format.",
false,
(version) -> version <= DEFAULT_VERSION,
(version) -> version <= DEFAULT_NOMI_CEU_VERSION,
(modList) -> true,
(compound) -> compound.hasKey("MetaId", Constants.NBT.TAG_STRING) && compound.hasKey("id", Constants.NBT.TAG_STRING) &&
compound.getString("id").equals(new ResourceLocation(LabsValues.GREGTECH_MODID, "machine").toString()) &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nomiceu.nomilabs.remap.datafixer;

import com.nomiceu.nomilabs.NomiLabs;
import com.nomiceu.nomilabs.config.LabsConfig;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.storage.WorldSavedData;
Expand All @@ -14,7 +15,7 @@

public class LabsWorldFixData extends WorldSavedData {
// Fix Version stored in this world.
public int savedVersion = LabsFixes.DEFAULT_VERSION;
public int savedVersion;

// Base Data Key
public static final String BASE_DATA_KEY = "data";
Expand All @@ -24,6 +25,8 @@ public class LabsWorldFixData extends WorldSavedData {

public LabsWorldFixData() {
super(LabsFixes.DATA_NAME);
if (LabsConfig.advanced.enableNomiCEuDataFixes) savedVersion = LabsFixes.DEFAULT_NOMI_CEU_VERSION;
else savedVersion = LabsFixes.DEFAULT_VERSION;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/nomilabs/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ config.nomilabs.mod_integration.draconicevolution.auto_destructor_speed=Auto Des
config.nomilabs.advanced=Advanced Settings
config.nomilabs.advanced.allow_other_modes=Allow Other Modes
config.nomilabs.advanced.disable_xp_scaling=Disable Anvil XP Scaling
config.nomilabs.advanced.enable_data_fixes=Enable Data Fixes
config.nomilabs.advanced.enable_nomi_ceu_data_fixes=Enable Nomi-CEu Specific Data Fixes
config.nomilabs.advanced.ignore_items=ITEM Missing Registry Ignore List
config.nomilabs.advanced.ignore_blocks=BLOCK Missing Registry Ignore List
config.nomilabs.advanced.ignore_entities=ENTITY Missing Registry Ignore List
Expand Down

0 comments on commit 48d338f

Please sign in to comment.