From 55f709312da8dc82d3bf699fbb45c2d414055615 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 16 Dec 2018 12:32:57 +0300 Subject: [PATCH 01/17] External generator settings --- .../cubicchunks/cubicgen/CustomCubicMod.java | 8 ++ .../asm/mixin/common/MixinWorldInfo.java | 80 +++++++++++++++++++ src/main/resources/cubicgen.mixins.json | 1 + 3 files changed, 89 insertions(+) create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java index d09d94a..3bd21c6 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java @@ -44,6 +44,7 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.populator.TaigaDecorator; import io.github.opencubicchunks.cubicchunks.cubicgen.flat.FlatCubicWorldType; import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.BiomeBeach; @@ -69,6 +70,7 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.ForgeRegistries; import org.apache.logging.log4j.Logger; @@ -93,6 +95,7 @@ public class CustomCubicMod { public static final int FIXER_VERSION = 2; public static final boolean DEBUG_ENABLED = false; public static Logger LOGGER = null; + public static MinecraftServer SERVER = null; @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { @@ -112,6 +115,11 @@ public void preInit(FMLPreInitializationEvent e) { public void preInit(FMLPostInitializationEvent e) { CubicBiome.postInit(); } + + @Mod.EventHandler + public void serverStart(FMLServerAboutToStartEvent event) { + SERVER = event.getServer(); + } @SubscribeEvent public static void registerRegistries(RegistryEvent.NewRegistry evt) { diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java new file mode 100644 index 0000000..8166381 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java @@ -0,0 +1,80 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.asm.mixin.common; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.nio.CharBuffer; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomCubicWorldType; +import net.minecraft.world.WorldType; +import net.minecraft.world.storage.SaveFormatOld; +import net.minecraft.world.storage.WorldInfo; + +@Mixin(WorldInfo.class) +public class MixinWorldInfo { + + @Shadow + private String levelName; + @Shadow + private WorldType terrainType; + + @Inject(method = "getGeneratorOptions", at = @At("HEAD"), cancellable = true) + private void getGeneratorOptionsFromExternalFile(CallbackInfoReturnable cbir) { + if (!(terrainType instanceof CustomCubicWorldType)) + return; + if(levelName.equals("MpServer")) + return; + if (CustomCubicMod.SERVER == null) + throw new NullPointerException("Server is null"); + File externalGeneratorPresetFile = new File(((SaveFormatOld) CustomCubicMod.SERVER.getActiveAnvilConverter()).savesDirectory, + levelName + "/data/" + CustomCubicMod.MODID + "/custom_generator_settings.json"); + if (!externalGeneratorPresetFile.exists()) { + CustomCubicMod.LOGGER.info("No settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + CustomCubicMod.LOGGER.info("Loading settings from 'level.dat'"); + return; + } + try { + FileReader reader = new FileReader(externalGeneratorPresetFile); + CharBuffer sb = CharBuffer.allocate(Short.MAX_VALUE << 3); + reader.read(sb); + sb.flip(); + cbir.setReturnValue(sb.toString()); + cbir.cancel(); + reader.close(); + CustomCubicMod.LOGGER.info("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/cubicgen.mixins.json b/src/main/resources/cubicgen.mixins.json index 6a990cd..ae99b42 100644 --- a/src/main/resources/cubicgen.mixins.json +++ b/src/main/resources/cubicgen.mixins.json @@ -6,6 +6,7 @@ "minVersion": "0.6.15-SNAPSHOT", "plugin": "io.github.opencubicchunks.cubicchunks.cubicgen.asm.CubicGenMixinConfig", "mixins": [ + "common.MixinWorldInfo", "common.structuregen.MixinStructureStart", "common.extras.FarLands" ], From 4d76206e4c658223fcee1c75682cce4bc59cc896 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 16 Dec 2018 14:06:35 +0300 Subject: [PATCH 02/17] No mixin --- .../cubicchunks/cubicgen/CustomCubicMod.java | 8 -- .../asm/mixin/common/MixinWorldInfo.java | 80 ------------------- .../customcubic/CustomCubicWorldType.java | 3 +- .../customcubic/CustomGeneratorSettings.java | 33 ++++++++ .../customcubic/CustomTerrainGenerator.java | 2 +- .../customcubic/gui/CustomCubicGui.java | 25 +++++- .../META-INF/cubicchunks_cubicgen_at.cfg | 1 + src/main/resources/cubicgen.mixins.json | 1 - 8 files changed, 60 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java index 3bd21c6..99fc22d 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java @@ -44,7 +44,6 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.populator.TaigaDecorator; import io.github.opencubicchunks.cubicchunks.cubicgen.flat.FlatCubicWorldType; import mcp.MethodsReturnNonnullByDefault; -import net.minecraft.server.MinecraftServer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.BiomeBeach; @@ -70,7 +69,6 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.ForgeRegistries; import org.apache.logging.log4j.Logger; @@ -95,7 +93,6 @@ public class CustomCubicMod { public static final int FIXER_VERSION = 2; public static final boolean DEBUG_ENABLED = false; public static Logger LOGGER = null; - public static MinecraftServer SERVER = null; @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { @@ -116,11 +113,6 @@ public void preInit(FMLPostInitializationEvent e) { CubicBiome.postInit(); } - @Mod.EventHandler - public void serverStart(FMLServerAboutToStartEvent event) { - SERVER = event.getServer(); - } - @SubscribeEvent public static void registerRegistries(RegistryEvent.NewRegistry evt) { CubicBiome.init(); diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java deleted file mode 100644 index 8166381..0000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/asm/mixin/common/MixinWorldInfo.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of Cubic World Generation, licensed under the MIT License (MIT). - * - * Copyright (c) 2015 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.github.opencubicchunks.cubicchunks.cubicgen.asm.mixin.common; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.nio.CharBuffer; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod; -import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomCubicWorldType; -import net.minecraft.world.WorldType; -import net.minecraft.world.storage.SaveFormatOld; -import net.minecraft.world.storage.WorldInfo; - -@Mixin(WorldInfo.class) -public class MixinWorldInfo { - - @Shadow - private String levelName; - @Shadow - private WorldType terrainType; - - @Inject(method = "getGeneratorOptions", at = @At("HEAD"), cancellable = true) - private void getGeneratorOptionsFromExternalFile(CallbackInfoReturnable cbir) { - if (!(terrainType instanceof CustomCubicWorldType)) - return; - if(levelName.equals("MpServer")) - return; - if (CustomCubicMod.SERVER == null) - throw new NullPointerException("Server is null"); - File externalGeneratorPresetFile = new File(((SaveFormatOld) CustomCubicMod.SERVER.getActiveAnvilConverter()).savesDirectory, - levelName + "/data/" + CustomCubicMod.MODID + "/custom_generator_settings.json"); - if (!externalGeneratorPresetFile.exists()) { - CustomCubicMod.LOGGER.info("No settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); - CustomCubicMod.LOGGER.info("Loading settings from 'level.dat'"); - return; - } - try { - FileReader reader = new FileReader(externalGeneratorPresetFile); - CharBuffer sb = CharBuffer.allocate(Short.MAX_VALUE << 3); - reader.read(sb); - sb.flip(); - cbir.setReturnValue(sb.toString()); - cbir.cancel(); - reader.close(); - CustomCubicMod.LOGGER.info("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java index 7ebe582..cbf2cb1 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java @@ -65,8 +65,7 @@ public static CustomCubicWorldType create() { } @Override public IntRange calculateGenerationHeightRange(WorldServer world) { - String string = world.getWorldInfo().getGeneratorOptions(); - CustomGeneratorSettings opts = CustomGeneratorSettings.fromJson(string); + CustomGeneratorSettings opts = CustomGeneratorSettings.load(world); // TODO: better handling of min height return new IntRange(0, (int) opts.actualHeight); } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 5578fbb..dc03b2e 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -56,14 +56,21 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.datafix.FixTypes; import net.minecraft.util.datafix.IFixableData; +import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.ChunkGeneratorSettings; +import net.minecraft.world.storage.SaveFormatOld; import net.minecraftforge.common.util.ModFixs; import net.minecraftforge.fml.common.registry.ForgeRegistries; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Field; import java.lang.reflect.Type; +import java.nio.CharBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -197,6 +204,32 @@ public static CustomGeneratorSettings fromJson(String json) { Gson gson = gson(true); // minimize option shouldn't matter when deserializing return gson.fromJson(json, CustomGeneratorSettings.class); } + + public static CustomGeneratorSettings load(World world) { + File externalGeneratorPresetFile = new File(world.getSaveHandler().getWorldDirectory(), + "/data/" + CustomCubicMod.MODID + "/custom_generator_settings.json"); + String jsonString = null; + if (externalGeneratorPresetFile.exists()) { + try { + FileReader reader = new FileReader(externalGeneratorPresetFile); + CharBuffer sb = CharBuffer.allocate(Short.MAX_VALUE << 3); + reader.read(sb); + sb.flip(); + jsonString = sb.toString(); + reader.close(); + CustomCubicMod.LOGGER.info("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); + } + } + else { + CustomCubicMod.LOGGER.info("No settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + CustomCubicMod.LOGGER.info("Loading settings from 'level.dat'"); + // Use old format to keep backward-compatibility + jsonString = world.getWorldInfo().getGeneratorOptions(); + } + return fromJson(jsonString); + } public static CustomGeneratorSettings defaults() { CustomGeneratorSettings settings = new CustomGeneratorSettings(); diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomTerrainGenerator.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomTerrainGenerator.java index db8137e..22bea6b 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomTerrainGenerator.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomTerrainGenerator.java @@ -92,7 +92,7 @@ public class CustomTerrainGenerator extends BasicCubeGenerator { @Nonnull private CubicFeatureGenerator strongholds; public CustomTerrainGenerator(World world, final long seed) { - this(world, CustomGeneratorSettings.fromJson(world.getWorldInfo().getGeneratorOptions()), seed); + this(world, CustomGeneratorSettings.load(world), seed); } public CustomTerrainGenerator(World world, CustomGeneratorSettings settings, final long seed) { diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java index 53b1c13..f59c0b1 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java @@ -51,10 +51,17 @@ import net.malisis.core.client.gui.component.interaction.UITextField; import net.malisis.core.client.gui.event.ComponentEvent; import net.malisis.core.renderer.font.FontOptions; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiCreateWorld; import net.minecraft.client.resources.I18n; import net.minecraft.util.ResourceLocation; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Map; import javax.annotation.ParametersAreNonnullByDefault; @@ -252,7 +259,23 @@ public void onClick(UIButton.ClickEvent evt) { } private void done() { - parent.chunkProviderSettingsJson = getSettingsJson(getConfig(), true); + String settingsJsonString = getSettingsJson(getConfig(), true); + File folder = new File(Minecraft.getMinecraft().mcDataDir, parent.saveDirName + "/data/" + CustomCubicMod.MODID +"/"); + try { + File settingsFile = new File(folder, "custom_generator_settings.json"); + settingsFile.mkdirs(); + FileWriter writer = new FileWriter(settingsFile); + writer.write(settingsJsonString); + writer.close(); + if(settingsFile.exists()) + CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); + else + CustomCubicMod.LOGGER.error("Error creating file at " + settingsFile.getAbsolutePath()); + } catch (IOException e) { + CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); + e.printStackTrace(); + } + parent.chunkProviderSettingsJson = settingsJsonString; this.mc.displayGuiScreen(parent); } diff --git a/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg b/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg index 3e8e116..57ed0e1 100644 --- a/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg +++ b/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg @@ -1,5 +1,6 @@ public net.minecraft.world.biome.BiomeProvider field_76944_d # genBiomes public net.minecraft.world.biome.BiomeProvider field_76945_e # biomeIndexLayer +public net.minecraft.client.gui.GuiCreateWorld field_146336_i # saveDirName # used by cubic chunks biome populators public net.minecraft.world.biome.Biome field_180281_af # GRASS_COLOR_NOISE diff --git a/src/main/resources/cubicgen.mixins.json b/src/main/resources/cubicgen.mixins.json index ae99b42..6a990cd 100644 --- a/src/main/resources/cubicgen.mixins.json +++ b/src/main/resources/cubicgen.mixins.json @@ -6,7 +6,6 @@ "minVersion": "0.6.15-SNAPSHOT", "plugin": "io.github.opencubicchunks.cubicchunks.cubicgen.asm.CubicGenMixinConfig", "mixins": [ - "common.MixinWorldInfo", "common.structuregen.MixinStructureStart", "common.extras.FarLands" ], From e7a596ab0f79997002e324ef9fa3005a02784d2d Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 16 Dec 2018 16:39:45 +0300 Subject: [PATCH 03/17] Data fixes --- .../cubicchunks/cubicgen/CustomCubicMod.java | 3 - .../customcubic/CustomGeneratorSettings.java | 421 +++++++++--------- .../customcubic/gui/CustomCubicGui.java | 16 +- 3 files changed, 205 insertions(+), 235 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java index 99fc22d..5dbe0ef 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java @@ -103,9 +103,6 @@ public void preInit(FMLPreInitializationEvent e) { CustomCubicWorldType.create(); DebugWorldType.create(); - - ModFixs fixes = FMLCommonHandler.instance().getDataFixer().init(MODID, FIXER_VERSION); - CustomGeneratorSettings.registerDataFixers(fixes); } @Mod.EventHandler diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index dc03b2e..bc5f851 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -47,6 +47,7 @@ import net.minecraft.block.BlockSilverfish; import net.minecraft.block.BlockStone; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.init.Biomes; import net.minecraft.init.Blocks; import net.minecraft.nbt.JsonToNBT; @@ -66,6 +67,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Field; @@ -181,6 +183,7 @@ public class CustomGeneratorSettings { public BiomeBlockReplacerConfig replacerConfig = BiomeBlockReplacerConfig.defaults(); // TODO: public boolean negativeHeightVariationInvertsTerrain = true; + public int version = 3; public CustomGeneratorSettings() { } @@ -209,6 +212,7 @@ public static CustomGeneratorSettings load(World world) { File externalGeneratorPresetFile = new File(world.getSaveHandler().getWorldDirectory(), "/data/" + CustomCubicMod.MODID + "/custom_generator_settings.json"); String jsonString = null; + CustomGeneratorSettings settings = null; if (externalGeneratorPresetFile.exists()) { try { FileReader reader = new FileReader(externalGeneratorPresetFile); @@ -218,6 +222,7 @@ public static CustomGeneratorSettings load(World world) { jsonString = sb.toString(); reader.close(); CustomCubicMod.LOGGER.info("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + settings = fromJson(jsonString); } catch (IOException e) { e.printStackTrace(); } @@ -227,8 +232,29 @@ public static CustomGeneratorSettings load(World world) { CustomCubicMod.LOGGER.info("Loading settings from 'level.dat'"); // Use old format to keep backward-compatibility jsonString = world.getWorldInfo().getGeneratorOptions(); + jsonString = fixGeneratorOptionsIfNecessary(jsonString); + settings = fromJson(jsonString); + settings.save(world.getSaveHandler().getWorldDirectory()); + } + return settings; + } + + public void save(File worldSaveFolder) { + File folder = new File(worldSaveFolder, "/data/" + CustomCubicMod.MODID +"/"); + try { + folder.mkdirs(); + File settingsFile = new File(folder, "custom_generator_settings.json"); + FileWriter writer = new FileWriter(settingsFile); + writer.write(this.toJson(true)); + writer.close(); + if(settingsFile.exists()) + CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); + else + CustomCubicMod.LOGGER.error("Error creating file at " + settingsFile.getAbsolutePath()); + } catch (IOException e) { + CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); + e.printStackTrace(); } - return fromJson(jsonString); } public static CustomGeneratorSettings defaults() { @@ -334,237 +360,198 @@ public static CustomGeneratorSettings fromVanilla(ChunkGeneratorSettings setting return obj; } - - public static void registerDataFixers(ModFixs fixes) { - // TODO: redo data fixers - - fixes.registerFix(FixTypes.LEVEL, new IFixableData() { - @Override public int getFixVersion() { - return 0; - } - - @Override public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (!compound.getString("generatorName").equals("CustomCubic")) { - return compound; - } - String generatorOptions = compound.getString("generatorOptions"); - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(false); - } - Gson gson = gson(false); - - JsonReader reader = new JsonReader(new StringReader(generatorOptions)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - - // some old saves are broken, especially 1.11.2 ones from the 1.12.2->1.11.2 backport, build 847 - // this preserves the existing ores - JsonArray standardOres = - root.has("standardOres") ? root.getAsJsonArray("standardOres") : new JsonArray(); - JsonArray periodicGaussianOres = - root.has("periodicGaussianOres") ? - root.getAsJsonArray("periodicGaussianOres") : new JsonArray(); - - - // kind of ugly but I don'twant to make a special class just so store these 3 objects... - String[] standard = { - "dirt", - "gravel", - "granite", - "diorite", - "andesite", - "coalOre", - "ironOre", - "goldOre", - "redstoneOre", - "diamondOre", - "hillsEmeraldOre", - "hillsSilverfishStone", - "mesaAddedGoldOre" - }; - IBlockState[] standardBlockstates = { - Blocks.DIRT.getDefaultState(), - Blocks.GRAVEL.getDefaultState(), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), - Blocks.COAL_ORE.getDefaultState(), - Blocks.IRON_ORE.getDefaultState(), - Blocks.GOLD_ORE.getDefaultState(), - Blocks.REDSTONE_ORE.getDefaultState(), - Blocks.DIAMOND_ORE.getDefaultState(), - Blocks.EMERALD_ORE.getDefaultState(), - Blocks.MONSTER_EGG.getDefaultState().withProperty(BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), - Blocks.GOLD_ORE.getDefaultState() - }; - Biome[][] standardBiomes = { - null, // dirt - null, // gravel - null, // granite - null, // diorite - null, // andesite - null, // coal - null, // iron - null, // gold - null, // redstone - null, // diamond - {Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.MUTATED_EXTREME_HILLS, - Biomes.MUTATED_EXTREME_HILLS_WITH_TREES},//emerald - {Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.MUTATED_EXTREME_HILLS, - Biomes.MUTATED_EXTREME_HILLS_WITH_TREES},//monster egg - {Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, Biomes.MUTATED_MESA_CLEAR_ROCK, - Biomes.MUTATED_MESA_ROCK},//mesa gold - }; - for (int i = 0; i < standard.length; i++) { - JsonObject obj = convertStandardOre(gson, root, standard[i], standardBlockstates[i], standardBiomes[i]); - if (obj != null) { - standardOres.add(obj); - } - - } - JsonObject lapis = convertGaussianPeriodicOre(gson, root, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), null); - if (lapis != null) { - periodicGaussianOres.add(lapis); - } - root.add("standardOres", standardOres); - root.add("periodicGaussianOres", periodicGaussianOres); - compound.setString("generatorOptions", gson.toJson(root)); - return compound; + + public static String fixGeneratorOptionsIfNecessary(String generatorOptions) { + if (generatorOptions.isEmpty()) { + generatorOptions = new CustomGeneratorSettings().toJson(false); + } + JsonReader reader = new JsonReader(new StringReader(generatorOptions)); + JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); + if(!root.has("version") ||root.get("version").getAsInt()<3) { + generatorOptions = fixGeneratorOptionsVersion0(generatorOptions); + generatorOptions = fixGeneratorOptionsVersion1(generatorOptions); + generatorOptions = fixGeneratorOptionsVersion3(generatorOptions); + } + + return generatorOptions; + } + + public static String fixGeneratorOptionsVersion0(String generatorOptions) { + if (generatorOptions.isEmpty()) { + generatorOptions = new CustomGeneratorSettings().toJson(false); + } + Gson gson = gson(false); + + JsonReader reader = new JsonReader(new StringReader(generatorOptions)); + JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); + + // some old saves are broken, especially 1.11.2 ones from the + // 1.12.2->1.11.2 backport, build 847 + // this preserves the existing ores + JsonArray standardOres = root.has("standardOres") ? root.getAsJsonArray("standardOres") : new JsonArray(); + JsonArray periodicGaussianOres = root.has("periodicGaussianOres") ? root.getAsJsonArray("periodicGaussianOres") + : new JsonArray(); + + // kind of ugly but I don'twant to make a special class just so store + // these 3 objects... + String[] standard = { "dirt", "gravel", "granite", "diorite", "andesite", "coalOre", "ironOre", "goldOre", + "redstoneOre", "diamondOre", "hillsEmeraldOre", "hillsSilverfishStone", "mesaAddedGoldOre" }; + IBlockState[] standardBlockstates = { Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState(), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), + Blocks.COAL_ORE.getDefaultState(), Blocks.IRON_ORE.getDefaultState(), Blocks.GOLD_ORE.getDefaultState(), + Blocks.REDSTONE_ORE.getDefaultState(), Blocks.DIAMOND_ORE.getDefaultState(), + Blocks.EMERALD_ORE.getDefaultState(), Blocks.MONSTER_EGG.getDefaultState().withProperty( + BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), + Blocks.GOLD_ORE.getDefaultState() }; + Biome[][] standardBiomes = { null, // dirt + null, // gravel + null, // granite + null, // diorite + null, // andesite + null, // coal + null, // iron + null, // gold + null, // redstone + null, // diamond + { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, + Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // emerald + { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, + Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // monster + // egg + { Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, + Biomes.MUTATED_MESA_CLEAR_ROCK, Biomes.MUTATED_MESA_ROCK },// mesa + // gold + }; + for (int i = 0; i < standard.length; i++) { + JsonObject obj = convertStandardOre(gson, root, standard[i], standardBlockstates[i], standardBiomes[i]); + if (obj != null) { + standardOres.add(obj); } - private JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { - if (!root.has(ore + "SpawnTries")) { - // some old saves are broken, especially 1.11.2 ones from the 1.12.2->1.11.2 backport, build 847 - // this avoids adding a lot of air ores - return null; - } + } + JsonObject lapis = convertGaussianPeriodicOre(gson, root, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), + null); + if (lapis != null) { + periodicGaussianOres.add(lapis); + } + root.add("standardOres", standardOres); + root.add("periodicGaussianOres", periodicGaussianOres); + return gson.toJson(root); + } - JsonObject obj = new JsonObject(); - obj.add("blockstate", gson.toJsonTree(state)); - if (biomes != null) { - obj.add("biomes", gson.toJsonTree(biomes)); - } - if (root.has(ore + "SpawnSize")) { - obj.add("spawnSize", root.remove(ore + "SpawnSize")); - } else { - // emerald doesn't have size defined in the old format - obj.add("spawnSize", new JsonPrimitive(3)); - } - obj.add("spawnTries", root.remove(ore + "SpawnTries")); - obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); - obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); - obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); - return obj; - } + private static JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { + if (!root.has(ore + "SpawnTries")) { + // some old saves are broken, especially 1.11.2 ones from the + // 1.12.2->1.11.2 backport, build 847 + // this avoids adding a lot of air ores + return null; + } - private JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { - JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); - if (obj == null) { - return null; - } - obj.add("heightMean", root.remove(ore + "HeightMean")); - obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); - obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); - return obj; - } - }); + JsonObject obj = new JsonObject(); + obj.add("blockstate", gson.toJsonTree(state)); + if (biomes != null) { + obj.add("biomes", gson.toJsonTree(biomes)); + } + if (root.has(ore + "SpawnSize")) { + obj.add("spawnSize", root.remove(ore + "SpawnSize")); + } else { + // emerald doesn't have size defined in the old format + obj.add("spawnSize", new JsonPrimitive(3)); + } + obj.add("spawnTries", root.remove(ore + "SpawnTries")); + obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); + obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); + obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); + return obj; + } - fixes.registerFix(FixTypes.LEVEL, new IFixableData() { - @Override public int getFixVersion() { - return 1; - } + private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, + Biome[] biomes) { + JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); + if (obj == null) { + return null; + } + obj.add("heightMean", root.remove(ore + "HeightMean")); + obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); + obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); + return obj; + } - @Override public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (!compound.getString("generatorName").equals("CustomCubic")) { - return compound; - } - String generatorOptions = compound.getString("generatorOptions"); - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(false); - } - Gson gson = gson(false); + public static String fixGeneratorOptionsVersion1(String generatorOptions) { + if (generatorOptions.isEmpty()) { + generatorOptions = new CustomGeneratorSettings().toJson(false); + } + Gson gson = gson(false); - JsonReader reader = new JsonReader(new StringReader(generatorOptions)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); + JsonReader reader = new JsonReader(new StringReader(generatorOptions)); + JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - float heightVariationOffset = root.get("heightVariationOffset").getAsFloat(); - float offset = root.get("heightOffset").getAsFloat(); - float factor = root.get("heightFactor").getAsFloat(); - if (!root.has("expectedBaseHeight")) { - root.add("expectedBaseHeight", root.get("heightOffset")); - } - if (!root.has("expectedHeightVariation")) { - root.add("expectedHeightVariation", root.get("heightFactor")); - } - if (!root.has("actualHeight")) { - root.add("actualHeight", new JsonPrimitive( - (offset + heightVariationOffset + - Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)) - )); - } - if (!root.has("cubeAreas")) { - root.add("cubeAreas", new JsonObject()); - } - if (!root.has("replacerConfig")) { - JsonObject replacerConf = new JsonObject(); + float heightVariationOffset = root.get("heightVariationOffset").getAsFloat(); + float offset = root.get("heightOffset").getAsFloat(); + float factor = root.get("heightFactor").getAsFloat(); + if (!root.has("expectedBaseHeight")) { + root.add("expectedBaseHeight", root.get("heightOffset")); + } + if (!root.has("expectedHeightVariation")) { + root.add("expectedHeightVariation", root.get("heightFactor")); + } + if (!root.has("actualHeight")) { + root.add("actualHeight", new JsonPrimitive((offset + heightVariationOffset + + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); + } + if (!root.has("cubeAreas")) { + root.add("cubeAreas", new JsonObject()); + } + if (!root.has("replacerConfig")) { + JsonObject replacerConf = new JsonObject(); + { + JsonObject defaults = new JsonObject(); + { + defaults.add(MODID + ":horizontal_gradient_depth_decrease_weight", new JsonPrimitive(1.0f)); + defaults.add(MODID + ":height_offset", new JsonPrimitive(offset)); + JsonObject terrainfill = new JsonObject(); { - JsonObject defaults = new JsonObject(); - { - defaults.add(MODID + ":horizontal_gradient_depth_decrease_weight", new JsonPrimitive(1.0f)); - defaults.add(MODID + ":height_offset", new JsonPrimitive(offset)); - JsonObject terrainfill = new JsonObject(); - { - JsonObject properties = new JsonObject(); - properties.add("variant", new JsonPrimitive("stone")); - terrainfill.add("Properties", properties); - terrainfill.add("Name", new JsonPrimitive("minecraft:stone")); - } - JsonObject oceanblock = new JsonObject(); - - { - JsonObject properties = new JsonObject(); - properties.add("level", new JsonPrimitive("0")); - oceanblock.add("Properties", properties); - oceanblock.add("Name", new JsonPrimitive("minecraft:water")); - } - defaults.add(MODID + ":biome_fill_depth_offset", new JsonPrimitive(3.0f)); - defaults.add(MODID + ":biome_fill_noise_octaves", new JsonPrimitive(4.0f)); - defaults.add(MODID + ":height_scale", new JsonPrimitive(factor)); - defaults.add(MODID + ":biome_fill_depth_factor", new JsonPrimitive(2.3333333333333335f)); - defaults.add(MODID + ":mesa_depth", new JsonPrimitive(16.0f)); - defaults.add(MODID + ":water_level", root.get("waterLevel")); - defaults.add(MODID + ":biome_fill_noise_freq", new JsonPrimitive(0.0078125f)); - } - replacerConf.add("defaults", defaults); - replacerConf.add("overrides", new JsonObject()); + JsonObject properties = new JsonObject(); + properties.add("variant", new JsonPrimitive("stone")); + terrainfill.add("Properties", properties); + terrainfill.add("Name", new JsonPrimitive("minecraft:stone")); } + JsonObject oceanblock = new JsonObject(); - root.add("replacerConfig", replacerConf); + { + JsonObject properties = new JsonObject(); + properties.add("level", new JsonPrimitive("0")); + oceanblock.add("Properties", properties); + oceanblock.add("Name", new JsonPrimitive("minecraft:water")); + } + defaults.add(MODID + ":biome_fill_depth_offset", new JsonPrimitive(3.0f)); + defaults.add(MODID + ":biome_fill_noise_octaves", new JsonPrimitive(4.0f)); + defaults.add(MODID + ":height_scale", new JsonPrimitive(factor)); + defaults.add(MODID + ":biome_fill_depth_factor", new JsonPrimitive(2.3333333333333335f)); + defaults.add(MODID + ":mesa_depth", new JsonPrimitive(16.0f)); + defaults.add(MODID + ":water_level", root.get("waterLevel")); + defaults.add(MODID + ":biome_fill_noise_freq", new JsonPrimitive(0.0078125f)); } - compound.setString("generatorOptions", gson.toJson(root)); - return compound; + replacerConf.add("defaults", defaults); + replacerConf.add("overrides", new JsonObject()); } - }); - - fixes.registerFix(FixTypes.LEVEL, new IFixableData() { - @Override public int getFixVersion() { - return 2; - } + root.add("replacerConfig", replacerConf); + } + return gson.toJson(root); + } - @Override public NBTTagCompound fixTagCompound(NBTTagCompound compound) { - if (!compound.getString("generatorName").equals("CustomCubic")) { - return compound; - } - String generatorOptions = compound.getString("generatorOptions"); - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(true); - } - // this is far simpler that walking through the json and figurring out all the places where it occurs - // instead, just do string search and replace. The string shouldn't occur in any other context - compound.setString("generatorOptions", generatorOptions.replaceAll(MODID + ":", MODID + ":")); - return compound; - } - }); + public static String fixGeneratorOptionsVersion3(String generatorOptions) { + if (generatorOptions.isEmpty()) { + generatorOptions = new CustomGeneratorSettings().toJson(true); + } + // this is far simpler that walking through the json and figurring out + // all the places where it occurs + // instead, just do string search and replace. The string shouldn't + // occur in any other context + return generatorOptions.replaceAll(MODID + ":", MODID + ":"); } public static Gson gson(boolean minimize) { diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java index f59c0b1..d19a327 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java @@ -259,22 +259,8 @@ public void onClick(UIButton.ClickEvent evt) { } private void done() { + getConfig().save(new File(Minecraft.getMinecraft().mcDataDir, "saves/"+parent.saveDirName+"/")); String settingsJsonString = getSettingsJson(getConfig(), true); - File folder = new File(Minecraft.getMinecraft().mcDataDir, parent.saveDirName + "/data/" + CustomCubicMod.MODID +"/"); - try { - File settingsFile = new File(folder, "custom_generator_settings.json"); - settingsFile.mkdirs(); - FileWriter writer = new FileWriter(settingsFile); - writer.write(settingsJsonString); - writer.close(); - if(settingsFile.exists()) - CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); - else - CustomCubicMod.LOGGER.error("Error creating file at " + settingsFile.getAbsolutePath()); - } catch (IOException e) { - CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); - e.printStackTrace(); - } parent.chunkProviderSettingsJson = settingsJsonString; this.mc.displayGuiScreen(parent); } From ffdac8d2c42c83ccb8897372703a8f5908b59dc6 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 16 Dec 2018 17:54:39 +0300 Subject: [PATCH 04/17] Simplify fixes --- .../customcubic/CustomCubicWorldType.java | 7 + .../customcubic/CustomGeneratorSettings.java | 212 +++--------------- .../customcubic/gui/CustomCubicGui.java | 13 +- 3 files changed, 50 insertions(+), 182 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java index cbf2cb1..accfdda 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java @@ -47,6 +47,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; @@ -93,6 +94,12 @@ public ICubeGenerator createCubeGenerator(World world) { public boolean isCustomizable() { return true; } + + @Override + public void onGUICreateWorldPress() { + GuiCreateWorld gui = (GuiCreateWorld) Minecraft.getMinecraft().currentScreen; + CustomGeneratorSettings.fromJson(CustomCubicGui.settingsJsonString).save(new File(Minecraft.getMinecraft().mcDataDir, "saves/"+gui.saveDirName+"/")); + } @SideOnly(Side.CLIENT) public void onCustomizeButton(Minecraft mc, GuiCreateWorld guiCreateWorld) { diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index bc5f851..9d170c5 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -79,6 +79,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import javax.annotation.Nullable; @@ -214,18 +215,25 @@ public static CustomGeneratorSettings load(World world) { String jsonString = null; CustomGeneratorSettings settings = null; if (externalGeneratorPresetFile.exists()) { + FileReader reader = null; try { - FileReader reader = new FileReader(externalGeneratorPresetFile); + reader = new FileReader(externalGeneratorPresetFile); CharBuffer sb = CharBuffer.allocate(Short.MAX_VALUE << 3); reader.read(sb); sb.flip(); jsonString = sb.toString(); - reader.close(); CustomCubicMod.LOGGER.info("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); settings = fromJson(jsonString); } catch (IOException e) { e.printStackTrace(); } + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } else { CustomCubicMod.LOGGER.info("No settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); @@ -241,12 +249,12 @@ public static CustomGeneratorSettings load(World world) { public void save(File worldSaveFolder) { File folder = new File(worldSaveFolder, "/data/" + CustomCubicMod.MODID +"/"); + FileWriter writer = null; try { folder.mkdirs(); File settingsFile = new File(folder, "custom_generator_settings.json"); - FileWriter writer = new FileWriter(settingsFile); + writer = new FileWriter(settingsFile); writer.write(this.toJson(true)); - writer.close(); if(settingsFile.exists()) CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); else @@ -255,6 +263,13 @@ public void save(File worldSaveFolder) { CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); e.printStackTrace(); } + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } public static CustomGeneratorSettings defaults() { @@ -367,191 +382,30 @@ public static String fixGeneratorOptionsIfNecessary(String generatorOptions) { } JsonReader reader = new JsonReader(new StringReader(generatorOptions)); JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - if(!root.has("version") ||root.get("version").getAsInt()<3) { - generatorOptions = fixGeneratorOptionsVersion0(generatorOptions); - generatorOptions = fixGeneratorOptionsVersion1(generatorOptions); - generatorOptions = fixGeneratorOptionsVersion3(generatorOptions); + if (!root.has("version") || root.get("version").getAsInt() < 3) { + generatorOptions = fixGeneratorOptions(generatorOptions); } - return generatorOptions; } - - public static String fixGeneratorOptionsVersion0(String generatorOptions) { - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(false); - } - Gson gson = gson(false); - - JsonReader reader = new JsonReader(new StringReader(generatorOptions)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - - // some old saves are broken, especially 1.11.2 ones from the - // 1.12.2->1.11.2 backport, build 847 - // this preserves the existing ores - JsonArray standardOres = root.has("standardOres") ? root.getAsJsonArray("standardOres") : new JsonArray(); - JsonArray periodicGaussianOres = root.has("periodicGaussianOres") ? root.getAsJsonArray("periodicGaussianOres") - : new JsonArray(); - - // kind of ugly but I don'twant to make a special class just so store - // these 3 objects... - String[] standard = { "dirt", "gravel", "granite", "diorite", "andesite", "coalOre", "ironOre", "goldOre", - "redstoneOre", "diamondOre", "hillsEmeraldOre", "hillsSilverfishStone", "mesaAddedGoldOre" }; - IBlockState[] standardBlockstates = { Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState(), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), - Blocks.COAL_ORE.getDefaultState(), Blocks.IRON_ORE.getDefaultState(), Blocks.GOLD_ORE.getDefaultState(), - Blocks.REDSTONE_ORE.getDefaultState(), Blocks.DIAMOND_ORE.getDefaultState(), - Blocks.EMERALD_ORE.getDefaultState(), Blocks.MONSTER_EGG.getDefaultState().withProperty( - BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), - Blocks.GOLD_ORE.getDefaultState() }; - Biome[][] standardBiomes = { null, // dirt - null, // gravel - null, // granite - null, // diorite - null, // andesite - null, // coal - null, // iron - null, // gold - null, // redstone - null, // diamond - { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, - Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // emerald - { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, - Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // monster - // egg - { Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, - Biomes.MUTATED_MESA_CLEAR_ROCK, Biomes.MUTATED_MESA_ROCK },// mesa - // gold - }; - for (int i = 0; i < standard.length; i++) { - JsonObject obj = convertStandardOre(gson, root, standard[i], standardBlockstates[i], standardBiomes[i]); - if (obj != null) { - standardOres.add(obj); - } - - } - JsonObject lapis = convertGaussianPeriodicOre(gson, root, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), - null); - if (lapis != null) { - periodicGaussianOres.add(lapis); - } - root.add("standardOres", standardOres); - root.add("periodicGaussianOres", periodicGaussianOres); - return gson.toJson(root); - } - - private static JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { - if (!root.has(ore + "SpawnTries")) { - // some old saves are broken, especially 1.11.2 ones from the - // 1.12.2->1.11.2 backport, build 847 - // this avoids adding a lot of air ores - return null; - } - JsonObject obj = new JsonObject(); - obj.add("blockstate", gson.toJsonTree(state)); - if (biomes != null) { - obj.add("biomes", gson.toJsonTree(biomes)); - } - if (root.has(ore + "SpawnSize")) { - obj.add("spawnSize", root.remove(ore + "SpawnSize")); - } else { - // emerald doesn't have size defined in the old format - obj.add("spawnSize", new JsonPrimitive(3)); - } - obj.add("spawnTries", root.remove(ore + "SpawnTries")); - obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); - obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); - obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); - return obj; - } - - private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, - Biome[] biomes) { - JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); - if (obj == null) { - return null; - } - obj.add("heightMean", root.remove(ore + "HeightMean")); - obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); - obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); - return obj; - } - - public static String fixGeneratorOptionsVersion1(String generatorOptions) { - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(false); - } + public static String fixGeneratorOptions(String generatorOptionsToFix) { + generatorOptionsToFix = generatorOptionsToFix.replaceAll("cubicchunks:", MODID + ":"); + String newGeneratorOptions = new CustomGeneratorSettings().toJson(true); Gson gson = gson(false); + + JsonReader readerToFix = new JsonReader(new StringReader(generatorOptionsToFix)); + JsonObject rootToFix = new JsonParser().parse(readerToFix).getAsJsonObject(); - JsonReader reader = new JsonReader(new StringReader(generatorOptions)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - - float heightVariationOffset = root.get("heightVariationOffset").getAsFloat(); - float offset = root.get("heightOffset").getAsFloat(); - float factor = root.get("heightFactor").getAsFloat(); - if (!root.has("expectedBaseHeight")) { - root.add("expectedBaseHeight", root.get("heightOffset")); - } - if (!root.has("expectedHeightVariation")) { - root.add("expectedHeightVariation", root.get("heightFactor")); - } - if (!root.has("actualHeight")) { - root.add("actualHeight", new JsonPrimitive((offset + heightVariationOffset - + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); - } - if (!root.has("cubeAreas")) { - root.add("cubeAreas", new JsonObject()); - } - if (!root.has("replacerConfig")) { - JsonObject replacerConf = new JsonObject(); - { - JsonObject defaults = new JsonObject(); - { - defaults.add(MODID + ":horizontal_gradient_depth_decrease_weight", new JsonPrimitive(1.0f)); - defaults.add(MODID + ":height_offset", new JsonPrimitive(offset)); - JsonObject terrainfill = new JsonObject(); - { - JsonObject properties = new JsonObject(); - properties.add("variant", new JsonPrimitive("stone")); - terrainfill.add("Properties", properties); - terrainfill.add("Name", new JsonPrimitive("minecraft:stone")); - } - JsonObject oceanblock = new JsonObject(); + JsonReader newReader = new JsonReader(new StringReader(newGeneratorOptions)); + JsonObject newRoot = new JsonParser().parse(newReader).getAsJsonObject(); - { - JsonObject properties = new JsonObject(); - properties.add("level", new JsonPrimitive("0")); - oceanblock.add("Properties", properties); - oceanblock.add("Name", new JsonPrimitive("minecraft:water")); - } - defaults.add(MODID + ":biome_fill_depth_offset", new JsonPrimitive(3.0f)); - defaults.add(MODID + ":biome_fill_noise_octaves", new JsonPrimitive(4.0f)); - defaults.add(MODID + ":height_scale", new JsonPrimitive(factor)); - defaults.add(MODID + ":biome_fill_depth_factor", new JsonPrimitive(2.3333333333333335f)); - defaults.add(MODID + ":mesa_depth", new JsonPrimitive(16.0f)); - defaults.add(MODID + ":water_level", root.get("waterLevel")); - defaults.add(MODID + ":biome_fill_noise_freq", new JsonPrimitive(0.0078125f)); - } - replacerConf.add("defaults", defaults); - replacerConf.add("overrides", new JsonObject()); + for(Entry entry:rootToFix.entrySet()) { + if(newRoot.has(entry.getKey())) { + newRoot.add(entry.getKey(), entry.getValue()); } - - root.add("replacerConfig", replacerConf); } - return gson.toJson(root); - } - public static String fixGeneratorOptionsVersion3(String generatorOptions) { - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(true); - } - // this is far simpler that walking through the json and figurring out - // all the places where it occurs - // instead, just do string search and replace. The string shouldn't - // occur in any other context - return generatorOptions.replaceAll(MODID + ":", MODID + ":"); + return gson.toJson(newRoot); } public static Gson gson(boolean minimize) { diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java index d19a327..679e221 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java @@ -88,6 +88,10 @@ public class CustomCubicGui extends ExtraGui { private AdvancedTerrainShapeTab advancedterrainShapeSettings; private Map areas; private BiomeBlockReplacerConfig replacerConf; + // Store config here between GUI calls, so we would not need to store it in + // parent GUI. As a negative side effect - settings will persist across + // different new world GUI calls. + public static String settingsJsonString = ""; public CustomCubicGui(GuiCreateWorld parent) { super(); @@ -100,7 +104,11 @@ public CustomCubicGui(GuiCreateWorld parent) { */ @Override public void construct() { - CustomGeneratorSettings conf = CustomGeneratorSettings.fromJson(parent.chunkProviderSettingsJson); + CustomGeneratorSettings conf = null; + if (settingsJsonString != null) + conf = CustomGeneratorSettings.fromJson(settingsJsonString); + else + conf = new CustomGeneratorSettings(); reinit(conf); } @@ -260,8 +268,7 @@ public void onClick(UIButton.ClickEvent evt) { private void done() { getConfig().save(new File(Minecraft.getMinecraft().mcDataDir, "saves/"+parent.saveDirName+"/")); - String settingsJsonString = getSettingsJson(getConfig(), true); - parent.chunkProviderSettingsJson = settingsJsonString; + settingsJsonString = getSettingsJson(getConfig(), true); this.mc.displayGuiScreen(parent); } From ded565f8d576eaa079e6d131ef47dd391364c690 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 16 Dec 2018 18:04:20 +0300 Subject: [PATCH 05/17] Remove saving on done --- .../cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java index 679e221..44bdf30 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java @@ -267,7 +267,6 @@ public void onClick(UIButton.ClickEvent evt) { } private void done() { - getConfig().save(new File(Minecraft.getMinecraft().mcDataDir, "saves/"+parent.saveDirName+"/")); settingsJsonString = getSettingsJson(getConfig(), true); this.mc.displayGuiScreen(parent); } From 4bd1b8f826127246ae70485a8a66c8b184677425 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 16 Dec 2018 22:23:25 +0300 Subject: [PATCH 06/17] Saving settings only using provided World instance path --- .../customcubic/CustomCubicWorldType.java | 8 +- .../customcubic/CustomGeneratorSettings.java | 85 ++----- .../CustomGeneratorSettingsDataFixer.java | 222 ++++++++++++++++++ .../customcubic/gui/CustomCubicGui.java | 6 +- 4 files changed, 246 insertions(+), 75 deletions(-) create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java index accfdda..e079810 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java @@ -57,6 +57,10 @@ @MethodsReturnNonnullByDefault public class CustomCubicWorldType extends WorldType implements ICubicWorldType { + // This string is not empty when and only when someone used a CustomCubicGUI + // and press a Done button both in this CustomCubicGUI and in a WorldCreationGUI + public static String pendingCustomCubicSettingsJsonString = ""; + private CustomCubicWorldType() { super("CustomCubic"); } @@ -97,8 +101,8 @@ public boolean isCustomizable() { @Override public void onGUICreateWorldPress() { - GuiCreateWorld gui = (GuiCreateWorld) Minecraft.getMinecraft().currentScreen; - CustomGeneratorSettings.fromJson(CustomCubicGui.settingsJsonString).save(new File(Minecraft.getMinecraft().mcDataDir, "saves/"+gui.saveDirName+"/")); + pendingCustomCubicSettingsJsonString = CustomCubicGui.settingsJsonString; + CustomCubicGui.settingsJsonString = ""; } @SideOnly(Side.CLIENT) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 9d170c5..62b7b37 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -215,9 +215,8 @@ public static CustomGeneratorSettings load(World world) { String jsonString = null; CustomGeneratorSettings settings = null; if (externalGeneratorPresetFile.exists()) { - FileReader reader = null; - try { - reader = new FileReader(externalGeneratorPresetFile); + try (FileReader reader = new FileReader(externalGeneratorPresetFile)){ + ; CharBuffer sb = CharBuffer.allocate(Short.MAX_VALUE << 3); reader.read(sb); sb.flip(); @@ -227,13 +226,11 @@ public static CustomGeneratorSettings load(World world) { } catch (IOException e) { e.printStackTrace(); } - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + } + else if(!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) { + settings = CustomGeneratorSettings.fromJson(CustomCubicWorldType.pendingCustomCubicSettingsJsonString); + CustomCubicWorldType.pendingCustomCubicSettingsJsonString = ""; + settings.save(world); } else { CustomCubicMod.LOGGER.info("No settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); @@ -242,20 +239,19 @@ public static CustomGeneratorSettings load(World world) { jsonString = world.getWorldInfo().getGeneratorOptions(); jsonString = fixGeneratorOptionsIfNecessary(jsonString); settings = fromJson(jsonString); - settings.save(world.getSaveHandler().getWorldDirectory()); + settings.save(world); } return settings; } - public void save(File worldSaveFolder) { - File folder = new File(worldSaveFolder, "/data/" + CustomCubicMod.MODID +"/"); - FileWriter writer = null; - try { + public void save(World world) { + File folder = new File(world.getSaveHandler().getWorldDirectory(), "/data/" + CustomCubicMod.MODID +"/"); + File settingsFile = new File(folder, "custom_generator_settings.json"); + try (FileWriter writer = new FileWriter(settingsFile)) { folder.mkdirs(); - File settingsFile = new File(folder, "custom_generator_settings.json"); - writer = new FileWriter(settingsFile); + ; writer.write(this.toJson(true)); - if(settingsFile.exists()) + if (settingsFile.exists()) CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); else CustomCubicMod.LOGGER.error("Error creating file at " + settingsFile.getAbsolutePath()); @@ -263,13 +259,6 @@ public void save(File worldSaveFolder) { CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); e.printStackTrace(); } - if (writer != null) { - try { - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } } public static CustomGeneratorSettings defaults() { @@ -351,31 +340,6 @@ public static CustomGeneratorSettings defaults() { return settings; } - public static CustomGeneratorSettings fromVanilla(ChunkGeneratorSettings settings) { - CustomGeneratorSettings obj = defaults(); - - obj.lowNoiseFactor = 512.0f / settings.lowerLimitScale; - obj.highNoiseFactor = 512.0f / settings.upperLimitScale; - - obj.depthNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.depthNoiseScaleX, 16); - obj.depthNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.depthNoiseScaleZ, 16); - // settings.depthNoiseScaleExponent is ignored by vanilla - - obj.selectorNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale / settings.mainNoiseScaleX, 8); - obj.selectorNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale / settings.mainNoiseScaleY, 8); - obj.selectorNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale / settings.mainNoiseScaleZ, 8); - - obj.lowNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - obj.lowNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale, 16); - obj.lowNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - - obj.highNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - obj.highNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale, 16); - obj.highNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - - return obj; - } - public static String fixGeneratorOptionsIfNecessary(String generatorOptions) { if (generatorOptions.isEmpty()) { generatorOptions = new CustomGeneratorSettings().toJson(false); @@ -383,30 +347,11 @@ public static String fixGeneratorOptionsIfNecessary(String generatorOptions) { JsonReader reader = new JsonReader(new StringReader(generatorOptions)); JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); if (!root.has("version") || root.get("version").getAsInt() < 3) { - generatorOptions = fixGeneratorOptions(generatorOptions); + generatorOptions = CustomGeneratorSettingsDataFixer.fixGeneratorOptions(generatorOptions); } return generatorOptions; } - public static String fixGeneratorOptions(String generatorOptionsToFix) { - generatorOptionsToFix = generatorOptionsToFix.replaceAll("cubicchunks:", MODID + ":"); - String newGeneratorOptions = new CustomGeneratorSettings().toJson(true); - Gson gson = gson(false); - - JsonReader readerToFix = new JsonReader(new StringReader(generatorOptionsToFix)); - JsonObject rootToFix = new JsonParser().parse(readerToFix).getAsJsonObject(); - - JsonReader newReader = new JsonReader(new StringReader(newGeneratorOptions)); - JsonObject newRoot = new JsonParser().parse(newReader).getAsJsonObject(); - - for(Entry entry:rootToFix.entrySet()) { - if(newRoot.has(entry.getKey())) { - newRoot.add(entry.getKey(), entry.getValue()); - } - } - - return gson.toJson(newRoot); - } public static Gson gson(boolean minimize) { return new GsonBuilder().serializeSpecialFloatingPointValues() diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java new file mode 100644 index 0000000..bb386d0 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java @@ -0,0 +1,222 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.customcubic; + +import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; + +import java.io.StringReader; +import java.util.Map.Entry; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.gson.stream.JsonReader; + +import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; +import net.minecraft.block.BlockSilverfish; +import net.minecraft.block.BlockStone; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Biomes; +import net.minecraft.init.Blocks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.ChunkGeneratorSettings; + +public class CustomGeneratorSettingsDataFixer { + + private static final String[] standard = { + "dirt", + "gravel", + "granite", + "diorite", + "andesite", + "coalOre", + "ironOre", + "goldOre", + "redstoneOre", + "diamondOre", + "hillsEmeraldOre", + "hillsSilverfishStone", + "mesaAddedGoldOre" + }; + + private static final IBlockState[] standardBlockstates = { + Blocks.DIRT.getDefaultState(), + Blocks.GRAVEL.getDefaultState(), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), + Blocks.COAL_ORE.getDefaultState(), + Blocks.IRON_ORE.getDefaultState(), + Blocks.GOLD_ORE.getDefaultState(), + Blocks.REDSTONE_ORE.getDefaultState(), + Blocks.DIAMOND_ORE.getDefaultState(), + Blocks.EMERALD_ORE.getDefaultState(), + Blocks.MONSTER_EGG.getDefaultState().withProperty(BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), + Blocks.GOLD_ORE.getDefaultState() + }; + private static final Biome[][] standardBiomes = { + null, // dirt + null, // gravel + null, // granite + null, // diorite + null, // andesite + null, // coal + null, // iron + null, // gold + null, // redstone + null, // diamond + {Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.MUTATED_EXTREME_HILLS, + Biomes.MUTATED_EXTREME_HILLS_WITH_TREES},//emerald + {Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.MUTATED_EXTREME_HILLS, + Biomes.MUTATED_EXTREME_HILLS_WITH_TREES},//monster egg + {Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, Biomes.MUTATED_MESA_CLEAR_ROCK, + Biomes.MUTATED_MESA_ROCK},//mesa gold + }; + + @SuppressWarnings("unused") + private static CustomGeneratorSettings fromVanilla(ChunkGeneratorSettings settings) { + CustomGeneratorSettings obj = CustomGeneratorSettings.defaults(); + + obj.lowNoiseFactor = 512.0f / settings.lowerLimitScale; + obj.highNoiseFactor = 512.0f / settings.upperLimitScale; + + obj.depthNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.depthNoiseScaleX, 16); + obj.depthNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.depthNoiseScaleZ, 16); + // settings.depthNoiseScaleExponent is ignored by vanilla + + obj.selectorNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale / settings.mainNoiseScaleX, 8); + obj.selectorNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale / settings.mainNoiseScaleY, 8); + obj.selectorNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale / settings.mainNoiseScaleZ, 8); + + obj.lowNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); + obj.lowNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale, 16); + obj.lowNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); + + obj.highNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); + obj.highNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale, 16); + obj.highNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); + + return obj; + } + + public static String fixGeneratorOptions(String generatorOptionsToFix) { + String newGeneratorOptions = CustomGeneratorSettings.defaults().toJson(true); + Gson gson = CustomGeneratorSettings.gson(false); + + JsonReader readerToFix = new JsonReader(new StringReader(generatorOptionsToFix)); + JsonObject rootToFix = new JsonParser().parse(readerToFix).getAsJsonObject(); + + JsonReader newReader = new JsonReader(new StringReader(newGeneratorOptions)); + JsonObject newRoot = new JsonParser().parse(newReader).getAsJsonObject(); + + for(Entry entry:rootToFix.entrySet()) { + if(newRoot.has(entry.getKey())) { + newRoot.add(entry.getKey(), entry.getValue()); + } + } + + if (!rootToFix.has("standardOres")) { + JsonArray standardOres = new JsonArray(); + for (int i = 0; i < standard.length; i++) { + JsonObject obj = convertStandardOre(gson, rootToFix, standard[i], standardBlockstates[i], + standardBiomes[i]); + if (obj != null) { + standardOres.add(obj); + } + } + newRoot.add("standardOres", standardOres); + } + if (!rootToFix.has("periodicGaussianOres")) { + JsonArray periodicGaussianOres = new JsonArray(); + JsonObject obj = convertGaussianPeriodicOre(gson, rootToFix, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), + null); + if (obj != null) { + periodicGaussianOres.add(obj); + } + newRoot.add("periodicGaussianOres", periodicGaussianOres); + } + + if (!rootToFix.has("expectedBaseHeight") && rootToFix.has("heightOffset")) { + newRoot.add("expectedBaseHeight", rootToFix.get("heightOffset")); + } + + if (!rootToFix.has("expectedHeightVariation") && rootToFix.has("heightFactor")) { + newRoot.add("expectedHeightVariation", rootToFix.get("heightFactor")); + } + + if (!rootToFix.has("actualHeight") + && rootToFix.has("heightOffset") + && rootToFix.has("heightVariationOffset") + && rootToFix.has("heightFactor")) { + float heightVariationOffset = rootToFix.get("heightVariationOffset").getAsFloat(); + float offset = rootToFix.get("heightOffset").getAsFloat(); + float factor = rootToFix.get("heightFactor").getAsFloat(); + newRoot.add("actualHeight", new JsonPrimitive((offset + heightVariationOffset + + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); + } + + newGeneratorOptions = gson.toJson(newRoot).replaceAll("cubicchunks:", MODID + ":"); + return newGeneratorOptions; + } + + private static JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { + if (!root.has(ore + "SpawnTries")) { + // some old saves are broken, especially 1.11.2 ones from the 1.12.2->1.11.2 backport, build 847 + // this avoids adding a lot of air ores + return null; + } + + JsonObject obj = new JsonObject(); + obj.add("blockstate", gson.toJsonTree(state)); + if (biomes != null) { + obj.add("biomes", gson.toJsonTree(biomes)); + } + if (root.has(ore + "SpawnSize")) { + obj.add("spawnSize", root.remove(ore + "SpawnSize")); + } else { + // emerald doesn't have size defined in the old format + obj.add("spawnSize", new JsonPrimitive(3)); + } + obj.add("spawnTries", root.remove(ore + "SpawnTries")); + obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); + obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); + obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); + return obj; + } + + private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { + JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); + if (obj == null) { + return null; + } + obj.add("heightMean", root.remove(ore + "HeightMean")); + obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); + obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); + return obj; + } + +} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java index 44bdf30..f067ebe 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java @@ -89,8 +89,8 @@ public class CustomCubicGui extends ExtraGui { private Map areas; private BiomeBlockReplacerConfig replacerConf; // Store config here between GUI calls, so we would not need to store it in - // parent GUI. As a negative side effect - settings will persist across - // different new world GUI calls. + // parent GUI. Whenever player will press create world GUI button it will be + // transfered to CustomCubicWorld type to be saved. public static String settingsJsonString = ""; public CustomCubicGui(GuiCreateWorld parent) { @@ -105,7 +105,7 @@ public CustomCubicGui(GuiCreateWorld parent) { @Override public void construct() { CustomGeneratorSettings conf = null; - if (settingsJsonString != null) + if (!settingsJsonString.isEmpty()) conf = CustomGeneratorSettings.fromJson(settingsJsonString); else conf = new CustomGeneratorSettings(); From da1e965cc0812b8859e475c5ff1309a3a7f660c4 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Tue, 18 Dec 2018 19:24:12 +0300 Subject: [PATCH 07/17] Expanded transversion json fixer --- .../customcubic/CustomGeneratorSettings.java | 47 +- .../CustomGeneratorSettingsDataFixer.java | 222 --------- .../CustomGeneratorSettingsFixer.java | 467 ++++++++++++++++++ .../cubicgen/TestCustomTerrainGenerator.java | 65 +++ 4 files changed, 552 insertions(+), 249 deletions(-) delete mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java create mode 100644 src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 62b7b37..4796d1d 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -184,7 +184,7 @@ public class CustomGeneratorSettings { public BiomeBlockReplacerConfig replacerConfig = BiomeBlockReplacerConfig.defaults(); // TODO: public boolean negativeHeightVariationInvertsTerrain = true; - public int version = 3; + public int version = CustomGeneratorSettingsFixer.VERSION; public CustomGeneratorSettings() { } @@ -200,13 +200,22 @@ public String toJson(boolean minimize) { Gson gson = gson(minimize); return gson.toJson(this); } + + public static boolean isOutdated(String settingsJsonString) { + JsonReader reader = new JsonReader(new StringReader(settingsJsonString)); + JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); + return !root.has("version") || root.get("version").getAsInt() != CustomGeneratorSettingsFixer.VERSION; + } - public static CustomGeneratorSettings fromJson(String json) { - if (json.isEmpty()) { + public static CustomGeneratorSettings fromJson(String jsonString) { + if (jsonString.isEmpty()) { return defaults(); } + if (isOutdated(jsonString)) { + jsonString = CustomGeneratorSettingsFixer.fixGeneratorOptions(jsonString); + } Gson gson = gson(true); // minimize option shouldn't matter when deserializing - return gson.fromJson(json, CustomGeneratorSettings.class); + return gson.fromJson(jsonString, CustomGeneratorSettings.class); } public static CustomGeneratorSettings load(World world) { @@ -216,13 +225,15 @@ public static CustomGeneratorSettings load(World world) { CustomGeneratorSettings settings = null; if (externalGeneratorPresetFile.exists()) { try (FileReader reader = new FileReader(externalGeneratorPresetFile)){ - ; CharBuffer sb = CharBuffer.allocate(Short.MAX_VALUE << 3); reader.read(sb); sb.flip(); jsonString = sb.toString(); - CustomCubicMod.LOGGER.info("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + CustomCubicMod.LOGGER.debug("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + boolean isOutdated = isOutdated(jsonString); settings = fromJson(jsonString); + if(isOutdated) + settings.save(world); } catch (IOException e) { e.printStackTrace(); } @@ -236,9 +247,7 @@ else if(!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) { CustomCubicMod.LOGGER.info("No settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); CustomCubicMod.LOGGER.info("Loading settings from 'level.dat'"); // Use old format to keep backward-compatibility - jsonString = world.getWorldInfo().getGeneratorOptions(); - jsonString = fixGeneratorOptionsIfNecessary(jsonString); - settings = fromJson(jsonString); + settings = fromJson(world.getWorldInfo().getGeneratorOptions()); settings.save(world); } return settings; @@ -249,14 +258,11 @@ public void save(World world) { File settingsFile = new File(folder, "custom_generator_settings.json"); try (FileWriter writer = new FileWriter(settingsFile)) { folder.mkdirs(); - ; writer.write(this.toJson(true)); - if (settingsFile.exists()) - CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); - else - CustomCubicMod.LOGGER.error("Error creating file at " + settingsFile.getAbsolutePath()); + CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); } catch (IOException e) { CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); + CustomCubicMod.LOGGER.error(this.toJson(true)); e.printStackTrace(); } } @@ -340,19 +346,6 @@ public static CustomGeneratorSettings defaults() { return settings; } - public static String fixGeneratorOptionsIfNecessary(String generatorOptions) { - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(false); - } - JsonReader reader = new JsonReader(new StringReader(generatorOptions)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - if (!root.has("version") || root.get("version").getAsInt() < 3) { - generatorOptions = CustomGeneratorSettingsDataFixer.fixGeneratorOptions(generatorOptions); - } - return generatorOptions; - } - - public static Gson gson(boolean minimize) { return new GsonBuilder().serializeSpecialFloatingPointValues() .enableComplexMapKeySerialization() diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java deleted file mode 100644 index bb386d0..0000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsDataFixer.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * This file is part of Cubic World Generation, licensed under the MIT License (MIT). - * - * Copyright (c) 2015 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.github.opencubicchunks.cubicchunks.cubicgen.customcubic; - -import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; - -import java.io.StringReader; -import java.util.Map.Entry; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.google.gson.stream.JsonReader; - -import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; -import net.minecraft.block.BlockSilverfish; -import net.minecraft.block.BlockStone; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Biomes; -import net.minecraft.init.Blocks; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.ChunkGeneratorSettings; - -public class CustomGeneratorSettingsDataFixer { - - private static final String[] standard = { - "dirt", - "gravel", - "granite", - "diorite", - "andesite", - "coalOre", - "ironOre", - "goldOre", - "redstoneOre", - "diamondOre", - "hillsEmeraldOre", - "hillsSilverfishStone", - "mesaAddedGoldOre" - }; - - private static final IBlockState[] standardBlockstates = { - Blocks.DIRT.getDefaultState(), - Blocks.GRAVEL.getDefaultState(), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), - Blocks.COAL_ORE.getDefaultState(), - Blocks.IRON_ORE.getDefaultState(), - Blocks.GOLD_ORE.getDefaultState(), - Blocks.REDSTONE_ORE.getDefaultState(), - Blocks.DIAMOND_ORE.getDefaultState(), - Blocks.EMERALD_ORE.getDefaultState(), - Blocks.MONSTER_EGG.getDefaultState().withProperty(BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), - Blocks.GOLD_ORE.getDefaultState() - }; - private static final Biome[][] standardBiomes = { - null, // dirt - null, // gravel - null, // granite - null, // diorite - null, // andesite - null, // coal - null, // iron - null, // gold - null, // redstone - null, // diamond - {Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.MUTATED_EXTREME_HILLS, - Biomes.MUTATED_EXTREME_HILLS_WITH_TREES},//emerald - {Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.MUTATED_EXTREME_HILLS, - Biomes.MUTATED_EXTREME_HILLS_WITH_TREES},//monster egg - {Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, Biomes.MUTATED_MESA_CLEAR_ROCK, - Biomes.MUTATED_MESA_ROCK},//mesa gold - }; - - @SuppressWarnings("unused") - private static CustomGeneratorSettings fromVanilla(ChunkGeneratorSettings settings) { - CustomGeneratorSettings obj = CustomGeneratorSettings.defaults(); - - obj.lowNoiseFactor = 512.0f / settings.lowerLimitScale; - obj.highNoiseFactor = 512.0f / settings.upperLimitScale; - - obj.depthNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.depthNoiseScaleX, 16); - obj.depthNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.depthNoiseScaleZ, 16); - // settings.depthNoiseScaleExponent is ignored by vanilla - - obj.selectorNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale / settings.mainNoiseScaleX, 8); - obj.selectorNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale / settings.mainNoiseScaleY, 8); - obj.selectorNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale / settings.mainNoiseScaleZ, 8); - - obj.lowNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - obj.lowNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale, 16); - obj.lowNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - - obj.highNoiseFrequencyX = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - obj.highNoiseFrequencyY = ConversionUtils.frequencyFromVanilla(settings.heightScale, 16); - obj.highNoiseFrequencyZ = ConversionUtils.frequencyFromVanilla(settings.coordinateScale, 16); - - return obj; - } - - public static String fixGeneratorOptions(String generatorOptionsToFix) { - String newGeneratorOptions = CustomGeneratorSettings.defaults().toJson(true); - Gson gson = CustomGeneratorSettings.gson(false); - - JsonReader readerToFix = new JsonReader(new StringReader(generatorOptionsToFix)); - JsonObject rootToFix = new JsonParser().parse(readerToFix).getAsJsonObject(); - - JsonReader newReader = new JsonReader(new StringReader(newGeneratorOptions)); - JsonObject newRoot = new JsonParser().parse(newReader).getAsJsonObject(); - - for(Entry entry:rootToFix.entrySet()) { - if(newRoot.has(entry.getKey())) { - newRoot.add(entry.getKey(), entry.getValue()); - } - } - - if (!rootToFix.has("standardOres")) { - JsonArray standardOres = new JsonArray(); - for (int i = 0; i < standard.length; i++) { - JsonObject obj = convertStandardOre(gson, rootToFix, standard[i], standardBlockstates[i], - standardBiomes[i]); - if (obj != null) { - standardOres.add(obj); - } - } - newRoot.add("standardOres", standardOres); - } - if (!rootToFix.has("periodicGaussianOres")) { - JsonArray periodicGaussianOres = new JsonArray(); - JsonObject obj = convertGaussianPeriodicOre(gson, rootToFix, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), - null); - if (obj != null) { - periodicGaussianOres.add(obj); - } - newRoot.add("periodicGaussianOres", periodicGaussianOres); - } - - if (!rootToFix.has("expectedBaseHeight") && rootToFix.has("heightOffset")) { - newRoot.add("expectedBaseHeight", rootToFix.get("heightOffset")); - } - - if (!rootToFix.has("expectedHeightVariation") && rootToFix.has("heightFactor")) { - newRoot.add("expectedHeightVariation", rootToFix.get("heightFactor")); - } - - if (!rootToFix.has("actualHeight") - && rootToFix.has("heightOffset") - && rootToFix.has("heightVariationOffset") - && rootToFix.has("heightFactor")) { - float heightVariationOffset = rootToFix.get("heightVariationOffset").getAsFloat(); - float offset = rootToFix.get("heightOffset").getAsFloat(); - float factor = rootToFix.get("heightFactor").getAsFloat(); - newRoot.add("actualHeight", new JsonPrimitive((offset + heightVariationOffset - + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); - } - - newGeneratorOptions = gson.toJson(newRoot).replaceAll("cubicchunks:", MODID + ":"); - return newGeneratorOptions; - } - - private static JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { - if (!root.has(ore + "SpawnTries")) { - // some old saves are broken, especially 1.11.2 ones from the 1.12.2->1.11.2 backport, build 847 - // this avoids adding a lot of air ores - return null; - } - - JsonObject obj = new JsonObject(); - obj.add("blockstate", gson.toJsonTree(state)); - if (biomes != null) { - obj.add("biomes", gson.toJsonTree(biomes)); - } - if (root.has(ore + "SpawnSize")) { - obj.add("spawnSize", root.remove(ore + "SpawnSize")); - } else { - // emerald doesn't have size defined in the old format - obj.add("spawnSize", new JsonPrimitive(3)); - } - obj.add("spawnTries", root.remove(ore + "SpawnTries")); - obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); - obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); - obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); - return obj; - } - - private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { - JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); - if (obj == null) { - return null; - } - obj.add("heightMean", root.remove(ore + "HeightMean")); - obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); - obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); - return obj; - } - -} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java new file mode 100644 index 0000000..4eea712 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java @@ -0,0 +1,467 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.customcubic; + +import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; + +import java.io.StringReader; +import java.util.Map.Entry; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.gson.stream.JsonReader; + +import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; +import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.BiomeBlockReplacerConfig; +import net.minecraft.block.BlockSilverfish; +import net.minecraft.block.BlockStone; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Biomes; +import net.minecraft.init.Blocks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.ChunkGeneratorSettings; + +public class CustomGeneratorSettingsFixer { + + public static final int VERSION = 3; + + private static final String[] standard = { "dirt", "gravel", "granite", "diorite", "andesite", "coalOre", "ironOre", + "goldOre", "redstoneOre", "diamondOre", "hillsEmeraldOre", "hillsSilverfishStone", "mesaAddedGoldOre" }; + + private static final IBlockState[] standardBlockstates = { Blocks.DIRT.getDefaultState(), + Blocks.GRAVEL.getDefaultState(), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), + Blocks.COAL_ORE.getDefaultState(), Blocks.IRON_ORE.getDefaultState(), Blocks.GOLD_ORE.getDefaultState(), + Blocks.REDSTONE_ORE.getDefaultState(), Blocks.DIAMOND_ORE.getDefaultState(), + Blocks.EMERALD_ORE.getDefaultState(), + Blocks.MONSTER_EGG.getDefaultState().withProperty(BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), + Blocks.GOLD_ORE.getDefaultState() }; + private static final Biome[][] standardBiomes = { null, // dirt + null, // gravel + null, // granite + null, // diorite + null, // andesite + null, // coal + null, // iron + null, // gold + null, // redstone + null, // diamond + { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, + Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // emerald + { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, + Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // monster + // egg + { Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, + Biomes.MUTATED_MESA_CLEAR_ROCK, Biomes.MUTATED_MESA_ROCK },// mesa + // gold + }; + + public static String fixGeneratorOptions(String generatorOptionsToFix) { + Gson gson = CustomGeneratorSettings.gson(false); + + JsonReader oldReader = new JsonReader(new StringReader(generatorOptionsToFix)); + JsonObject oldRoot = new JsonParser().parse(oldReader).getAsJsonObject(); + + JsonReader newReader = new JsonReader(new StringReader("")); + JsonObject newRoot = new JsonParser().parse(newReader).getAsJsonObject(); + + newRoot.add("version", new JsonPrimitive(VERSION)); + newRoot.add("waterLevel", getWaterLevel(oldRoot)); + newRoot.add("caves", getCaves(oldRoot)); + newRoot.add("strongholds", getStrongholds(oldRoot)); + newRoot.add("alternateStrongholdsPositions", getAlternateStrongholdsPositions(oldRoot)); + newRoot.add("villages", getVillages(oldRoot)); + newRoot.add("mineshafts", getMineshafts(oldRoot)); + newRoot.add("temples", getTemples(oldRoot)); + newRoot.add("oceanMonuments", getOceanMonuments(oldRoot)); + newRoot.add("woodlandMansions", getWoodlandMansions(oldRoot)); + newRoot.add("ravines", getRavines(oldRoot)); + newRoot.add("dungeons", getDungeons(oldRoot)); + newRoot.add("dungeonCount", getDungeonCount(oldRoot)); + newRoot.add("waterLakes", getWaterLakes(oldRoot)); + newRoot.add("waterLakeRarity", getWaterLakeRarity(oldRoot)); + newRoot.add("lavaLakes", getLavaLakes(oldRoot)); + newRoot.add("lavaLakeRarity", getLavaLakeRarity(oldRoot)); + newRoot.add("aboveSeaLavaLakeRarity", getAboveSeaLavaLakeRarity(oldRoot)); + newRoot.add("lavaOceans", getLavaOceans(oldRoot)); + newRoot.add("biome", getBiome(oldRoot)); + newRoot.add("biomeSize", getBiomeSize(oldRoot)); + newRoot.add("riverSize", getRiverSize(oldRoot)); + newRoot.add("standardOres", getStandardOres(oldRoot)); + newRoot.add("periodicGaussianOres", getPeriodicGaussianOres(oldRoot)); + newRoot.add("expectedBaseHeight", getExpectedBaseHeight(oldRoot)); + newRoot.add("expectedHeightVariation", getExpectedHeightVariation(oldRoot)); + newRoot.add("actualHeight", getActualHeight(oldRoot)); + newRoot.add("heightVariationFactor", getHeightVariationFactor(oldRoot)); + newRoot.add("specialHeightVariationFactorBelowAverageY", getSpecialHeightVariationFactorBelowAverageY(oldRoot)); + newRoot.add("heightVariationOffset", getHeightVariationOffset(oldRoot)); + newRoot.add("heightFactor", getHeightFactor(oldRoot)); + newRoot.add("heightOffset", getHeightOffset(oldRoot)); + newRoot.add("depthNoiseFactor", getDepthNoiseFactor(oldRoot)); + newRoot.add("depthNoiseOffset", getDepthNoiseOffset(oldRoot)); + newRoot.add("depthNoiseFrequencyX", getDepthNoiseFrequencyX(oldRoot)); + newRoot.add("depthNoiseFrequencyZ", getDepthNoiseFrequencyZ(oldRoot)); + newRoot.add("depthNoiseOctaves", getDepthNoiseOctaves(oldRoot)); + newRoot.add("selectorNoiseFactor", getSelectorNoiseFactor(oldRoot)); + newRoot.add("selectorNoiseOffset", getSelectorNoiseOffset(oldRoot)); + newRoot.add("selectorNoiseFrequencyX", getSelectorNoiseFrequencyX(oldRoot)); + newRoot.add("selectorNoiseFrequencyY", getSelectorNoiseFrequencyY(oldRoot)); + newRoot.add("selectorNoiseFrequencyZ", getSelectorNoiseFrequencyZ(oldRoot)); + newRoot.add("selectorNoiseOctaves", getSelectorNoiseOctaves(oldRoot)); + newRoot.add("lowNoiseFactor", getLowNoiseFactor(oldRoot)); + newRoot.add("lowNoiseOffset", getLowNoiseOffset(oldRoot)); + newRoot.add("lowNoiseFrequencyX", getLowNoiseFrequencyX(oldRoot)); + newRoot.add("lowNoiseFrequencyY", getLowNoiseFrequencyY(oldRoot)); + newRoot.add("lowNoiseFrequencyZ", getLowNoiseFrequencyZ(oldRoot)); + newRoot.add("lowNoiseOctaves", getLowNoiseOctaves(oldRoot)); + newRoot.add("highNoiseFactor", getHighNoiseFactor(oldRoot)); + newRoot.add("highNoiseOffset", getHighNoiseOffset(oldRoot)); + newRoot.add("highNoiseFrequencyX", getHighNoiseFrequencyX(oldRoot)); + newRoot.add("highNoiseFrequencyY", getHighNoiseFrequencyY(oldRoot)); + newRoot.add("highNoiseFrequencyZ", getHighNoiseFrequencyZ(oldRoot)); + newRoot.add("highNoiseOctaves", getHighNoiseOctaves(oldRoot)); + newRoot.add("cubeAreas", getCubeAreas(oldRoot)); + newRoot.add("replacerConfig", getReplacerConfig(oldRoot)); + + String newGeneratorOptions = gson.toJson(newRoot).replaceAll("cubicchunks:", MODID + ":"); + return newGeneratorOptions; + } + + private static JsonElement getReplacerConfig(JsonObject json) { + Gson gson = CustomGeneratorSettings.gson(false); + return getOrDefault(json, "replacerConfig", gson.toJsonTree(BiomeBlockReplacerConfig.defaults())); + } + + private static JsonElement getCubeAreas(JsonObject json) { + return getOrDefault(json, "cubeAreas", new JsonArray()); + } + + private static JsonElement getHighNoiseOctaves(JsonObject json) { + return getOrDefault(json, "highNoiseOctaves", new JsonPrimitive(16)); + } + + private static JsonElement getHighNoiseFrequencyZ(JsonObject json) { + return getOrDefault(json, "highNoiseFrequencyZ", + new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + } + + private static JsonElement getHighNoiseFrequencyY(JsonObject json) { + return getOrDefault(json, "highNoiseFrequencyY", + new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_Y)); + } + + private static JsonElement getHighNoiseFrequencyX(JsonObject json) { + return getOrDefault(json, "highNoiseFrequencyX", + new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + } + + private static JsonElement getHighNoiseOffset(JsonObject json) { + return getOrDefault(json, "highNoiseOffset", new JsonPrimitive(0)); + } + + private static JsonElement getHighNoiseFactor(JsonObject json) { + return getOrDefault(json, "highNoiseFactor", new JsonPrimitive(1)); + } + + private static JsonElement getLowNoiseFrequencyZ(JsonObject json) { + return getOrDefault(json, "lowNoiseFrequencyZ", + new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + } + + private static JsonElement getLowNoiseFrequencyY(JsonObject json) { + return getOrDefault(json, "lowNoiseFrequencyY", + new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_Y)); + } + + private static JsonElement getLowNoiseFrequencyX(JsonObject json) { + return getOrDefault(json, "lowNoiseFrequencyX", + new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + } + + private static JsonElement getLowNoiseOffset(JsonObject json) { + return getOrDefault(json, "lowNoiseOffset", new JsonPrimitive(0)); + } + + private static JsonElement getLowNoiseFactor(JsonObject json) { + return getOrDefault(json, "lowNoiseFactor", new JsonPrimitive(1)); + } + + private static JsonElement getLowNoiseOctaves(JsonObject json) { + return getOrDefault(json, "lowNoiseOctaves", new JsonPrimitive(16)); + } + + private static JsonElement getSelectorNoiseOctaves(JsonObject json) { + return getOrDefault(json, "selectorNoiseOctaves", new JsonPrimitive(8)); + } + + private static JsonElement getSelectorNoiseFrequencyZ(JsonObject json) { + return getOrDefault(json, "selectorNoiseFrequencyZ", + new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FREQUENCY_XZ)); + } + + private static JsonElement getSelectorNoiseFrequencyX(JsonObject json) { + return getOrDefault(json, "selectorNoiseFrequencyX", + new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FREQUENCY_XZ)); + } + + private static JsonElement getSelectorNoiseFrequencyY(JsonObject json) { + return getOrDefault(json, "selectorNoiseFrequencyY", + new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FREQUENCY_Y)); + } + + private static JsonElement getSelectorNoiseOffset(JsonObject json) { + return getOrDefault(json, "selectorNoiseOffset", + new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_OFFSET)); + } + + private static JsonElement getSelectorNoiseFactor(JsonObject json) { + return getOrDefault(json, "selectorNoiseFactor", + new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FACTOR)); + } + + private static JsonElement getDepthNoiseOctaves(JsonObject json) { + return getOrDefault(json, "depthNoiseOctaves", new JsonPrimitive(16)); + } + + private static JsonElement getDepthNoiseFrequencyZ(JsonObject json) { + return getOrDefault(json, "depthNoiseFrequencyZ", + new JsonPrimitive(ConversionUtils.VANILLA_DEPTH_NOISE_FREQUENCY)); + } + + private static JsonElement getDepthNoiseFrequencyX(JsonObject json) { + return getOrDefault(json, "depthNoiseFrequencyX", + new JsonPrimitive(ConversionUtils.VANILLA_DEPTH_NOISE_FREQUENCY)); + } + + private static JsonElement getDepthNoiseOffset(JsonObject json) { + return getOrDefault(json, "depthNoiseOffset", new JsonPrimitive(0)); + } + + private static JsonElement getDepthNoiseFactor(JsonObject json) { + return getOrDefault(json, "depthNoiseFactor", new JsonPrimitive(ConversionUtils.VANILLA_DEPTH_NOISE_FACTOR)); + } + + private static JsonElement getHeightOffset(JsonObject json) { + return getOrDefault(json, "heightOffset", new JsonPrimitive(64)); + } + + private static JsonElement getHeightFactor(JsonObject json) { + return getOrDefault(json, "heightFactor", new JsonPrimitive(64)); + } + + private static JsonElement getHeightVariationOffset(JsonObject json) { + return getOrDefault(json, "heightVariationOffset", new JsonPrimitive(0)); + } + + private static JsonElement getSpecialHeightVariationFactorBelowAverageY(JsonObject json) { + return getOrDefault(json, "specialHeightVariationFactorBelowAverageY", new JsonPrimitive(0.25f)); + } + + private static JsonElement getHeightVariationFactor(JsonObject json) { + return getOrDefault(json, "heightVariationFactor", new JsonPrimitive(64)); + } + + private static JsonElement getActualHeight(JsonObject json) { + if (json.has("heightOffset") && json.has("heightVariationOffset") && json.has("heightFactor")) { + float heightVariationOffset = json.get("heightVariationOffset").getAsFloat(); + float offset = json.get("heightOffset").getAsFloat(); + float factor = json.get("heightFactor").getAsFloat(); + return getOrDefault(json, "actualHeight", new JsonPrimitive((offset + heightVariationOffset + + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); + } + return getOrDefault(json, "actualHeight", new JsonPrimitive(64)); + } + + private static JsonElement getExpectedBaseHeight(JsonObject json) { + if (json.has("expectedBaseHeight")) + return json.get("expectedBaseHeight"); + return getOrDefault(json, "heightOffset", new JsonPrimitive(64)); + } + + private static JsonElement getExpectedHeightVariation(JsonObject json) { + return getOrDefault(json, "expectedHeightVariation", getOrDefault(json, "heightFactor", new JsonPrimitive(64))); + } + + private static JsonElement getPeriodicGaussianOres(JsonObject oldRoot) { + if (oldRoot.has("periodicGaussianOres")) + return oldRoot.get("periodicGaussianOres"); + Gson gson = CustomGeneratorSettings.gson(false); + JsonArray periodicGaussianOres = new JsonArray(); + JsonObject obj = convertGaussianPeriodicOre(gson, oldRoot, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), + null); + if (obj != null) { + periodicGaussianOres.add(obj); + } + return periodicGaussianOres; + } + + private static JsonElement getStandardOres(JsonObject oldRoot) { + if (oldRoot.has("standardOres")) + return oldRoot.get("standardOres"); + Gson gson = CustomGeneratorSettings.gson(false); + JsonArray standardOres = new JsonArray(); + for (int i = 0; i < standard.length; i++) { + JsonObject obj = convertStandardOre(gson, oldRoot, standard[i], standardBlockstates[i], standardBiomes[i]); + if (obj != null) { + standardOres.add(obj); + } + } + return standardOres; + } + + private static JsonElement getRiverSize(JsonObject json) { + return getOrDefault(json, "riverSize", new JsonPrimitive(4)); + } + + private static JsonElement getBiomeSize(JsonObject json) { + return getOrDefault(json, "biomeSize", new JsonPrimitive(4)); + } + + private static JsonElement getBiome(JsonObject json) { + return getOrDefault(json, "biome", new JsonPrimitive(-1)); + } + + private static JsonElement getLavaOceans(JsonObject json) { + return getOrDefault(json, "lavaOceans", new JsonPrimitive(false)); + } + + private static JsonElement getAboveSeaLavaLakeRarity(JsonObject json) { + return getOrDefault(json, "aboveSeaLavaLakeRarity", new JsonPrimitive(13)); + } + + private static JsonElement getLavaLakeRarity(JsonObject json) { + return getOrDefault(json, "lavaLakeRarity", new JsonPrimitive(8)); + } + + private static JsonElement getLavaLakes(JsonObject json) { + return getOrDefault(json, "lavaLakes", new JsonPrimitive(true)); + } + + private static JsonElement getWaterLakeRarity(JsonObject json) { + return getOrDefault(json, "waterLakeRarity", new JsonPrimitive(4)); + } + + private static JsonElement getWaterLakes(JsonObject json) { + return getOrDefault(json, "waterLakes", new JsonPrimitive(true)); + } + + private static JsonElement getDungeonCount(JsonObject json) { + return getOrDefault(json, "dungeonCount", new JsonPrimitive(7)); + } + + private static JsonElement getDungeons(JsonObject json) { + return getOrDefault(json, "dungeons", new JsonPrimitive(true)); + } + + private static JsonElement getRavines(JsonObject json) { + return getOrDefault(json, "ravines", new JsonPrimitive(true)); + } + + private static JsonElement getWoodlandMansions(JsonObject json) { + return getOrDefault(json, "woodlandMansions", new JsonPrimitive(true)); + } + + private static JsonElement getOceanMonuments(JsonObject json) { + return getOrDefault(json, "oceanMonuments", new JsonPrimitive(true)); + } + + private static JsonElement getTemples(JsonObject json) { + return getOrDefault(json, "temples", new JsonPrimitive(true)); + } + + private static JsonElement getMineshafts(JsonObject json) { + return getOrDefault(json, "mineshafts", new JsonPrimitive(true)); + } + + private static JsonElement getVillages(JsonObject json) { + return getOrDefault(json, "villages", new JsonPrimitive(true)); + } + + private static JsonElement getAlternateStrongholdsPositions(JsonObject json) { + return getOrDefault(json, "alternateStrongholdsPositions", new JsonPrimitive(false)); + } + + private static JsonElement getStrongholds(JsonObject json) { + return getOrDefault(json, "strongholds", new JsonPrimitive(true)); + } + + private static JsonElement getCaves(JsonObject json) { + return getOrDefault(json, "caves", new JsonPrimitive(true)); + } + + private static JsonElement getWaterLevel(JsonObject json) { + return getOrDefault(json, "waterLevel", new JsonPrimitive(63)); + } + + private static JsonElement getOrDefault(JsonObject source, String name, JsonElement jsonElement) { + if (source.has(name)) + return source.get(name); + return jsonElement; + } + + private static JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, + Biome[] biomes) { + if (!root.has(ore + "SpawnTries")) { + // some old saves are broken, especially 1.11.2 ones from the + // 1.12.2->1.11.2 backport, build 847 + // this avoids adding a lot of air ores + return null; + } + + JsonObject obj = new JsonObject(); + obj.add("blockstate", gson.toJsonTree(state)); + if (biomes != null) { + obj.add("biomes", gson.toJsonTree(biomes)); + } + if (root.has(ore + "SpawnSize")) { + obj.add("spawnSize", root.remove(ore + "SpawnSize")); + } else { + // emerald doesn't have size defined in the old format + obj.add("spawnSize", new JsonPrimitive(3)); + } + obj.add("spawnTries", root.remove(ore + "SpawnTries")); + obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); + obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); + obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); + return obj; + } + + private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, + Biome[] biomes) { + JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); + if (obj == null) { + return null; + } + obj.add("heightMean", root.remove(ore + "HeightMean")); + obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); + obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); + return obj; + } +} diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java new file mode 100644 index 0000000..1fbae97 --- /dev/null +++ b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java @@ -0,0 +1,65 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen; + +import static org.mockito.Mockito.when; + +import javax.annotation.ParametersAreNonnullByDefault; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorld; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomTerrainGenerator; +import io.github.opencubicchunks.cubicchunks.cubicgen.testutil.MinecraftEnvironment; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.world.World; +import net.minecraft.world.storage.WorldInfo; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class TestCustomTerrainGenerator { + + @Before + public void setUp() { + MinecraftEnvironment.init(); + } + + @Test + public void testCustomTerrainGenerator() { + int checkFromY = -1; + int checkToY = 1; + CustomGeneratorSettings cgs = new CustomGeneratorSettings(); + World world = Mockito.mock(World.class, Mockito.withSettings().extraInterfaces(ICubicWorld.class)); + WorldInfo worldInfo = Mockito.mock(WorldInfo.class); + when(world.getWorldInfo()).thenReturn(worldInfo); + + when(worldInfo.getGeneratorOptions()).thenReturn(cgs.toJson(true)); + CustomTerrainGenerator ctp = new CustomTerrainGenerator(world, 0); + for (int i = checkFromY; i <= checkToY; i++) + ctp.generateCube(0, i, 0); + } +} From 9d3560104d624e107e25b269ecf72949e8dd6ea6 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Tue, 18 Dec 2018 21:36:08 +0300 Subject: [PATCH 08/17] Half-assed fixer for JSON preset --- .../customcubic/CustomGeneratorSettings.java | 4 +- .../CustomGeneratorSettingsFixer.java | 6 +- ...CustomGeneratorSettingsHalfAssedFixer.java | 233 ++++++++++++++++++ .../cubicgen/TestCustomTerrainGenerator.java | 65 ----- 4 files changed, 237 insertions(+), 71 deletions(-) create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java delete mode 100644 src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 4796d1d..33e5a41 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -212,7 +212,7 @@ public static CustomGeneratorSettings fromJson(String jsonString) { return defaults(); } if (isOutdated(jsonString)) { - jsonString = CustomGeneratorSettingsFixer.fixGeneratorOptions(jsonString); + jsonString = CustomGeneratorSettingsHalfAssedFixer.fixGeneratorOptions(jsonString); } Gson gson = gson(true); // minimize option shouldn't matter when deserializing return gson.fromJson(jsonString, CustomGeneratorSettings.class); @@ -263,7 +263,7 @@ public void save(World world) { } catch (IOException e) { CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); CustomCubicMod.LOGGER.error(this.toJson(true)); - e.printStackTrace(); + CustomCubicMod.LOGGER.catching(e); } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java index 4eea712..793d9e3 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java @@ -26,7 +26,6 @@ import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; import java.io.StringReader; -import java.util.Map.Entry; import com.google.gson.Gson; import com.google.gson.JsonArray; @@ -44,7 +43,6 @@ import net.minecraft.init.Biomes; import net.minecraft.init.Blocks; import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.ChunkGeneratorSettings; public class CustomGeneratorSettingsFixer { @@ -89,10 +87,10 @@ public static String fixGeneratorOptions(String generatorOptionsToFix) { JsonReader oldReader = new JsonReader(new StringReader(generatorOptionsToFix)); JsonObject oldRoot = new JsonParser().parse(oldReader).getAsJsonObject(); - JsonReader newReader = new JsonReader(new StringReader("")); + JsonReader newReader = new JsonReader(new StringReader("{}")); JsonObject newRoot = new JsonParser().parse(newReader).getAsJsonObject(); - newRoot.add("version", new JsonPrimitive(VERSION)); + newRoot.add("version", new JsonPrimitive(3)); newRoot.add("waterLevel", getWaterLevel(oldRoot)); newRoot.add("caves", getCaves(oldRoot)); newRoot.add("strongholds", getStrongholds(oldRoot)); diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java new file mode 100644 index 0000000..82e79bd --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java @@ -0,0 +1,233 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.customcubic; + +import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; + +import java.io.StringReader; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.gson.stream.JsonReader; + +import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; +import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.BiomeBlockReplacerConfig; +import net.minecraft.block.BlockSilverfish; +import net.minecraft.block.BlockStone; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Biomes; +import net.minecraft.init.Blocks; +import net.minecraft.world.biome.Biome; + +public class CustomGeneratorSettingsHalfAssedFixer { + + public static String fixGeneratorOptions(String generatorOptions) { + generatorOptions = fixGeneratorOptionsVersion0(generatorOptions); + generatorOptions = fixGeneratorOptionsVersion1(generatorOptions); + generatorOptions = fixGeneratorOptionsVersion3(generatorOptions); + return CustomGeneratorSettings.fromJson(generatorOptions).toJson(true); + } + + public static String fixGeneratorOptionsVersion0(String generatorOptions) { + if (generatorOptions.isEmpty()) { + generatorOptions = new CustomGeneratorSettings().toJson(false); + } + Gson gson = CustomGeneratorSettings.gson(false); + + JsonReader reader = new JsonReader(new StringReader(generatorOptions)); + JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); + + // some old saves are broken, especially 1.11.2 ones from the + // 1.12.2->1.11.2 backport, build 847 + // this preserves the existing ores + JsonArray standardOres = root.has("standardOres") ? root.getAsJsonArray("standardOres") : new JsonArray(); + JsonArray periodicGaussianOres = root.has("periodicGaussianOres") ? root.getAsJsonArray("periodicGaussianOres") + : new JsonArray(); + + // kind of ugly but I don'twant to make a special class just so store + // these 3 objects... + String[] standard = { "dirt", "gravel", "granite", "diorite", "andesite", "coalOre", "ironOre", "goldOre", + "redstoneOre", "diamondOre", "hillsEmeraldOre", "hillsSilverfishStone", "mesaAddedGoldOre" }; + IBlockState[] standardBlockstates = { Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState(), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), + Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), + Blocks.COAL_ORE.getDefaultState(), Blocks.IRON_ORE.getDefaultState(), Blocks.GOLD_ORE.getDefaultState(), + Blocks.REDSTONE_ORE.getDefaultState(), Blocks.DIAMOND_ORE.getDefaultState(), + Blocks.EMERALD_ORE.getDefaultState(), Blocks.MONSTER_EGG.getDefaultState().withProperty( + BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), + Blocks.GOLD_ORE.getDefaultState() }; + Biome[][] standardBiomes = { null, // dirt + null, // gravel + null, // granite + null, // diorite + null, // andesite + null, // coal + null, // iron + null, // gold + null, // redstone + null, // diamond + { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, + Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // emerald + { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, + Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // monster + // egg + { Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, + Biomes.MUTATED_MESA_CLEAR_ROCK, Biomes.MUTATED_MESA_ROCK },// mesa + // gold + }; + for (int i = 0; i < standard.length; i++) { + JsonObject obj = convertStandardOre(gson, root, standard[i], standardBlockstates[i], standardBiomes[i]); + if (obj != null) { + standardOres.add(obj); + } + + } + JsonObject lapis = convertGaussianPeriodicOre(gson, root, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), + null); + if (lapis != null) { + periodicGaussianOres.add(lapis); + } + root.add("standardOres", standardOres); + root.add("periodicGaussianOres", periodicGaussianOres); + return gson.toJson(root); + } + + private static JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { + if (!root.has(ore + "SpawnTries")) { + // some old saves are broken, especially 1.11.2 ones from the + // 1.12.2->1.11.2 backport, build 847 + // this avoids adding a lot of air ores + return null; + } + + JsonObject obj = new JsonObject(); + obj.add("blockstate", gson.toJsonTree(state)); + if (biomes != null) { + obj.add("biomes", gson.toJsonTree(biomes)); + } + if (root.has(ore + "SpawnSize")) { + obj.add("spawnSize", root.remove(ore + "SpawnSize")); + } else { + // emerald doesn't have size defined in the old format + obj.add("spawnSize", new JsonPrimitive(3)); + } + obj.add("spawnTries", root.remove(ore + "SpawnTries")); + obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); + obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); + obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); + return obj; + } + + private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, + Biome[] biomes) { + JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); + if (obj == null) { + return null; + } + obj.add("heightMean", root.remove(ore + "HeightMean")); + obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); + obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); + return obj; + } + + public static String fixGeneratorOptionsVersion1(String generatorOptions) { + if (generatorOptions.isEmpty()) { + generatorOptions = new CustomGeneratorSettings().toJson(false); + } + Gson gson = CustomGeneratorSettings.gson(false); + + JsonReader reader = new JsonReader(new StringReader(generatorOptions)); + JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); + + float heightVariationOffset = root.get("heightVariationOffset").getAsFloat(); + float offset = root.get("heightOffset").getAsFloat(); + float factor = root.get("heightFactor").getAsFloat(); + if (!root.has("expectedBaseHeight")) { + root.add("expectedBaseHeight", root.get("heightOffset")); + } + if (!root.has("expectedHeightVariation")) { + root.add("expectedHeightVariation", root.get("heightFactor")); + } + if (!root.has("actualHeight")) { + root.add("actualHeight", new JsonPrimitive((offset + heightVariationOffset + + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); + } + if (!root.has("cubeAreas")) { + root.add("cubeAreas", new JsonObject()); + } + if (!root.has("replacerConfig")) { + JsonObject replacerConf = new JsonObject(); + { + JsonObject defaults = new JsonObject(); + { + defaults.add(MODID + ":horizontal_gradient_depth_decrease_weight", new JsonPrimitive(1.0f)); + defaults.add(MODID + ":height_offset", new JsonPrimitive(offset)); + JsonObject terrainfill = new JsonObject(); + { + JsonObject properties = new JsonObject(); + properties.add("variant", new JsonPrimitive("stone")); + terrainfill.add("Properties", properties); + terrainfill.add("Name", new JsonPrimitive("minecraft:stone")); + } + JsonObject oceanblock = new JsonObject(); + + { + JsonObject properties = new JsonObject(); + properties.add("level", new JsonPrimitive("0")); + oceanblock.add("Properties", properties); + oceanblock.add("Name", new JsonPrimitive("minecraft:water")); + } + defaults.add(MODID + ":biome_fill_depth_offset", new JsonPrimitive(3.0f)); + defaults.add(MODID + ":biome_fill_noise_octaves", new JsonPrimitive(4.0f)); + defaults.add(MODID + ":height_scale", new JsonPrimitive(factor)); + defaults.add(MODID + ":biome_fill_depth_factor", new JsonPrimitive(2.3333333333333335f)); + defaults.add(MODID + ":mesa_depth", new JsonPrimitive(16.0f)); + defaults.add(MODID + ":water_level", root.get("waterLevel")); + defaults.add(MODID + ":biome_fill_noise_freq", new JsonPrimitive(0.0078125f)); + } + replacerConf.add("defaults", defaults); + replacerConf.add("overrides", new JsonObject()); + } + + root.add("replacerConfig", replacerConf); + } + return gson.toJson(root); + } + + public static String fixGeneratorOptionsVersion3(String generatorOptions) { + if (generatorOptions.isEmpty()) { + generatorOptions = new CustomGeneratorSettings().toJson(true); + } + // this is far simpler that walking through the json and figurring out + // all the places where it occurs + // instead, just do string search and replace. The string shouldn't + // occur in any other context + return generatorOptions.replaceAll(MODID + ":", MODID + ":"); + } +} diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java deleted file mode 100644 index 1fbae97..0000000 --- a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomTerrainGenerator.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of Cubic World Generation, licensed under the MIT License (MIT). - * - * Copyright (c) 2015 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.github.opencubicchunks.cubicchunks.cubicgen; - -import static org.mockito.Mockito.when; - -import javax.annotation.ParametersAreNonnullByDefault; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorld; -import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; -import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomTerrainGenerator; -import io.github.opencubicchunks.cubicchunks.cubicgen.testutil.MinecraftEnvironment; -import mcp.MethodsReturnNonnullByDefault; -import net.minecraft.world.World; -import net.minecraft.world.storage.WorldInfo; - -@ParametersAreNonnullByDefault -@MethodsReturnNonnullByDefault -public class TestCustomTerrainGenerator { - - @Before - public void setUp() { - MinecraftEnvironment.init(); - } - - @Test - public void testCustomTerrainGenerator() { - int checkFromY = -1; - int checkToY = 1; - CustomGeneratorSettings cgs = new CustomGeneratorSettings(); - World world = Mockito.mock(World.class, Mockito.withSettings().extraInterfaces(ICubicWorld.class)); - WorldInfo worldInfo = Mockito.mock(WorldInfo.class); - when(world.getWorldInfo()).thenReturn(worldInfo); - - when(worldInfo.getGeneratorOptions()).thenReturn(cgs.toJson(true)); - CustomTerrainGenerator ctp = new CustomTerrainGenerator(world, 0); - for (int i = checkFromY; i <= checkToY; i++) - ctp.generateCube(0, i, 0); - } -} From bfeaf97980c593bbc588ddc238f0b1af719e9ed9 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Tue, 18 Dec 2018 21:46:51 +0300 Subject: [PATCH 09/17] False --- .../customcubic/CustomGeneratorSettingsHalfAssedFixer.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java index 82e79bd..4eb061d 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java @@ -29,14 +29,11 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import com.google.gson.stream.JsonReader; -import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; -import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.BiomeBlockReplacerConfig; import net.minecraft.block.BlockSilverfish; import net.minecraft.block.BlockStone; import net.minecraft.block.state.IBlockState; @@ -50,7 +47,7 @@ public static String fixGeneratorOptions(String generatorOptions) { generatorOptions = fixGeneratorOptionsVersion0(generatorOptions); generatorOptions = fixGeneratorOptionsVersion1(generatorOptions); generatorOptions = fixGeneratorOptionsVersion3(generatorOptions); - return CustomGeneratorSettings.fromJson(generatorOptions).toJson(true); + return CustomGeneratorSettings.fromJson(generatorOptions).toJson(false); } public static String fixGeneratorOptionsVersion0(String generatorOptions) { From 6a572b711f70fd0d58ec46b8668764da016bb0f0 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sat, 22 Dec 2018 14:04:14 +0300 Subject: [PATCH 10/17] Full-assed generator settings fixer --- .../customcubic/CustomGeneratorSettings.java | 11 +- .../CustomGeneratorSettingsFixer.java | 239 ++++++++++++------ ...CustomGeneratorSettingsHalfAssedFixer.java | 230 ----------------- .../TestCustomGeneratorSettingsFixer.java | 184 ++++++++++++++ 4 files changed, 346 insertions(+), 318 deletions(-) delete mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java create mode 100644 src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 33e5a41..395e7fd 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -202,8 +202,7 @@ public String toJson(boolean minimize) { } public static boolean isOutdated(String settingsJsonString) { - JsonReader reader = new JsonReader(new StringReader(settingsJsonString)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); + JsonObject root = CustomGeneratorSettingsFixer.stringToJson(settingsJsonString); return !root.has("version") || root.get("version").getAsInt() != CustomGeneratorSettingsFixer.VERSION; } @@ -212,9 +211,9 @@ public static CustomGeneratorSettings fromJson(String jsonString) { return defaults(); } if (isOutdated(jsonString)) { - jsonString = CustomGeneratorSettingsHalfAssedFixer.fixGeneratorOptions(jsonString); + jsonString = CustomGeneratorSettingsFixer.fixGeneratorOptions(CustomGeneratorSettingsFixer.stringToJson(jsonString), false); } - Gson gson = gson(true); // minimize option shouldn't matter when deserializing + Gson gson = gson(false); return gson.fromJson(jsonString, CustomGeneratorSettings.class); } @@ -258,11 +257,11 @@ public void save(World world) { File settingsFile = new File(folder, "custom_generator_settings.json"); try (FileWriter writer = new FileWriter(settingsFile)) { folder.mkdirs(); - writer.write(this.toJson(true)); + writer.write(this.toJson(false)); CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); } catch (IOException e) { CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); - CustomCubicMod.LOGGER.error(this.toJson(true)); + CustomCubicMod.LOGGER.error(this.toJson(false)); CustomCubicMod.LOGGER.catching(e); } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java index 793d9e3..baf754a 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java @@ -26,6 +26,8 @@ import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; import com.google.gson.Gson; import com.google.gson.JsonArray; @@ -37,6 +39,7 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.BiomeBlockReplacerConfig; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings.IntAABB; import net.minecraft.block.BlockSilverfish; import net.minecraft.block.BlockStone; import net.minecraft.block.state.IBlockState; @@ -81,84 +84,151 @@ public class CustomGeneratorSettingsFixer { // gold }; - public static String fixGeneratorOptions(String generatorOptionsToFix) { + public static String fixGeneratorOptions(JsonObject oldRoot, boolean calledForCubeArea) { Gson gson = CustomGeneratorSettings.gson(false); - - JsonReader oldReader = new JsonReader(new StringReader(generatorOptionsToFix)); - JsonObject oldRoot = new JsonParser().parse(oldReader).getAsJsonObject(); - - JsonReader newReader = new JsonReader(new StringReader("{}")); - JsonObject newRoot = new JsonParser().parse(newReader).getAsJsonObject(); - - newRoot.add("version", new JsonPrimitive(3)); - newRoot.add("waterLevel", getWaterLevel(oldRoot)); - newRoot.add("caves", getCaves(oldRoot)); - newRoot.add("strongholds", getStrongholds(oldRoot)); - newRoot.add("alternateStrongholdsPositions", getAlternateStrongholdsPositions(oldRoot)); - newRoot.add("villages", getVillages(oldRoot)); - newRoot.add("mineshafts", getMineshafts(oldRoot)); - newRoot.add("temples", getTemples(oldRoot)); - newRoot.add("oceanMonuments", getOceanMonuments(oldRoot)); - newRoot.add("woodlandMansions", getWoodlandMansions(oldRoot)); - newRoot.add("ravines", getRavines(oldRoot)); - newRoot.add("dungeons", getDungeons(oldRoot)); - newRoot.add("dungeonCount", getDungeonCount(oldRoot)); - newRoot.add("waterLakes", getWaterLakes(oldRoot)); - newRoot.add("waterLakeRarity", getWaterLakeRarity(oldRoot)); - newRoot.add("lavaLakes", getLavaLakes(oldRoot)); - newRoot.add("lavaLakeRarity", getLavaLakeRarity(oldRoot)); - newRoot.add("aboveSeaLavaLakeRarity", getAboveSeaLavaLakeRarity(oldRoot)); - newRoot.add("lavaOceans", getLavaOceans(oldRoot)); - newRoot.add("biome", getBiome(oldRoot)); - newRoot.add("biomeSize", getBiomeSize(oldRoot)); - newRoot.add("riverSize", getRiverSize(oldRoot)); - newRoot.add("standardOres", getStandardOres(oldRoot)); - newRoot.add("periodicGaussianOres", getPeriodicGaussianOres(oldRoot)); - newRoot.add("expectedBaseHeight", getExpectedBaseHeight(oldRoot)); - newRoot.add("expectedHeightVariation", getExpectedHeightVariation(oldRoot)); - newRoot.add("actualHeight", getActualHeight(oldRoot)); - newRoot.add("heightVariationFactor", getHeightVariationFactor(oldRoot)); - newRoot.add("specialHeightVariationFactorBelowAverageY", getSpecialHeightVariationFactorBelowAverageY(oldRoot)); - newRoot.add("heightVariationOffset", getHeightVariationOffset(oldRoot)); - newRoot.add("heightFactor", getHeightFactor(oldRoot)); - newRoot.add("heightOffset", getHeightOffset(oldRoot)); - newRoot.add("depthNoiseFactor", getDepthNoiseFactor(oldRoot)); - newRoot.add("depthNoiseOffset", getDepthNoiseOffset(oldRoot)); - newRoot.add("depthNoiseFrequencyX", getDepthNoiseFrequencyX(oldRoot)); - newRoot.add("depthNoiseFrequencyZ", getDepthNoiseFrequencyZ(oldRoot)); - newRoot.add("depthNoiseOctaves", getDepthNoiseOctaves(oldRoot)); - newRoot.add("selectorNoiseFactor", getSelectorNoiseFactor(oldRoot)); - newRoot.add("selectorNoiseOffset", getSelectorNoiseOffset(oldRoot)); - newRoot.add("selectorNoiseFrequencyX", getSelectorNoiseFrequencyX(oldRoot)); - newRoot.add("selectorNoiseFrequencyY", getSelectorNoiseFrequencyY(oldRoot)); - newRoot.add("selectorNoiseFrequencyZ", getSelectorNoiseFrequencyZ(oldRoot)); - newRoot.add("selectorNoiseOctaves", getSelectorNoiseOctaves(oldRoot)); - newRoot.add("lowNoiseFactor", getLowNoiseFactor(oldRoot)); - newRoot.add("lowNoiseOffset", getLowNoiseOffset(oldRoot)); - newRoot.add("lowNoiseFrequencyX", getLowNoiseFrequencyX(oldRoot)); - newRoot.add("lowNoiseFrequencyY", getLowNoiseFrequencyY(oldRoot)); - newRoot.add("lowNoiseFrequencyZ", getLowNoiseFrequencyZ(oldRoot)); - newRoot.add("lowNoiseOctaves", getLowNoiseOctaves(oldRoot)); - newRoot.add("highNoiseFactor", getHighNoiseFactor(oldRoot)); - newRoot.add("highNoiseOffset", getHighNoiseOffset(oldRoot)); - newRoot.add("highNoiseFrequencyX", getHighNoiseFrequencyX(oldRoot)); - newRoot.add("highNoiseFrequencyY", getHighNoiseFrequencyY(oldRoot)); - newRoot.add("highNoiseFrequencyZ", getHighNoiseFrequencyZ(oldRoot)); - newRoot.add("highNoiseOctaves", getHighNoiseOctaves(oldRoot)); - newRoot.add("cubeAreas", getCubeAreas(oldRoot)); - newRoot.add("replacerConfig", getReplacerConfig(oldRoot)); + JsonObject newRoot = stringToJson("{}"); + + if (!calledForCubeArea) + newRoot.add("version", new JsonPrimitive(3)); + if (!calledForCubeArea || oldRoot.has("waterLevel")) + newRoot.add("waterLevel", getWaterLevel(oldRoot)); + if (!calledForCubeArea || oldRoot.has("caves")) + newRoot.add("caves", getCaves(oldRoot)); + if (!calledForCubeArea || oldRoot.has("strongholds")) + newRoot.add("strongholds", getStrongholds(oldRoot)); + if (!calledForCubeArea || oldRoot.has("alternateStrongholdsPositions")) + newRoot.add("alternateStrongholdsPositions", getAlternateStrongholdsPositions(oldRoot)); + if (!calledForCubeArea || oldRoot.has("villages")) + newRoot.add("villages", getVillages(oldRoot)); + if (!calledForCubeArea || oldRoot.has("mineshafts")) + newRoot.add("mineshafts", getMineshafts(oldRoot)); + if (!calledForCubeArea || oldRoot.has("temples")) + newRoot.add("temples", getTemples(oldRoot)); + if (!calledForCubeArea || oldRoot.has("oceanMonuments")) + newRoot.add("oceanMonuments", getOceanMonuments(oldRoot)); + if (!calledForCubeArea || oldRoot.has("woodlandMansions")) + newRoot.add("woodlandMansions", getWoodlandMansions(oldRoot)); + if (!calledForCubeArea || oldRoot.has("ravines")) + newRoot.add("ravines", getRavines(oldRoot)); + if (!calledForCubeArea || oldRoot.has("dungeons")) + newRoot.add("dungeons", getDungeons(oldRoot)); + if (!calledForCubeArea || oldRoot.has("dungeonCount")) + newRoot.add("dungeonCount", getDungeonCount(oldRoot)); + if (!calledForCubeArea || oldRoot.has("waterLakes")) + newRoot.add("waterLakes", getWaterLakes(oldRoot)); + if (!calledForCubeArea || oldRoot.has("waterLakeRarity")) + newRoot.add("waterLakeRarity", getWaterLakeRarity(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lavaLakes")) + newRoot.add("lavaLakes", getLavaLakes(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lavaLakeRarity")) + newRoot.add("lavaLakeRarity", getLavaLakeRarity(oldRoot)); + if (!calledForCubeArea || oldRoot.has("aboveSeaLavaLakeRarity")) + newRoot.add("aboveSeaLavaLakeRarity", getAboveSeaLavaLakeRarity(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lavaOceans")) + newRoot.add("lavaOceans", getLavaOceans(oldRoot)); + if (!calledForCubeArea || oldRoot.has("biome")) + newRoot.add("biome", getBiome(oldRoot)); + if (!calledForCubeArea || oldRoot.has("biomeSize")) + newRoot.add("biomeSize", getBiomeSize(oldRoot)); + if (!calledForCubeArea || oldRoot.has("riverSize")) + newRoot.add("riverSize", getRiverSize(oldRoot)); + if (!calledForCubeArea || oldRoot.has("standardOres")) + newRoot.add("standardOres", getStandardOres(oldRoot)); + if (!calledForCubeArea || oldRoot.has("periodicGaussianOres")) + newRoot.add("periodicGaussianOres", getPeriodicGaussianOres(oldRoot)); + if (!calledForCubeArea || oldRoot.has("expectedBaseHeight")) + newRoot.add("expectedBaseHeight", getExpectedBaseHeight(oldRoot)); + if (!calledForCubeArea || oldRoot.has("expectedHeightVariation")) + newRoot.add("expectedHeightVariation", getExpectedHeightVariation(oldRoot)); + if (!calledForCubeArea || oldRoot.has("actualHeight")) + newRoot.add("actualHeight", getActualHeight(oldRoot)); + if (!calledForCubeArea || oldRoot.has("heightVariationFactor")) + newRoot.add("heightVariationFactor", getHeightVariationFactor(oldRoot)); + if (!calledForCubeArea || oldRoot.has("specialHeightVariationFactorBelowAverageY")) + newRoot.add("specialHeightVariationFactorBelowAverageY", + getSpecialHeightVariationFactorBelowAverageY(oldRoot)); + if (!calledForCubeArea || oldRoot.has("heightVariationOffset")) + newRoot.add("heightVariationOffset", getHeightVariationOffset(oldRoot)); + if (!calledForCubeArea || oldRoot.has("heightFactor")) + newRoot.add("heightFactor", getHeightFactor(oldRoot)); + if (!calledForCubeArea || oldRoot.has("heightOffset")) + newRoot.add("heightOffset", getHeightOffset(oldRoot)); + if (!calledForCubeArea || oldRoot.has("depthNoiseFactor")) + newRoot.add("depthNoiseFactor", getDepthNoiseFactor(oldRoot)); + if (!calledForCubeArea || oldRoot.has("depthNoiseOffset")) + newRoot.add("depthNoiseOffset", getDepthNoiseOffset(oldRoot)); + if (!calledForCubeArea || oldRoot.has("depthNoiseFrequencyX")) + newRoot.add("depthNoiseFrequencyX", getDepthNoiseFrequencyX(oldRoot)); + if (!calledForCubeArea || oldRoot.has("depthNoiseFrequencyZ")) + newRoot.add("depthNoiseFrequencyZ", getDepthNoiseFrequencyZ(oldRoot)); + if (!calledForCubeArea || oldRoot.has("depthNoiseOctaves")) + newRoot.add("depthNoiseOctaves", getDepthNoiseOctaves(oldRoot)); + if (!calledForCubeArea || oldRoot.has("selectorNoiseFactor")) + newRoot.add("selectorNoiseFactor", getSelectorNoiseFactor(oldRoot)); + if (!calledForCubeArea || oldRoot.has("selectorNoiseOffset")) + newRoot.add("selectorNoiseOffset", getSelectorNoiseOffset(oldRoot)); + if (!calledForCubeArea || oldRoot.has("selectorNoiseFrequencyX")) + newRoot.add("selectorNoiseFrequencyX", getSelectorNoiseFrequencyX(oldRoot)); + if (!calledForCubeArea || oldRoot.has("selectorNoiseFrequencyY")) + newRoot.add("selectorNoiseFrequencyY", getSelectorNoiseFrequencyY(oldRoot)); + if (!calledForCubeArea || oldRoot.has("selectorNoiseFrequencyZ")) + newRoot.add("selectorNoiseFrequencyZ", getSelectorNoiseFrequencyZ(oldRoot)); + if (!calledForCubeArea || oldRoot.has("selectorNoiseOctaves")) + newRoot.add("selectorNoiseOctaves", getSelectorNoiseOctaves(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lowNoiseFactor")) + newRoot.add("lowNoiseFactor", getLowNoiseFactor(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lowNoiseOffset")) + newRoot.add("lowNoiseOffset", getLowNoiseOffset(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lowNoiseFrequencyX")) + newRoot.add("lowNoiseFrequencyX", getLowNoiseFrequencyX(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lowNoiseFrequencyY")) + newRoot.add("lowNoiseFrequencyY", getLowNoiseFrequencyY(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lowNoiseFrequencyZ")) + newRoot.add("lowNoiseFrequencyZ", getLowNoiseFrequencyZ(oldRoot)); + if (!calledForCubeArea || oldRoot.has("lowNoiseOctaves")) + newRoot.add("lowNoiseOctaves", getLowNoiseOctaves(oldRoot)); + if (!calledForCubeArea || oldRoot.has("highNoiseFactor")) + newRoot.add("highNoiseFactor", getHighNoiseFactor(oldRoot)); + if (!calledForCubeArea || oldRoot.has("highNoiseOffset")) + newRoot.add("highNoiseOffset", getHighNoiseOffset(oldRoot)); + if (!calledForCubeArea || oldRoot.has("highNoiseFrequencyX")) + newRoot.add("highNoiseFrequencyX", getHighNoiseFrequencyX(oldRoot)); + if (!calledForCubeArea || oldRoot.has("highNoiseFrequencyY")) + newRoot.add("highNoiseFrequencyY", getHighNoiseFrequencyY(oldRoot)); + if (!calledForCubeArea || oldRoot.has("highNoiseFrequencyZ")) + newRoot.add("highNoiseFrequencyZ", getHighNoiseFrequencyZ(oldRoot)); + if (!calledForCubeArea || oldRoot.has("highNoiseOctaves")) + newRoot.add("highNoiseOctaves", getHighNoiseOctaves(oldRoot)); + if (!calledForCubeArea) + newRoot.add("cubeAreas", getCubeAreas(oldRoot)); + if (!calledForCubeArea || oldRoot.has("replacerConfig")) + newRoot.add("replacerConfig", getReplacerConfig(oldRoot)); String newGeneratorOptions = gson.toJson(newRoot).replaceAll("cubicchunks:", MODID + ":"); return newGeneratorOptions; } private static JsonElement getReplacerConfig(JsonObject json) { - Gson gson = CustomGeneratorSettings.gson(false); - return getOrDefault(json, "replacerConfig", gson.toJsonTree(BiomeBlockReplacerConfig.defaults())); + JsonReader reader = new JsonReader(new StringReader("{\"defaults\":{\"cubicgen:biome_fill_noise_octaves\":4.0,\"cubicgen:ocean_block\":{\"Properties\":{\"level\":\"0\"},\"Name\":\"minecraft:water\"},\"cubicgen:height_scale\":64.0,\"cubicgen:biome_fill_noise_freq\":0.0078125,\"cubicgen:water_level\":63.0,\"cubicgen:biome_fill_depth_factor\":2.3333333333333335,\"cubicgen:terrain_fill_block\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:stone\"},\"cubicgen:mesa_depth\":16.0,\"cubicgen:biome_fill_depth_offset\":3.0,\"cubicgen:horizontal_gradient_depth_decrease_weight\":1.0,\"cubicgen:height_offset\":64.0},\"overrides\":{}}")); + JsonObject biomeBlockReplacerConfigDefaultJson = new JsonParser().parse(reader).getAsJsonObject(); + return getOrDefault(json, "replacerConfig", biomeBlockReplacerConfigDefaultJson); } private static JsonElement getCubeAreas(JsonObject json) { - return getOrDefault(json, "cubeAreas", new JsonArray()); + JsonArray cubeAreas = new JsonArray(); + if (json.has("cubeAreas") && json.get("cubeAreas").isJsonArray()) { + JsonArray array = json.get("cubeAreas").getAsJsonArray(); + for (JsonElement entry : array) { + JsonArray mapEntry = entry.getAsJsonArray(); + JsonElement key = mapEntry.get(0); + JsonObject value = stringToJson(fixGeneratorOptions(mapEntry.get(1).getAsJsonObject(), true)); + JsonArray newEntry = new JsonArray(); + newEntry.add(key); + newEntry.add(value); + cubeAreas.add(newEntry); + } + } + return cubeAreas; } private static JsonElement getHighNoiseOctaves(JsonObject json) { @@ -167,17 +237,17 @@ private static JsonElement getHighNoiseOctaves(JsonObject json) { private static JsonElement getHighNoiseFrequencyZ(JsonObject json) { return getOrDefault(json, "highNoiseFrequencyZ", - new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + new JsonPrimitive(0.005221649)); } private static JsonElement getHighNoiseFrequencyY(JsonObject json) { return getOrDefault(json, "highNoiseFrequencyY", - new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_Y)); + new JsonPrimitive(0.0026108245)); } private static JsonElement getHighNoiseFrequencyX(JsonObject json) { return getOrDefault(json, "highNoiseFrequencyX", - new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + new JsonPrimitive(0.005221649)); } private static JsonElement getHighNoiseOffset(JsonObject json) { @@ -190,17 +260,17 @@ private static JsonElement getHighNoiseFactor(JsonObject json) { private static JsonElement getLowNoiseFrequencyZ(JsonObject json) { return getOrDefault(json, "lowNoiseFrequencyZ", - new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + new JsonPrimitive(0.005221649)); } private static JsonElement getLowNoiseFrequencyY(JsonObject json) { return getOrDefault(json, "lowNoiseFrequencyY", - new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_Y)); + new JsonPrimitive(0.0026108245)); } private static JsonElement getLowNoiseFrequencyX(JsonObject json) { return getOrDefault(json, "lowNoiseFrequencyX", - new JsonPrimitive(ConversionUtils.VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ)); + new JsonPrimitive(0.005221649)); } private static JsonElement getLowNoiseOffset(JsonObject json) { @@ -221,27 +291,27 @@ private static JsonElement getSelectorNoiseOctaves(JsonObject json) { private static JsonElement getSelectorNoiseFrequencyZ(JsonObject json) { return getOrDefault(json, "selectorNoiseFrequencyZ", - new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FREQUENCY_XZ)); + new JsonPrimitive(0.016709277)); } private static JsonElement getSelectorNoiseFrequencyX(JsonObject json) { return getOrDefault(json, "selectorNoiseFrequencyX", - new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FREQUENCY_XZ)); + new JsonPrimitive(0.016709277)); } private static JsonElement getSelectorNoiseFrequencyY(JsonObject json) { return getOrDefault(json, "selectorNoiseFrequencyY", - new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FREQUENCY_Y)); + new JsonPrimitive(0.008354639)); } private static JsonElement getSelectorNoiseOffset(JsonObject json) { return getOrDefault(json, "selectorNoiseOffset", - new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_OFFSET)); + new JsonPrimitive(0.5)); } private static JsonElement getSelectorNoiseFactor(JsonObject json) { return getOrDefault(json, "selectorNoiseFactor", - new JsonPrimitive(ConversionUtils.VANILLA_SELECTOR_NOISE_FACTOR)); + new JsonPrimitive(12.75)); } private static JsonElement getDepthNoiseOctaves(JsonObject json) { @@ -250,12 +320,12 @@ private static JsonElement getDepthNoiseOctaves(JsonObject json) { private static JsonElement getDepthNoiseFrequencyZ(JsonObject json) { return getOrDefault(json, "depthNoiseFrequencyZ", - new JsonPrimitive(ConversionUtils.VANILLA_DEPTH_NOISE_FREQUENCY)); + new JsonPrimitive(0.0015258789)); } private static JsonElement getDepthNoiseFrequencyX(JsonObject json) { return getOrDefault(json, "depthNoiseFrequencyX", - new JsonPrimitive(ConversionUtils.VANILLA_DEPTH_NOISE_FREQUENCY)); + new JsonPrimitive(0.0015258789)); } private static JsonElement getDepthNoiseOffset(JsonObject json) { @@ -263,7 +333,7 @@ private static JsonElement getDepthNoiseOffset(JsonObject json) { } private static JsonElement getDepthNoiseFactor(JsonObject json) { - return getOrDefault(json, "depthNoiseFactor", new JsonPrimitive(ConversionUtils.VANILLA_DEPTH_NOISE_FACTOR)); + return getOrDefault(json, "depthNoiseFactor", new JsonPrimitive(1.024)); } private static JsonElement getHeightOffset(JsonObject json) { @@ -462,4 +532,9 @@ private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); return obj; } + + static JsonObject stringToJson(String jsonString) { + JsonReader reader = new JsonReader(new StringReader(jsonString)); + return new JsonParser().parse(reader).getAsJsonObject(); + } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java deleted file mode 100644 index 4eb061d..0000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsHalfAssedFixer.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * This file is part of Cubic World Generation, licensed under the MIT License (MIT). - * - * Copyright (c) 2015 contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.github.opencubicchunks.cubicchunks.cubicgen.customcubic; - -import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; - -import java.io.StringReader; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.google.gson.stream.JsonReader; - -import net.minecraft.block.BlockSilverfish; -import net.minecraft.block.BlockStone; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Biomes; -import net.minecraft.init.Blocks; -import net.minecraft.world.biome.Biome; - -public class CustomGeneratorSettingsHalfAssedFixer { - - public static String fixGeneratorOptions(String generatorOptions) { - generatorOptions = fixGeneratorOptionsVersion0(generatorOptions); - generatorOptions = fixGeneratorOptionsVersion1(generatorOptions); - generatorOptions = fixGeneratorOptionsVersion3(generatorOptions); - return CustomGeneratorSettings.fromJson(generatorOptions).toJson(false); - } - - public static String fixGeneratorOptionsVersion0(String generatorOptions) { - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(false); - } - Gson gson = CustomGeneratorSettings.gson(false); - - JsonReader reader = new JsonReader(new StringReader(generatorOptions)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - - // some old saves are broken, especially 1.11.2 ones from the - // 1.12.2->1.11.2 backport, build 847 - // this preserves the existing ores - JsonArray standardOres = root.has("standardOres") ? root.getAsJsonArray("standardOres") : new JsonArray(); - JsonArray periodicGaussianOres = root.has("periodicGaussianOres") ? root.getAsJsonArray("periodicGaussianOres") - : new JsonArray(); - - // kind of ugly but I don'twant to make a special class just so store - // these 3 objects... - String[] standard = { "dirt", "gravel", "granite", "diorite", "andesite", "coalOre", "ironOre", "goldOre", - "redstoneOre", "diamondOre", "hillsEmeraldOre", "hillsSilverfishStone", "mesaAddedGoldOre" }; - IBlockState[] standardBlockstates = { Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState(), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.DIORITE), - Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.ANDESITE), - Blocks.COAL_ORE.getDefaultState(), Blocks.IRON_ORE.getDefaultState(), Blocks.GOLD_ORE.getDefaultState(), - Blocks.REDSTONE_ORE.getDefaultState(), Blocks.DIAMOND_ORE.getDefaultState(), - Blocks.EMERALD_ORE.getDefaultState(), Blocks.MONSTER_EGG.getDefaultState().withProperty( - BlockSilverfish.VARIANT, BlockSilverfish.EnumType.STONE), - Blocks.GOLD_ORE.getDefaultState() }; - Biome[][] standardBiomes = { null, // dirt - null, // gravel - null, // granite - null, // diorite - null, // andesite - null, // coal - null, // iron - null, // gold - null, // redstone - null, // diamond - { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, - Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // emerald - { Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_EDGE, Biomes.EXTREME_HILLS_WITH_TREES, - Biomes.MUTATED_EXTREME_HILLS, Biomes.MUTATED_EXTREME_HILLS_WITH_TREES }, // monster - // egg - { Biomes.MESA, Biomes.MESA_CLEAR_ROCK, Biomes.MESA_ROCK, Biomes.MUTATED_MESA, - Biomes.MUTATED_MESA_CLEAR_ROCK, Biomes.MUTATED_MESA_ROCK },// mesa - // gold - }; - for (int i = 0; i < standard.length; i++) { - JsonObject obj = convertStandardOre(gson, root, standard[i], standardBlockstates[i], standardBiomes[i]); - if (obj != null) { - standardOres.add(obj); - } - - } - JsonObject lapis = convertGaussianPeriodicOre(gson, root, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), - null); - if (lapis != null) { - periodicGaussianOres.add(lapis); - } - root.add("standardOres", standardOres); - root.add("periodicGaussianOres", periodicGaussianOres); - return gson.toJson(root); - } - - private static JsonObject convertStandardOre(Gson gson, JsonObject root, String ore, IBlockState state, Biome[] biomes) { - if (!root.has(ore + "SpawnTries")) { - // some old saves are broken, especially 1.11.2 ones from the - // 1.12.2->1.11.2 backport, build 847 - // this avoids adding a lot of air ores - return null; - } - - JsonObject obj = new JsonObject(); - obj.add("blockstate", gson.toJsonTree(state)); - if (biomes != null) { - obj.add("biomes", gson.toJsonTree(biomes)); - } - if (root.has(ore + "SpawnSize")) { - obj.add("spawnSize", root.remove(ore + "SpawnSize")); - } else { - // emerald doesn't have size defined in the old format - obj.add("spawnSize", new JsonPrimitive(3)); - } - obj.add("spawnTries", root.remove(ore + "SpawnTries")); - obj.add("spawnProbability", root.remove(ore + "SpawnProbability")); - obj.add("minHeight", root.remove(ore + "SpawnMinHeight")); - obj.add("maxHeight", root.remove(ore + "SpawnMaxHeight")); - return obj; - } - - private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, String ore, IBlockState state, - Biome[] biomes) { - JsonObject obj = convertStandardOre(gson, root, ore, state, biomes); - if (obj == null) { - return null; - } - obj.add("heightMean", root.remove(ore + "HeightMean")); - obj.add("heightStdDeviation", root.remove(ore + "HeightStdDeviation")); - obj.add("heightSpacing", root.remove(ore + "HeightSpacing")); - return obj; - } - - public static String fixGeneratorOptionsVersion1(String generatorOptions) { - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(false); - } - Gson gson = CustomGeneratorSettings.gson(false); - - JsonReader reader = new JsonReader(new StringReader(generatorOptions)); - JsonObject root = new JsonParser().parse(reader).getAsJsonObject(); - - float heightVariationOffset = root.get("heightVariationOffset").getAsFloat(); - float offset = root.get("heightOffset").getAsFloat(); - float factor = root.get("heightFactor").getAsFloat(); - if (!root.has("expectedBaseHeight")) { - root.add("expectedBaseHeight", root.get("heightOffset")); - } - if (!root.has("expectedHeightVariation")) { - root.add("expectedHeightVariation", root.get("heightFactor")); - } - if (!root.has("actualHeight")) { - root.add("actualHeight", new JsonPrimitive((offset + heightVariationOffset - + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); - } - if (!root.has("cubeAreas")) { - root.add("cubeAreas", new JsonObject()); - } - if (!root.has("replacerConfig")) { - JsonObject replacerConf = new JsonObject(); - { - JsonObject defaults = new JsonObject(); - { - defaults.add(MODID + ":horizontal_gradient_depth_decrease_weight", new JsonPrimitive(1.0f)); - defaults.add(MODID + ":height_offset", new JsonPrimitive(offset)); - JsonObject terrainfill = new JsonObject(); - { - JsonObject properties = new JsonObject(); - properties.add("variant", new JsonPrimitive("stone")); - terrainfill.add("Properties", properties); - terrainfill.add("Name", new JsonPrimitive("minecraft:stone")); - } - JsonObject oceanblock = new JsonObject(); - - { - JsonObject properties = new JsonObject(); - properties.add("level", new JsonPrimitive("0")); - oceanblock.add("Properties", properties); - oceanblock.add("Name", new JsonPrimitive("minecraft:water")); - } - defaults.add(MODID + ":biome_fill_depth_offset", new JsonPrimitive(3.0f)); - defaults.add(MODID + ":biome_fill_noise_octaves", new JsonPrimitive(4.0f)); - defaults.add(MODID + ":height_scale", new JsonPrimitive(factor)); - defaults.add(MODID + ":biome_fill_depth_factor", new JsonPrimitive(2.3333333333333335f)); - defaults.add(MODID + ":mesa_depth", new JsonPrimitive(16.0f)); - defaults.add(MODID + ":water_level", root.get("waterLevel")); - defaults.add(MODID + ":biome_fill_noise_freq", new JsonPrimitive(0.0078125f)); - } - replacerConf.add("defaults", defaults); - replacerConf.add("overrides", new JsonObject()); - } - - root.add("replacerConfig", replacerConf); - } - return gson.toJson(root); - } - - public static String fixGeneratorOptionsVersion3(String generatorOptions) { - if (generatorOptions.isEmpty()) { - generatorOptions = new CustomGeneratorSettings().toJson(true); - } - // this is far simpler that walking through the json and figurring out - // all the places where it occurs - // instead, just do string search and replace. The string shouldn't - // occur in any other context - return generatorOptions.replaceAll(MODID + ":", MODID + ":"); - } -} diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java new file mode 100644 index 0000000..1173c9b --- /dev/null +++ b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java @@ -0,0 +1,184 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import java.io.IOException; + +import javax.annotation.ParametersAreNonnullByDefault; + +import io.github.opencubicchunks.cubicchunks.api.worldgen.CubePrimer; +import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorld; +import io.github.opencubicchunks.cubicchunks.api.util.Coords; +import io.github.opencubicchunks.cubicchunks.cubicgen.testutil.MinecraftEnvironment; +import net.minecraft.world.World; +import org.junit.Before; +import org.junit.Test; + +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; +import io.github.opencubicchunks.cubicchunks.cubicgen.flat.FlatGeneratorSettings; +import io.github.opencubicchunks.cubicchunks.cubicgen.flat.FlatTerrainProcessor; +import io.github.opencubicchunks.cubicchunks.cubicgen.flat.Layer; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.world.storage.WorldInfo; +import org.mockito.Mockito; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class TestCustomGeneratorSettingsFixer { + String cc655ExamplePreset = "{\n" + + " \"waterLevel\":63,\n" + + " \"caves\":true,\n" + + " \"strongholds\":true,\n" + + " \"villages\":true,\n" + + " \"mineshafts\":true,\n" + + " \"temples\":true,\n" + + " \"oceanMonuments\":true,\n" + + " \"woodlandMansions\":true,\n" + + " \"ravines\":true,\n" + + " \"dungeons\":true,\n" + + " \"dungeonCount\":7,\n" + + " \"waterLakes\":true,\n" + + " \"waterLakeRarity\":4,\n" + + " \"lavaLakes\":true,\n" + + " \"lavaLakeRarity\":8,\n" + + " \"aboveSeaLavaLakeRarity\":13,\n" + + " \"lavaOceans\":false,\n" + + " \"biome\":-1,\n" + + " \"biomeSize\":4,\n" + + " \"riverSize\":4,\n" + + " \"dirtSpawnSize\":33,\n" + + " \"dirtSpawnTries\":10,\n" + + " \"dirtSpawnProbability\":0.0625,\n" + + " \"dirtSpawnMinHeight\":-Infinity,\n" + + " \"dirtSpawnMaxHeight\":Infinity,\n" + + " \"gravelSpawnSize\":33,\n" + + " \"gravelSpawnTries\":8,\n" + + " \"gravelSpawnProbability\":0.0625,\n" + + " \"gravelSpawnMinHeight\":-Infinity,\n" + + " \"gravelSpawnMaxHeight\":Infinity,\n" + + " \"graniteSpawnSize\":33,\n" + + " \"graniteSpawnTries\":10,\n" + + " \"graniteSpawnProbability\":0.2,\n" + + " \"graniteSpawnMinHeight\":-Infinity,\n" + + " \"graniteSpawnMaxHeight\":0.25,\n" + + " \"dioriteSpawnSize\":33,\n" + + " \"dioriteSpawnTries\":10,\n" + + " \"dioriteSpawnProbability\":0.2,\n" + + " \"dioriteSpawnMinHeight\":-Infinity,\n" + + " \"dioriteSpawnMaxHeight\":0.25,\n" + + " \"andesiteSpawnSize\":33,\n" + + " \"andesiteSpawnTries\":10,\n" + + " \"andesiteSpawnProbability\":0.2,\n" + + " \"andesiteSpawnMinHeight\":-Infinity,\n" + + " \"andesiteSpawnMaxHeight\":0.25,\n" + + " \"coalOreSpawnSize\":17,\n" + + " \"coalOreSpawnTries\":20,\n" + + " \"coalOreSpawnProbability\":0.125,\n" + + " \"coalOreSpawnMinHeight\":-Infinity,\n" + + " \"coalOreSpawnMaxHeight\":1.0,\n" + + " \"ironOreSpawnSize\":9,\n" + + " \"ironOreSpawnTries\":20,\n" + + " \"ironOreSpawnProbability\":0.25,\n" + + " \"ironOreSpawnMinHeight\":-Infinity,\n" + + " \"ironOreSpawnMaxHeight\":0.0,\n" + + " \"goldOreSpawnSize\":9,\n" + + " \"goldOreSpawnTries\":2,\n" + + " \"goldOreSpawnProbability\":0.5,\n" + + " \"goldOreSpawnMinHeight\":-Infinity,\n" + + " \"goldOreSpawnMaxHeight\":-0.5,\n" + + " \"redstoneOreSpawnSize\":8,\n" + + " \"redstoneOreSpawnTries\":8,\n" + + " \"redstoneOreSpawnProbability\":1.0,\n" + + " \"redstoneOreSpawnMinHeight\":-Infinity,\n" + + " \"redstoneOreSpawnMaxHeight\":-0.75,\n" + + " \"diamondOreSpawnSize\":8,\n" + + " \"diamondOreSpawnTries\":1,\n" + + " \"diamondOreSpawnProbability\":1.0,\n" + + " \"diamondOreSpawnMinHeight\":-Infinity,\n" + + " \"diamondOreSpawnMaxHeight\":-0.75,\n" + + " \"lapisLazuliSpawnSize\":7,\n" + + " \"lapisLazuliSpawnTries\":1,\n" + + " \"lapisLazuliSpawnProbability\":0.5,\n" + + " \"lapisLazuliHeightMean\":0.25,\n" + + " \"lapisLazuliHeightStdDeviation\":0.125,\n" + + " \"hillsEmeraldOreSpawnTries\":11,\n" + + " \"hillsEmeraldOreSpawnProbability\":0.2857143,\n" + + " \"hillsEmeraldOreSpawnMinHeight\":-Infinity,\n" + + " \"hillsEmeraldOreSpawnMaxHeight\":-0.5,\n" + + " \"hillsSilverfishStoneSpawnSize\":7,\n" + + " \"hillsSilverfishStoneSpawnTries\":7,\n" + + " \"hillsSilverfishStoneSpawnProbability\":0.25,\n" + + " \"hillsSilverfishStoneSpawnMinHeight\":-Infinity,\n" + + " \"hillsSilverfishStoneSpawnMaxHeight\":0.0,\n" + + " \"mesaAddedGoldOreSpawnSize\":20,\n" + + " \"mesaAddedGoldOreSpawnTries\":2,\n" + + " \"mesaAddedGoldOreSpawnProbability\":0.5,\n" + + " \"mesaAddedGoldOreSpawnMinHeight\":-0.5,\n" + + " \"mesaAddedGoldOreSpawnMaxHeight\":0.25,\n" + + " \"heightVariationFactor\":64.0,\n" + + " \"specialHeightVariationFactorBelowAverageY\":0.25,\n" + + " \"heightVariationOffset\":0.0,\n" + + " \"heightFactor\":64.0,\n" + + " \"heightOffset\":64.0,\n" + + " \"depthNoiseFactor\":1.024,\n" + + " \"depthNoiseOffset\":0.0,\n" + + " \"depthNoiseFrequencyX\":0.0015258789,\n" + + " \"depthNoiseFrequencyZ\":0.0015258789,\n" + + " \"depthNoiseOctaves\":16,\n" + + " \"selectorNoiseFactor\":12.75,\n" + + " \"selectorNoiseOffset\":0.5,\n" + + " \"selectorNoiseFrequencyX\":0.016709277,\n" + + " \"selectorNoiseFrequencyY\":0.008354639,\n" + + " \"selectorNoiseFrequencyZ\":0.016709277,\n" + + " \"selectorNoiseOctaves\":8,\n" + + " \"lowNoiseFactor\":1.0,\n" + + " \"lowNoiseOffset\":0.0,\n" + + " \"lowNoiseFrequencyX\":0.005221649,\n" + + " \"lowNoiseFrequencyY\":0.0026108245,\n" + + " \"lowNoiseFrequencyZ\":0.005221649,\n" + + " \"lowNoiseOctaves\":16,\n" + + " \"highNoiseFactor\":1.0,\n" + + " \"highNoiseOffset\":0.0,\n" + + " \"highNoiseFrequencyX\":0.005221649,\n" + + " \"highNoiseFrequencyY\":0.0026108245,\n" + + " \"highNoiseFrequencyZ\":0.005221649,\n" + + " \"highNoiseOctaves\":16\n" + + "}"; + + @Before + public void setUp() { + MinecraftEnvironment.init(); + } + + @Test + public void testCustomGeneratorSettingsFixer() { + CustomGeneratorSettings settings = CustomGeneratorSettings.fromJson(cc655ExamplePreset); + assertEquals(settings.standardOres.size(),10); + } +} From 23b470cb3eaeeec6041f676d55120d6a03097c11 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sat, 22 Dec 2018 17:10:22 +0300 Subject: [PATCH 11/17] Fixing Unit Test --- .../customcubic/CustomGeneratorSettings.java | 22 +++++++--------- .../TestCustomGeneratorSettingsFixer.java | 26 +++++++------------ 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 395e7fd..5fd7f04 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -346,22 +346,18 @@ public static CustomGeneratorSettings defaults() { } public static Gson gson(boolean minimize) { - return new GsonBuilder().serializeSpecialFloatingPointValues() - .enableComplexMapKeySerialization() - .registerTypeAdapter(CustomGeneratorSettings.class, new Serializer(minimize)) - .registerTypeHierarchyAdapter(IBlockState.class, BlockStateSerializer.INSTANCE) - .registerTypeHierarchyAdapter(Biome.class, new BiomeSerializer()) - .registerTypeAdapter(BiomeBlockReplacerConfig.class, new BiomeBlockReplacerConfigSerializer(minimize)) - .create(); + return gsonBuilder(minimize).create(); } public static GsonBuilder gsonBuilder(boolean minimize) { - return new GsonBuilder().serializeSpecialFloatingPointValues() - .enableComplexMapKeySerialization() - .registerTypeAdapter(CustomGeneratorSettings.class, new Serializer(minimize)) - .registerTypeHierarchyAdapter(IBlockState.class, BlockStateSerializer.INSTANCE) - .registerTypeHierarchyAdapter(Biome.class, new BiomeSerializer()) - .registerTypeAdapter(BiomeBlockReplacerConfig.class, new BiomeBlockReplacerConfigSerializer(minimize)); + GsonBuilder builder = new GsonBuilder(); + builder.serializeSpecialFloatingPointValues(); + builder.enableComplexMapKeySerialization(); + builder.registerTypeAdapter(CustomGeneratorSettings.class, new Serializer(minimize)); + builder.registerTypeHierarchyAdapter(IBlockState.class, BlockStateSerializer.INSTANCE); + builder.registerTypeHierarchyAdapter(Biome.class, new BiomeSerializer()); + builder.registerTypeAdapter(BiomeBlockReplacerConfig.class, new BiomeBlockReplacerConfigSerializer(minimize)); + return builder; } public static class StandardOreConfig { diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java index 1173c9b..83dee8f 100644 --- a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java +++ b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java @@ -24,29 +24,20 @@ package io.github.opencubicchunks.cubicchunks.cubicgen; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import java.io.IOException; +import java.lang.reflect.Field; import javax.annotation.ParametersAreNonnullByDefault; -import io.github.opencubicchunks.cubicchunks.api.worldgen.CubePrimer; -import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorld; -import io.github.opencubicchunks.cubicchunks.api.util.Coords; -import io.github.opencubicchunks.cubicchunks.cubicgen.testutil.MinecraftEnvironment; -import net.minecraft.world.World; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import org.junit.Before; import org.junit.Test; +import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.CubicBiome; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; -import io.github.opencubicchunks.cubicchunks.cubicgen.flat.FlatGeneratorSettings; -import io.github.opencubicchunks.cubicchunks.cubicgen.flat.FlatTerrainProcessor; -import io.github.opencubicchunks.cubicchunks.cubicgen.flat.Layer; +import io.github.opencubicchunks.cubicchunks.cubicgen.testutil.MinecraftEnvironment; import mcp.MethodsReturnNonnullByDefault; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.world.storage.WorldInfo; -import org.mockito.Mockito; @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault @@ -174,11 +165,14 @@ public class TestCustomGeneratorSettingsFixer { @Before public void setUp() { MinecraftEnvironment.init(); + CustomCubicMod.LOGGER = LogManager.getLogger("CustomCubicModTest");; + CubicBiome.init(); + CubicBiome.postInit(); } @Test public void testCustomGeneratorSettingsFixer() { - CustomGeneratorSettings settings = CustomGeneratorSettings.fromJson(cc655ExamplePreset); - assertEquals(settings.standardOres.size(),10); + CustomGeneratorSettings settings = CustomGeneratorSettings.fromJson(cc655ExamplePreset); + assertEquals(13,settings.standardOres.size()); } } From aeeded65b6b5bc66385eca8c45f847a0a4944fef Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sat, 22 Dec 2018 19:19:18 +0300 Subject: [PATCH 12/17] Removing minimization code --- .../cubicchunks/cubicgen/CustomCubicMod.java | 4 - .../customcubic/CustomCubicWorldType.java | 3 - .../customcubic/CustomGeneratorSettings.java | 88 ++++++------------- .../CustomGeneratorSettingsFixer.java | 12 +-- .../customcubic/gui/CustomCubicGui.java | 25 ++---- 5 files changed, 37 insertions(+), 95 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java index 5dbe0ef..62fefcb 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java @@ -32,7 +32,6 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.replacer.SwampWaterWithLilypadReplacer; import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.replacer.TaigaSurfaceReplacer; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomCubicWorldType; -import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.populator.DefaultDecorator; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.populator.DesertDecorator; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.populator.ForestDecorator; @@ -63,9 +62,7 @@ import net.minecraft.world.biome.BiomeStoneBeach; import net.minecraft.world.biome.BiomeSwamp; import net.minecraft.world.biome.BiomeTaiga; -import net.minecraftforge.common.util.ModFixs; import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -102,7 +99,6 @@ public void preInit(FMLPreInitializationEvent e) { FlatCubicWorldType.create(); CustomCubicWorldType.create(); DebugWorldType.create(); - } @Mod.EventHandler diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java index e079810..9c464ba 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java @@ -33,9 +33,7 @@ import net.minecraft.client.gui.GuiCreateWorld; import net.minecraft.client.gui.GuiErrorScreen; import net.minecraft.init.Biomes; -import net.minecraft.world.DimensionType; import net.minecraft.world.World; -import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldProviderSurface; import net.minecraft.world.WorldServer; import net.minecraft.world.WorldType; @@ -47,7 +45,6 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 5fd7f04..91b58e6 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -25,7 +25,23 @@ import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; -import com.google.common.base.Objects; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Type; +import java.nio.CharBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Nullable; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -39,7 +55,7 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.gson.JsonSyntaxException; -import com.google.gson.stream.JsonReader; + import io.github.opencubicchunks.cubicchunks.api.world.ICube; import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; import io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod; @@ -47,7 +63,6 @@ import net.minecraft.block.BlockSilverfish; import net.minecraft.block.BlockStone; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.init.Biomes; import net.minecraft.init.Blocks; import net.minecraft.nbt.JsonToNBT; @@ -55,35 +70,10 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTUtil; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.datafix.FixTypes; -import net.minecraft.util.datafix.IFixableData; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.ChunkGeneratorSettings; -import net.minecraft.world.storage.SaveFormatOld; -import net.minecraftforge.common.util.ModFixs; import net.minecraftforge.fml.common.registry.ForgeRegistries; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.StringReader; -import java.lang.reflect.Field; -import java.lang.reflect.Type; -import java.nio.CharBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.annotation.Nullable; - public class CustomGeneratorSettings { /** * Note: many of these values are unused yet @@ -196,8 +186,8 @@ public BiomeBlockReplacerConfig createBiomeBlockReplacerConfig() { return replacerConfig; } - public String toJson(boolean minimize) { - Gson gson = gson(minimize); + public String toJson() { + Gson gson = gson(); return gson.toJson(this); } @@ -213,7 +203,7 @@ public static CustomGeneratorSettings fromJson(String jsonString) { if (isOutdated(jsonString)) { jsonString = CustomGeneratorSettingsFixer.fixGeneratorOptions(CustomGeneratorSettingsFixer.stringToJson(jsonString), false); } - Gson gson = gson(false); + Gson gson = gson(); return gson.fromJson(jsonString, CustomGeneratorSettings.class); } @@ -257,11 +247,11 @@ public void save(World world) { File settingsFile = new File(folder, "custom_generator_settings.json"); try (FileWriter writer = new FileWriter(settingsFile)) { folder.mkdirs(); - writer.write(this.toJson(false)); + writer.write(this.toJson()); CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); } catch (IOException e) { CustomCubicMod.LOGGER.error("Cannot create new directory at " + folder.getAbsolutePath()); - CustomCubicMod.LOGGER.error(this.toJson(false)); + CustomCubicMod.LOGGER.error(this.toJson()); CustomCubicMod.LOGGER.catching(e); } } @@ -345,18 +335,18 @@ public static CustomGeneratorSettings defaults() { return settings; } - public static Gson gson(boolean minimize) { - return gsonBuilder(minimize).create(); + public static Gson gson() { + return gsonBuilder().create(); } - public static GsonBuilder gsonBuilder(boolean minimize) { + public static GsonBuilder gsonBuilder() { GsonBuilder builder = new GsonBuilder(); builder.serializeSpecialFloatingPointValues(); builder.enableComplexMapKeySerialization(); - builder.registerTypeAdapter(CustomGeneratorSettings.class, new Serializer(minimize)); + builder.registerTypeAdapter(CustomGeneratorSettings.class, new Serializer()); builder.registerTypeHierarchyAdapter(IBlockState.class, BlockStateSerializer.INSTANCE); builder.registerTypeHierarchyAdapter(Biome.class, new BiomeSerializer()); - builder.registerTypeAdapter(BiomeBlockReplacerConfig.class, new BiomeBlockReplacerConfigSerializer(minimize)); + builder.registerTypeAdapter(BiomeBlockReplacerConfig.class, new BiomeBlockReplacerConfigSerializer()); return builder; } @@ -398,7 +388,6 @@ public static class Builder { private float spawnProbability; private float minHeight = Float.NEGATIVE_INFINITY; private float maxHeight = Float.POSITIVE_INFINITY; - private Set blockstates = new HashSet<>(); public Builder block(IBlockState blockstate) { this.blockstate = blockstate; @@ -624,11 +613,6 @@ private static class Serializer implements JsonDeserializer entry : src.cubeAreas.entrySet()) { @@ -735,12 +715,6 @@ private static class BlockStateSerializer implements JsonDeserializer, JsonSerializer { - private final boolean minimize; - - public BiomeBlockReplacerConfigSerializer(boolean minimize) { - this.minimize = minimize; - } - @Override public BiomeBlockReplacerConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { @@ -775,19 +749,13 @@ private Object getObject(JsonDeserializationContext context, Map.Entry e : src.getDefaults().entrySet()) { - if (minimize && Objects.equal(defaultValues.getValue(e.getKey()), e.getValue())) { - continue; - } defaults.add(e.getKey().toString(), getJsonElement(context, e)); } for (Map.Entry e : src.getOverrides().entrySet()) { - // don't "minimize" overrides overrides.add(e.getKey().toString(), getJsonElement(context, e)); } root.add("defaults", defaults); diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java index baf754a..1c103bf 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java @@ -26,9 +26,6 @@ import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; import java.io.StringReader; -import java.util.HashMap; -import java.util.Map; - import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -37,9 +34,6 @@ import com.google.gson.JsonPrimitive; import com.google.gson.stream.JsonReader; -import io.github.opencubicchunks.cubicchunks.cubicgen.ConversionUtils; -import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.BiomeBlockReplacerConfig; -import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings.IntAABB; import net.minecraft.block.BlockSilverfish; import net.minecraft.block.BlockStone; import net.minecraft.block.state.IBlockState; @@ -85,7 +79,7 @@ public class CustomGeneratorSettingsFixer { }; public static String fixGeneratorOptions(JsonObject oldRoot, boolean calledForCubeArea) { - Gson gson = CustomGeneratorSettings.gson(false); + Gson gson = CustomGeneratorSettings.gson(); JsonObject newRoot = stringToJson("{}"); if (!calledForCubeArea) @@ -380,7 +374,7 @@ private static JsonElement getExpectedHeightVariation(JsonObject json) { private static JsonElement getPeriodicGaussianOres(JsonObject oldRoot) { if (oldRoot.has("periodicGaussianOres")) return oldRoot.get("periodicGaussianOres"); - Gson gson = CustomGeneratorSettings.gson(false); + Gson gson = CustomGeneratorSettings.gson(); JsonArray periodicGaussianOres = new JsonArray(); JsonObject obj = convertGaussianPeriodicOre(gson, oldRoot, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), null); @@ -393,7 +387,7 @@ private static JsonElement getPeriodicGaussianOres(JsonObject oldRoot) { private static JsonElement getStandardOres(JsonObject oldRoot) { if (oldRoot.has("standardOres")) return oldRoot.get("standardOres"); - Gson gson = CustomGeneratorSettings.gson(false); + Gson gson = CustomGeneratorSettings.gson(); JsonArray standardOres = new JsonArray(); for (int i = 0; i < standard.length; i++) { JsonObject obj = convertStandardOre(gson, oldRoot, standard[i], standardBlockstates[i], standardBiomes[i]); diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java index f067ebe..f94a67b 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java @@ -28,10 +28,8 @@ import com.google.common.eventbus.Subscribe; import com.google.gson.JsonSyntaxException; -import io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod; import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.BiomeBlockReplacerConfig; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.ExtraGui; -import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.MalisisGuiUtils; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UISplitLayout; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UITextFieldFixed; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; @@ -40,10 +38,8 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UIColoredPanel; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UIMultilineLabel; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UITabbedContainer; -import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UIVerticalTableLayout; import mcp.MethodsReturnNonnullByDefault; import net.malisis.core.client.gui.Anchor; -import net.malisis.core.client.gui.GuiTexture; import net.malisis.core.client.gui.MalisisGui; import net.malisis.core.client.gui.component.UIComponent; import net.malisis.core.client.gui.component.container.UIContainer; @@ -51,17 +47,8 @@ import net.malisis.core.client.gui.component.interaction.UITextField; import net.malisis.core.client.gui.event.ComponentEvent; import net.malisis.core.renderer.font.FontOptions; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiCreateWorld; import net.minecraft.client.resources.I18n; -import net.minecraft.util.ResourceLocation; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Map; import javax.annotation.ParametersAreNonnullByDefault; @@ -207,7 +194,7 @@ public void onChange(ComponentEvent.ValueChange event) { public void onChange(ComponentEvent.ValueChange event) { try { CustomGeneratorSettings settings = CustomGeneratorSettings.fromJson(event.getNewValue()); - textMinified.setText(getSettingsJson(settings, true)); + textMinified.setText(getSettingsJson(settings)); } catch (JsonSyntaxException | NumberFormatException ex) { textMinified.setText(I18n.format("cubicgen.gui.cubicgen.presets.invalid_json")); } @@ -222,7 +209,7 @@ public void onChange(ComponentEvent.ValueChange event) { // textField, making the text invisible by default textMinified.setSize(this.width - HORIZONTAL_PADDING*2, 10); textMinified.setFont(NoTranslationFont.DEFAULT); - textMinified.setText(getSettingsJson(getConfig(), true)); + textMinified.setText(getSettingsJson(getConfig())); textMinified.getCursorPosition().jumpToEnd(); done.register(new Object() { @@ -267,7 +254,7 @@ public void onClick(UIButton.ClickEvent evt) { } private void done() { - settingsJsonString = getSettingsJson(getConfig(), true); + settingsJsonString = getSettingsJson(getConfig()); this.mc.displayGuiScreen(parent); } @@ -282,11 +269,11 @@ public CustomGeneratorSettings getConfig() { return conf; } - String getSettingsJson(CustomGeneratorSettings conf, boolean minimized) { - return conf.toJson(minimized); + String getSettingsJson(CustomGeneratorSettings conf) { + return conf.toJson(); } String getFormattedJson(CustomGeneratorSettings conf) { - return CustomGeneratorSettings.gsonBuilder(false).setPrettyPrinting().create().toJson(conf); + return CustomGeneratorSettings.gsonBuilder().setPrettyPrinting().create().toJson(conf); } } From a1e01bf4c662bf846a666892e39cdd7991c14c9c Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sat, 22 Dec 2018 21:18:21 +0300 Subject: [PATCH 13/17] Expanding test to expected conversion case --- .../CustomGeneratorSettingsFixer.java | 2 +- .../TestCustomGeneratorSettingsFixer.java | 215 +++++++++--------- 2 files changed, 112 insertions(+), 105 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java index 1c103bf..1b1380c 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java @@ -527,7 +527,7 @@ private static JsonObject convertGaussianPeriodicOre(Gson gson, JsonObject root, return obj; } - static JsonObject stringToJson(String jsonString) { + public static JsonObject stringToJson(String jsonString) { JsonReader reader = new JsonReader(new StringReader(jsonString)); return new JsonParser().parse(reader).getAsJsonObject(); } diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java index 83dee8f..2d4e10b 100644 --- a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java +++ b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java @@ -34,8 +34,11 @@ import org.junit.Before; import org.junit.Test; +import com.google.gson.JsonObject; + import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.CubicBiome; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettingsFixer; import io.github.opencubicchunks.cubicchunks.cubicgen.testutil.MinecraftEnvironment; import mcp.MethodsReturnNonnullByDefault; @@ -43,124 +46,126 @@ @MethodsReturnNonnullByDefault public class TestCustomGeneratorSettingsFixer { String cc655ExamplePreset = "{\n" + - " \"waterLevel\":63,\n" + - " \"caves\":true,\n" + - " \"strongholds\":true,\n" + - " \"villages\":true,\n" + - " \"mineshafts\":true,\n" + - " \"temples\":true,\n" + - " \"oceanMonuments\":true,\n" + - " \"woodlandMansions\":true,\n" + - " \"ravines\":true,\n" + - " \"dungeons\":true,\n" + - " \"dungeonCount\":7,\n" + - " \"waterLakes\":true,\n" + - " \"waterLakeRarity\":4,\n" + - " \"lavaLakes\":true,\n" + - " \"lavaLakeRarity\":8,\n" + - " \"aboveSeaLavaLakeRarity\":13,\n" + - " \"lavaOceans\":false,\n" + - " \"biome\":-1,\n" + - " \"biomeSize\":4,\n" + - " \"riverSize\":4,\n" + - " \"dirtSpawnSize\":33,\n" + - " \"dirtSpawnTries\":10,\n" + - " \"dirtSpawnProbability\":0.0625,\n" + + " \"waterLevel\":100,\n" + + " \"caves\":false,\n" + + " \"strongholds\":false,\n" + + " \"villages\":false,\n" + + " \"mineshafts\":false,\n" + + " \"temples\":false,\n" + + " \"oceanMonuments\":false,\n" + + " \"woodlandMansions\":false,\n" + + " \"ravines\":false,\n" + + " \"dungeons\":false,\n" + + " \"dungeonCount\":101,\n" + + " \"waterLakes\":false,\n" + + " \"waterLakeRarity\":102,\n" + + " \"lavaLakes\":false,\n" + + " \"lavaLakeRarity\":103,\n" + + " \"aboveSeaLavaLakeRarity\":104,\n" + + " \"lavaOceans\":true,\n" + + " \"biome\":1,\n" + + " \"biomeSize\":104,\n" + + " \"riverSize\":105,\n" + + " \"dirtSpawnSize\":134,\n" + + " \"dirtSpawnTries\":135,\n" + + " \"dirtSpawnProbability\":136.0,\n" + " \"dirtSpawnMinHeight\":-Infinity,\n" + " \"dirtSpawnMaxHeight\":Infinity,\n" + - " \"gravelSpawnSize\":33,\n" + - " \"gravelSpawnTries\":8,\n" + - " \"gravelSpawnProbability\":0.0625,\n" + + " \"gravelSpawnSize\":137,\n" + + " \"gravelSpawnTries\":138,\n" + + " \"gravelSpawnProbability\":139.0,\n" + " \"gravelSpawnMinHeight\":-Infinity,\n" + " \"gravelSpawnMaxHeight\":Infinity,\n" + - " \"graniteSpawnSize\":33,\n" + - " \"graniteSpawnTries\":10,\n" + - " \"graniteSpawnProbability\":0.2,\n" + + " \"graniteSpawnSize\":140,\n" + + " \"graniteSpawnTries\":141,\n" + + " \"graniteSpawnProbability\":142.0,\n" + " \"graniteSpawnMinHeight\":-Infinity,\n" + - " \"graniteSpawnMaxHeight\":0.25,\n" + - " \"dioriteSpawnSize\":33,\n" + - " \"dioriteSpawnTries\":10,\n" + - " \"dioriteSpawnProbability\":0.2,\n" + + " \"graniteSpawnMaxHeight\":143.0,\n" + + " \"dioriteSpawnSize\":144,\n" + + " \"dioriteSpawnTries\":145,\n" + + " \"dioriteSpawnProbability\":146.0,\n" + " \"dioriteSpawnMinHeight\":-Infinity,\n" + - " \"dioriteSpawnMaxHeight\":0.25,\n" + - " \"andesiteSpawnSize\":33,\n" + - " \"andesiteSpawnTries\":10,\n" + - " \"andesiteSpawnProbability\":0.2,\n" + + " \"dioriteSpawnMaxHeight\":147.0,\n" + + " \"andesiteSpawnSize\":148,\n" + + " \"andesiteSpawnTries\":149,\n" + + " \"andesiteSpawnProbability\":150.0,\n" + " \"andesiteSpawnMinHeight\":-Infinity,\n" + - " \"andesiteSpawnMaxHeight\":0.25,\n" + - " \"coalOreSpawnSize\":17,\n" + - " \"coalOreSpawnTries\":20,\n" + - " \"coalOreSpawnProbability\":0.125,\n" + + " \"andesiteSpawnMaxHeight\":151.0,\n" + + " \"coalOreSpawnSize\":152,\n" + + " \"coalOreSpawnTries\":153,\n" + + " \"coalOreSpawnProbability\":154.0,\n" + " \"coalOreSpawnMinHeight\":-Infinity,\n" + - " \"coalOreSpawnMaxHeight\":1.0,\n" + - " \"ironOreSpawnSize\":9,\n" + - " \"ironOreSpawnTries\":20,\n" + - " \"ironOreSpawnProbability\":0.25,\n" + + " \"coalOreSpawnMaxHeight\":155.0,\n" + + " \"ironOreSpawnSize\":156,\n" + + " \"ironOreSpawnTries\":157,\n" + + " \"ironOreSpawnProbability\":158.0,\n" + " \"ironOreSpawnMinHeight\":-Infinity,\n" + - " \"ironOreSpawnMaxHeight\":0.0,\n" + - " \"goldOreSpawnSize\":9,\n" + - " \"goldOreSpawnTries\":2,\n" + - " \"goldOreSpawnProbability\":0.5,\n" + + " \"ironOreSpawnMaxHeight\":159.0,\n" + + " \"goldOreSpawnSize\":160,\n" + + " \"goldOreSpawnTries\":161,\n" + + " \"goldOreSpawnProbability\":162.0,\n" + " \"goldOreSpawnMinHeight\":-Infinity,\n" + - " \"goldOreSpawnMaxHeight\":-0.5,\n" + - " \"redstoneOreSpawnSize\":8,\n" + - " \"redstoneOreSpawnTries\":8,\n" + - " \"redstoneOreSpawnProbability\":1.0,\n" + + " \"goldOreSpawnMaxHeight\":-163.0,\n" + + " \"redstoneOreSpawnSize\":164,\n" + + " \"redstoneOreSpawnTries\":165,\n" + + " \"redstoneOreSpawnProbability\":166.0,\n" + " \"redstoneOreSpawnMinHeight\":-Infinity,\n" + - " \"redstoneOreSpawnMaxHeight\":-0.75,\n" + - " \"diamondOreSpawnSize\":8,\n" + - " \"diamondOreSpawnTries\":1,\n" + - " \"diamondOreSpawnProbability\":1.0,\n" + + " \"redstoneOreSpawnMaxHeight\":-167.0,\n" + + " \"diamondOreSpawnSize\":168,\n" + + " \"diamondOreSpawnTries\":169,\n" + + " \"diamondOreSpawnProbability\":170.0,\n" + " \"diamondOreSpawnMinHeight\":-Infinity,\n" + - " \"diamondOreSpawnMaxHeight\":-0.75,\n" + - " \"lapisLazuliSpawnSize\":7,\n" + - " \"lapisLazuliSpawnTries\":1,\n" + - " \"lapisLazuliSpawnProbability\":0.5,\n" + - " \"lapisLazuliHeightMean\":0.25,\n" + - " \"lapisLazuliHeightStdDeviation\":0.125,\n" + - " \"hillsEmeraldOreSpawnTries\":11,\n" + - " \"hillsEmeraldOreSpawnProbability\":0.2857143,\n" + + " \"diamondOreSpawnMaxHeight\":-178.0,\n" + + " \"lapisLazuliSpawnSize\":179,\n" + + " \"lapisLazuliSpawnTries\":180,\n" + + " \"lapisLazuliSpawnProbability\":181.0,\n" + + " \"lapisLazuliHeightMean\":182.0,\n" + + " \"lapisLazuliHeightStdDeviation\":183.0,\n" + + " \"hillsEmeraldOreSpawnTries\":184,\n" + + " \"hillsEmeraldOreSpawnProbability\":185.0,\n" + " \"hillsEmeraldOreSpawnMinHeight\":-Infinity,\n" + - " \"hillsEmeraldOreSpawnMaxHeight\":-0.5,\n" + - " \"hillsSilverfishStoneSpawnSize\":7,\n" + - " \"hillsSilverfishStoneSpawnTries\":7,\n" + - " \"hillsSilverfishStoneSpawnProbability\":0.25,\n" + + " \"hillsEmeraldOreSpawnMaxHeight\":-186.0,\n" + + " \"hillsSilverfishStoneSpawnSize\":187,\n" + + " \"hillsSilverfishStoneSpawnTries\":188,\n" + + " \"hillsSilverfishStoneSpawnProbability\":189.0,\n" + " \"hillsSilverfishStoneSpawnMinHeight\":-Infinity,\n" + - " \"hillsSilverfishStoneSpawnMaxHeight\":0.0,\n" + - " \"mesaAddedGoldOreSpawnSize\":20,\n" + - " \"mesaAddedGoldOreSpawnTries\":2,\n" + - " \"mesaAddedGoldOreSpawnProbability\":0.5,\n" + - " \"mesaAddedGoldOreSpawnMinHeight\":-0.5,\n" + - " \"mesaAddedGoldOreSpawnMaxHeight\":0.25,\n" + - " \"heightVariationFactor\":64.0,\n" + - " \"specialHeightVariationFactorBelowAverageY\":0.25,\n" + - " \"heightVariationOffset\":0.0,\n" + - " \"heightFactor\":64.0,\n" + - " \"heightOffset\":64.0,\n" + - " \"depthNoiseFactor\":1.024,\n" + - " \"depthNoiseOffset\":0.0,\n" + - " \"depthNoiseFrequencyX\":0.0015258789,\n" + - " \"depthNoiseFrequencyZ\":0.0015258789,\n" + - " \"depthNoiseOctaves\":16,\n" + - " \"selectorNoiseFactor\":12.75,\n" + - " \"selectorNoiseOffset\":0.5,\n" + - " \"selectorNoiseFrequencyX\":0.016709277,\n" + - " \"selectorNoiseFrequencyY\":0.008354639,\n" + - " \"selectorNoiseFrequencyZ\":0.016709277,\n" + - " \"selectorNoiseOctaves\":8,\n" + - " \"lowNoiseFactor\":1.0,\n" + - " \"lowNoiseOffset\":0.0,\n" + - " \"lowNoiseFrequencyX\":0.005221649,\n" + - " \"lowNoiseFrequencyY\":0.0026108245,\n" + - " \"lowNoiseFrequencyZ\":0.005221649,\n" + - " \"lowNoiseOctaves\":16,\n" + - " \"highNoiseFactor\":1.0,\n" + - " \"highNoiseOffset\":0.0,\n" + - " \"highNoiseFrequencyX\":0.005221649,\n" + - " \"highNoiseFrequencyY\":0.0026108245,\n" + - " \"highNoiseFrequencyZ\":0.005221649,\n" + - " \"highNoiseOctaves\":16\n" + + " \"hillsSilverfishStoneSpawnMaxHeight\":190.0,\n" + + " \"mesaAddedGoldOreSpawnSize\":191,\n" + + " \"mesaAddedGoldOreSpawnTries\":192,\n" + + " \"mesaAddedGoldOreSpawnProbability\":193.0,\n" + + " \"mesaAddedGoldOreSpawnMinHeight\":-194.0,\n" + + " \"mesaAddedGoldOreSpawnMaxHeight\":196.0,\n" + + " \"heightVariationFactor\":106.0,\n" + + " \"specialHeightVariationFactorBelowAverageY\":107.0,\n" + + " \"heightVariationOffset\":108.0,\n" + + " \"heightFactor\":109.0,\n" + + " \"heightOffset\":110.0,\n" + + " \"depthNoiseFactor\":111.0,\n" + + " \"depthNoiseOffset\":112.0,\n" + + " \"depthNoiseFrequencyX\":113.0,\n" + + " \"depthNoiseFrequencyZ\":114.0,\n" + + " \"depthNoiseOctaves\":5,\n" + + " \"selectorNoiseFactor\":116.0,\n" + + " \"selectorNoiseOffset\":117.0,\n" + + " \"selectorNoiseFrequencyX\":118.0,\n" + + " \"selectorNoiseFrequencyY\":119.0,\n" + + " \"selectorNoiseFrequencyZ\":120.0,\n" + + " \"selectorNoiseOctaves\":1,\n" + + " \"lowNoiseFactor\":122.0,\n" + + " \"lowNoiseOffset\":123.0,\n" + + " \"lowNoiseFrequencyX\":124.0,\n" + + " \"lowNoiseFrequencyY\":125.0,\n" + + " \"lowNoiseFrequencyZ\":126.0,\n" + + " \"lowNoiseOctaves\":7,\n" + + " \"highNoiseFactor\":128.0,\n" + + " \"highNoiseOffset\":129.0,\n" + + " \"highNoiseFrequencyX\":130.0,\n" + + " \"highNoiseFrequencyY\":131.0,\n" + + " \"highNoiseFrequencyZ\":132.0,\n" + + " \"highNoiseOctaves\":3\n" + "}"; + + String expectedConversionResult = "{\"waterLevel\":100,\"caves\":false,\"strongholds\":false,\"alternateStrongholdsPositions\":false,\"villages\":false,\"mineshafts\":false,\"temples\":false,\"oceanMonuments\":false,\"woodlandMansions\":false,\"ravines\":false,\"dungeons\":false,\"dungeonCount\":101,\"waterLakes\":false,\"waterLakeRarity\":102,\"lavaLakes\":false,\"lavaLakeRarity\":103,\"aboveSeaLavaLakeRarity\":104,\"lavaOceans\":true,\"biome\":1,\"biomeSize\":104,\"riverSize\":105,\"standardOres\":[{\"blockstate\":{\"Properties\":{\"variant\":\"dirt\",\"snowy\":\"false\"},\"Name\":\"minecraft:dirt\"},\"spawnSize\":134,\"spawnTries\":135,\"spawnProbability\":136.0,\"minHeight\":-Infinity,\"maxHeight\":Infinity},{\"blockstate\":{\"Name\":\"minecraft:gravel\"},\"spawnSize\":137,\"spawnTries\":138,\"spawnProbability\":139.0,\"minHeight\":-Infinity,\"maxHeight\":Infinity},{\"blockstate\":{\"Properties\":{\"variant\":\"granite\"},\"Name\":\"minecraft:stone\"},\"spawnSize\":140,\"spawnTries\":141,\"spawnProbability\":142.0,\"minHeight\":-Infinity,\"maxHeight\":143.0},{\"blockstate\":{\"Properties\":{\"variant\":\"diorite\"},\"Name\":\"minecraft:stone\"},\"spawnSize\":144,\"spawnTries\":145,\"spawnProbability\":146.0,\"minHeight\":-Infinity,\"maxHeight\":147.0},{\"blockstate\":{\"Properties\":{\"variant\":\"andesite\"},\"Name\":\"minecraft:stone\"},\"spawnSize\":148,\"spawnTries\":149,\"spawnProbability\":150.0,\"minHeight\":-Infinity,\"maxHeight\":151.0},{\"blockstate\":{\"Name\":\"minecraft:coal_ore\"},\"spawnSize\":152,\"spawnTries\":153,\"spawnProbability\":154.0,\"minHeight\":-Infinity,\"maxHeight\":155.0},{\"blockstate\":{\"Name\":\"minecraft:iron_ore\"},\"spawnSize\":156,\"spawnTries\":157,\"spawnProbability\":158.0,\"minHeight\":-Infinity,\"maxHeight\":159.0},{\"blockstate\":{\"Name\":\"minecraft:gold_ore\"},\"spawnSize\":160,\"spawnTries\":161,\"spawnProbability\":162.0,\"minHeight\":-Infinity,\"maxHeight\":-163.0},{\"blockstate\":{\"Name\":\"minecraft:redstone_ore\"},\"spawnSize\":164,\"spawnTries\":165,\"spawnProbability\":166.0,\"minHeight\":-Infinity,\"maxHeight\":-167.0},{\"blockstate\":{\"Name\":\"minecraft:diamond_ore\"},\"spawnSize\":168,\"spawnTries\":169,\"spawnProbability\":170.0,\"minHeight\":-Infinity,\"maxHeight\":-178.0},{\"blockstate\":{\"Name\":\"minecraft:emerald_ore\"},\"biomes\":[\"minecraft:extreme_hills\",\"minecraft:smaller_extreme_hills\",\"minecraft:extreme_hills_with_trees\",\"minecraft:mutated_extreme_hills\",\"minecraft:mutated_extreme_hills_with_trees\"],\"spawnSize\":3,\"spawnTries\":184,\"spawnProbability\":185.0,\"minHeight\":-Infinity,\"maxHeight\":-186.0},{\"blockstate\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:monster_egg\"},\"biomes\":[\"minecraft:extreme_hills\",\"minecraft:smaller_extreme_hills\",\"minecraft:extreme_hills_with_trees\",\"minecraft:mutated_extreme_hills\",\"minecraft:mutated_extreme_hills_with_trees\"],\"spawnSize\":187,\"spawnTries\":188,\"spawnProbability\":189.0,\"minHeight\":-Infinity,\"maxHeight\":190.0},{\"blockstate\":{\"Name\":\"minecraft:gold_ore\"},\"biomes\":[\"minecraft:mesa\",\"minecraft:mesa_clear_rock\",\"minecraft:mesa_rock\",\"minecraft:mutated_mesa\",\"minecraft:mutated_mesa_clear_rock\",\"minecraft:mutated_mesa_rock\"],\"spawnSize\":191,\"spawnTries\":192,\"spawnProbability\":193.0,\"minHeight\":-194.0,\"maxHeight\":196.0}],\"periodicGaussianOres\":[{\"blockstate\":{\"Name\":\"minecraft:lapis_ore\"},\"spawnSize\":179,\"spawnTries\":180,\"spawnProbability\":181.0,\"heightMean\":182.0,\"heightStdDeviation\":183.0,\"heightSpacing\":0.0,\"minHeight\":0.0,\"maxHeight\":0.0}],\"expectedBaseHeight\":110.0,\"expectedHeightVariation\":109.0,\"actualHeight\":544.0,\"heightVariationFactor\":106.0,\"specialHeightVariationFactorBelowAverageY\":107.0,\"heightVariationOffset\":108.0,\"heightFactor\":109.0,\"heightOffset\":110.0,\"depthNoiseFactor\":111.0,\"depthNoiseOffset\":112.0,\"depthNoiseFrequencyX\":113.0,\"depthNoiseFrequencyZ\":114.0,\"depthNoiseOctaves\":5,\"selectorNoiseFactor\":116.0,\"selectorNoiseOffset\":117.0,\"selectorNoiseFrequencyX\":118.0,\"selectorNoiseFrequencyY\":119.0,\"selectorNoiseFrequencyZ\":120.0,\"selectorNoiseOctaves\":1,\"lowNoiseFactor\":122.0,\"lowNoiseOffset\":123.0,\"lowNoiseFrequencyX\":124.0,\"lowNoiseFrequencyY\":125.0,\"lowNoiseFrequencyZ\":126.0,\"lowNoiseOctaves\":7,\"highNoiseFactor\":128.0,\"highNoiseOffset\":129.0,\"highNoiseFrequencyX\":130.0,\"highNoiseFrequencyY\":131.0,\"highNoiseFrequencyZ\":132.0,\"highNoiseOctaves\":3,\"cubeAreas\":[],\"replacerConfig\":{\"defaults\":{\"cubicgen:biome_fill_noise_octaves\":4.0,\"cubicgen:ocean_block\":{\"Properties\":{\"level\":\"0\"},\"Name\":\"minecraft:water\"},\"cubicgen:height_scale\":64.0,\"cubicgen:biome_fill_noise_freq\":0.0078125,\"cubicgen:water_level\":63.0,\"cubicgen:biome_fill_depth_factor\":2.3333333333333335,\"cubicgen:terrain_fill_block\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:stone\"},\"cubicgen:mesa_depth\":16.0,\"cubicgen:biome_fill_depth_offset\":3.0,\"cubicgen:horizontal_gradient_depth_decrease_weight\":1.0,\"cubicgen:height_offset\":64.0},\"overrides\":{}},\"version\":3}"; @Before public void setUp() { @@ -173,6 +178,8 @@ public void setUp() { @Test public void testCustomGeneratorSettingsFixer() { CustomGeneratorSettings settings = CustomGeneratorSettings.fromJson(cc655ExamplePreset); - assertEquals(13,settings.standardOres.size()); + JsonObject fixed = CustomGeneratorSettingsFixer.stringToJson(settings.toJson()); + JsonObject expected = CustomGeneratorSettingsFixer.stringToJson(expectedConversionResult); + assertEquals(expected,fixed); } } From 0f9f5ff150ab9cd075fc69c72bb485372a416e56 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Fri, 4 Jan 2019 12:05:02 +0300 Subject: [PATCH 14/17] Fix creating file writer before creating directories --- .../cubicgen/customcubic/CustomGeneratorSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 91b58e6..b7c1a76 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -244,9 +244,9 @@ else if(!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) { public void save(World world) { File folder = new File(world.getSaveHandler().getWorldDirectory(), "/data/" + CustomCubicMod.MODID +"/"); + folder.mkdirs(); File settingsFile = new File(folder, "custom_generator_settings.json"); try (FileWriter writer = new FileWriter(settingsFile)) { - folder.mkdirs(); writer.write(this.toJson()); CustomCubicMod.LOGGER.info("Generator settings saved at " + settingsFile.getAbsolutePath()); } catch (IOException e) { From a7c572a206317535482ff4d1a16b4129cf6dc007 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sat, 19 Jan 2019 19:02:17 +0300 Subject: [PATCH 15/17] Extend hardcoded limit of char buffer to accept presets with any size. Use GSON nice formatting. --- .../opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java | 2 +- .../cubicgen/customcubic/CustomGeneratorSettings.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java index 62fefcb..4bb2f28 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java @@ -105,7 +105,7 @@ public void preInit(FMLPreInitializationEvent e) { public void preInit(FMLPostInitializationEvent e) { CubicBiome.postInit(); } - + @SubscribeEvent public static void registerRegistries(RegistryEvent.NewRegistry evt) { CubicBiome.init(); diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index b7c1a76..ff4fe29 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -214,7 +214,7 @@ public static CustomGeneratorSettings load(World world) { CustomGeneratorSettings settings = null; if (externalGeneratorPresetFile.exists()) { try (FileReader reader = new FileReader(externalGeneratorPresetFile)){ - CharBuffer sb = CharBuffer.allocate(Short.MAX_VALUE << 3); + CharBuffer sb = CharBuffer.allocate((int) externalGeneratorPresetFile.length() * 2); reader.read(sb); sb.flip(); jsonString = sb.toString(); @@ -341,6 +341,7 @@ public static Gson gson() { public static GsonBuilder gsonBuilder() { GsonBuilder builder = new GsonBuilder(); + builder.setPrettyPrinting(); builder.serializeSpecialFloatingPointValues(); builder.enableComplexMapKeySerialization(); builder.registerTypeAdapter(CustomGeneratorSettings.class, new Serializer()); From b819ef213605ea998f1808d171f6707136e42bf8 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 20 Jan 2019 17:15:35 +0300 Subject: [PATCH 16/17] Creating copy of a world will copy generator settings --- .../cubicchunks/cubicgen/CustomCubicMod.java | 7 + .../cubicgen/common/gui/GuiEventHandler.java | 68 +++ .../customcubic/CustomGeneratorSettings.java | 44 +- .../CustomGeneratorSettingsFixer.java | 433 +++++++++--------- .../cubicgen/proxy/ClientProxy.java | 35 ++ .../cubicgen/proxy/CommonProxy.java | 29 ++ .../cubicgen/proxy/ServerProxy.java | 28 ++ .../META-INF/cubicchunks_cubicgen_at.cfg | 2 + .../TestCustomGeneratorSettingsFixer.java | 161 ++++++- 9 files changed, 562 insertions(+), 245 deletions(-) create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ClientProxy.java create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/CommonProxy.java create mode 100644 src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ServerProxy.java diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java index 4bb2f28..b0be707 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/CustomCubicMod.java @@ -42,6 +42,7 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.populator.SwampDecorator; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.populator.TaigaDecorator; import io.github.opencubicchunks.cubicchunks.cubicgen.flat.FlatCubicWorldType; +import io.github.opencubicchunks.cubicchunks.cubicgen.proxy.CommonProxy; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; @@ -64,6 +65,7 @@ import net.minecraft.world.biome.BiomeTaiga; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -90,6 +92,10 @@ public class CustomCubicMod { public static final int FIXER_VERSION = 2; public static final boolean DEBUG_ENABLED = false; public static Logger LOGGER = null; + + @SidedProxy(clientSide = "io.github.opencubicchunks.cubicchunks.cubicgen.proxy.ClientProxy", serverSide = "io.github.opencubicchunks.cubicchunks.cubicgen.proxy.ServerProxy") + public static CommonProxy proxy; + @Mod.EventHandler public void preInit(FMLPreInitializationEvent e) { @@ -99,6 +105,7 @@ public void preInit(FMLPreInitializationEvent e) { FlatCubicWorldType.create(); CustomCubicWorldType.create(); DebugWorldType.create(); + proxy.preInit(); } @Mod.EventHandler diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java new file mode 100644 index 0000000..51a3488 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java @@ -0,0 +1,68 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.common.gui; + +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomCubicWorldType; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.gui.CustomCubicGui; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiListWorldSelectionEntry; +import net.minecraft.client.gui.GuiWorldSelection; +import net.minecraft.world.storage.ISaveHandler; +import net.minecraft.world.storage.WorldInfo; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +/** + * This GUI handler serve a sole purpose to copy CustomCubic generator settings + * in case if player making a copy of such world + */ +public class GuiEventHandler { + + @SubscribeEvent + public void onButtonPressed(GuiScreenEvent.ActionPerformedEvent.Pre action) { + if (action.getGui() instanceof GuiWorldSelection) { + if (!action.getButton().enabled) + return; + // "Recreate world" has button id = 5 + if (action.getButton().id != 5) + return; + GuiWorldSelection gui = (GuiWorldSelection) action.getGui(); + if (gui.selectionList.getSelectedWorld() == null) + return; + GuiListWorldSelectionEntry entry = gui.selectionList.getSelectedWorld(); + ISaveHandler isavehandler = Minecraft.getMinecraft().getSaveLoader() + .getSaveLoader(entry.worldSummary.getFileName(), false); + WorldInfo worldinfo = isavehandler.loadWorldInfo(); + + if (worldinfo == null || !(worldinfo.getTerrainType() instanceof CustomCubicWorldType)) + return; + String json = CustomGeneratorSettings.loadJsonStringFromSaveFolder(isavehandler); + isavehandler.flush(); + if (json != null) { + CustomCubicGui.settingsJsonString = json; + } + } + } +} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index ff4fe29..2ab6e31 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -72,6 +72,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; +import net.minecraft.world.storage.ISaveHandler; import net.minecraftforge.fml.common.registry.ForgeRegistries; public class CustomGeneratorSettings { @@ -201,39 +202,48 @@ public static CustomGeneratorSettings fromJson(String jsonString) { return defaults(); } if (isOutdated(jsonString)) { - jsonString = CustomGeneratorSettingsFixer.fixGeneratorOptions(CustomGeneratorSettingsFixer.stringToJson(jsonString), false); + jsonString = CustomGeneratorSettingsFixer.fixGeneratorOptions(jsonString, null); } Gson gson = gson(); return gson.fromJson(jsonString, CustomGeneratorSettings.class); } - public static CustomGeneratorSettings load(World world) { - File externalGeneratorPresetFile = new File(world.getSaveHandler().getWorldDirectory(), - "/data/" + CustomCubicMod.MODID + "/custom_generator_settings.json"); - String jsonString = null; - CustomGeneratorSettings settings = null; + @Nullable + public static String loadJsonStringFromSaveFolder(ISaveHandler saveHandler) { + File externalGeneratorPresetFile = getPresetFile(saveHandler); if (externalGeneratorPresetFile.exists()) { try (FileReader reader = new FileReader(externalGeneratorPresetFile)){ - CharBuffer sb = CharBuffer.allocate((int) externalGeneratorPresetFile.length() * 2); + CharBuffer sb = CharBuffer.allocate((int) externalGeneratorPresetFile.length()); reader.read(sb); sb.flip(); - jsonString = sb.toString(); - CustomCubicMod.LOGGER.debug("Loading settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); - boolean isOutdated = isOutdated(jsonString); - settings = fromJson(jsonString); - if(isOutdated) - settings.save(world); + return sb.toString(); } catch (IOException e) { e.printStackTrace(); } } - else if(!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) { + return null; + } + + public static File getPresetFile(ISaveHandler saveHandler) { + return new File(saveHandler.getWorldDirectory(), + "/data/" + CustomCubicMod.MODID + "/custom_generator_settings.json"); + } + + public static CustomGeneratorSettings load(World world) { + String jsonString = loadJsonStringFromSaveFolder(world.getSaveHandler()); + CustomGeneratorSettings settings = null; + if (jsonString != null) { + boolean isOutdated = isOutdated(jsonString); + settings = fromJson(jsonString); + if (isOutdated) + settings.save(world); + } else if (!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) { settings = CustomGeneratorSettings.fromJson(CustomCubicWorldType.pendingCustomCubicSettingsJsonString); CustomCubicWorldType.pendingCustomCubicSettingsJsonString = ""; settings.save(world); - } - else { - CustomCubicMod.LOGGER.info("No settings provided at " + externalGeneratorPresetFile.getAbsolutePath()); + } else { + CustomCubicMod.LOGGER + .info("No settings provided at " + getPresetFile(world.getSaveHandler()).getAbsolutePath()); CustomCubicMod.LOGGER.info("Loading settings from 'level.dat'"); // Use old format to keep backward-compatibility settings = fromJson(world.getWorldInfo().getGeneratorOptions()); diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java index 1b1380c..7661d5b 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettingsFixer.java @@ -26,6 +26,9 @@ import static io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod.MODID; import java.io.StringReader; + +import javax.annotation.Nullable; + import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -78,134 +81,104 @@ public class CustomGeneratorSettingsFixer { // gold }; - public static String fixGeneratorOptions(JsonObject oldRoot, boolean calledForCubeArea) { + private static boolean isActual(JsonObject root) { + return root.has("version") && root.get("version").getAsInt() == 3; + } + + public static String fixGeneratorOptions(String json, @Nullable JsonObject parent) { Gson gson = CustomGeneratorSettings.gson(); + JsonObject oldRoot = CustomGeneratorSettingsFixer.stringToJson(json); + boolean rootIsActual = isActual(oldRoot); + if (rootIsActual) { + if (parent != null) { + return json; + } else { + boolean cubeAreasHasOutdatedContent = false; + if (oldRoot.has("cubeAreas") && oldRoot.get("cubeAreas").isJsonArray()) { + JsonArray array = oldRoot.get("cubeAreas").getAsJsonArray(); + for (JsonElement entry : array) { + JsonArray mapEntry = entry.getAsJsonArray(); + JsonObject value = mapEntry.get(1).getAsJsonObject(); + if (!isActual(value)) { + cubeAreasHasOutdatedContent = true; + break; + } + } + } + if (!cubeAreasHasOutdatedContent) { + // Do not touch anything if all data is OK + return json; + } + } + } JsonObject newRoot = stringToJson("{}"); - - if (!calledForCubeArea) - newRoot.add("version", new JsonPrimitive(3)); - if (!calledForCubeArea || oldRoot.has("waterLevel")) - newRoot.add("waterLevel", getWaterLevel(oldRoot)); - if (!calledForCubeArea || oldRoot.has("caves")) - newRoot.add("caves", getCaves(oldRoot)); - if (!calledForCubeArea || oldRoot.has("strongholds")) - newRoot.add("strongholds", getStrongholds(oldRoot)); - if (!calledForCubeArea || oldRoot.has("alternateStrongholdsPositions")) - newRoot.add("alternateStrongholdsPositions", getAlternateStrongholdsPositions(oldRoot)); - if (!calledForCubeArea || oldRoot.has("villages")) - newRoot.add("villages", getVillages(oldRoot)); - if (!calledForCubeArea || oldRoot.has("mineshafts")) - newRoot.add("mineshafts", getMineshafts(oldRoot)); - if (!calledForCubeArea || oldRoot.has("temples")) - newRoot.add("temples", getTemples(oldRoot)); - if (!calledForCubeArea || oldRoot.has("oceanMonuments")) - newRoot.add("oceanMonuments", getOceanMonuments(oldRoot)); - if (!calledForCubeArea || oldRoot.has("woodlandMansions")) - newRoot.add("woodlandMansions", getWoodlandMansions(oldRoot)); - if (!calledForCubeArea || oldRoot.has("ravines")) - newRoot.add("ravines", getRavines(oldRoot)); - if (!calledForCubeArea || oldRoot.has("dungeons")) - newRoot.add("dungeons", getDungeons(oldRoot)); - if (!calledForCubeArea || oldRoot.has("dungeonCount")) - newRoot.add("dungeonCount", getDungeonCount(oldRoot)); - if (!calledForCubeArea || oldRoot.has("waterLakes")) - newRoot.add("waterLakes", getWaterLakes(oldRoot)); - if (!calledForCubeArea || oldRoot.has("waterLakeRarity")) - newRoot.add("waterLakeRarity", getWaterLakeRarity(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lavaLakes")) - newRoot.add("lavaLakes", getLavaLakes(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lavaLakeRarity")) - newRoot.add("lavaLakeRarity", getLavaLakeRarity(oldRoot)); - if (!calledForCubeArea || oldRoot.has("aboveSeaLavaLakeRarity")) - newRoot.add("aboveSeaLavaLakeRarity", getAboveSeaLavaLakeRarity(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lavaOceans")) - newRoot.add("lavaOceans", getLavaOceans(oldRoot)); - if (!calledForCubeArea || oldRoot.has("biome")) - newRoot.add("biome", getBiome(oldRoot)); - if (!calledForCubeArea || oldRoot.has("biomeSize")) - newRoot.add("biomeSize", getBiomeSize(oldRoot)); - if (!calledForCubeArea || oldRoot.has("riverSize")) - newRoot.add("riverSize", getRiverSize(oldRoot)); - if (!calledForCubeArea || oldRoot.has("standardOres")) - newRoot.add("standardOres", getStandardOres(oldRoot)); - if (!calledForCubeArea || oldRoot.has("periodicGaussianOres")) - newRoot.add("periodicGaussianOres", getPeriodicGaussianOres(oldRoot)); - if (!calledForCubeArea || oldRoot.has("expectedBaseHeight")) - newRoot.add("expectedBaseHeight", getExpectedBaseHeight(oldRoot)); - if (!calledForCubeArea || oldRoot.has("expectedHeightVariation")) - newRoot.add("expectedHeightVariation", getExpectedHeightVariation(oldRoot)); - if (!calledForCubeArea || oldRoot.has("actualHeight")) - newRoot.add("actualHeight", getActualHeight(oldRoot)); - if (!calledForCubeArea || oldRoot.has("heightVariationFactor")) - newRoot.add("heightVariationFactor", getHeightVariationFactor(oldRoot)); - if (!calledForCubeArea || oldRoot.has("specialHeightVariationFactorBelowAverageY")) - newRoot.add("specialHeightVariationFactorBelowAverageY", - getSpecialHeightVariationFactorBelowAverageY(oldRoot)); - if (!calledForCubeArea || oldRoot.has("heightVariationOffset")) - newRoot.add("heightVariationOffset", getHeightVariationOffset(oldRoot)); - if (!calledForCubeArea || oldRoot.has("heightFactor")) - newRoot.add("heightFactor", getHeightFactor(oldRoot)); - if (!calledForCubeArea || oldRoot.has("heightOffset")) - newRoot.add("heightOffset", getHeightOffset(oldRoot)); - if (!calledForCubeArea || oldRoot.has("depthNoiseFactor")) - newRoot.add("depthNoiseFactor", getDepthNoiseFactor(oldRoot)); - if (!calledForCubeArea || oldRoot.has("depthNoiseOffset")) - newRoot.add("depthNoiseOffset", getDepthNoiseOffset(oldRoot)); - if (!calledForCubeArea || oldRoot.has("depthNoiseFrequencyX")) - newRoot.add("depthNoiseFrequencyX", getDepthNoiseFrequencyX(oldRoot)); - if (!calledForCubeArea || oldRoot.has("depthNoiseFrequencyZ")) - newRoot.add("depthNoiseFrequencyZ", getDepthNoiseFrequencyZ(oldRoot)); - if (!calledForCubeArea || oldRoot.has("depthNoiseOctaves")) - newRoot.add("depthNoiseOctaves", getDepthNoiseOctaves(oldRoot)); - if (!calledForCubeArea || oldRoot.has("selectorNoiseFactor")) - newRoot.add("selectorNoiseFactor", getSelectorNoiseFactor(oldRoot)); - if (!calledForCubeArea || oldRoot.has("selectorNoiseOffset")) - newRoot.add("selectorNoiseOffset", getSelectorNoiseOffset(oldRoot)); - if (!calledForCubeArea || oldRoot.has("selectorNoiseFrequencyX")) - newRoot.add("selectorNoiseFrequencyX", getSelectorNoiseFrequencyX(oldRoot)); - if (!calledForCubeArea || oldRoot.has("selectorNoiseFrequencyY")) - newRoot.add("selectorNoiseFrequencyY", getSelectorNoiseFrequencyY(oldRoot)); - if (!calledForCubeArea || oldRoot.has("selectorNoiseFrequencyZ")) - newRoot.add("selectorNoiseFrequencyZ", getSelectorNoiseFrequencyZ(oldRoot)); - if (!calledForCubeArea || oldRoot.has("selectorNoiseOctaves")) - newRoot.add("selectorNoiseOctaves", getSelectorNoiseOctaves(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lowNoiseFactor")) - newRoot.add("lowNoiseFactor", getLowNoiseFactor(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lowNoiseOffset")) - newRoot.add("lowNoiseOffset", getLowNoiseOffset(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lowNoiseFrequencyX")) - newRoot.add("lowNoiseFrequencyX", getLowNoiseFrequencyX(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lowNoiseFrequencyY")) - newRoot.add("lowNoiseFrequencyY", getLowNoiseFrequencyY(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lowNoiseFrequencyZ")) - newRoot.add("lowNoiseFrequencyZ", getLowNoiseFrequencyZ(oldRoot)); - if (!calledForCubeArea || oldRoot.has("lowNoiseOctaves")) - newRoot.add("lowNoiseOctaves", getLowNoiseOctaves(oldRoot)); - if (!calledForCubeArea || oldRoot.has("highNoiseFactor")) - newRoot.add("highNoiseFactor", getHighNoiseFactor(oldRoot)); - if (!calledForCubeArea || oldRoot.has("highNoiseOffset")) - newRoot.add("highNoiseOffset", getHighNoiseOffset(oldRoot)); - if (!calledForCubeArea || oldRoot.has("highNoiseFrequencyX")) - newRoot.add("highNoiseFrequencyX", getHighNoiseFrequencyX(oldRoot)); - if (!calledForCubeArea || oldRoot.has("highNoiseFrequencyY")) - newRoot.add("highNoiseFrequencyY", getHighNoiseFrequencyY(oldRoot)); - if (!calledForCubeArea || oldRoot.has("highNoiseFrequencyZ")) - newRoot.add("highNoiseFrequencyZ", getHighNoiseFrequencyZ(oldRoot)); - if (!calledForCubeArea || oldRoot.has("highNoiseOctaves")) - newRoot.add("highNoiseOctaves", getHighNoiseOctaves(oldRoot)); - if (!calledForCubeArea) + newRoot.add("version", new JsonPrimitive(3)); + newRoot.add("waterLevel", getWaterLevel(oldRoot,parent)); + newRoot.add("caves", getCaves(oldRoot,parent)); + newRoot.add("strongholds", getStrongholds(oldRoot,parent)); + newRoot.add("alternateStrongholdsPositions", getAlternateStrongholdsPositions(oldRoot,parent)); + newRoot.add("villages", getVillages(oldRoot,parent)); + newRoot.add("mineshafts", getMineshafts(oldRoot,parent)); + newRoot.add("temples", getTemples(oldRoot,parent)); + newRoot.add("oceanMonuments", getOceanMonuments(oldRoot,parent)); + newRoot.add("woodlandMansions", getWoodlandMansions(oldRoot,parent)); + newRoot.add("ravines", getRavines(oldRoot,parent)); + newRoot.add("dungeons", getDungeons(oldRoot,parent)); + newRoot.add("dungeonCount", getDungeonCount(oldRoot,parent)); + newRoot.add("waterLakes", getWaterLakes(oldRoot,parent)); + newRoot.add("waterLakeRarity", getWaterLakeRarity(oldRoot,parent)); + newRoot.add("lavaLakes", getLavaLakes(oldRoot,parent)); + newRoot.add("lavaLakeRarity", getLavaLakeRarity(oldRoot,parent)); + newRoot.add("aboveSeaLavaLakeRarity", getAboveSeaLavaLakeRarity(oldRoot,parent)); + newRoot.add("lavaOceans", getLavaOceans(oldRoot,parent)); + newRoot.add("biome", getBiome(oldRoot,parent)); + newRoot.add("biomeSize", getBiomeSize(oldRoot,parent)); + newRoot.add("riverSize", getRiverSize(oldRoot,parent)); + newRoot.add("standardOres", getStandardOres(oldRoot,parent)); + newRoot.add("periodicGaussianOres", getPeriodicGaussianOres(oldRoot,parent)); + newRoot.add("expectedBaseHeight", getExpectedBaseHeight(oldRoot,parent)); + newRoot.add("expectedHeightVariation", getExpectedHeightVariation(oldRoot,parent)); + newRoot.add("actualHeight", getActualHeight(oldRoot,parent)); + newRoot.add("heightVariationFactor", getHeightVariationFactor(oldRoot,parent)); + newRoot.add("specialHeightVariationFactorBelowAverageY", getSpecialHeightVariationFactorBelowAverageY(oldRoot,parent)); + newRoot.add("heightVariationOffset", getHeightVariationOffset(oldRoot,parent)); + newRoot.add("heightFactor", getHeightFactor(oldRoot,parent)); + newRoot.add("heightOffset", getHeightOffset(oldRoot,parent)); + newRoot.add("depthNoiseFactor", getDepthNoiseFactor(oldRoot,parent)); + newRoot.add("depthNoiseOffset", getDepthNoiseOffset(oldRoot,parent)); + newRoot.add("depthNoiseFrequencyX", getDepthNoiseFrequencyX(oldRoot,parent)); + newRoot.add("depthNoiseFrequencyZ", getDepthNoiseFrequencyZ(oldRoot,parent)); + newRoot.add("depthNoiseOctaves", getDepthNoiseOctaves(oldRoot,parent)); + newRoot.add("selectorNoiseFactor", getSelectorNoiseFactor(oldRoot,parent)); + newRoot.add("selectorNoiseOffset", getSelectorNoiseOffset(oldRoot,parent)); + newRoot.add("selectorNoiseFrequencyX", getSelectorNoiseFrequencyX(oldRoot,parent)); + newRoot.add("selectorNoiseFrequencyY", getSelectorNoiseFrequencyY(oldRoot,parent)); + newRoot.add("selectorNoiseFrequencyZ", getSelectorNoiseFrequencyZ(oldRoot,parent)); + newRoot.add("selectorNoiseOctaves", getSelectorNoiseOctaves(oldRoot,parent)); + newRoot.add("lowNoiseFactor", getLowNoiseFactor(oldRoot,parent)); + newRoot.add("lowNoiseOffset", getLowNoiseOffset(oldRoot,parent)); + newRoot.add("lowNoiseFrequencyX", getLowNoiseFrequencyX(oldRoot,parent)); + newRoot.add("lowNoiseFrequencyY", getLowNoiseFrequencyY(oldRoot,parent)); + newRoot.add("lowNoiseFrequencyZ", getLowNoiseFrequencyZ(oldRoot,parent)); + newRoot.add("lowNoiseOctaves", getLowNoiseOctaves(oldRoot,parent)); + newRoot.add("highNoiseFactor", getHighNoiseFactor(oldRoot,parent)); + newRoot.add("highNoiseOffset", getHighNoiseOffset(oldRoot,parent)); + newRoot.add("highNoiseFrequencyX", getHighNoiseFrequencyX(oldRoot,parent)); + newRoot.add("highNoiseFrequencyY", getHighNoiseFrequencyY(oldRoot,parent)); + newRoot.add("highNoiseFrequencyZ", getHighNoiseFrequencyZ(oldRoot,parent)); + newRoot.add("highNoiseOctaves", getHighNoiseOctaves(oldRoot,parent)); + newRoot.add("replacerConfig", getReplacerConfig(oldRoot,parent)); + if (parent == null) // cube areas allowed only for root newRoot.add("cubeAreas", getCubeAreas(oldRoot)); - if (!calledForCubeArea || oldRoot.has("replacerConfig")) - newRoot.add("replacerConfig", getReplacerConfig(oldRoot)); String newGeneratorOptions = gson.toJson(newRoot).replaceAll("cubicchunks:", MODID + ":"); return newGeneratorOptions; } - private static JsonElement getReplacerConfig(JsonObject json) { + private static JsonElement getReplacerConfig(JsonObject json, @Nullable JsonObject parent) { JsonReader reader = new JsonReader(new StringReader("{\"defaults\":{\"cubicgen:biome_fill_noise_octaves\":4.0,\"cubicgen:ocean_block\":{\"Properties\":{\"level\":\"0\"},\"Name\":\"minecraft:water\"},\"cubicgen:height_scale\":64.0,\"cubicgen:biome_fill_noise_freq\":0.0078125,\"cubicgen:water_level\":63.0,\"cubicgen:biome_fill_depth_factor\":2.3333333333333335,\"cubicgen:terrain_fill_block\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:stone\"},\"cubicgen:mesa_depth\":16.0,\"cubicgen:biome_fill_depth_offset\":3.0,\"cubicgen:horizontal_gradient_depth_decrease_weight\":1.0,\"cubicgen:height_offset\":64.0},\"overrides\":{}}")); JsonObject biomeBlockReplacerConfigDefaultJson = new JsonParser().parse(reader).getAsJsonObject(); - return getOrDefault(json, "replacerConfig", biomeBlockReplacerConfigDefaultJson); + return getOrDefault(json, parent, "replacerConfig", biomeBlockReplacerConfigDefaultJson); } private static JsonElement getCubeAreas(JsonObject json) { @@ -215,7 +188,7 @@ private static JsonElement getCubeAreas(JsonObject json) { for (JsonElement entry : array) { JsonArray mapEntry = entry.getAsJsonArray(); JsonElement key = mapEntry.get(0); - JsonObject value = stringToJson(fixGeneratorOptions(mapEntry.get(1).getAsJsonObject(), true)); + JsonObject value = stringToJson(fixGeneratorOptions(CustomGeneratorSettings.gson().toJson(mapEntry.get(1).getAsJsonObject()), json)); JsonArray newEntry = new JsonArray(); newEntry.add(key); newEntry.add(value); @@ -225,155 +198,157 @@ private static JsonElement getCubeAreas(JsonObject json) { return cubeAreas; } - private static JsonElement getHighNoiseOctaves(JsonObject json) { - return getOrDefault(json, "highNoiseOctaves", new JsonPrimitive(16)); + private static JsonElement getHighNoiseOctaves(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "highNoiseOctaves", new JsonPrimitive(16)); } - private static JsonElement getHighNoiseFrequencyZ(JsonObject json) { - return getOrDefault(json, "highNoiseFrequencyZ", + private static JsonElement getHighNoiseFrequencyZ(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "highNoiseFrequencyZ", new JsonPrimitive(0.005221649)); } - private static JsonElement getHighNoiseFrequencyY(JsonObject json) { - return getOrDefault(json, "highNoiseFrequencyY", + private static JsonElement getHighNoiseFrequencyY(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "highNoiseFrequencyY", new JsonPrimitive(0.0026108245)); } - private static JsonElement getHighNoiseFrequencyX(JsonObject json) { - return getOrDefault(json, "highNoiseFrequencyX", + private static JsonElement getHighNoiseFrequencyX(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "highNoiseFrequencyX", new JsonPrimitive(0.005221649)); } - private static JsonElement getHighNoiseOffset(JsonObject json) { - return getOrDefault(json, "highNoiseOffset", new JsonPrimitive(0)); + private static JsonElement getHighNoiseOffset(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "highNoiseOffset", new JsonPrimitive(0)); } - private static JsonElement getHighNoiseFactor(JsonObject json) { - return getOrDefault(json, "highNoiseFactor", new JsonPrimitive(1)); + private static JsonElement getHighNoiseFactor(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "highNoiseFactor", new JsonPrimitive(1)); } - private static JsonElement getLowNoiseFrequencyZ(JsonObject json) { - return getOrDefault(json, "lowNoiseFrequencyZ", + private static JsonElement getLowNoiseFrequencyZ(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lowNoiseFrequencyZ", new JsonPrimitive(0.005221649)); } - private static JsonElement getLowNoiseFrequencyY(JsonObject json) { - return getOrDefault(json, "lowNoiseFrequencyY", + private static JsonElement getLowNoiseFrequencyY(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lowNoiseFrequencyY", new JsonPrimitive(0.0026108245)); } - private static JsonElement getLowNoiseFrequencyX(JsonObject json) { - return getOrDefault(json, "lowNoiseFrequencyX", + private static JsonElement getLowNoiseFrequencyX(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lowNoiseFrequencyX", new JsonPrimitive(0.005221649)); } - private static JsonElement getLowNoiseOffset(JsonObject json) { - return getOrDefault(json, "lowNoiseOffset", new JsonPrimitive(0)); + private static JsonElement getLowNoiseOffset(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lowNoiseOffset", new JsonPrimitive(0)); } - private static JsonElement getLowNoiseFactor(JsonObject json) { - return getOrDefault(json, "lowNoiseFactor", new JsonPrimitive(1)); + private static JsonElement getLowNoiseFactor(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lowNoiseFactor", new JsonPrimitive(1)); } - private static JsonElement getLowNoiseOctaves(JsonObject json) { - return getOrDefault(json, "lowNoiseOctaves", new JsonPrimitive(16)); + private static JsonElement getLowNoiseOctaves(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lowNoiseOctaves", new JsonPrimitive(16)); } - private static JsonElement getSelectorNoiseOctaves(JsonObject json) { - return getOrDefault(json, "selectorNoiseOctaves", new JsonPrimitive(8)); + private static JsonElement getSelectorNoiseOctaves(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "selectorNoiseOctaves", new JsonPrimitive(8)); } - private static JsonElement getSelectorNoiseFrequencyZ(JsonObject json) { - return getOrDefault(json, "selectorNoiseFrequencyZ", + private static JsonElement getSelectorNoiseFrequencyZ(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "selectorNoiseFrequencyZ", new JsonPrimitive(0.016709277)); } - private static JsonElement getSelectorNoiseFrequencyX(JsonObject json) { - return getOrDefault(json, "selectorNoiseFrequencyX", + private static JsonElement getSelectorNoiseFrequencyX(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "selectorNoiseFrequencyX", new JsonPrimitive(0.016709277)); } - private static JsonElement getSelectorNoiseFrequencyY(JsonObject json) { - return getOrDefault(json, "selectorNoiseFrequencyY", + private static JsonElement getSelectorNoiseFrequencyY(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "selectorNoiseFrequencyY", new JsonPrimitive(0.008354639)); } - private static JsonElement getSelectorNoiseOffset(JsonObject json) { - return getOrDefault(json, "selectorNoiseOffset", + private static JsonElement getSelectorNoiseOffset(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "selectorNoiseOffset", new JsonPrimitive(0.5)); } - private static JsonElement getSelectorNoiseFactor(JsonObject json) { - return getOrDefault(json, "selectorNoiseFactor", + private static JsonElement getSelectorNoiseFactor(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "selectorNoiseFactor", new JsonPrimitive(12.75)); } - private static JsonElement getDepthNoiseOctaves(JsonObject json) { - return getOrDefault(json, "depthNoiseOctaves", new JsonPrimitive(16)); + private static JsonElement getDepthNoiseOctaves(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "depthNoiseOctaves", new JsonPrimitive(16)); } - private static JsonElement getDepthNoiseFrequencyZ(JsonObject json) { - return getOrDefault(json, "depthNoiseFrequencyZ", + private static JsonElement getDepthNoiseFrequencyZ(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "depthNoiseFrequencyZ", new JsonPrimitive(0.0015258789)); } - private static JsonElement getDepthNoiseFrequencyX(JsonObject json) { - return getOrDefault(json, "depthNoiseFrequencyX", + private static JsonElement getDepthNoiseFrequencyX(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "depthNoiseFrequencyX", new JsonPrimitive(0.0015258789)); } - private static JsonElement getDepthNoiseOffset(JsonObject json) { - return getOrDefault(json, "depthNoiseOffset", new JsonPrimitive(0)); + private static JsonElement getDepthNoiseOffset(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "depthNoiseOffset", new JsonPrimitive(0)); } - private static JsonElement getDepthNoiseFactor(JsonObject json) { - return getOrDefault(json, "depthNoiseFactor", new JsonPrimitive(1.024)); + private static JsonElement getDepthNoiseFactor(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "depthNoiseFactor", new JsonPrimitive(1.024)); } - private static JsonElement getHeightOffset(JsonObject json) { - return getOrDefault(json, "heightOffset", new JsonPrimitive(64)); + private static JsonElement getHeightOffset(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "heightOffset", new JsonPrimitive(64)); } - private static JsonElement getHeightFactor(JsonObject json) { - return getOrDefault(json, "heightFactor", new JsonPrimitive(64)); + private static JsonElement getHeightFactor(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "heightFactor", new JsonPrimitive(64)); } - private static JsonElement getHeightVariationOffset(JsonObject json) { - return getOrDefault(json, "heightVariationOffset", new JsonPrimitive(0)); + private static JsonElement getHeightVariationOffset(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "heightVariationOffset", new JsonPrimitive(0)); } - private static JsonElement getSpecialHeightVariationFactorBelowAverageY(JsonObject json) { - return getOrDefault(json, "specialHeightVariationFactorBelowAverageY", new JsonPrimitive(0.25f)); + private static JsonElement getSpecialHeightVariationFactorBelowAverageY(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "specialHeightVariationFactorBelowAverageY", new JsonPrimitive(0.25f)); } - private static JsonElement getHeightVariationFactor(JsonObject json) { - return getOrDefault(json, "heightVariationFactor", new JsonPrimitive(64)); + private static JsonElement getHeightVariationFactor(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "heightVariationFactor", new JsonPrimitive(64)); } - private static JsonElement getActualHeight(JsonObject json) { + private static JsonElement getActualHeight(JsonObject json, @Nullable JsonObject parent) { if (json.has("heightOffset") && json.has("heightVariationOffset") && json.has("heightFactor")) { float heightVariationOffset = json.get("heightVariationOffset").getAsFloat(); float offset = json.get("heightOffset").getAsFloat(); float factor = json.get("heightFactor").getAsFloat(); - return getOrDefault(json, "actualHeight", new JsonPrimitive((offset + heightVariationOffset + return getOrDefault(json, parent, "actualHeight", new JsonPrimitive((offset + heightVariationOffset + Math.max(factor * 2 + heightVariationOffset, factor + heightVariationOffset * 2)))); } - return getOrDefault(json, "actualHeight", new JsonPrimitive(64)); + return getOrDefault(json, parent, "actualHeight", new JsonPrimitive(64)); } - private static JsonElement getExpectedBaseHeight(JsonObject json) { + private static JsonElement getExpectedBaseHeight(JsonObject json, @Nullable JsonObject parent) { if (json.has("expectedBaseHeight")) return json.get("expectedBaseHeight"); - return getOrDefault(json, "heightOffset", new JsonPrimitive(64)); + return getOrDefault(json, parent, "heightOffset", new JsonPrimitive(64)); } - private static JsonElement getExpectedHeightVariation(JsonObject json) { - return getOrDefault(json, "expectedHeightVariation", getOrDefault(json, "heightFactor", new JsonPrimitive(64))); + private static JsonElement getExpectedHeightVariation(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "expectedHeightVariation", getOrDefault(json, parent, "heightFactor", new JsonPrimitive(64))); } - private static JsonElement getPeriodicGaussianOres(JsonObject oldRoot) { + private static JsonElement getPeriodicGaussianOres(JsonObject oldRoot, JsonObject parent) { if (oldRoot.has("periodicGaussianOres")) return oldRoot.get("periodicGaussianOres"); + if (parent != null && parent.has("periodicGaussianOres")) + return parent.get("periodicGaussianOres"); Gson gson = CustomGeneratorSettings.gson(); JsonArray periodicGaussianOres = new JsonArray(); JsonObject obj = convertGaussianPeriodicOre(gson, oldRoot, "lapisLazuli", Blocks.LAPIS_ORE.getDefaultState(), @@ -384,9 +359,11 @@ private static JsonElement getPeriodicGaussianOres(JsonObject oldRoot) { return periodicGaussianOres; } - private static JsonElement getStandardOres(JsonObject oldRoot) { + private static JsonElement getStandardOres(JsonObject oldRoot, JsonObject parent) { if (oldRoot.has("standardOres")) return oldRoot.get("standardOres"); + if (parent != null && parent.has("standardOres")) + return parent.get("standardOres"); Gson gson = CustomGeneratorSettings.gson(); JsonArray standardOres = new JsonArray(); for (int i = 0; i < standard.length; i++) { @@ -398,93 +375,95 @@ private static JsonElement getStandardOres(JsonObject oldRoot) { return standardOres; } - private static JsonElement getRiverSize(JsonObject json) { - return getOrDefault(json, "riverSize", new JsonPrimitive(4)); + private static JsonElement getRiverSize(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "riverSize", new JsonPrimitive(4)); } - private static JsonElement getBiomeSize(JsonObject json) { - return getOrDefault(json, "biomeSize", new JsonPrimitive(4)); + private static JsonElement getBiomeSize(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "biomeSize", new JsonPrimitive(4)); } - private static JsonElement getBiome(JsonObject json) { - return getOrDefault(json, "biome", new JsonPrimitive(-1)); + private static JsonElement getBiome(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "biome", new JsonPrimitive(-1)); } - private static JsonElement getLavaOceans(JsonObject json) { - return getOrDefault(json, "lavaOceans", new JsonPrimitive(false)); + private static JsonElement getLavaOceans(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lavaOceans", new JsonPrimitive(false)); } - private static JsonElement getAboveSeaLavaLakeRarity(JsonObject json) { - return getOrDefault(json, "aboveSeaLavaLakeRarity", new JsonPrimitive(13)); + private static JsonElement getAboveSeaLavaLakeRarity(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "aboveSeaLavaLakeRarity", new JsonPrimitive(13)); } - private static JsonElement getLavaLakeRarity(JsonObject json) { - return getOrDefault(json, "lavaLakeRarity", new JsonPrimitive(8)); + private static JsonElement getLavaLakeRarity(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lavaLakeRarity", new JsonPrimitive(8)); } - private static JsonElement getLavaLakes(JsonObject json) { - return getOrDefault(json, "lavaLakes", new JsonPrimitive(true)); + private static JsonElement getLavaLakes(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "lavaLakes", new JsonPrimitive(true)); } - private static JsonElement getWaterLakeRarity(JsonObject json) { - return getOrDefault(json, "waterLakeRarity", new JsonPrimitive(4)); + private static JsonElement getWaterLakeRarity(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "waterLakeRarity", new JsonPrimitive(4)); } - private static JsonElement getWaterLakes(JsonObject json) { - return getOrDefault(json, "waterLakes", new JsonPrimitive(true)); + private static JsonElement getWaterLakes(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "waterLakes", new JsonPrimitive(true)); } - private static JsonElement getDungeonCount(JsonObject json) { - return getOrDefault(json, "dungeonCount", new JsonPrimitive(7)); + private static JsonElement getDungeonCount(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "dungeonCount", new JsonPrimitive(7)); } - private static JsonElement getDungeons(JsonObject json) { - return getOrDefault(json, "dungeons", new JsonPrimitive(true)); + private static JsonElement getDungeons(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "dungeons", new JsonPrimitive(true)); } - private static JsonElement getRavines(JsonObject json) { - return getOrDefault(json, "ravines", new JsonPrimitive(true)); + private static JsonElement getRavines(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "ravines", new JsonPrimitive(true)); } - private static JsonElement getWoodlandMansions(JsonObject json) { - return getOrDefault(json, "woodlandMansions", new JsonPrimitive(true)); + private static JsonElement getWoodlandMansions(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "woodlandMansions", new JsonPrimitive(true)); } - private static JsonElement getOceanMonuments(JsonObject json) { - return getOrDefault(json, "oceanMonuments", new JsonPrimitive(true)); + private static JsonElement getOceanMonuments(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "oceanMonuments", new JsonPrimitive(true)); } - private static JsonElement getTemples(JsonObject json) { - return getOrDefault(json, "temples", new JsonPrimitive(true)); + private static JsonElement getTemples(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "temples", new JsonPrimitive(true)); } - private static JsonElement getMineshafts(JsonObject json) { - return getOrDefault(json, "mineshafts", new JsonPrimitive(true)); + private static JsonElement getMineshafts(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "mineshafts", new JsonPrimitive(true)); } - private static JsonElement getVillages(JsonObject json) { - return getOrDefault(json, "villages", new JsonPrimitive(true)); + private static JsonElement getVillages(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "villages", new JsonPrimitive(true)); } - private static JsonElement getAlternateStrongholdsPositions(JsonObject json) { - return getOrDefault(json, "alternateStrongholdsPositions", new JsonPrimitive(false)); + private static JsonElement getAlternateStrongholdsPositions(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "alternateStrongholdsPositions", new JsonPrimitive(false)); } - private static JsonElement getStrongholds(JsonObject json) { - return getOrDefault(json, "strongholds", new JsonPrimitive(true)); + private static JsonElement getStrongholds(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "strongholds", new JsonPrimitive(true)); } - private static JsonElement getCaves(JsonObject json) { - return getOrDefault(json, "caves", new JsonPrimitive(true)); + private static JsonElement getCaves(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "caves", new JsonPrimitive(true)); } - private static JsonElement getWaterLevel(JsonObject json) { - return getOrDefault(json, "waterLevel", new JsonPrimitive(63)); + private static JsonElement getWaterLevel(JsonObject json, @Nullable JsonObject parent) { + return getOrDefault(json, parent, "waterLevel", new JsonPrimitive(63)); } - private static JsonElement getOrDefault(JsonObject source, String name, JsonElement jsonElement) { + private static JsonElement getOrDefault(JsonObject source, @Nullable JsonObject parent, String name, JsonElement jsonElement) { if (source.has(name)) return source.get(name); + if (parent != null && parent.has(name)) + return parent.get(name); return jsonElement; } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ClientProxy.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ClientProxy.java new file mode 100644 index 0000000..8a41761 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ClientProxy.java @@ -0,0 +1,35 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.proxy; + +import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.GuiEventHandler; +import net.minecraftforge.common.MinecraftForge; + +public class ClientProxy extends CommonProxy { + + @Override + public void preInit() { + MinecraftForge.EVENT_BUS.register(new GuiEventHandler()); + } +} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/CommonProxy.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/CommonProxy.java new file mode 100644 index 0000000..c3afebf --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/CommonProxy.java @@ -0,0 +1,29 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.proxy; + +public class CommonProxy { + + public void preInit() {} +} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ServerProxy.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ServerProxy.java new file mode 100644 index 0000000..dad53d9 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/proxy/ServerProxy.java @@ -0,0 +1,28 @@ +/* + * This file is part of Cubic World Generation, licensed under the MIT License (MIT). + * + * Copyright (c) 2015 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.opencubicchunks.cubicchunks.cubicgen.proxy; + +public class ServerProxy extends CommonProxy { + +} diff --git a/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg b/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg index 57ed0e1..0d4f183 100644 --- a/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg +++ b/src/main/resources/META-INF/cubicchunks_cubicgen_at.cfg @@ -1,6 +1,8 @@ public net.minecraft.world.biome.BiomeProvider field_76944_d # genBiomes public net.minecraft.world.biome.BiomeProvider field_76945_e # biomeIndexLayer public net.minecraft.client.gui.GuiCreateWorld field_146336_i # saveDirName +public net.minecraft.client.gui.GuiWorldSelection field_184866_u # selectionList +public net.minecraft.client.gui.GuiListWorldSelectionEntry field_186786_g # worldSummary # used by cubic chunks biome populators public net.minecraft.world.biome.Biome field_180281_af # GRASS_COLOR_NOISE diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java index 2d4e10b..5c34ca0 100644 --- a/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java +++ b/src/test/java/io/github/opencubicchunks/cubicchunks/cubicgen/TestCustomGeneratorSettingsFixer.java @@ -165,7 +165,166 @@ public class TestCustomGeneratorSettingsFixer { " \"highNoiseOctaves\":3\n" + "}"; - String expectedConversionResult = "{\"waterLevel\":100,\"caves\":false,\"strongholds\":false,\"alternateStrongholdsPositions\":false,\"villages\":false,\"mineshafts\":false,\"temples\":false,\"oceanMonuments\":false,\"woodlandMansions\":false,\"ravines\":false,\"dungeons\":false,\"dungeonCount\":101,\"waterLakes\":false,\"waterLakeRarity\":102,\"lavaLakes\":false,\"lavaLakeRarity\":103,\"aboveSeaLavaLakeRarity\":104,\"lavaOceans\":true,\"biome\":1,\"biomeSize\":104,\"riverSize\":105,\"standardOres\":[{\"blockstate\":{\"Properties\":{\"variant\":\"dirt\",\"snowy\":\"false\"},\"Name\":\"minecraft:dirt\"},\"spawnSize\":134,\"spawnTries\":135,\"spawnProbability\":136.0,\"minHeight\":-Infinity,\"maxHeight\":Infinity},{\"blockstate\":{\"Name\":\"minecraft:gravel\"},\"spawnSize\":137,\"spawnTries\":138,\"spawnProbability\":139.0,\"minHeight\":-Infinity,\"maxHeight\":Infinity},{\"blockstate\":{\"Properties\":{\"variant\":\"granite\"},\"Name\":\"minecraft:stone\"},\"spawnSize\":140,\"spawnTries\":141,\"spawnProbability\":142.0,\"minHeight\":-Infinity,\"maxHeight\":143.0},{\"blockstate\":{\"Properties\":{\"variant\":\"diorite\"},\"Name\":\"minecraft:stone\"},\"spawnSize\":144,\"spawnTries\":145,\"spawnProbability\":146.0,\"minHeight\":-Infinity,\"maxHeight\":147.0},{\"blockstate\":{\"Properties\":{\"variant\":\"andesite\"},\"Name\":\"minecraft:stone\"},\"spawnSize\":148,\"spawnTries\":149,\"spawnProbability\":150.0,\"minHeight\":-Infinity,\"maxHeight\":151.0},{\"blockstate\":{\"Name\":\"minecraft:coal_ore\"},\"spawnSize\":152,\"spawnTries\":153,\"spawnProbability\":154.0,\"minHeight\":-Infinity,\"maxHeight\":155.0},{\"blockstate\":{\"Name\":\"minecraft:iron_ore\"},\"spawnSize\":156,\"spawnTries\":157,\"spawnProbability\":158.0,\"minHeight\":-Infinity,\"maxHeight\":159.0},{\"blockstate\":{\"Name\":\"minecraft:gold_ore\"},\"spawnSize\":160,\"spawnTries\":161,\"spawnProbability\":162.0,\"minHeight\":-Infinity,\"maxHeight\":-163.0},{\"blockstate\":{\"Name\":\"minecraft:redstone_ore\"},\"spawnSize\":164,\"spawnTries\":165,\"spawnProbability\":166.0,\"minHeight\":-Infinity,\"maxHeight\":-167.0},{\"blockstate\":{\"Name\":\"minecraft:diamond_ore\"},\"spawnSize\":168,\"spawnTries\":169,\"spawnProbability\":170.0,\"minHeight\":-Infinity,\"maxHeight\":-178.0},{\"blockstate\":{\"Name\":\"minecraft:emerald_ore\"},\"biomes\":[\"minecraft:extreme_hills\",\"minecraft:smaller_extreme_hills\",\"minecraft:extreme_hills_with_trees\",\"minecraft:mutated_extreme_hills\",\"minecraft:mutated_extreme_hills_with_trees\"],\"spawnSize\":3,\"spawnTries\":184,\"spawnProbability\":185.0,\"minHeight\":-Infinity,\"maxHeight\":-186.0},{\"blockstate\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:monster_egg\"},\"biomes\":[\"minecraft:extreme_hills\",\"minecraft:smaller_extreme_hills\",\"minecraft:extreme_hills_with_trees\",\"minecraft:mutated_extreme_hills\",\"minecraft:mutated_extreme_hills_with_trees\"],\"spawnSize\":187,\"spawnTries\":188,\"spawnProbability\":189.0,\"minHeight\":-Infinity,\"maxHeight\":190.0},{\"blockstate\":{\"Name\":\"minecraft:gold_ore\"},\"biomes\":[\"minecraft:mesa\",\"minecraft:mesa_clear_rock\",\"minecraft:mesa_rock\",\"minecraft:mutated_mesa\",\"minecraft:mutated_mesa_clear_rock\",\"minecraft:mutated_mesa_rock\"],\"spawnSize\":191,\"spawnTries\":192,\"spawnProbability\":193.0,\"minHeight\":-194.0,\"maxHeight\":196.0}],\"periodicGaussianOres\":[{\"blockstate\":{\"Name\":\"minecraft:lapis_ore\"},\"spawnSize\":179,\"spawnTries\":180,\"spawnProbability\":181.0,\"heightMean\":182.0,\"heightStdDeviation\":183.0,\"heightSpacing\":0.0,\"minHeight\":0.0,\"maxHeight\":0.0}],\"expectedBaseHeight\":110.0,\"expectedHeightVariation\":109.0,\"actualHeight\":544.0,\"heightVariationFactor\":106.0,\"specialHeightVariationFactorBelowAverageY\":107.0,\"heightVariationOffset\":108.0,\"heightFactor\":109.0,\"heightOffset\":110.0,\"depthNoiseFactor\":111.0,\"depthNoiseOffset\":112.0,\"depthNoiseFrequencyX\":113.0,\"depthNoiseFrequencyZ\":114.0,\"depthNoiseOctaves\":5,\"selectorNoiseFactor\":116.0,\"selectorNoiseOffset\":117.0,\"selectorNoiseFrequencyX\":118.0,\"selectorNoiseFrequencyY\":119.0,\"selectorNoiseFrequencyZ\":120.0,\"selectorNoiseOctaves\":1,\"lowNoiseFactor\":122.0,\"lowNoiseOffset\":123.0,\"lowNoiseFrequencyX\":124.0,\"lowNoiseFrequencyY\":125.0,\"lowNoiseFrequencyZ\":126.0,\"lowNoiseOctaves\":7,\"highNoiseFactor\":128.0,\"highNoiseOffset\":129.0,\"highNoiseFrequencyX\":130.0,\"highNoiseFrequencyY\":131.0,\"highNoiseFrequencyZ\":132.0,\"highNoiseOctaves\":3,\"cubeAreas\":[],\"replacerConfig\":{\"defaults\":{\"cubicgen:biome_fill_noise_octaves\":4.0,\"cubicgen:ocean_block\":{\"Properties\":{\"level\":\"0\"},\"Name\":\"minecraft:water\"},\"cubicgen:height_scale\":64.0,\"cubicgen:biome_fill_noise_freq\":0.0078125,\"cubicgen:water_level\":63.0,\"cubicgen:biome_fill_depth_factor\":2.3333333333333335,\"cubicgen:terrain_fill_block\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:stone\"},\"cubicgen:mesa_depth\":16.0,\"cubicgen:biome_fill_depth_offset\":3.0,\"cubicgen:horizontal_gradient_depth_decrease_weight\":1.0,\"cubicgen:height_offset\":64.0},\"overrides\":{}},\"version\":3}"; + String expectedConversionResult = "{\"waterLevel\":100," + + "\"caves\":false," + + "\"strongholds\":false," + + "\"alternateStrongholdsPositions\":false," + + "\"villages\":false," + + "\"mineshafts\":false," + + "\"temples\":false," + + "\"oceanMonuments\":false," + + "\"woodlandMansions\":false," + + "\"ravines\":false," + + "\"dungeons\":false," + + "\"dungeonCount\":101," + + "\"waterLakes\":false," + + "\"waterLakeRarity\":102," + + "\"lavaLakes\":false," + + "\"lavaLakeRarity\":103," + + "\"aboveSeaLavaLakeRarity\":104," + + "\"lavaOceans\":true," + + "\"biome\":1," + + "\"biomeSize\":104," + + "\"riverSize\":105," + + "\"standardOres\":[" + + "{\"blockstate\":{\"Properties\":{\"variant\":\"dirt\",\"snowy\":\"false\"},\"Name\":\"minecraft:dirt\"}," + + "\"spawnSize\":134," + + "\"spawnTries\":135," + + "\"spawnProbability\":136.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":Infinity}," + + "{\"blockstate\":{\"Name\":\"minecraft:gravel\"}," + + "\"spawnSize\":137," + + "\"spawnTries\":138," + + "\"spawnProbability\":139.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":Infinity}," + + "{\"blockstate\":{\"Properties\":{\"variant\":\"granite\"},\"Name\":\"minecraft:stone\"}," + + "\"spawnSize\":140," + + "\"spawnTries\":141," + + "\"spawnProbability\":142.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":143.0}," + + "{\"blockstate\":{\"Properties\":{\"variant\":\"diorite\"},\"Name\":\"minecraft:stone\"}," + + "\"spawnSize\":144," + + "\"spawnTries\":145," + + "\"spawnProbability\":146.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":147.0}," + + "{\"blockstate\":{\"Properties\":{\"variant\":\"andesite\"},\"Name\":\"minecraft:stone\"}," + + "\"spawnSize\":148," + + "\"spawnTries\":149," + + "\"spawnProbability\":150.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":151.0}," + + "{\"blockstate\":{\"Name\":\"minecraft:coal_ore\"}," + + "\"spawnSize\":152," + + "\"spawnTries\":153," + + "\"spawnProbability\":154.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":155.0}," + + "{\"blockstate\":{\"Name\":\"minecraft:iron_ore\"}," + + "\"spawnSize\":156," + + "\"spawnTries\":157," + + "\"spawnProbability\":158.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":159.0}," + + "{\"blockstate\":{\"Name\":\"minecraft:gold_ore\"}," + + "\"spawnSize\":160," + + "\"spawnTries\":161," + + "\"spawnProbability\":162.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":-163.0}," + + "{\"blockstate\":{\"Name\":\"minecraft:redstone_ore\"}," + + "\"spawnSize\":164," + + "\"spawnTries\":165," + + "\"spawnProbability\":166.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":-167.0}," + + "{\"blockstate\":{\"Name\":\"minecraft:diamond_ore\"}," + + "\"spawnSize\":168," + + "\"spawnTries\":169," + + "\"spawnProbability\":170.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":-178.0}," + + "{\"blockstate\":{\"Name\":\"minecraft:emerald_ore\"}," + + "\"biomes\":[\"minecraft:extreme_hills\",\"minecraft:smaller_extreme_hills\",\"minecraft:extreme_hills_with_trees\",\"minecraft:mutated_extreme_hills\",\"minecraft:mutated_extreme_hills_with_trees\"]," + + "\"spawnSize\":3," + + "\"spawnTries\":184," + + "\"spawnProbability\":185.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":-186.0}," + + "{\"blockstate\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:monster_egg\"}," + + "\"biomes\":[\"minecraft:extreme_hills\",\"minecraft:smaller_extreme_hills\",\"minecraft:extreme_hills_with_trees\",\"minecraft:mutated_extreme_hills\",\"minecraft:mutated_extreme_hills_with_trees\"]," + + "\"spawnSize\":187," + + "\"spawnTries\":188," + + "\"spawnProbability\":189.0," + + "\"minHeight\":-Infinity," + + "\"maxHeight\":190.0}," + + "{\"blockstate\":{\"Name\":\"minecraft:gold_ore\"}," + + "\"biomes\":[\"minecraft:mesa\",\"minecraft:mesa_clear_rock\",\"minecraft:mesa_rock\",\"minecraft:mutated_mesa\",\"minecraft:mutated_mesa_clear_rock\",\"minecraft:mutated_mesa_rock\"]," + + "\"spawnSize\":191," + + "\"spawnTries\":192," + + "\"spawnProbability\":193.0," + + "\"minHeight\":-194.0," + + "\"maxHeight\":196.0}]," + + "\"periodicGaussianOres\":[" + + "{\"blockstate\":{\"Name\":\"minecraft:lapis_ore\"}," + + "\"spawnSize\":179," + + "\"spawnTries\":180," + + "\"spawnProbability\":181.0," + + "\"heightMean\":182.0," + + "\"heightStdDeviation\":183.0," + + "\"heightSpacing\":0.0," + + "\"minHeight\":0.0," + + "\"maxHeight\":0.0}]," + + "\"expectedBaseHeight\":110.0," + + "\"expectedHeightVariation\":109.0," + + "\"actualHeight\":544.0," + + "\"heightVariationFactor\":106.0," + + "\"specialHeightVariationFactorBelowAverageY\":107.0," + + "\"heightVariationOffset\":108.0," + + "\"heightFactor\":109.0," + + "\"heightOffset\":110.0," + + "\"depthNoiseFactor\":111.0," + + "\"depthNoiseOffset\":112.0," + + "\"depthNoiseFrequencyX\":113.0," + + "\"depthNoiseFrequencyZ\":114.0," + + "\"depthNoiseOctaves\":5," + + "\"selectorNoiseFactor\":116.0," + + "\"selectorNoiseOffset\":117.0," + + "\"selectorNoiseFrequencyX\":118.0," + + "\"selectorNoiseFrequencyY\":119.0," + + "\"selectorNoiseFrequencyZ\":120.0," + + "\"selectorNoiseOctaves\":1," + + "\"lowNoiseFactor\":122.0," + + "\"lowNoiseOffset\":123.0," + + "\"lowNoiseFrequencyX\":124.0," + + "\"lowNoiseFrequencyY\":125.0," + + "\"lowNoiseFrequencyZ\":126.0," + + "\"lowNoiseOctaves\":7," + + "\"highNoiseFactor\":128.0," + + "\"highNoiseOffset\":129.0," + + "\"highNoiseFrequencyX\":130.0," + + "\"highNoiseFrequencyY\":131.0," + + "\"highNoiseFrequencyZ\":132.0," + + "\"highNoiseOctaves\":3," + + "\"cubeAreas\":[]," + + "\"replacerConfig\":{" + + "\"defaults\":{" + + "\"cubicgen:biome_fill_noise_octaves\":4.0," + + "\"cubicgen:ocean_block\":{\"Properties\":{\"level\":\"0\"},\"Name\":\"minecraft:water\"}," + + "\"cubicgen:height_scale\":64.0," + + "\"cubicgen:biome_fill_noise_freq\":0.0078125," + + "\"cubicgen:water_level\":63.0," + + "\"cubicgen:biome_fill_depth_factor\":2.3333333333333335," + + "\"cubicgen:terrain_fill_block\":{\"Properties\":{\"variant\":\"stone\"},\"Name\":\"minecraft:stone\"}," + + "\"cubicgen:mesa_depth\":16.0," + + "\"cubicgen:biome_fill_depth_offset\":3.0," + + "\"cubicgen:horizontal_gradient_depth_decrease_weight\":1.0," + + "\"cubicgen:height_offset\":64.0}," + + "\"overrides\":{}}," + + "\"version\":3}"; @Before public void setUp() { From c79512feb61130a7798b8e7bc39f309e48583037 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 20 Jan 2019 18:40:26 +0300 Subject: [PATCH 17/17] Remove unnecessary Malisiscore dependency, fix missing ore entries on new world creation --- .../cubicgen/common/gui/GuiEventHandler.java | 2 +- .../cubicgen/customcubic/CustomCubicWorldType.java | 4 ++-- .../customcubic/CustomGeneratorSettings.java | 3 ++- .../cubicgen/customcubic/gui/CustomCubicGui.java | 13 +++++-------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java index 51a3488..f40c6c6 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/common/gui/GuiEventHandler.java @@ -61,7 +61,7 @@ public void onButtonPressed(GuiScreenEvent.ActionPerformedEvent.Pre action) { String json = CustomGeneratorSettings.loadJsonStringFromSaveFolder(isavehandler); isavehandler.flush(); if (json != null) { - CustomCubicGui.settingsJsonString = json; + CustomCubicWorldType.pendingCustomCubicSettingsJsonString = json; } } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java index 9c464ba..07993c8 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomCubicWorldType.java @@ -57,6 +57,7 @@ public class CustomCubicWorldType extends WorldType implements ICubicWorldType { // This string is not empty when and only when someone used a CustomCubicGUI // and press a Done button both in this CustomCubicGUI and in a WorldCreationGUI public static String pendingCustomCubicSettingsJsonString = ""; + public static boolean createNewWorld = false; private CustomCubicWorldType() { super("CustomCubic"); @@ -98,8 +99,7 @@ public boolean isCustomizable() { @Override public void onGUICreateWorldPress() { - pendingCustomCubicSettingsJsonString = CustomCubicGui.settingsJsonString; - CustomCubicGui.settingsJsonString = ""; + createNewWorld = true; } @SideOnly(Side.CLIENT) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java index 2ab6e31..498c131 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/CustomGeneratorSettings.java @@ -237,9 +237,10 @@ public static CustomGeneratorSettings load(World world) { settings = fromJson(jsonString); if (isOutdated) settings.save(world); - } else if (!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) { + } else if (CustomCubicWorldType.createNewWorld && !CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) { settings = CustomGeneratorSettings.fromJson(CustomCubicWorldType.pendingCustomCubicSettingsJsonString); CustomCubicWorldType.pendingCustomCubicSettingsJsonString = ""; + CustomCubicWorldType.createNewWorld = false; settings.save(world); } else { CustomCubicMod.LOGGER diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java index f94a67b..67b47e4 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/cubicgen/customcubic/gui/CustomCubicGui.java @@ -32,6 +32,7 @@ import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.ExtraGui; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UISplitLayout; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UITextFieldFixed; +import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomCubicWorldType; import io.github.opencubicchunks.cubicchunks.cubicgen.customcubic.CustomGeneratorSettings; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.NoTranslationFont; import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UIBorderLayout; @@ -75,10 +76,6 @@ public class CustomCubicGui extends ExtraGui { private AdvancedTerrainShapeTab advancedterrainShapeSettings; private Map areas; private BiomeBlockReplacerConfig replacerConf; - // Store config here between GUI calls, so we would not need to store it in - // parent GUI. Whenever player will press create world GUI button it will be - // transfered to CustomCubicWorld type to be saved. - public static String settingsJsonString = ""; public CustomCubicGui(GuiCreateWorld parent) { super(); @@ -92,10 +89,10 @@ public CustomCubicGui(GuiCreateWorld parent) { @Override public void construct() { CustomGeneratorSettings conf = null; - if (!settingsJsonString.isEmpty()) - conf = CustomGeneratorSettings.fromJson(settingsJsonString); + if (!CustomCubicWorldType.pendingCustomCubicSettingsJsonString.isEmpty()) + conf = CustomGeneratorSettings.fromJson(CustomCubicWorldType.pendingCustomCubicSettingsJsonString); else - conf = new CustomGeneratorSettings(); + conf = CustomGeneratorSettings.defaults(); reinit(conf); } @@ -254,7 +251,7 @@ public void onClick(UIButton.ClickEvent evt) { } private void done() { - settingsJsonString = getSettingsJson(getConfig()); + CustomCubicWorldType.pendingCustomCubicSettingsJsonString = getSettingsJson(getConfig()); this.mc.displayGuiScreen(parent); }