From 5ec7870453e55062f4707a769d7fcbbb9acb98e8 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Mon, 7 Apr 2025 13:02:35 +0700 Subject: [PATCH 01/21] refactor: [WIP] Merge custom gen with basic gen --- .../github/null2264/cobblegen/CobbleGen.java | 6 ++-- .../cobblegen/data/config/ConfigData.java | 31 ++++++++++++++----- .../cobblegen/data/config/ConfigHelper.java | 15 ++++++--- .../cobblegen/data/config/CustomGen.java | 4 +-- .../cobblegen/data/config/WeightedBlock.java | 2 ++ .../cobblegen/integration/BuiltInPlugin.java | 4 +-- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java index 753f4b0b..484be566 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java @@ -40,11 +40,11 @@ public class CobbleGen private static final File configFile = new File(configPath + File.separator + MOD_ID + ".json5"); private static final File metaConfigFile = new File(configPath + File.separator + MOD_ID + "-meta.json5"); @ApiStatus.Internal - public static ConfigMetaData META_CONFIG = loadConfig(false, metaConfigFile, null, new ConfigMetaData(), ConfigMetaData.class); + public static ConfigMetaData META_CONFIG = loadConfig("metadata", false, metaConfigFile, null, new ConfigMetaData(), ConfigMetaData.class); public CobbleGen() { // Force config to be generated when loading up the game instead of having to load a world - loadConfig(false, configFile, null, ConfigData.defaultConfig(), ConfigData.class); + loadConfig("generator", false, configFile, null, ConfigData.defaultConfig(), ConfigData.class); #if FORGE && MC>=11801 && MC<12105 // I was gonna do RegisterGameTestsEvent like a normal person, but there's a check that I need to bypass otherwise Forge won't register my test net.minecraft.gametest.framework.GameTestRegistry.register(io.github.null2264.cobblegen.gametest.BlockGenerationTest.class); @@ -62,7 +62,7 @@ public static void initCommands(CommandDispatcher dispatcher LiteralArgumentBuilder.literal("cobblegen") .then(LiteralArgumentBuilder.literal("reload-meta").requires(arg -> arg.hasPermission(OP_LEVEL_GAMEMASTERS)).executes(c -> { CGLog.info("Reloading meta config..."); - META_CONFIG = loadConfig(true, metaConfigFile, META_CONFIG, new ConfigMetaData(), ConfigMetaData.class); + META_CONFIG = loadConfig("metadata", true, metaConfigFile, META_CONFIG, new ConfigMetaData(), ConfigMetaData.class); c.getSource().sendSuccess( #if MC>=12001 () -> diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index fa3c6320..5888f5b9 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -6,6 +6,7 @@ import io.github.null2264.cobblegen.data.CGIdentifier; import io.github.null2264.cobblegen.data.JanksonSerializable; import io.github.null2264.cobblegen.data.Pair; +import io.github.null2264.cobblegen.util.Util; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -16,7 +17,7 @@ public class ConfigData implements Config, JanksonSerializable { @Comment(value = "CobbleGen Format Version, you can leave this alone for now. v2.0 will be released in CobbleGen v6.0") @NotNull - public String formatVersion = "1.0"; + public String formatVersion = "1.1"; @Nullable @Comment(value = "Default Generators\n" + @@ -32,7 +33,8 @@ public class ConfigData implements Config, JanksonSerializable " \"mod_id:dimension_id\"\n" + " ],\n" + " \"minY\": 0,\n" + - " \"maxY\": 69\n" + + " \"maxY\": 69,\n" + + " \"modifier\": 69\n" + "}") public ResultList cobbleGen; @@ -143,15 +145,28 @@ public static ConfigData fromJson(JsonObject json) { ConfigData config = new ConfigData(); JsonElement formatVersion = json.get("formatVersion"); config.formatVersion = (formatVersion instanceof JsonPrimitive) ? ((JsonPrimitive) formatVersion).asString() : "1.0"; - /* TODO - if (config.formatVersion.equals("1.0")) { - // TODO: Migrate to 2.0 - } - */ config.cobbleGen = ResultList.fromJson(json.get("cobbleGen")); config.stoneGen = ResultList.fromJson(json.get("stoneGen")); config.basaltGen = ResultList.fromJson(json.get("basaltGen")); - config.customGen = CustomGen.fromJson(json.getObject("customGen")); + CustomGen customGen = CustomGen.fromJson(json.getObject("customGen")); + if (config.formatVersion.equals("1.0") && customGen != null) { + // TODO + Util.optional(customGen.cobbleGen).ifPresent(gen -> gen.forEach((modifier, value) -> { + if (config.cobbleGen != null) { + config.cobbleGen.addAll(value.stream().peek(result -> result.modifier = modifier.toString()).toList()); + } + })); + Util.optional(customGen.stoneGen).ifPresent(gen -> gen.forEach((modifier, value) -> { + if (config.stoneGen != null) { + config.stoneGen.addAll(value.stream().peek(result -> result.modifier = modifier.toString()).toList()); + } + })); + Util.optional(customGen.basaltGen).ifPresent(gen -> gen.forEach((modifier, value) -> { + if (config.basaltGen != null) { + config.basaltGen.addAll(value.stream().peek(result -> result.modifier = modifier.toString()).toList()); + } + })); + } config.advanced = FluidInteractionMap.fromJson(json.getObject("advanced")); return config; } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java index a770e3ad..65cf387b 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java @@ -16,14 +16,21 @@ public class ConfigHelper { @ApiStatus.Internal - public static T loadConfig(boolean reload, File configFile, T workingConfig, T defaultConfig, Class clazz) { + public static T loadConfig( + String name, + boolean reload, + File configFile, + T workingConfig, + T defaultConfig, + Class clazz + ) { String string = reload ? "reload" : "load"; try { - CGLog.info("Trying to " + string + " config file..."); + CGLog.info(() -> "Trying to " + string + " '" + name + "' config file..."); JsonObject json = JANKSON.load(configFile); return JANKSON.fromJson(json, clazz); } catch (Exception e) { - CGLog.error("There was an error while " + string + "ing the config file!\n" + e); + CGLog.error("There was an error while " + string + "ing '" + name + "' config file!\n" + e); if (reload && workingConfig != null) { CGLog.warn("Falling back to previously working config..."); @@ -76,4 +83,4 @@ private static void saveConfig(Config config, File configFile) { CGLog.error("There was an error while creating the config file!\n" + e); } } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java index 6e13a55c..7f5c2a05 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java @@ -38,7 +38,7 @@ public CustomGen( @Serializer public JsonObject toJson() { JsonObject json = new JsonObject(); - if (cobbleGen != null) json.put("cobbleGen", cobbleGen.toJson()); + if (cobbleGen != null) json.put("cobbleGen", JANKSON.toJson(cobbleGen)); if (stoneGen != null) json.put("stoneGen", JANKSON.toJson(stoneGen)); if (basaltGen != null) json.put("basaltGen", JANKSON.toJson(basaltGen)); return json; @@ -53,4 +53,4 @@ public static CustomGen fromJson(JsonObject json) { GeneratorMap basaltGen = GeneratorMap.fromJson(json.getObject("basaltGen")); return new CustomGen(cobbleGen, stoneGen, basaltGen); } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java index 6777de91..3b4f1fad 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java @@ -38,6 +38,8 @@ public class WeightedBlock implements PacketSerializable, Jankson public List biomes; @Nullable public List excludedBiomes; + @Nullable + public String modifier; public WeightedBlock(String id, Double weight) { this(id, weight, null, null); diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java index d2b4c6a7..0546bc32 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java @@ -61,7 +61,7 @@ private Block getBlockFromString(String string) { @Override public void registerInteraction(CGRegistry registry) { CGLog.info((!isReload ? "L" : "Rel") + "oading config..."); - if (config == null || isReload) config = loadConfig(isReload, configFile, config, ConfigData.defaultConfig(), ConfigData.class); + if (config == null || isReload) config = loadConfig("generator", isReload, configFile, config, ConfigData.defaultConfig(), ConfigData.class); if (config == null) throw new RuntimeException("How?"); AtomicInteger count = new AtomicInteger(); @@ -141,4 +141,4 @@ public void onReload() { CGLog.info("Reloading built-in plugin..."); isReload = true; } -} \ No newline at end of file +} From 81e9ed2d15e5cd63907899a05dab08a7e9a0422b Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Tue, 8 Apr 2025 06:34:37 +0700 Subject: [PATCH 02/21] refactor: Rename notNullOr -> elvis --- .../io/github/null2264/cobblegen/FluidInteraction.java | 5 ++--- .../null2264/cobblegen/gametest/CobbleGenTestLoader.java | 8 +++++--- .../null2264/cobblegen/integration/BuiltInPlugin.java | 9 ++++----- .../cobblegen/integration/viewer/emi/CGEMIPlugin.java | 6 +++--- .../cobblegen/integration/viewer/jei/CGJEIPlugin.java | 6 +++--- .../cobblegen/integration/viewer/rei/CGREIPlugin.java | 6 +++--- .../java/io/github/null2264/cobblegen/util/Util.java | 4 +--- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java index 0df760f8..1ef329ef 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java @@ -1,6 +1,5 @@ package io.github.null2264.cobblegen; -import io.github.null2264.cobblegen.CobbleGen; import io.github.null2264.cobblegen.data.CGRegistryImpl; import io.github.null2264.cobblegen.data.model.CGRegistry; import io.github.null2264.cobblegen.data.model.Generator; @@ -27,7 +26,7 @@ import static io.github.null2264.cobblegen.compat.CollectionCompat.listOf; import static io.github.null2264.cobblegen.util.Constants.LAVA_FIZZ; -import static io.github.null2264.cobblegen.util.Util.notNullOr; +import static io.github.null2264.cobblegen.util.Util.elvis; /** * Replacement for BlockGenerator. This will act like Vanilla's registry system @@ -60,7 +59,7 @@ public Map> getLocalGenerators() { @NotNull public Map> getGenerators() { - return notNullOr(serverGeneratorMap, generatorMap); + return elvis(serverGeneratorMap, generatorMap); } @ApiStatus.Internal diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java index 69f43863..27e41ec6 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java @@ -2,6 +2,7 @@ package io.github.null2264.cobblegen.gametest; import io.github.null2264.cobblegen.util.CGLog; +import io.github.null2264.cobblegen.util.Util; import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.gametest.framework.TestFunctionLoader; import net.minecraft.resources.ResourceKey; @@ -15,12 +16,13 @@ public class CobbleGenTestLoader extends TestFunctionLoader { private static final AtomicBoolean SHOULD_REGISTER = new AtomicBoolean(true); public static final boolean ENABLED = boolFromString( - System.getProperty("null2264.cobblegen.gametest", System.getenv("ENABLE_NULL2264_COBBLEGEN_GAMETEST")) + System.getProperty( + "null2264.cobblegen.gametest", + Util.elvis(System.getenv("ENABLE_NULL2264_COBBLEGEN_GAMETEST"), "false") + ) ); private static boolean boolFromString(String string) { - if (string == null) return false; - List yes = List.of("yes", "y", "true", "t", "1", "enable", "on"); List no = List.of("no", "n", "false", "f", "0", "disable", "off"); diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java index 0546bc32..6c40d511 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java @@ -23,12 +23,11 @@ import java.io.File; import java.nio.file.Path; -import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import static io.github.null2264.cobblegen.CobbleGen.MOD_ID; import static io.github.null2264.cobblegen.data.config.ConfigHelper.loadConfig; -import static io.github.null2264.cobblegen.util.Util.notNullOr; +import static io.github.null2264.cobblegen.util.Util.elvis; @CGPlugin public class BuiltInPlugin implements CobbleGenPlugin @@ -76,9 +75,9 @@ public void registerInteraction(CGRegistry registry) { if (config.customGen != null && config.customGen.basaltGen != null) basaltGen = config.customGen.basaltGen; - stoneGen.put(CGIdentifier.wildcard(), notNullOr(config.stoneGen, new ResultList())); - cobbleGen.put(CGIdentifier.wildcard(), notNullOr(config.cobbleGen, new ResultList())); - basaltGen.put(CGIdentifier.fromBlock(Blocks.SOUL_SOIL), notNullOr(config.basaltGen, new ResultList())); + stoneGen.put(CGIdentifier.wildcard(), elvis(config.stoneGen, new ResultList())); + cobbleGen.put(CGIdentifier.wildcard(), elvis(config.cobbleGen, new ResultList())); + basaltGen.put(CGIdentifier.fromBlock(Blocks.SOUL_SOIL), elvis(config.basaltGen, new ResultList())); if (config.advanced != null) config.advanced.forEach((fluid, value) -> { diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/emi/CGEMIPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/emi/CGEMIPlugin.java index 8bfdb39a..aa7cfaae 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/emi/CGEMIPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/emi/CGEMIPlugin.java @@ -101,11 +101,11 @@ public void register(EmiRegistry registry) { registry.addRecipe( new FluidInteractionRecipe( fluid, - Util.notNullOr(generator.getFluid(), Fluids.EMPTY), - Util.notNullOr(generator.getBlock(), Blocks.AIR), + Util.elvis(generator.getFluid(), Fluids.EMPTY), + Util.elvis(generator.getBlock(), Blocks.AIR), block, generator.getType(), - Util.notNullOr(modifier, Blocks.AIR) + Util.elvis(modifier, Blocks.AIR) ) ); }))); diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/jei/CGJEIPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/jei/CGJEIPlugin.java index a5561339..160b3af7 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/jei/CGJEIPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/jei/CGJEIPlugin.java @@ -63,11 +63,11 @@ public void registerRecipes(IRecipeRegistration registration) { recipes.add( new FluidInteractionRecipeHolder( fluid, - Util.notNullOr(generator.getFluid(), Fluids.EMPTY), - Util.notNullOr(generator.getBlock(), Blocks.AIR), + Util.elvis(generator.getFluid(), Fluids.EMPTY), + Util.elvis(generator.getBlock(), Blocks.AIR), block, generator.getType(), - Util.notNullOr(modifier, Blocks.AIR) + Util.elvis(modifier, Blocks.AIR) ) ); registration.addRecipes(new RecipeType<>( diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/rei/CGREIPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/rei/CGREIPlugin.java index 960b54dc..c3aad6a4 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/rei/CGREIPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/viewer/rei/CGREIPlugin.java @@ -44,11 +44,11 @@ public void registerDisplays(DisplayRegistry registry) { registry.add( new FluidInteractionRecipe( fluid, - Util.notNullOr(generator.getFluid(), Fluids.EMPTY), - Util.notNullOr(generator.getBlock(), Blocks.AIR), + Util.elvis(generator.getFluid(), Fluids.EMPTY), + Util.elvis(generator.getBlock(), Blocks.AIR), block, generator.getType(), - Util.notNullOr(modifier, Blocks.AIR) + Util.elvis(modifier, Blocks.AIR) ) ); }))); diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java index 84f9c7ea..a5aa0ace 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java @@ -3,7 +3,6 @@ import io.github.null2264.cobblegen.compat.LoaderCompat; import io.github.null2264.cobblegen.compat.RegistryCompat; import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -15,7 +14,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.NoSuchElementException; import java.util.Optional; import static io.github.null2264.cobblegen.CobbleGen.MOD_ID; @@ -47,7 +45,7 @@ public static ResourceLocation identifierOf(String namespace, String id) { } @NotNull - public static T notNullOr(@Nullable T nullable, @NotNull T notNull) { + public static T elvis(@Nullable T nullable, @NotNull T notNull) { if (nullable == null) return notNull; return nullable; From 48cf09318f1cf5d88a9891ff93c46ce4b11bf78b Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Tue, 8 Apr 2025 07:29:47 +0700 Subject: [PATCH 03/21] refactor: Use 'neighbours' to hold modifier --- .../cobblegen/compat/CollectionCompat.java | 9 ++- .../cobblegen/data/config/ConfigData.java | 80 ++++++------------- .../cobblegen/data/config/GeneratorMap.java | 1 + .../cobblegen/data/config/WeightedBlock.java | 58 +++++++++++--- .../cobblegen/integration/BuiltInPlugin.java | 24 +++--- 5 files changed, 97 insertions(+), 75 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/compat/CollectionCompat.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/compat/CollectionCompat.java index 6ba54088..4146942a 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/compat/CollectionCompat.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/compat/CollectionCompat.java @@ -23,4 +23,11 @@ public static Map mapOf(K key, V value) { public static List streamToList(Stream stream) { return (List) Collections.unmodifiableList(new ArrayList<>(Arrays.asList(stream.toArray()))); } -} \ No newline at end of file + + public static List mergeList(List list, List list2) { + List rt = new ArrayList<>(); + rt.addAll(list); + rt.addAll(list2); + return rt; + } +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index 5888f5b9..c1196095 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -72,57 +72,28 @@ public class ConfigData implements Config, JanksonSerializable public static ConfigData defaultConfig() { ConfigData config = new ConfigData(); - config.cobbleGen = ResultList.of(new WeightedBlock( - "minecraft:cobblestone", - 100.0, - null, - null, - null, - 0, - null, - null, - null - ), new WeightedBlock("minecraft:cobbled_deepslate", 100.0, null, null, 0, null, null, null, null)); - config.stoneGen = ResultList.of(new WeightedBlock("minecraft:stone", 100.0)); - config.basaltGen = ResultList.of(new WeightedBlock("minecraft:basalt", 100.0)); - config.customGen = new CustomGen( - // Cobble Gen - GeneratorMap.of( - Pair.of( - CGIdentifier.of("minecraft:bedrock"), - ResultList.of( - new WeightedBlock("minecraft:emerald_ore", 2.0), - new WeightedBlock("minecraft:diamond_ore", 5.0), - new WeightedBlock("minecraft:lapis_ore", 8.0), - new WeightedBlock("minecraft:gold_ore", 10.0), - new WeightedBlock("minecraft:iron_ore", 15.0), - new WeightedBlock("minecraft:coal_ore", 20.0), - new WeightedBlock("minecraft:cobblestone", 80.0) - ) - ) - ), - // Stone Gen - GeneratorMap.of( - Pair.of( - CGIdentifier.of("minecraft:bedrock"), - ResultList.of( - new WeightedBlock("minecraft:stone", 40.0), - new WeightedBlock("minecraft:diorite", 20.0), - new WeightedBlock("minecraft:andesite", 20.0), - new WeightedBlock("minecraft:granite", 20.0) - ) - ) - ), - // Basalt Gen - GeneratorMap.of( - Pair.of( - CGIdentifier.of("minecraft:bedrock"), - ResultList.of( - new WeightedBlock("minecraft:end_stone", 100.0, listOf("minecraft:the_end")), - new WeightedBlock("minecraft:blackstone", 100.0, null, listOf("minecraft:overworld")) - ) - ) - ) + config.cobbleGen = ResultList.of( + new WeightedBlock("minecraft:cobblestone", 100.0, null, null, null, 0, null, null, null), + new WeightedBlock("minecraft:cobbled_deepslate", 100.0, null, null, 0, null, null, null, null), + new WeightedBlock("minecraft:emerald_ore", 2.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:diamond_ore", 5.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:lapis_ore", 8.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:gold_ore", 10.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:iron_ore", 15.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:coal_ore", 20.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:cobblestone", 80.0).setModifier("minecraft:bedrock") + ); + config.stoneGen = ResultList.of( + new WeightedBlock("minecraft:stone", 100.0), + new WeightedBlock("minecraft:stone", 40.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:diorite", 20.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:andesite", 20.0).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:granite", 20.0).setModifier("minecraft:bedrock") + ); + config.basaltGen = ResultList.of( + new WeightedBlock("minecraft:basalt", 100.0), + new WeightedBlock("minecraft:end_stone", 100.0, listOf("minecraft:the_end")).setModifier("minecraft:bedrock"), + new WeightedBlock("minecraft:blackstone", 100.0, null, listOf("minecraft:overworld")).setModifier("minecraft:bedrock") ); return config; } @@ -135,7 +106,6 @@ public JsonObject toJson() { if (cobbleGen != null) json.put("cobbleGen", cobbleGen.toJson()); if (stoneGen != null) json.put("stoneGen", stoneGen.toJson()); if (basaltGen != null) json.put("basaltGen", basaltGen.toJson()); - if (customGen != null) json.put("customGen", customGen.toJson()); if (advanced != null) json.put("advanced", advanced.toJson()); return json; } @@ -153,17 +123,17 @@ public static ConfigData fromJson(JsonObject json) { // TODO Util.optional(customGen.cobbleGen).ifPresent(gen -> gen.forEach((modifier, value) -> { if (config.cobbleGen != null) { - config.cobbleGen.addAll(value.stream().peek(result -> result.modifier = modifier.toString()).toList()); + config.cobbleGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); } })); Util.optional(customGen.stoneGen).ifPresent(gen -> gen.forEach((modifier, value) -> { if (config.stoneGen != null) { - config.stoneGen.addAll(value.stream().peek(result -> result.modifier = modifier.toString()).toList()); + config.stoneGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); } })); Util.optional(customGen.basaltGen).ifPresent(gen -> gen.forEach((modifier, value) -> { if (config.basaltGen != null) { - config.basaltGen.addAll(value.stream().peek(result -> result.modifier = modifier.toString()).toList()); + config.basaltGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); } })); } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/GeneratorMap.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/GeneratorMap.java index a4a00644..aec26f8e 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/GeneratorMap.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/GeneratorMap.java @@ -16,6 +16,7 @@ import java.util.HashMap; import java.util.List; +// FIXME: CGIdentifier -> CGModifier public class GeneratorMap extends HashMap implements JanksonSerializable, PacketSerializable { public GeneratorMap() {} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java index 3b4f1fad..c171db39 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Optional; +import static io.github.null2264.cobblegen.compat.CollectionCompat.mergeList; import static io.github.null2264.cobblegen.util.Constants.JANKSON; public class WeightedBlock implements PacketSerializable, JanksonSerializable @@ -32,14 +33,13 @@ public class WeightedBlock implements PacketSerializable, Jankson public Integer maxY; @Nullable public Integer minY; + // FIXME: Currently only the first element is being used @Nullable public List neighbours; @Nullable public List biomes; @Nullable public List excludedBiomes; - @Nullable - public String modifier; public WeightedBlock(String id, Double weight) { this(id, weight, null, null); @@ -119,19 +119,44 @@ public Optional> getExcludedBiomes() { return Util.optional(excludedBiomes); } + public Optional> getNeighbours() { + return Util.optional(neighbours); + } + + public String getModifier() { + if (neighbours == null) return "*"; + return neighbours[0]; + } + + public WeightedBlock setNeighbours(@Nullable List neighbours) { + this.neighbours = neighbours; + return this; + } + + public WeightedBlock setModifier(String neighbours) { + if (this.neighbours == null) { + this.neighbours = List.of(neighbours); + return this; + } + this.neighbours = mergeList(this.neighbours, List.of(neighbours)); + return this; + } + @Override public void toPacket(FriendlyByteBuf buf) { buf.writeUtf(id); buf.writeDouble(weight); - buf.writeOptional(Util.optional(dimensions), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); - buf.writeOptional(Util.optional(excludedDimensions), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); + buf.writeOptional(getDimensions(), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); + buf.writeOptional(getExcludedDimensions(), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); - buf.writeOptional(Util.optional(maxY), FriendlyByteBuf::writeInt); - buf.writeOptional(Util.optional(minY), FriendlyByteBuf::writeInt); + buf.writeOptional(getMaxY(), FriendlyByteBuf::writeInt); + buf.writeOptional(getMinY(), FriendlyByteBuf::writeInt); - buf.writeOptional(Util.optional(biomes), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); - buf.writeOptional(Util.optional(excludedBiomes), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); + buf.writeOptional(getBiomes(), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); + buf.writeOptional(getExcludedBiomes(), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); + + buf.writeOptional(getNeighbours(), (o, value) -> o.writeCollection(value, FriendlyByteBuf::writeUtf)); } public static WeightedBlock fromPacket(FriendlyByteBuf buf) { @@ -147,6 +172,8 @@ public static WeightedBlock fromPacket(FriendlyByteBuf buf) { Optional> biomes = buf.readOptional((o) -> o.readList(FriendlyByteBuf::readUtf)); Optional> excludedBiomes = buf.readOptional((o) -> o.readList(FriendlyByteBuf::readUtf)); + Optional> neighbours = buf.readOptional((o) -> o.readList(FriendlyByteBuf::readUtf)); + return new WeightedBlock( id, weight, @@ -154,7 +181,7 @@ public static WeightedBlock fromPacket(FriendlyByteBuf buf) { excludedDimensions.orElse(null), maxY.orElse(null), minY.orElse(null), - null, + neighbours.orElse(null), biomes.orElse(null), excludedBiomes.orElse(null) ); @@ -172,6 +199,7 @@ public JsonObject toJson() { json.put("minY", JANKSON.toJson(minY)); json.put("biomes", JANKSON.toJson(biomes)); json.put("excludedBiomes", JANKSON.toJson(excludedBiomes)); + json.put("neighbours", JANKSON.toJson(excludedBiomes)); return json; } @@ -238,6 +266,16 @@ public static WeightedBlock fromJson(JsonObject json) { excludedBiomes = null; } - return new WeightedBlock(id, weight, dimensions, excludedDimensions, maxY, minY, null, biomes, excludedBiomes); + @Nullable + List neighbours; + JsonElement _neighbours = json.get("neighbours"); + if (_neighbours instanceof JsonArray) { + neighbours = new ArrayList<>(); + ((JsonArray) _neighbours).forEach(value -> neighbours.add(((JsonPrimitive) value).asString())); + } else { + neighbours = null; + } + + return new WeightedBlock(id, weight, dimensions, excludedDimensions, maxY, minY, neighbours, biomes, excludedBiomes); } } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java index 6c40d511..e070e5da 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java @@ -23,11 +23,13 @@ import java.io.File; import java.nio.file.Path; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import static io.github.null2264.cobblegen.CobbleGen.MOD_ID; import static io.github.null2264.cobblegen.data.config.ConfigHelper.loadConfig; import static io.github.null2264.cobblegen.util.Util.elvis; +import static io.github.null2264.cobblegen.util.Util.optional; @CGPlugin public class BuiltInPlugin implements CobbleGenPlugin @@ -66,18 +68,22 @@ public void registerInteraction(CGRegistry registry) { AtomicInteger count = new AtomicInteger(); GeneratorMap stoneGen = new GeneratorMap(); - if (config.customGen != null && config.customGen.stoneGen != null) - stoneGen = config.customGen.stoneGen; GeneratorMap cobbleGen = new GeneratorMap(); - if (config.customGen != null && config.customGen.cobbleGen != null) - cobbleGen = config.customGen.cobbleGen; GeneratorMap basaltGen = new GeneratorMap(); - if (config.customGen != null && config.customGen.basaltGen != null) - basaltGen = config.customGen.basaltGen; - stoneGen.put(CGIdentifier.wildcard(), elvis(config.stoneGen, new ResultList())); - cobbleGen.put(CGIdentifier.wildcard(), elvis(config.cobbleGen, new ResultList())); - basaltGen.put(CGIdentifier.fromBlock(Blocks.SOUL_SOIL), elvis(config.basaltGen, new ResultList())); + elvis(config.stoneGen, new ResultList()) + .forEach(result -> + stoneGen.put(CGIdentifier.of(result.getModifier()), elvis(config.stoneGen, new ResultList())) + ); + elvis(config.cobbleGen, new ResultList()) + .forEach(result -> + cobbleGen.put(CGIdentifier.of(result.getModifier()), elvis(config.cobbleGen, new ResultList())) + ); + elvis(config.basaltGen, new ResultList()) + .forEach(result -> + // FIXME: Default modifier should be CGIdentifier.fromBlock(Blocks.SOUL_SOIL) + basaltGen.put(CGIdentifier.of(result.getModifier()), elvis(config.basaltGen, new ResultList())) + ); if (config.advanced != null) config.advanced.forEach((fluid, value) -> { From 5f29dc8ab269f644e0248e246c7b2ef54c0e8624 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 9 Apr 2025 07:35:40 +0700 Subject: [PATCH 04/21] feat: Add Builder API for WeightedBlock to make constructing result a lot cleaner --- .../cobblegen/data/config/ConfigData.java | 34 ++--- .../cobblegen/data/config/WeightedBlock.java | 129 ++++++++++++++++-- .../data/generator/StoneGenerator.java | 4 +- .../data/model/BuiltInGenerator.java | 2 +- .../cobblegen/integration/CreatePlugin.java | 8 +- 5 files changed, 140 insertions(+), 37 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index c1196095..d2a990f5 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -73,27 +73,27 @@ public class ConfigData implements Config, JanksonSerializable public static ConfigData defaultConfig() { ConfigData config = new ConfigData(); config.cobbleGen = ResultList.of( - new WeightedBlock("minecraft:cobblestone", 100.0, null, null, null, 0, null, null, null), - new WeightedBlock("minecraft:cobbled_deepslate", 100.0, null, null, 0, null, null, null, null), - new WeightedBlock("minecraft:emerald_ore", 2.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:diamond_ore", 5.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:lapis_ore", 8.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:gold_ore", 10.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:iron_ore", 15.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:coal_ore", 20.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:cobblestone", 80.0).setModifier("minecraft:bedrock") + new WeightedBlock.Builder().setId("minecraft:cobblestone").setWeight(100.0).setMinY(0).build(), + new WeightedBlock.Builder().setId("minecraft:cobbled_deepslate").setWeight(100.0).setMaxY(0).build(), + new WeightedBlock.Builder().setId("minecraft:emerald_ore").setWeight(2.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:diamond_ore").setWeight(5.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:lapis_ore").setWeight(8.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:gold_ore").setWeight(10.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:iron_ore").setWeight(15.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:coal_ore").setWeight(20.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:cobblestone").setWeight(80.0).setModifier("minecraft:bedrock").build() ); config.stoneGen = ResultList.of( - new WeightedBlock("minecraft:stone", 100.0), - new WeightedBlock("minecraft:stone", 40.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:diorite", 20.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:andesite", 20.0).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:granite", 20.0).setModifier("minecraft:bedrock") + new WeightedBlock.Builder().setId("minecraft:stone").setWeight(100.0).build(), + new WeightedBlock.Builder().setId("minecraft:stone").setWeight(40.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:diorite").setWeight(20.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:andesite").setWeight(20.0).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:granite").setWeight(20.0).setModifier("minecraft:bedrock").build() ); config.basaltGen = ResultList.of( - new WeightedBlock("minecraft:basalt", 100.0), - new WeightedBlock("minecraft:end_stone", 100.0, listOf("minecraft:the_end")).setModifier("minecraft:bedrock"), - new WeightedBlock("minecraft:blackstone", 100.0, null, listOf("minecraft:overworld")).setModifier("minecraft:bedrock") + new WeightedBlock.Builder().setId("minecraft:basalt").setWeight(100.0).build(), + new WeightedBlock.Builder().setId("minecraft:end_stone").setWeight(100.0).setDimensions(listOf("minecraft:the_end")).setModifier("minecraft:bedrock").build(), + new WeightedBlock.Builder().setId("minecraft:blackstone").setWeight(100.0).setExcludedDimensions(listOf("minecraft:overworld")).setModifier("minecraft:bedrock").build() ); return config; } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java index c171db39..5cbd5d88 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java @@ -18,7 +18,7 @@ import java.util.List; import java.util.Optional; -import static io.github.null2264.cobblegen.compat.CollectionCompat.mergeList; +import static io.github.null2264.cobblegen.compat.CollectionCompat.listOf; import static io.github.null2264.cobblegen.util.Constants.JANKSON; public class WeightedBlock implements PacketSerializable, JanksonSerializable @@ -41,18 +41,30 @@ public class WeightedBlock implements PacketSerializable, Jankson @Nullable public List excludedBiomes; + /** + * @deprecated Use {@link WeightedBlock.Builder} instead. + */ public WeightedBlock(String id, Double weight) { this(id, weight, null, null); } + /** + * @deprecated Use {@link WeightedBlock.Builder} instead. + */ public WeightedBlock(String id, Double weight, List dimIds) { this(id, weight, dimIds, null); } + /** + * @deprecated Use {@link WeightedBlock.Builder} instead. + */ public WeightedBlock(String id, Double weight, List dimIds, List excludedDimensions) { this(id, weight, dimIds, excludedDimensions, null, null, null, null, null); } + /** + * @deprecated Use {@link WeightedBlock.Builder} instead. + */ public WeightedBlock( String id, Double weight, @@ -75,10 +87,18 @@ public WeightedBlock( this.excludedBiomes = excludedBiomes; } + /** + * @deprecated Use {@link WeightedBlock.Builder} instead. + */ + @Deprecated(since = "5.4.1") public static WeightedBlock fromBlock(Block block, Double weight) { return fromBlock(block, weight, null, null, null, null); } + /** + * @deprecated Use {@link WeightedBlock.Builder} instead. + */ + @Deprecated(since = "5.4.1") public static WeightedBlock fromBlock( Block block, Double weight, @@ -128,20 +148,6 @@ public String getModifier() { return neighbours[0]; } - public WeightedBlock setNeighbours(@Nullable List neighbours) { - this.neighbours = neighbours; - return this; - } - - public WeightedBlock setModifier(String neighbours) { - if (this.neighbours == null) { - this.neighbours = List.of(neighbours); - return this; - } - this.neighbours = mergeList(this.neighbours, List.of(neighbours)); - return this; - } - @Override public void toPacket(FriendlyByteBuf buf) { buf.writeUtf(id); @@ -278,4 +284,97 @@ public static WeightedBlock fromJson(JsonObject json) { return new WeightedBlock(id, weight, dimensions, excludedDimensions, maxY, minY, neighbours, biomes, excludedBiomes); } + + public static class Builder { + @Nullable + public String id; + @Nullable + public Double weight; + @Nullable + public List dimensions; + @Nullable + public List excludedDimensions; + @Nullable + public Integer maxY; + @Nullable + public Integer minY; + @Nullable + public List neighbours; + @Nullable + public List biomes; + @Nullable + public List excludedBiomes; + + public static Builder of(Block block) { + return new Builder().setId(Util.getBlockId(block).toString()); + } + + public WeightedBlock build() { + if (id == null && weight == null) { + throw new IllegalStateException("Block ID and generation weight can't be unset!"); + } + + return new WeightedBlock( + id, + weight, + dimensions, + excludedDimensions, + maxY, + minY, + neighbours, + biomes, + excludedBiomes + ); + } + + public Builder setId(String value) { + this.id = value; + return this; + } + + public Builder setWeight(Double value) { + this.weight = value; + return this; + } + + public Builder setDimensions(List value) { + this.dimensions = value; + return this; + } + + public Builder setExcludedDimensions(List value) { + this.excludedDimensions = value; + return this; + } + + public Builder setMaxY(Integer value) { + this.maxY = value; + return this; + } + + public Builder setMinY(Integer value) { + this.minY = value; + return this; + } + + public Builder setNeighbours(List value) { + this.neighbours = value; + return this; + } + + public Builder setModifier(String value) { + this.neighbours = listOf(value); + return this; + } + + public Builder setBiomes(List value) { + this.biomes = value; + return this; + } + + public Builder setExcludedBiomes(List value) { + this.excludedBiomes = value; + return this; + } + } } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/StoneGenerator.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/StoneGenerator.java index 9ee07be0..ad4f9bc8 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/StoneGenerator.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/StoneGenerator.java @@ -57,7 +57,7 @@ public static StoneGenerator fromString(Map> possibl @Override public GeneratorMap getObsidianOutput() { - return GeneratorMap.of(Pair.of(CGIdentifier.wildcard(), ResultList.of(WeightedBlock.fromBlock(Blocks.STONE, 100D)))); + return GeneratorMap.of(Pair.of(CGIdentifier.wildcard(), ResultList.of(WeightedBlock.Builder.of(Blocks.STONE).setWeight(100D).build()))); } @Override @@ -119,4 +119,4 @@ public static Generator fromPacket(FriendlyByteBuf buf) { return new StoneGenerator(outMap, fluid, silent); } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java index 334104dc..9ce9ce57 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java @@ -58,7 +58,7 @@ public interface BuiltInGenerator extends Generator try { List taggedBlocks = Util.getTaggedBlockIds(ResourceLocation.tryParse(block.id.substring(1))); for (ResourceLocation taggedBlock : taggedBlocks) { - filteredBlockIds.add(new WeightedBlock(taggedBlock.toString(), block.weight)); + filteredBlockIds.add(new WeightedBlock.Builder().setId(taggedBlock.toString()).setWeight(block.weight).build()); totalWeight.updateAndGet(v -> v + block.weight); } } catch (Exception ignored) { diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/CreatePlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/CreatePlugin.java index 0865594a..f6ad49c6 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/CreatePlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/CreatePlugin.java @@ -25,7 +25,9 @@ public void registerInteraction(CGRegistry registry) { registry.addGenerator( Fluids.LAVA, new CobbleGenerator( - ResultList.of(WeightedBlock.fromBlock(Util.getBlock(Util.identifierOf("create", "limestone")), 1.0)), + ResultList.of( + WeightedBlock.Builder.of(Util.getBlock(Util.identifierOf("create", "limestone"))).setWeight(1.0).build() + ), Util.getFluid(Util.identifierOf("create", "honey")), false ) @@ -33,7 +35,9 @@ public void registerInteraction(CGRegistry registry) { registry.addGenerator( Fluids.LAVA, new CobbleGenerator( - ResultList.of(WeightedBlock.fromBlock(Util.getBlock(Util.identifierOf("create", "scoria")), 1.0)), + ResultList.of( + WeightedBlock.Builder.of(Util.getBlock(Util.identifierOf("create", "scoria"))).setWeight(1.0).build() + ), Util.getFluid(Util.identifierOf("create", "chocolate")), false ) From 2774acfffd037855399d48f7d70382a6df461b5d Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 9 Apr 2025 07:48:40 +0700 Subject: [PATCH 05/21] fix: Basalt's default modifier should be soul soil --- .../cobblegen/data/config/WeightedBlock.java | 6 +++--- .../cobblegen/integration/BuiltInPlugin.java | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java index 5cbd5d88..23226bf8 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java @@ -143,9 +143,9 @@ public Optional> getNeighbours() { return Util.optional(neighbours); } - public String getModifier() { - if (neighbours == null) return "*"; - return neighbours[0]; + public Optional getModifier() { + if (neighbours == null) return Util.optional(null); + return Util.optional(neighbours[0]); } @Override diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java index e070e5da..0dc81ae1 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java @@ -23,13 +23,11 @@ import java.io.File; import java.nio.file.Path; -import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import static io.github.null2264.cobblegen.CobbleGen.MOD_ID; import static io.github.null2264.cobblegen.data.config.ConfigHelper.loadConfig; import static io.github.null2264.cobblegen.util.Util.elvis; -import static io.github.null2264.cobblegen.util.Util.optional; @CGPlugin public class BuiltInPlugin implements CobbleGenPlugin @@ -73,17 +71,17 @@ public void registerInteraction(CGRegistry registry) { elvis(config.stoneGen, new ResultList()) .forEach(result -> - stoneGen.put(CGIdentifier.of(result.getModifier()), elvis(config.stoneGen, new ResultList())) + stoneGen.put(CGIdentifier.of(result.getModifier().orElse("*")), elvis(config.stoneGen, new ResultList())) ); elvis(config.cobbleGen, new ResultList()) .forEach(result -> - cobbleGen.put(CGIdentifier.of(result.getModifier()), elvis(config.cobbleGen, new ResultList())) + cobbleGen.put(CGIdentifier.of(result.getModifier().orElse("*")), elvis(config.cobbleGen, new ResultList())) ); elvis(config.basaltGen, new ResultList()) - .forEach(result -> - // FIXME: Default modifier should be CGIdentifier.fromBlock(Blocks.SOUL_SOIL) - basaltGen.put(CGIdentifier.of(result.getModifier()), elvis(config.basaltGen, new ResultList())) - ); + .forEach(result -> { + CGIdentifier id = result.getModifier().map(CGIdentifier::of).orElseGet(() -> CGIdentifier.fromBlock(Blocks.SOUL_SOIL)); + basaltGen.put(id, elvis(config.basaltGen, new ResultList())); + }); if (config.advanced != null) config.advanced.forEach((fluid, value) -> { From e8c596f12c75b5a287bb099bdf8583aa3553ee3e Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 9 Apr 2025 09:02:56 +0700 Subject: [PATCH 06/21] fix: Don't mix up the formatting Also warn the user that the config is using the old format --- .../cobblegen/data/config/ConfigData.java | 52 +++++++------ .../cobblegen/data/config/ResultList.java | 16 ++-- .../cobblegen/data/config/WeightedBlock.java | 77 ++++++++++--------- .../data/model/BuiltInGenerator.java | 4 +- 4 files changed, 80 insertions(+), 69 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index d2a990f5..8ff99e40 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -6,6 +6,7 @@ import io.github.null2264.cobblegen.data.CGIdentifier; import io.github.null2264.cobblegen.data.JanksonSerializable; import io.github.null2264.cobblegen.data.Pair; +import io.github.null2264.cobblegen.util.CGLog; import io.github.null2264.cobblegen.util.Util; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,9 +16,12 @@ @SuppressWarnings("TextBlockMigration") public class ConfigData implements Config, JanksonSerializable { + public static String LATEST_FORMAT_VERSION = "1.1"; + + // FIXME: Make this SemVer object @Comment(value = "CobbleGen Format Version, you can leave this alone for now. v2.0 will be released in CobbleGen v6.0") @NotNull - public String formatVersion = "1.1"; + public String formatVersion = LATEST_FORMAT_VERSION; @Nullable @Comment(value = "Default Generators\n" + @@ -102,7 +106,7 @@ public static ConfigData defaultConfig() { @Serializer public JsonObject toJson() { JsonObject json = new JsonObject(); - json.put("formatVersion", JsonPrimitive.of(formatVersion)); + json.put("formatVersion", JsonPrimitive.of(LATEST_FORMAT_VERSION)); if (cobbleGen != null) json.put("cobbleGen", cobbleGen.toJson()); if (stoneGen != null) json.put("stoneGen", stoneGen.toJson()); if (basaltGen != null) json.put("basaltGen", basaltGen.toJson()); @@ -114,28 +118,30 @@ public JsonObject toJson() { public static ConfigData fromJson(JsonObject json) { ConfigData config = new ConfigData(); JsonElement formatVersion = json.get("formatVersion"); - config.formatVersion = (formatVersion instanceof JsonPrimitive) ? ((JsonPrimitive) formatVersion).asString() : "1.0"; - config.cobbleGen = ResultList.fromJson(json.get("cobbleGen")); - config.stoneGen = ResultList.fromJson(json.get("stoneGen")); - config.basaltGen = ResultList.fromJson(json.get("basaltGen")); + config.formatVersion = (formatVersion instanceof JsonPrimitive) ? ((JsonPrimitive) formatVersion).asString() : LATEST_FORMAT_VERSION; + config.cobbleGen = ResultList.fromJson(json.get("cobbleGen"), config.formatVersion); + config.stoneGen = ResultList.fromJson(json.get("stoneGen"), config.formatVersion); + config.basaltGen = ResultList.fromJson(json.get("basaltGen"), config.formatVersion); CustomGen customGen = CustomGen.fromJson(json.getObject("customGen")); - if (config.formatVersion.equals("1.0") && customGen != null) { - // TODO - Util.optional(customGen.cobbleGen).ifPresent(gen -> gen.forEach((modifier, value) -> { - if (config.cobbleGen != null) { - config.cobbleGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); - } - })); - Util.optional(customGen.stoneGen).ifPresent(gen -> gen.forEach((modifier, value) -> { - if (config.stoneGen != null) { - config.stoneGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); - } - })); - Util.optional(customGen.basaltGen).ifPresent(gen -> gen.forEach((modifier, value) -> { - if (config.basaltGen != null) { - config.basaltGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); - } - })); + if (config.formatVersion.equals("1.0")) { + CGLog.warn(() -> "CobbleGen config format v1.0 is deprecated, please consider migrating to v" + LATEST_FORMAT_VERSION); + if (customGen != null) { + Util.optional(customGen.cobbleGen).ifPresent(gen -> gen.forEach((modifier, value) -> { + if (config.cobbleGen != null) { + config.cobbleGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); + } + })); + Util.optional(customGen.stoneGen).ifPresent(gen -> gen.forEach((modifier, value) -> { + if (config.stoneGen != null) { + config.stoneGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); + } + })); + Util.optional(customGen.basaltGen).ifPresent(gen -> gen.forEach((modifier, value) -> { + if (config.basaltGen != null) { + config.basaltGen.addAll(value.stream().peek(result -> result.neighbours = listOf(modifier.toString())).toList()); + } + })); + } } config.advanced = FluidInteractionMap.fromJson(json.getObject("advanced")); return config; diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ResultList.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ResultList.java index d9b9e6e5..fe2b117a 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ResultList.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ResultList.java @@ -32,15 +32,19 @@ public JsonElement toJson() { @Deserializer public static ResultList fromJson(JsonElement json) { + return fromJson(json, ConfigData.LATEST_FORMAT_VERSION); + } + + public static ResultList fromJson(JsonElement json, String formatVersion) { if (json == null) return null; ResultList result = new ResultList(); ((JsonArray) json).stream() - .filter((e) -> e instanceof JsonObject) - .forEach((e) -> { - WeightedBlock block = WeightedBlock.fromJson((JsonObject) e); - if (block != null) result.add(block); - }); + .filter((e) -> e instanceof JsonObject) + .forEach((e) -> { + WeightedBlock block = WeightedBlock.fromJson((JsonObject) e, formatVersion); + if (block != null) result.add(block); + }); return result; } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java index 23226bf8..a3b7efc1 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java @@ -205,84 +205,85 @@ public JsonObject toJson() { json.put("minY", JANKSON.toJson(minY)); json.put("biomes", JANKSON.toJson(biomes)); json.put("excludedBiomes", JANKSON.toJson(excludedBiomes)); - json.put("neighbours", JANKSON.toJson(excludedBiomes)); + if (neighbours != null) { + if (neighbours.size() > 1) + json.put("neighbours", JANKSON.toJson(neighbours)); + else + json.put("modifier", JANKSON.toJson(neighbours[0])); + } return json; } - @SuppressWarnings("PatternVariableCanBeUsed") @Deserializer public static WeightedBlock fromJson(JsonObject json) { + return fromJson(json, "1.1"); + } + + public static WeightedBlock fromJson(JsonObject json, String formatVersion) { + Builder builder = new WeightedBlock.Builder(); + JsonElement _id = json.get("id"); if (!(_id instanceof JsonPrimitive)) return null; - String id = ((JsonPrimitive) _id).asString(); - Double weight = json.getDouble("weight", 0.0); + builder.setId(((JsonPrimitive) _id).asString()); + builder.setWeight(json.getDouble("weight", 0.0)); - @Nullable - List dimensions; JsonElement _dimensions = json.get("dimensions"); if (_dimensions instanceof JsonArray) { - dimensions = new ArrayList<>(); + List dimensions = new ArrayList<>(); ((JsonArray) _dimensions).forEach(value -> dimensions.add(((JsonPrimitive) value).asString())); - } else { - dimensions = null; + builder.setDimensions(dimensions); } @Nullable - List excludedDimensions; JsonElement _excludedDimensions = json.get("excludedDimensions"); if (_excludedDimensions instanceof JsonArray) { - excludedDimensions = new ArrayList<>(); + List excludedDimensions = new ArrayList<>(); ((JsonArray) _excludedDimensions).forEach(value -> excludedDimensions.add(((JsonPrimitive) value).asString())); - } else { - excludedDimensions = null; + builder.setExcludedDimensions(excludedDimensions); } - @Nullable - Integer maxY = null; JsonElement _maxY = json.get("maxY"); if (_maxY instanceof JsonPrimitive) { - maxY = ((JsonPrimitive) _maxY).asInt(0); + builder.setMaxY(((JsonPrimitive) _maxY).asInt(0)); } - @Nullable - Integer minY = null; JsonElement _minY = json.get("minY"); if (_minY instanceof JsonPrimitive) { - minY = ((JsonPrimitive) _minY).asInt(0); + builder.setMinY(((JsonPrimitive) _minY).asInt(0)); } - @Nullable - List biomes; JsonElement _biomes = json.get("biomes"); if (_biomes instanceof JsonArray) { - biomes = new ArrayList<>(); + List biomes = new ArrayList<>(); ((JsonArray) _biomes).forEach(value -> biomes.add(((JsonPrimitive) value).asString())); - } else { - biomes = null; + builder.setBiomes(biomes); } - @Nullable - List excludedBiomes; JsonElement _excludedBiomes = json.get("excludedBiomes"); if (_excludedBiomes instanceof JsonArray) { - excludedBiomes = new ArrayList<>(); + List excludedBiomes = new ArrayList<>(); ((JsonArray) _excludedBiomes).forEach(value -> excludedBiomes.add(((JsonPrimitive) value).asString())); - } else { - excludedBiomes = null; + builder.setExcludedBiomes(excludedBiomes); } - @Nullable - List neighbours; - JsonElement _neighbours = json.get("neighbours"); - if (_neighbours instanceof JsonArray) { - neighbours = new ArrayList<>(); - ((JsonArray) _neighbours).forEach(value -> neighbours.add(((JsonPrimitive) value).asString())); - } else { - neighbours = null; + if (formatVersion.equals("1.1")) { + JsonElement _neighbours = json.get("neighbours"); + if (_neighbours instanceof JsonArray) { + List neighbours = new ArrayList<>(); + ((JsonArray) _neighbours).forEach(value -> neighbours.add(((JsonPrimitive) value).asString())); + builder.setNeighbours(neighbours); + } + + if (_neighbours == null) { + JsonElement _modifier = json.get("modifier"); + if (_modifier instanceof JsonPrimitive) { + builder.setNeighbours(listOf(((JsonPrimitive) _modifier).asString())); + } + } } - return new WeightedBlock(id, weight, dimensions, excludedDimensions, maxY, minY, neighbours, biomes, excludedBiomes); + return builder.build(); } public static class Builder { diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java index 9ce9ce57..1a602633 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/BuiltInGenerator.java @@ -32,8 +32,8 @@ public interface BuiltInGenerator extends Generator #endif randomizeBlockId(Block key, String dim, Integer yLevel, GeneratorMap candidates, @Nullable String biome) { ResultList blockIds = candidates.getOrDefault( - CGIdentifier.fromMC(Util.getBlockId(key)), - candidates.getOrDefault(CGIdentifier.wildcard(), new ResultList()) + CGIdentifier.fromBlock(key), + candidates.getOrDefault(CGIdentifier.wildcard(), new ResultList()) ); ResultList filteredBlockIds = new ResultList(); From 54b5c8ca8d50dbe0f1687425ab0d14a17d20ab24 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 9 Apr 2025 09:36:59 +0700 Subject: [PATCH 07/21] fix: Not sure why this still here, should already been replaced by Generator.check --- .../io/github/null2264/cobblegen/FluidInteraction.java | 1 - .../null2264/cobblegen/data/generator/BasaltGenerator.java | 7 ++++++- .../null2264/cobblegen/data/generator/CobbleGenerator.java | 7 ++++++- .../io/github/null2264/cobblegen/data/model/Generator.java | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java index 1ef329ef..99b7a343 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/FluidInteraction.java @@ -142,7 +142,6 @@ public boolean interact(LevelAccessor level, BlockPos pos, BlockState state, boo for (Generator generator : generators) { if (!generator.check(level, pos, state, fromTop)) continue; - if (fromTop && generator.getType() != GeneratorType.STONE) continue; final Optional result = generator.tryGenerate(level, pos, state); if (result.isPresent()) { diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/BasaltGenerator.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/BasaltGenerator.java index eb1436ee..20f63d81 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/BasaltGenerator.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/BasaltGenerator.java @@ -75,6 +75,11 @@ public boolean isSilent() { return silent; } + @Override + public boolean check(LevelAccessor level, BlockPos pos, BlockState state, boolean fromTop) { + return !fromTop; + } + @Override public Optional tryGenerate(LevelAccessor level, BlockPos pos, BlockState state, Direction direction) { BlockPos blockPos = pos.relative(direction.getOpposite()); @@ -102,4 +107,4 @@ public static Generator fromPacket(FriendlyByteBuf buf) { return new BasaltGenerator(outMap, block, silent); } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/CobbleGenerator.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/CobbleGenerator.java index a314cda3..48c21d99 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/CobbleGenerator.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/generator/CobbleGenerator.java @@ -98,6 +98,11 @@ public boolean isSilent() { return silent; } + @Override + public boolean check(LevelAccessor level, BlockPos pos, BlockState state, boolean fromTop) { + return !fromTop; + } + @Override public Optional tryGenerate(LevelAccessor level, BlockPos pos, BlockState state, Direction direction) { BlockPos blockPos = pos.relative(direction.getOpposite()); @@ -139,4 +144,4 @@ public static Generator fromPacket(FriendlyByteBuf buf) { return new CobbleGenerator(outMap, fluid, silent, obiMap); } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/Generator.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/Generator.java index 9fd185cc..bd7722b8 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/Generator.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/model/Generator.java @@ -1,7 +1,6 @@ package io.github.null2264.cobblegen.data.model; #if MC>=12005 -import io.github.null2264.cobblegen.data.model.Generator; import io.netty.buffer.ByteBuf; #endif @@ -24,6 +23,7 @@ import java.lang.reflect.Method; import java.util.Optional; +// TODO: Simplify this interface to make it truly a public API public interface Generator extends PacketSerializable { #if MC>=12005 From 842cbbd7981b8a580dd99ee87ffb7fd589833a92 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 9 Apr 2025 20:33:43 +0700 Subject: [PATCH 08/21] chore: Deprecate CustomGen class --- .../github/null2264/cobblegen/data/config/ConfigData.java | 1 + .../io/github/null2264/cobblegen/data/config/CustomGen.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index 8ff99e40..54ca2766 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -122,6 +122,7 @@ public static ConfigData fromJson(JsonObject json) { config.cobbleGen = ResultList.fromJson(json.get("cobbleGen"), config.formatVersion); config.stoneGen = ResultList.fromJson(json.get("stoneGen"), config.formatVersion); config.basaltGen = ResultList.fromJson(json.get("basaltGen"), config.formatVersion); + // TODO: Delete later CustomGen customGen = CustomGen.fromJson(json.getObject("customGen")); if (config.formatVersion.equals("1.0")) { CGLog.warn(() -> "CobbleGen config format v1.0 is deprecated, please consider migrating to v" + LATEST_FORMAT_VERSION); diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java index 7f5c2a05..54f286d6 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java @@ -12,7 +12,11 @@ import static io.github.null2264.cobblegen.util.Constants.JANKSON; -public class CustomGen implements JanksonSerializable +/** + * @deprecated No longer used + */ +@Deprecated(since = "5.4.1") +class CustomGen implements JanksonSerializable { @Nullable public GeneratorMap cobbleGen; From dd402844955478ed5175d6b10475e54645139b80 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 9 Apr 2025 20:46:19 +0700 Subject: [PATCH 09/21] test: Auto generate test config if gametest is enabled --- .github/workflows/build.yml | 50 ------------------- .../github/null2264/cobblegen/CobbleGen.java | 10 +++- .../cobblegen/data/config/ConfigData.java | 17 +++++++ .../gametest/BlockGenerationTest.java | 10 ++-- .../gametest/CobbleGenTestConfig.java | 13 +++++ .../gametest/CobbleGenTestLoader.java | 21 +------- .../mixin/core/CobbleGenMixinPlugin.java | 2 +- 7 files changed, 46 insertions(+), 77 deletions(-) create mode 100644 cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b991194..f1cdd981 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -134,56 +134,6 @@ jobs: pauseOnLostFocus:false EOF - cat <> run/test-${{ matrix.mc }}-${{ matrix.loader }}/config/cobblegen.json5 - { - "formatVersion": "1.0", - "cobbleGen": [ - { - "id": "minecraft:bedrock", - "weight": 100.0, - }, - ], - "stoneGen": [ - { - "id": "minecraft:bedrock", - "weight": 100.0, - }, - ], - "basaltGen": [ - { - "id": "minecraft:bedrock", - "weight": 100.0, - }, - ], - "customGen": { - "cobbleGen": { - "minecraft:bedrock": [ - { - "id": "minecraft:bedrock", - "weight": 100.0, - }, - ], - }, - "stoneGen": { - "minecraft:bedrock": [ - { - "id": "minecraft:bedrock", - "weight": 100.0, - }, - ], - }, - "basaltGen": { - "minecraft:bedrock": [ - { - "id": "minecraft:bedrock", - "weight": 100.0, - }, - ], - }, - }, - } - EOF - json="$(cat ./headlessmc.json)" url="$(echo $json | jq -r '.assets[].browser_download_url' | grep .jar | grep launcher | grep -v jfx | grep -v wrapper)" curl -Ls -o "headlessmc-launcher.jar" $url diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java index 484be566..89a08619 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java @@ -7,6 +7,7 @@ import io.github.null2264.cobblegen.data.config.ConfigData; import io.github.null2264.cobblegen.data.config.ConfigMetaData; import io.github.null2264.cobblegen.data.model.CGRegistry; +import io.github.null2264.cobblegen.gametest.CobbleGenTestConfig; import io.github.null2264.cobblegen.util.CGLog; import net.minecraft.commands.CommandSourceStack; import org.jetbrains.annotations.ApiStatus; @@ -44,7 +45,14 @@ public class CobbleGen public CobbleGen() { // Force config to be generated when loading up the game instead of having to load a world - loadConfig("generator", false, configFile, null, ConfigData.defaultConfig(), ConfigData.class); + loadConfig( + "generator", + false, + configFile, + null, + CobbleGenTestConfig.ENABLED ? ConfigData.testConfig() : ConfigData.defaultConfig(), + ConfigData.class + ); #if FORGE && MC>=11801 && MC<12105 // I was gonna do RegisterGameTestsEvent like a normal person, but there's a check that I need to bypass otherwise Forge won't register my test net.minecraft.gametest.framework.GameTestRegistry.register(io.github.null2264.cobblegen.gametest.BlockGenerationTest.class); diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index 54ca2766..7be96745 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -74,6 +74,23 @@ public class ConfigData implements Config, JanksonSerializable @Nullable public FluidInteractionMap advanced; + public static ConfigData testConfig() { + ConfigData config = new ConfigData(); + config.cobbleGen = ResultList.of( + new WeightedBlock.Builder().setId("minecraft:cobbled_deepslate").setWeight(100.0).build(), + new WeightedBlock.Builder().setId("minecraft:cobblestone").setWeight(100.0).setModifier("minecraft:bedrock").build() + ); + config.stoneGen = ResultList.of( + new WeightedBlock.Builder().setId("minecraft:deepslate").setWeight(100.0).build(), + new WeightedBlock.Builder().setId("minecraft:stone").setWeight(100.0).setModifier("minecraft:bedrock").build() + ); + config.basaltGen = ResultList.of( + new WeightedBlock.Builder().setId("minecraft:blackstone").setWeight(100.0).build(), + new WeightedBlock.Builder().setId("minecraft:basalt").setWeight(100.0).setModifier("minecraft:bedrock").build() + ); + return config; + } + public static ConfigData defaultConfig() { ConfigData config = new ConfigData(); config.cobbleGen = ResultList.of( diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/BlockGenerationTest.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/BlockGenerationTest.java index e01dad4d..14614ebd 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/BlockGenerationTest.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/BlockGenerationTest.java @@ -56,6 +56,7 @@ * -> Intercepted by CobbleGen's mixin -> Gated by -Dnull2264.cobblegen.gametest=true * -> BlockGenerationTest.registerInstances(...) */ +// TODO: Test modifiers public class BlockGenerationTest { public static final CGIdentifier TEMPLATE = CGIdentifier.of("empty"); public static final Integer TIMEOUT_TICKS = 120; @@ -183,8 +184,7 @@ public void cobbleGenerationTest(GameTestHelper context) { BlockPos generatedPos = new BlockPos(1, 2, 3); context.succeedWhen( () -> { - // A special config is needed for this test - context.assertBlockPresent(Blocks.BEDROCK, generatedPos); + context.assertBlockPresent(Blocks.COBBLED_DEEPSLATE, generatedPos); } ); } @@ -220,8 +220,7 @@ public void basaltGenerationTest(GameTestHelper context) { BlockPos generatedPos = new BlockPos(1, 2, 3); context.succeedWhen( () -> { - // A special config is needed for this test - context.assertBlockPresent(Blocks.BEDROCK, generatedPos); + context.assertBlockPresent(Blocks.BLACKSTONE, generatedPos); } ); } @@ -269,8 +268,7 @@ public void stoneGenerationTest(GameTestHelper context) { BlockPos generatedPos = new BlockPos(1, 1, 1); context.succeedWhen( () -> { - // A special config is needed for this test - context.assertBlockPresent(Blocks.BEDROCK, generatedPos); + context.assertBlockPresent(Blocks.DEEPSLATE, generatedPos); } ); } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java new file mode 100644 index 00000000..5d4c6186 --- /dev/null +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java @@ -0,0 +1,13 @@ +package io.github.null2264.cobblegen.gametest; + +import io.github.null2264.cobblegen.util.Util; + +// NOTE: Do NOT use Minecraft related stuff here! +public class CobbleGenTestConfig { + public static final boolean ENABLED = Boolean.parseBoolean( + System.getProperty( + "null2264.cobblegen.gametest", + Util.elvis(System.getenv("ENABLE_NULL2264_COBBLEGEN_GAMETEST"), "false") + ) + ); +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java index 27e41ec6..8b726653 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestLoader.java @@ -15,27 +15,10 @@ public class CobbleGenTestLoader extends TestFunctionLoader { private static final AtomicBoolean SHOULD_REGISTER = new AtomicBoolean(true); - public static final boolean ENABLED = boolFromString( - System.getProperty( - "null2264.cobblegen.gametest", - Util.elvis(System.getenv("ENABLE_NULL2264_COBBLEGEN_GAMETEST"), "false") - ) - ); - - private static boolean boolFromString(String string) { - List yes = List.of("yes", "y", "true", "t", "1", "enable", "on"); - List no = List.of("no", "n", "false", "f", "0", "disable", "off"); - - if (yes.contains(string.toLowerCase())) return true; - else if (no.contains(string.toLowerCase())) return false; - - // We supposed to throw an exception here, but we'll fallback to false instead - return false; - } public static void init() { - CGLog.info(() -> "Is CobbleGen GameTest enabled: " + ENABLED); - if (ENABLED && SHOULD_REGISTER.getAndSet(false)) + CGLog.info(() -> "Is CobbleGen GameTest enabled: " + CobbleGenTestConfig.ENABLED); + if (CobbleGenTestConfig.ENABLED && SHOULD_REGISTER.getAndSet(false)) TestFunctionLoader.registerLoader(new CobbleGenTestLoader()); } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java index feb43bcd..7b3cfb56 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java @@ -91,7 +91,7 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { } #if MC>=12105 - if (mixinClassName.endsWith("$GameTest") && io.github.null2264.cobblegen.gametest.CobbleGenTestLoader.ENABLED) { + if (mixinClassName.endsWith("$GameTest") && io.github.null2264.cobblegen.gametest.CobbleGenTestConfig.ENABLED) { // Datapack will not register automatically in Fabric without FAPI. // I usually prefer not depending on FAPI, but I'll make this one an exception... // because I ain't dealing with Resource Pack loading ever again From 8472a6c06bafcb820e2d0f0db06b103f73470543 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 07:35:11 +0700 Subject: [PATCH 10/21] fix: "since" on `@Deprecated` annotation didn't exist on Java 8 --- .../null2264/cobblegen/data/config/CustomGen.java | 5 +++-- .../cobblegen/data/config/WeightedBlock.java | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java index 54f286d6..c078cf28 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/CustomGen.java @@ -13,9 +13,10 @@ import static io.github.null2264.cobblegen.util.Constants.JANKSON; /** - * @deprecated No longer used + * @deprecated Has been merged with basic generators + * @see ConfigData */ -@Deprecated(since = "5.4.1") +@Deprecated class CustomGen implements JanksonSerializable { @Nullable diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java index a3b7efc1..0b232c5c 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/WeightedBlock.java @@ -44,6 +44,7 @@ public class WeightedBlock implements PacketSerializable, Jankson /** * @deprecated Use {@link WeightedBlock.Builder} instead. */ + @Deprecated public WeightedBlock(String id, Double weight) { this(id, weight, null, null); } @@ -51,6 +52,7 @@ public WeightedBlock(String id, Double weight) { /** * @deprecated Use {@link WeightedBlock.Builder} instead. */ + @Deprecated public WeightedBlock(String id, Double weight, List dimIds) { this(id, weight, dimIds, null); } @@ -58,6 +60,7 @@ public WeightedBlock(String id, Double weight, List dimIds) { /** * @deprecated Use {@link WeightedBlock.Builder} instead. */ + @Deprecated public WeightedBlock(String id, Double weight, List dimIds, List excludedDimensions) { this(id, weight, dimIds, excludedDimensions, null, null, null, null, null); } @@ -65,6 +68,7 @@ public WeightedBlock(String id, Double weight, List dimIds, List /** * @deprecated Use {@link WeightedBlock.Builder} instead. */ + @Deprecated public WeightedBlock( String id, Double weight, @@ -88,17 +92,17 @@ public WeightedBlock( } /** - * @deprecated Use {@link WeightedBlock.Builder} instead. + * @deprecated Use {@link WeightedBlock.Builder#of(Block)} instead. */ - @Deprecated(since = "5.4.1") + @Deprecated public static WeightedBlock fromBlock(Block block, Double weight) { return fromBlock(block, weight, null, null, null, null); } /** - * @deprecated Use {@link WeightedBlock.Builder} instead. + * @deprecated Use {@link WeightedBlock.Builder#of(Block)} instead. */ - @Deprecated(since = "5.4.1") + @Deprecated public static WeightedBlock fromBlock( Block block, Double weight, From ff8319cc5b9c539f7fbcba82946634be62cf0dc4 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 07:38:27 +0700 Subject: [PATCH 11/21] fix: "cannot find symbol" --- .../main/java/io/github/null2264/cobblegen/util/Util.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java index a5aa0ace..12bcd156 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/util/Util.java @@ -98,7 +98,7 @@ public static List getTaggedBlockIds(ResourceLocation tagId) { #if MC>11605 final TagKey blockTag = TagKey.create( #if MC<=11902 - Registry.BLOCK_REGISTRY, + net.minecraft.core.Registry.BLOCK_REGISTRY, #else net.minecraft.core.registries.Registries.BLOCK, #endif @@ -145,7 +145,7 @@ public static String getDimension(LevelAccessor level) { .registryOrThrow( #endif #if MC<=11902 - Registry.DIMENSION_TYPE_REGISTRY + net.minecraft.core.Registry.DIMENSION_TYPE_REGISTRY #else net.minecraft.core.registries.Registries.DIMENSION_TYPE #endif @@ -168,7 +168,7 @@ public static String getBiome(LevelAccessor level, BlockPos position) { .registryOrThrow( #endif #if MC<=11902 - Registry.BIOME_REGISTRY + net.minecraft.core.Registry.BIOME_REGISTRY #else net.minecraft.core.registries.Registries.BIOME #endif From 4343d72ff9783b8142690a2591ffad1659699c86 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 08:01:25 +0700 Subject: [PATCH 12/21] refactor: Reduce repetition trying to load/reload config Also add a subcommand to reload cobblegen generator config without reloading the entire MC resources --- .../github/null2264/cobblegen/CobbleGen.java | 49 ++++++++++--------- .../cobblegen/data/config/Config.java | 9 +++- .../cobblegen/data/config/ConfigData.java | 34 ++++++++++++- .../cobblegen/data/config/ConfigHelper.java | 3 +- .../cobblegen/data/config/ConfigMetaData.java | 36 ++++++++++++-- .../cobblegen/integration/BuiltInPlugin.java | 5 +- 6 files changed, 102 insertions(+), 34 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java index 89a08619..f51229aa 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/CobbleGen.java @@ -4,10 +4,10 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.github.null2264.cobblegen.compat.LoaderCompat; import io.github.null2264.cobblegen.compat.TextCompat; +import io.github.null2264.cobblegen.data.config.Config; import io.github.null2264.cobblegen.data.config.ConfigData; import io.github.null2264.cobblegen.data.config.ConfigMetaData; import io.github.null2264.cobblegen.data.model.CGRegistry; -import io.github.null2264.cobblegen.gametest.CobbleGenTestConfig; import io.github.null2264.cobblegen.util.CGLog; import net.minecraft.commands.CommandSourceStack; import org.jetbrains.annotations.ApiStatus; @@ -15,7 +15,6 @@ import java.io.File; import java.nio.file.Path; -import static io.github.null2264.cobblegen.data.config.ConfigHelper.loadConfig; import static io.github.null2264.cobblegen.util.Constants.OP_LEVEL_GAMEMASTERS; #if FORGE @@ -40,19 +39,13 @@ public class CobbleGen private static final Path configPath = LoaderCompat.getConfigDir(); private static final File configFile = new File(configPath + File.separator + MOD_ID + ".json5"); private static final File metaConfigFile = new File(configPath + File.separator + MOD_ID + "-meta.json5"); + private static final Config.Factory metaConfigFactory = new ConfigMetaData.Factory(); @ApiStatus.Internal - public static ConfigMetaData META_CONFIG = loadConfig("metadata", false, metaConfigFile, null, new ConfigMetaData(), ConfigMetaData.class); + public static ConfigMetaData META_CONFIG = metaConfigFactory.load(metaConfigFile); public CobbleGen() { // Force config to be generated when loading up the game instead of having to load a world - loadConfig( - "generator", - false, - configFile, - null, - CobbleGenTestConfig.ENABLED ? ConfigData.testConfig() : ConfigData.defaultConfig(), - ConfigData.class - ); + new ConfigData.Factory().load(configFile); #if FORGE && MC>=11801 && MC<12105 // I was gonna do RegisterGameTestsEvent like a normal person, but there's a check that I need to bypass otherwise Forge won't register my test net.minecraft.gametest.framework.GameTestRegistry.register(io.github.null2264.cobblegen.gametest.BlockGenerationTest.class); @@ -67,19 +60,27 @@ public void onInitialize() {} public static void initCommands(CommandDispatcher dispatcher) { CGLog.info("Registering command..."); dispatcher.register( - LiteralArgumentBuilder.literal("cobblegen") - .then(LiteralArgumentBuilder.literal("reload-meta").requires(arg -> arg.hasPermission(OP_LEVEL_GAMEMASTERS)).executes(c -> { - CGLog.info("Reloading meta config..."); - META_CONFIG = loadConfig("metadata", true, metaConfigFile, META_CONFIG, new ConfigMetaData(), ConfigMetaData.class); - c.getSource().sendSuccess( - #if MC>=12001 - () -> - #endif - TextCompat.literal("Meta config has been reloaded"), false - ); - CGLog.info("Meta config has been reloaded"); - return 0; - })) + LiteralArgumentBuilder.literal("cobblegen") + .then(LiteralArgumentBuilder.literal("reload-meta").requires(arg -> arg.hasPermission(OP_LEVEL_GAMEMASTERS)).executes(c -> { + META_CONFIG = metaConfigFactory.reload(metaConfigFile); + c.getSource().sendSuccess( + #if MC>=12001 + () -> + #endif + TextCompat.literal("Meta config has been reloaded"), false + ); + return 0; + })) + .then(LiteralArgumentBuilder.literal("reload").requires(arg -> arg.hasPermission(OP_LEVEL_GAMEMASTERS)).executes(c -> { + FLUID_INTERACTION.reload(); + c.getSource().sendSuccess( + #if MC>=12001 + () -> + #endif + TextCompat.literal("Generator config has been reloaded"), false + ); + return 0; + })) ); } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/Config.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/Config.java index 6276fc99..dcbdf169 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/Config.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/Config.java @@ -1,3 +1,10 @@ package io.github.null2264.cobblegen.data.config; -public interface Config {} \ No newline at end of file +import java.io.File; + +public interface Config { + interface Factory { + T load(File file); + T reload(File file); + } +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index 7be96745..362568e5 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -6,18 +6,48 @@ import io.github.null2264.cobblegen.data.CGIdentifier; import io.github.null2264.cobblegen.data.JanksonSerializable; import io.github.null2264.cobblegen.data.Pair; +import io.github.null2264.cobblegen.gametest.CobbleGenTestConfig; import io.github.null2264.cobblegen.util.CGLog; import io.github.null2264.cobblegen.util.Util; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.File; + import static io.github.null2264.cobblegen.compat.CollectionCompat.listOf; @SuppressWarnings("TextBlockMigration") -public class ConfigData implements Config, JanksonSerializable -{ +public class ConfigData implements Config, JanksonSerializable { + + private static String NAME = "generator"; public static String LATEST_FORMAT_VERSION = "1.1"; + public static class Factory implements Config.Factory { + @Override + public ConfigData load(File file) { + return ConfigHelper.loadConfig( + NAME, + false, + file, + null, + CobbleGenTestConfig.ENABLED ? ConfigData.testConfig() : ConfigData.defaultConfig(), + ConfigData.class + ); + } + + @Override + public ConfigData reload(File file) { + return ConfigHelper.loadConfig( + NAME, + true, + file, + null, + CobbleGenTestConfig.ENABLED ? ConfigData.testConfig() : ConfigData.defaultConfig(), + ConfigData.class + ); + } + } + // FIXME: Make this SemVer object @Comment(value = "CobbleGen Format Version, you can leave this alone for now. v2.0 will be released in CobbleGen v6.0") @NotNull diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java index 65cf387b..fa7f1f4b 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigHelper.java @@ -15,8 +15,7 @@ import static io.github.null2264.cobblegen.util.Constants.JANKSON; public class ConfigHelper { - @ApiStatus.Internal - public static T loadConfig( + static T loadConfig( String name, boolean reload, File configFile, diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigMetaData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigMetaData.java index 253f4103..7bd432be 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigMetaData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigMetaData.java @@ -3,8 +3,38 @@ import blue.endless.jankson.Comment; import org.jetbrains.annotations.NotNull; -public class ConfigMetaData implements Config -{ +import java.io.File; + +public class ConfigMetaData implements Config { + + private static final String NAME = "metadata"; + + public static class Factory implements Config.Factory { + @Override + public ConfigMetaData load(File file) { + return ConfigHelper.loadConfig( + NAME, + false, + file, + null, + new ConfigMetaData(), + ConfigMetaData.class + ); + } + + @Override + public ConfigMetaData reload(File file) { + return ConfigHelper.loadConfig( + NAME, + true, + file, + null, + new ConfigMetaData(), + ConfigMetaData.class + ); + } + } + @Comment(value="Enable Recipe Viewer support (EMI/REI/JEI)") @NotNull public Boolean enableRecipeViewer = true; @@ -44,4 +74,4 @@ public static class CreateData { @Comment(value="Disable Create's pipe support") public Boolean disablePipe = false; } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java index 0dc81ae1..f8eb1061 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java @@ -4,6 +4,7 @@ import io.github.null2264.cobblegen.CobbleGenPlugin; import io.github.null2264.cobblegen.compat.LoaderCompat; import io.github.null2264.cobblegen.data.CGIdentifier; +import io.github.null2264.cobblegen.data.config.Config; import io.github.null2264.cobblegen.data.config.ConfigData; import io.github.null2264.cobblegen.data.config.GeneratorMap; import io.github.null2264.cobblegen.data.config.ResultList; @@ -26,12 +27,12 @@ import java.util.concurrent.atomic.AtomicInteger; import static io.github.null2264.cobblegen.CobbleGen.MOD_ID; -import static io.github.null2264.cobblegen.data.config.ConfigHelper.loadConfig; import static io.github.null2264.cobblegen.util.Util.elvis; @CGPlugin public class BuiltInPlugin implements CobbleGenPlugin { + private static final Config.Factory factory = new ConfigData.Factory(); private static final Path configPath = LoaderCompat.getConfigDir(); private static final File configFile = new File(configPath + File.separator + MOD_ID + ".json5"); @Nullable @@ -60,7 +61,7 @@ private Block getBlockFromString(String string) { @Override public void registerInteraction(CGRegistry registry) { CGLog.info((!isReload ? "L" : "Rel") + "oading config..."); - if (config == null || isReload) config = loadConfig("generator", isReload, configFile, config, ConfigData.defaultConfig(), ConfigData.class); + if (config == null || isReload) config = isReload ? factory.reload(configFile) : factory.load(configFile); if (config == null) throw new RuntimeException("How?"); AtomicInteger count = new AtomicInteger(); From 55e6ae5c17e71c434ee8a87599f4cc118e89fc6d Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 08:24:04 +0700 Subject: [PATCH 13/21] fix: Backport some Java 16 API to Java 8 --- .../null2264/cobblegen/data/CGModifier.java | 6 ++--- .../null2264/cobblegen/util/PluginFinder.java | 22 ++++++++---------- .../extensions/java/util/List/ListExt.java | 20 ++++++++++++++++ .../java/util/stream/Stream/StreamExt.java | 23 +++++++++++++++++++ 4 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java create mode 100644 mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/stream/Stream/StreamExt.java diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/CGModifier.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/CGModifier.java index d62cb321..3a0fcd9f 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/CGModifier.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/CGModifier.java @@ -5,8 +5,6 @@ import java.util.List; import java.util.Objects; -import static io.github.null2264.cobblegen.compat.CollectionCompat.streamToList; - /** * Class to holds modifier as Map key */ @@ -15,7 +13,7 @@ public class CGModifier { public CGModifier(List modifiers) { if (modifiers.size() >= 4) throw new IllegalArgumentException("Cannot have more than 4 modifiers"); - this.modifiers = streamToList(modifiers.stream().sorted()); + this.modifiers = modifiers.stream().sorted().toList(); } public void writeToBuf(FriendlyByteBuf buf) { @@ -38,4 +36,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(modifiers); } -} \ No newline at end of file +} diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/util/PluginFinder.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/util/PluginFinder.java index 205e3114..2a5c2c33 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/util/PluginFinder.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/util/PluginFinder.java @@ -5,8 +5,6 @@ import java.util.*; -import static io.github.null2264.cobblegen.compat.CollectionCompat.streamToList; - #if FABRIC import net.fabricmc.loader.api.FabricLoader; #else @@ -28,12 +26,11 @@ public class PluginFinder { public static List getModPlugins() { #if FABRIC - return streamToList( - FabricLoader.getInstance() - .getEntrypointContainers("cobblegen_plugin", CobbleGenPlugin.class) - .stream() - .map(entrypoint -> new PlugInContainer(entrypoint.getProvider().getMetadata().getId(), entrypoint.getEntrypoint())) - ); + return FabricLoader.getInstance() + .getEntrypointContainers("cobblegen_plugin", CobbleGenPlugin.class) + .stream() + .map(entrypoint -> new PlugInContainer(entrypoint.getProvider().getMetadata().getId(), entrypoint.getEntrypoint())) + .toList(); #else return AnnotatedFinder.getInstances(CGPlugin.class, CobbleGenPlugin.class); #endif @@ -46,11 +43,10 @@ public static List getInstances(Class annotationClass, C List allScanData = ModList.get().getAllScanData(); List instances = new ArrayList<>(); for (ModFileScanData data : allScanData) { - List modIds = streamToList( - data.getIModInfoData().stream() - .flatMap(info -> info.getMods().stream()) - .map(IModInfo::getModId) - ); + List modIds = data.getIModInfoData().stream() + .flatMap(info -> info.getMods().stream()) + .map(IModInfo::getModId) + .toList(); String modId = "[" + String.join(", ", modIds) + "]"; Iterable annotations = data.getAnnotations(); diff --git a/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java new file mode 100644 index 00000000..26e06229 --- /dev/null +++ b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java @@ -0,0 +1,20 @@ +package io.github.null2264.cobblegen.extensions.java.util.List; + +import manifold.ext.rt.api.Extension; + +#if MC<11700 +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +#endif + +@Extension +public final class ListExt { + #if MC<11700 + @SafeVarargs + @Extension + public static List of(T... items) { + return new ArrayList<>(Arrays.asList(items)); + } + #endif +} diff --git a/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/stream/Stream/StreamExt.java b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/stream/Stream/StreamExt.java new file mode 100644 index 00000000..0f37ca9c --- /dev/null +++ b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/stream/Stream/StreamExt.java @@ -0,0 +1,23 @@ +package io.github.null2264.cobblegen.extensions.java.util.stream.Stream; + +import manifold.ext.rt.api.Extension; + +#if MC<11700 +import manifold.ext.rt.api.This; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; +#endif + +@Extension +public final class StreamExt { + + #if MC<11700 + @SuppressWarnings("unchecked") + public static List toList(@This Stream stream) { + return (List) Collections.unmodifiableList(new ArrayList<>(Arrays.asList(stream.toArray()))); + } + #endif +} From dd71342d0c4dffb13c69a868873014052fc6e621 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 09:03:43 +0700 Subject: [PATCH 14/21] fix(manifold): Use the full path --- .../cobblegen/extensions/java/util/List/ListExt.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java index 26e06229..5684faa2 100644 --- a/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java +++ b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java @@ -1,18 +1,16 @@ package io.github.null2264.cobblegen.extensions.java.util.List; -import manifold.ext.rt.api.Extension; - #if MC<11700 import java.util.ArrayList; import java.util.Arrays; import java.util.List; #endif -@Extension +@manifold.ext.rt.api.Extension public final class ListExt { #if MC<11700 @SafeVarargs - @Extension + @manifold.ext.rt.api.Extension public static List of(T... items) { return new ArrayList<>(Arrays.asList(items)); } From 0007a0f53e4ef42a355f228058722ffca9c0b564 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 09:34:07 +0700 Subject: [PATCH 15/21] fix: The built-in parseBoolean is not as good as I had hoped for... --- .../cobblegen/data/config/ConfigData.java | 6 +++--- .../gametest/CobbleGenTestConfig.java | 2 +- .../java/lang/Boolean/BooleanExt.java | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/lang/Boolean/BooleanExt.java diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index 362568e5..b859de14 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -108,15 +108,15 @@ public static ConfigData testConfig() { ConfigData config = new ConfigData(); config.cobbleGen = ResultList.of( new WeightedBlock.Builder().setId("minecraft:cobbled_deepslate").setWeight(100.0).build(), - new WeightedBlock.Builder().setId("minecraft:cobblestone").setWeight(100.0).setModifier("minecraft:bedrock").build() + new WeightedBlock.Builder().setId("minecraft:deepslate").setWeight(100.0).setModifier("minecraft:bedrock").build() ); config.stoneGen = ResultList.of( new WeightedBlock.Builder().setId("minecraft:deepslate").setWeight(100.0).build(), - new WeightedBlock.Builder().setId("minecraft:stone").setWeight(100.0).setModifier("minecraft:bedrock").build() + new WeightedBlock.Builder().setId("minecraft:cobbled_deepslate").setWeight(100.0).setModifier("minecraft:bedrock").build() ); config.basaltGen = ResultList.of( new WeightedBlock.Builder().setId("minecraft:blackstone").setWeight(100.0).build(), - new WeightedBlock.Builder().setId("minecraft:basalt").setWeight(100.0).setModifier("minecraft:bedrock").build() + new WeightedBlock.Builder().setId("minecraft:end_stone").setWeight(100.0).setModifier("minecraft:bedrock").build() ); return config; } diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java index 5d4c6186..e6449aef 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/gametest/CobbleGenTestConfig.java @@ -4,7 +4,7 @@ // NOTE: Do NOT use Minecraft related stuff here! public class CobbleGenTestConfig { - public static final boolean ENABLED = Boolean.parseBoolean( + public static final boolean ENABLED = Boolean.parse( System.getProperty( "null2264.cobblegen.gametest", Util.elvis(System.getenv("ENABLE_NULL2264_COBBLEGEN_GAMETEST"), "false") diff --git a/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/lang/Boolean/BooleanExt.java b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/lang/Boolean/BooleanExt.java new file mode 100644 index 00000000..d0e9cbdc --- /dev/null +++ b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/lang/Boolean/BooleanExt.java @@ -0,0 +1,19 @@ +package io.github.null2264.cobblegen.extensions.java.lang.Boolean; + +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; + +@manifold.ext.rt.api.Extension +public final class BooleanExt { + @manifold.ext.rt.api.Extension + public static boolean parse(@Nullable String string) { + if (string == null) return false; + + String[] yes = {"yes", "y", "true", "t", "1", "enable", "on"}; + //String[] no = {"no", "n", "false", "f", "0", "disable", "off"}; + + return Arrays.asList(yes).contains(string.toLowerCase()); + //else if (Arrays.asList(no).contains(string.toLowerCase())) return false; + } +} From de665b56bc327e19856b80a633879a49efbe5048 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 09:44:00 +0700 Subject: [PATCH 16/21] fix: Fix example comment --- .../io/github/null2264/cobblegen/data/config/ConfigData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index b859de14..0b1982b6 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -68,7 +68,7 @@ public ConfigData reload(File file) { " ],\n" + " \"minY\": 0,\n" + " \"maxY\": 69,\n" + - " \"modifier\": 69\n" + + " \"modifier\": \"mod_id:modifier_block_id\"\n" + "}") public ResultList cobbleGen; From f9e8305a3706e2aab3df6e390b86aeed2deb28f9 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 10 Apr 2025 10:25:31 +0700 Subject: [PATCH 17/21] fix(plugin/builtin): Accidentally copy the entire thing instead of splitting it --- .../cobblegen/integration/BuiltInPlugin.java | 16 +++++++++------- .../extensions/java/util/List/ListExt.java | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java index f8eb1061..85f5c8e6 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/integration/BuiltInPlugin.java @@ -71,17 +71,19 @@ public void registerInteraction(CGRegistry registry) { GeneratorMap basaltGen = new GeneratorMap(); elvis(config.stoneGen, new ResultList()) - .forEach(result -> - stoneGen.put(CGIdentifier.of(result.getModifier().orElse("*")), elvis(config.stoneGen, new ResultList())) - ); + .forEach(result -> { + CGIdentifier id = CGIdentifier.of(result.getModifier().orElse("*")); + stoneGen.computeIfAbsent(id, r -> new ResultList()).add(result); + }); elvis(config.cobbleGen, new ResultList()) - .forEach(result -> - cobbleGen.put(CGIdentifier.of(result.getModifier().orElse("*")), elvis(config.cobbleGen, new ResultList())) - ); + .forEach(result -> { + CGIdentifier id = CGIdentifier.of(result.getModifier().orElse("*")); + cobbleGen.computeIfAbsent(id, r -> new ResultList()).add(result); + }); elvis(config.basaltGen, new ResultList()) .forEach(result -> { CGIdentifier id = result.getModifier().map(CGIdentifier::of).orElseGet(() -> CGIdentifier.fromBlock(Blocks.SOUL_SOIL)); - basaltGen.put(id, elvis(config.basaltGen, new ResultList())); + basaltGen.computeIfAbsent(id, r -> new ResultList()).add(result); }); if (config.advanced != null) diff --git a/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java index 5684faa2..0b498fb4 100644 --- a/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java +++ b/mclib/src/main/java/io/github/null2264/cobblegen/extensions/java/util/List/ListExt.java @@ -8,9 +8,10 @@ @manifold.ext.rt.api.Extension public final class ListExt { + #if MC<11700 - @SafeVarargs @manifold.ext.rt.api.Extension + @SafeVarargs public static List of(T... items) { return new ArrayList<>(Arrays.asList(items)); } From 71b0a1ea50cb86b1d23794d2413a15d2fec572d5 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Fri, 11 Apr 2025 06:01:11 +0700 Subject: [PATCH 18/21] docs: Primer [skip ci] --- .github/primers/config/1.1/README.md | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/primers/config/1.1/README.md diff --git a/.github/primers/config/1.1/README.md b/.github/primers/config/1.1/README.md new file mode 100644 index 00000000..0b63e938 --- /dev/null +++ b/.github/primers/config/1.1/README.md @@ -0,0 +1,64 @@ +# Config Format v1.1 + +To make it less confusing for users to configure custom generator, I decided to merge `customGen` with basic generators (`cobbleGen`/`stoneGen`/`basaltGen`). This format is a partial port of [GH-53](https://github.com/null2264/CobbleGen/issues/53). + +> [!NOTE] +> If you still want to use format v1.1, you can set `formatVersion` to `1.0` (do note that it'll be removed completely at some point): +> +> ```json5 +> { +> "formatVersion": "1.0", +> "cobbleGen": [ +> ... +> ], +> "customGen": { +> ... +> } +> } +> ``` + +## v1.0 + +Previously in v1.0, you'd define custom generators inside `customGen`, but most people got confused about the `cobbleGen`/`stoneGen`/`basaltGen` and thought it's a name for the custom generator. + +```json5 +{ + "cobbleGen": [ + { + "id": "minecraft:cobblestone", + "weight": 100.0 + } + ], + "customGen": { + // This is the most confusing part for most people + "cobbleGen": { + "minecraft:bedrock": [ + { + "id": "#minecraft:ores", + "weight": 100.0 + } + ] + } + } +} +``` + +## v1.1 + +Now in v1.1, all you need to do to define a custom generator is by adding `modifier` value inside the "result block", similar to how you set the generation's `weight`. + +```json5 +{ + "cobbleGen": [ + { + "id": "minecraft:cobblestone", + "weight": 100.0 + }, + { + "id": "#minecraft:ores", + "weight": 100.0, + "modifier": "minecraft:bedrock" + } + ] +} +``` From e5ebc1db47a56f0f804d6ec723de75846762dc53 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Fri, 11 Apr 2025 06:04:30 +0700 Subject: [PATCH 19/21] docs: Typo [skip ci] --- .github/primers/config/1.1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/primers/config/1.1/README.md b/.github/primers/config/1.1/README.md index 0b63e938..b607c867 100644 --- a/.github/primers/config/1.1/README.md +++ b/.github/primers/config/1.1/README.md @@ -3,7 +3,7 @@ To make it less confusing for users to configure custom generator, I decided to merge `customGen` with basic generators (`cobbleGen`/`stoneGen`/`basaltGen`). This format is a partial port of [GH-53](https://github.com/null2264/CobbleGen/issues/53). > [!NOTE] -> If you still want to use format v1.1, you can set `formatVersion` to `1.0` (do note that it'll be removed completely at some point): +> If you still want to use format v1.0, you can set `formatVersion` to `1.0` (do note that it'll be removed completely at some point): > > ```json5 > { From 4560313e568ae307f61d2d1a4f881d0bc3522bff Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Fri, 11 Apr 2025 16:59:11 +0700 Subject: [PATCH 20/21] fix: Warn the user about the change --- .../io/github/null2264/cobblegen/data/config/ConfigData.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index 0b1982b6..4e2aa8e4 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -190,6 +190,9 @@ public static ConfigData fromJson(JsonObject json) { } })); } + } else if (customGen != null) { + // TODO: This probably should be sent to the chat when player joined a world. + CGLog.warn(() -> "You're using \"customGen\" on config format v" + config.formatVersion + "! Please migrate to format v" + LATEST_FORMAT_VERSION + " or specify \"formatVersion\" on the config file, otherwise the custom generator(s) won't be used by the mod."); } config.advanced = FluidInteractionMap.fromJson(json.getObject("advanced")); return config; From e2e256ae12164b66fd781f6964f87a6a767f71cb Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Mon, 21 Apr 2025 13:24:31 +0700 Subject: [PATCH 21/21] fix(config): Add link to migration documentation --- .../null2264/cobblegen/data/config/ConfigData.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java index 4e2aa8e4..3b4b65be 100644 --- a/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java +++ b/cobblegen/src/main/java/io/github/null2264/cobblegen/data/config/ConfigData.java @@ -192,7 +192,14 @@ public static ConfigData fromJson(JsonObject json) { } } else if (customGen != null) { // TODO: This probably should be sent to the chat when player joined a world. - CGLog.warn(() -> "You're using \"customGen\" on config format v" + config.formatVersion + "! Please migrate to format v" + LATEST_FORMAT_VERSION + " or specify \"formatVersion\" on the config file, otherwise the custom generator(s) won't be used by the mod."); + CGLog.warn(() -> + "You're using \"customGen\" on config format v" + + config.formatVersion + + "! Please migrate to format v" + + LATEST_FORMAT_VERSION + + " or specify \"formatVersion\" on the config file, otherwise the custom generator(s) won't be used by the mod." + + " Check out https://docs.aap.my.id/cobblegen/config/migration to learn how to migrate to newer format version." + ); } config.advanced = FluidInteractionMap.fromJson(json.getObject("advanced")); return config;