diff --git a/src/main/java/ru/bclib/BCLibPatch.java b/src/main/java/ru/bclib/BCLibPatch.java index b0a13c9c..8ef4fe24 100644 --- a/src/main/java/ru/bclib/BCLibPatch.java +++ b/src/main/java/ru/bclib/BCLibPatch.java @@ -4,24 +4,22 @@ import net.minecraft.nbt.CompoundTag; import ru.bclib.api.datafixer.DataFixerAPI; import ru.bclib.api.datafixer.ForcedLevelPatch; import ru.bclib.api.datafixer.MigrationProfile; -import ru.bclib.api.datafixer.Patch; -import ru.bclib.config.Configs; -import ru.bclib.interfaces.PatchFunction; - - +import ru.bclib.world.generator.GeneratorOptions; public final class BCLibPatch { public static void register(){ - DataFixerAPI.registerPatch(BiomeSourcePatch::new); - if (Configs.MAIN_CONFIG.repairBiomes()) { - DataFixerAPI.registerPatch(BiomeFixPatch::new); + if (GeneratorOptions.fixBiomeSource()) { + DataFixerAPI.registerPatch(BiomeSourcePatch::new); } } } -final class BiomeFixPatch extends ForcedLevelPatch{ - protected BiomeFixPatch() { - super(BCLib.MOD_ID, "0.5.0"); +final class BiomeSourcePatch extends ForcedLevelPatch{ + private static final String NETHER_BIOME_SOURCE = "bclib:nether_biome_source"; + private static final String END_BIOME_SOURCE = "bclib:end_biome_source"; + + protected BiomeSourcePatch() { + super(BCLib.MOD_ID, "1.2.1"); } @Override @@ -31,89 +29,33 @@ final class BiomeFixPatch extends ForcedLevelPatch{ long seed = worldGenSettings.getLong("seed"); boolean result = false; - if (!dimensions.contains("minecraft:the_nether")) { - BCLib.LOGGER.info("Repairing Nether biome source"); - result = true; - + if (!dimensions.contains("minecraft:the_nether") || !isBCLibEntry(dimensions.getCompound("minecraft:the_nether"))) { CompoundTag dimRoot = new CompoundTag(); - dimRoot.put("generator", BiomeSourcePatch.makeNetherGenerator(seed)); + dimRoot.put("generator", makeNetherGenerator(seed)); dimRoot.putString("type", "minecraft:the_nether"); dimensions.put("minecraft:the_nether", dimRoot); - } else { - result |= BiomeSourcePatch.repairNetherSource(dimensions, seed); + result = true; } - if (!dimensions.contains("minecraft:the_end")) { - BCLib.LOGGER.info("Repairing End biome source"); - result = true; - + if (!dimensions.contains("minecraft:the_end") || !isBCLibEntry(dimensions.getCompound("minecraft:the_end"))) { CompoundTag dimRoot = new CompoundTag(); - dimRoot.put("generator", BiomeSourcePatch.makeEndGenerator(seed)); + dimRoot.put("generator", makeEndGenerator(seed)); dimRoot.putString("type", "minecraft:the_end"); dimensions.put("minecraft:the_end", dimRoot); - } else { - result |= BiomeSourcePatch.repairEndSource(dimensions, seed); - } - - return result; - } -} - -final class BiomeSourcePatch extends Patch { - private static final String NETHER_BIOME_SOURCE = "bclib:nether_biome_source"; - private static final String END_BIOME_SOURCE = "bclib:end_biome_source"; - - protected BiomeSourcePatch() { - super(BCLib.MOD_ID, "0.4.0"); - } - - public PatchFunction getLevelDatPatcher() { - return BiomeSourcePatch::fixBiomeSources; - } - - private static boolean fixBiomeSources(CompoundTag root, MigrationProfile profile) { - CompoundTag worldGenSettings = root.getCompound("Data").getCompound("WorldGenSettings"); - CompoundTag dimensions = worldGenSettings.getCompound("dimensions"); - long seed = worldGenSettings.getLong("seed"); - boolean result = false; - - if (dimensions.contains("minecraft:the_nether")) { - result |= repairNetherSource(dimensions, seed); - } - - if (dimensions.contains("minecraft:the_end")) { - result |= repairEndSource(dimensions, seed); + result = true; } return result; } - public static boolean repairEndSource(CompoundTag dimensions, long seed) { - CompoundTag dimRoot = dimensions.getCompound("minecraft:the_end"); - CompoundTag biomeSource = dimRoot.getCompound("generator").getCompound("biome_source"); - if (!biomeSource.getString("type").equals(END_BIOME_SOURCE)) { - BCLib.LOGGER.info("Applying End biome source patch"); - dimRoot.put("generator", makeEndGenerator(seed)); - return true; + private boolean isBCLibEntry(CompoundTag dimRoot) { + String type = dimRoot.getCompound("generator").getCompound("biome_source").getString("type"); + if (type.isEmpty() || type.length() < 5) { + return false; } - - return false; + return type.substring(0, 5).equals("bclib"); } - public static boolean repairNetherSource(CompoundTag dimensions, long seed) { - CompoundTag dimRoot = dimensions.getCompound("minecraft:the_nether"); - CompoundTag biomeSource = dimRoot.getCompound("generator").getCompound("biome_source"); - if (!biomeSource.getString("type").equals(NETHER_BIOME_SOURCE)) { - BCLib.LOGGER.info("Applying Nether biome source patch"); - dimRoot.put("generator", makeNetherGenerator(seed)); - return true; - } - - return false; - } - - ; - public static CompoundTag makeNetherGenerator(long seed) { CompoundTag generator = new CompoundTag(); generator.putString("type", "minecraft:noise"); diff --git a/src/main/java/ru/bclib/config/MainConfig.java b/src/main/java/ru/bclib/config/MainConfig.java index ab44b1c4..e47c92e0 100644 --- a/src/main/java/ru/bclib/config/MainConfig.java +++ b/src/main/java/ru/bclib/config/MainConfig.java @@ -4,18 +4,8 @@ import ru.bclib.BCLib; public class MainConfig extends NamedPathConfig { public static final ConfigToken APPLY_PATCHES = ConfigToken.Boolean(true, "applyPatches", Configs.MAIN_PATCH_CATEGORY); - @ConfigUI(leftPadding = 8) - public static final ConfigToken REPAIR_BIOMES = DependendConfigToken.Boolean(false, "repairBiomesOnLoad", Configs.MAIN_PATCH_CATEGORY, (config) -> config.get(APPLY_PATCHES)); - public MainConfig() { super(BCLib.MOD_ID, "main", true, true); } - - public boolean applyPatches() { - return get(REPAIR_BIOMES); - } - public boolean repairBiomes() { - return get(REPAIR_BIOMES); - } } diff --git a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java index 77e227b3..7e37a647 100644 --- a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java @@ -19,6 +19,7 @@ public class GeneratorOptions { private static boolean useOldBiomeGenerator = false; private static boolean verticalBiomes = true; private static long farEndBiomesSqr = 1000000; + private static boolean fixBiomeSource = true; public static void init() { biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256); @@ -31,6 +32,7 @@ public class GeneratorOptions { addEndBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addEndBiomesByCategory", false); useOldBiomeGenerator = Configs.GENERATOR_CONFIG.useOldGenerator(); verticalBiomes = Configs.GENERATOR_CONFIG.getBoolean("options", "verticalBiomesInTallNether", true); + fixBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "fixBiomeSource", true); } public static int getBiomeSizeNether() { @@ -100,4 +102,8 @@ public class GeneratorOptions { public static boolean useVerticalBiomes() { return verticalBiomes; } + + public static boolean fixBiomeSource() { + return fixBiomeSource; + } }