diff --git a/build.gradle b/build.gradle index 104a02e..07930c8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,8 @@ plugins { id("java") id "me.modmuss50.mod-publish-plugin" version "0.3.0" - id("fabric-loom") version("1.3.9") apply(false) - id("net.minecraftforge.gradle") version("6.0.+") apply(false) + id("fabric-loom") version("1.4.2") apply(false) + id 'net.neoforged.gradle' version '[6.0.18,6.2)' apply(false) } java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -15,6 +15,8 @@ multiLoader.root() { minecraftVersion.set(project.property("minecraft_version")) modID.set(project.property("mod_id")) splitSources.set(true) + accessWidenerFile.set(project(":common").file("src/main/resources/${mod_id}.accesswidener")) + dataGen { useFabric.set(project(":common").file("src/generated/resources")) useForge.set(project(":forge").file("src/generated/resources")) diff --git a/common/src/generated/resources/.cache/12b48ce80665160388e37efcbe6ffc9c320247a7 b/common/src/generated/resources/.cache/12b48ce80665160388e37efcbe6ffc9c320247a7 new file mode 100644 index 0000000..ca8122d --- /dev/null +++ b/common/src/generated/resources/.cache/12b48ce80665160388e37efcbe6ffc9c320247a7 @@ -0,0 +1,2 @@ +// 1.20.1 2023-08-20T09:33:14.6325483 Just Another Mining Dimension/Language (en_us) +4d0b94d0ebdcaaafe16d0133c0028cf20bec5a5f assets\jamd\lang\en_us.json diff --git a/common/src/generated/resources/.cache/1d8aa9c5d04d534625d05e0315fa2dfc314eb45b b/common/src/generated/resources/.cache/1d8aa9c5d04d534625d05e0315fa2dfc314eb45b new file mode 100644 index 0000000..c4b9207 --- /dev/null +++ b/common/src/generated/resources/.cache/1d8aa9c5d04d534625d05e0315fa2dfc314eb45b @@ -0,0 +1,10 @@ +// 1.20.1 2023-08-20T09:33:14.6340461 Just Another Mining Dimension/Model Definitions +bf3a9f8231659d8cbc7ea68a7cdde8e3b029071f assets\jamd\blockstates\end_portal.json +7e626048016ba0c9d3b92a12b89eb0ec4d6fe677 assets\jamd\models\block\nether_portal.json +2d9db6c9191663e8106bc53141670ea054209f9a assets\jamd\models\block\portal_block.json +6b50f23823f194ff35bcec0e1694e77efd20e385 assets\jamd\blockstates\nether_portal.json +c43b79f0a1988c4d812f8e77f1c7506d596430a0 assets\jamd\models\item\end_portal.json +098aa69a37ff6ca1b266436f24e891314007f976 assets\jamd\blockstates\portal_block.json +76633e08f2190391221ca5bc14b6536cda1b87a9 assets\jamd\models\item\nether_portal.json +6048ff3f9c71f641213c1d7aa6d605d9b23fed72 assets\jamd\models\block\end_portal.json +155f13040d10cd90e514a56c4d7338c0db232883 assets\jamd\models\item\portal_block.json diff --git a/common/src/generated/resources/.cache/2a895680709e271705f445e2c6f6dbca16550c92 b/common/src/generated/resources/.cache/2a895680709e271705f445e2c6f6dbca16550c92 new file mode 100644 index 0000000..09b92ed --- /dev/null +++ b/common/src/generated/resources/.cache/2a895680709e271705f445e2c6f6dbca16550c92 @@ -0,0 +1,7 @@ +// 1.20.1 2023-08-20T09:33:14.633546 Just Another Mining Dimension/JAMD World Data +e022cecafe8e7e93c9e3e503c46197cf1fb33450 data\jamd\dimension_type\mining.json +9493a2c0221f086efbb4263f171937a72c6d6992 data\jamd\worldgen\biome\end.json +ac9e79911103955c5e8d0b82bd377f175796afac data\jamd\worldgen\biome\mining.json +5015669d20cfba456749215c51c22bc7ace1d4b3 data\jamd\dimension_type\nether.json +cbc1941a40b6da486531a2010be4e6db0866e4f4 data\jamd\dimension_type\end.json +9eb37f0889d455d2929fd947bb4667057ba1b0fe data\jamd\worldgen\biome\nether.json diff --git a/common/src/generated/resources/.cache/3803046a7d7b7ce0a060be8ae0299aa98c17094c b/common/src/generated/resources/.cache/3803046a7d7b7ce0a060be8ae0299aa98c17094c new file mode 100644 index 0000000..c4a5e17 --- /dev/null +++ b/common/src/generated/resources/.cache/3803046a7d7b7ce0a060be8ae0299aa98c17094c @@ -0,0 +1,3 @@ +// 1.20.1 2023-08-20T09:33:14.6345452 Just Another Mining Dimension/Tags for minecraft:block +d21a5dcdd4b5cd0b493217e7e9e4aa477a755db8 data\minecraft\tags\blocks\mineable\pickaxe.json +d21a5dcdd4b5cd0b493217e7e9e4aa477a755db8 data\minecraft\tags\blocks\needs_diamond_tool.json diff --git a/common/src/generated/resources/.cache/4b9da48b48cbb77fa11342e113f8c9a9cb9c99c1 b/common/src/generated/resources/.cache/4b9da48b48cbb77fa11342e113f8c9a9cb9c99c1 new file mode 100644 index 0000000..58304fb --- /dev/null +++ b/common/src/generated/resources/.cache/4b9da48b48cbb77fa11342e113f8c9a9cb9c99c1 @@ -0,0 +1,7 @@ +// 1.20.1 2023-08-20T09:33:14.6350463 Just Another Mining Dimension/Recipes +6a1227f9e0b372e3546b782215347c8c76dd6f4f data\jamd\advancements\recipes\transportation\nether_portal_block.json +be575abba95e7f591761941b8ce7b15805dd16f5 data\jamd\advancements\recipes\transportation\end_portal_block.json +64a379634715c9f4ea69b6fc5a330a0008cbb33f data\jamd\recipes\portal_block.json +351ba1cdc449781ef49cc5cdb4bfdd5bc5722a13 data\jamd\recipes\nether_portal_block.json +a202bbb60a616a623a317c3b0902f18436701002 data\jamd\recipes\end_portal_block.json +8be629b04926b089b8c6acc497e9fed86ca0ae1b data\jamd\advancements\recipes\transportation\portal_block.json diff --git a/common/src/generated/resources/.cache/e360e4cfe8a52d2933ccfa99feb357854d82856f b/common/src/generated/resources/.cache/e360e4cfe8a52d2933ccfa99feb357854d82856f new file mode 100644 index 0000000..08af990 --- /dev/null +++ b/common/src/generated/resources/.cache/e360e4cfe8a52d2933ccfa99feb357854d82856f @@ -0,0 +1,4 @@ +// 1.20.1 2023-08-20T09:33:14.633546 Just Another Mining Dimension/Block Loot Tables +d02ea46f3e4060ea18cb73c3b3fe1f1738d4e47c data\jamd\loot_tables\blocks\portal_block.json +8f213054226c115851779a7dd3fb5e0cfb8323f9 data\jamd\loot_tables\blocks\end_portal.json +d4122e44c4d0d50740cfa507d4d05078c7163a7d data\jamd\loot_tables\blocks\nether_portal.json diff --git a/common/src/generated/resources/data/jamd/recipes/end_portal_block.json b/common/src/generated/resources/data/jamd/recipes/end_portal_block.json deleted file mode 100644 index 4dd61f9..0000000 --- a/common/src/generated/resources/data/jamd/recipes/end_portal_block.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "type": "minecraft:crafting_shaped", - "category": "misc", - "key": { - "O": { - "item": "minecraft:end_stone" - }, - "P": { - "item": "minecraft:diamond_pickaxe" - } - }, - "pattern": [ - "OOO", - "OPO", - "OOO" - ], - "result": { - "item": "jamd:end_portal" - }, - "show_notification": true -} \ No newline at end of file diff --git a/common/src/generated/resources/data/jamd/recipes/nether_portal_block.json b/common/src/generated/resources/data/jamd/recipes/nether_portal_block.json deleted file mode 100644 index e3176f4..0000000 --- a/common/src/generated/resources/data/jamd/recipes/nether_portal_block.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "type": "minecraft:crafting_shaped", - "category": "misc", - "key": { - "O": { - "item": "minecraft:nether_bricks" - }, - "P": { - "item": "minecraft:netherite_pickaxe" - } - }, - "pattern": [ - "OOO", - "OPO", - "OOO" - ], - "result": { - "item": "jamd:nether_portal" - }, - "show_notification": true -} \ No newline at end of file diff --git a/common/src/generated/resources/data/jamd/recipes/portal_block.json b/common/src/generated/resources/data/jamd/recipes/portal_block.json deleted file mode 100644 index 88de21a..0000000 --- a/common/src/generated/resources/data/jamd/recipes/portal_block.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "type": "minecraft:crafting_shaped", - "category": "misc", - "key": { - "O": { - "item": "minecraft:obsidian" - }, - "P": { - "item": "minecraft:diamond_pickaxe" - } - }, - "pattern": [ - "OOO", - "OPO", - "OOO" - ], - "result": { - "item": "jamd:portal_block" - }, - "show_notification": true -} \ No newline at end of file diff --git a/common/src/generated/resources/data/jamd/worldgen/biome/mining.json b/common/src/generated/resources/data/jamd/worldgen/biome/mining.json index 6e6cba1..231017d 100644 --- a/common/src/generated/resources/data/jamd/worldgen/biome/mining.json +++ b/common/src/generated/resources/data/jamd/worldgen/biome/mining.json @@ -14,27 +14,7 @@ [], [], [], - [ - "minecraft:ore_coal_upper", - "minecraft:ore_coal_lower", - "minecraft:ore_iron_upper", - "minecraft:ore_iron_middle", - "minecraft:ore_iron_small", - "minecraft:ore_gold", - "minecraft:ore_gold_lower", - "minecraft:ore_redstone", - "minecraft:ore_redstone_lower", - "minecraft:ore_diamond", - "minecraft:ore_diamond_large", - "minecraft:ore_diamond_buried", - "minecraft:ore_lapis", - "minecraft:ore_lapis_buried", - "minecraft:ore_copper", - "minecraft:underwater_magma", - "minecraft:ore_emerald", - "minecraft:ore_copper_large", - "minecraft:ore_tuff" - ] + [] ], "has_precipitation": true, "spawn_costs": {}, diff --git a/common/src/generated/resources/data/jamd/worldgen/biome/nether.json b/common/src/generated/resources/data/jamd/worldgen/biome/nether.json index 98ffbfa..a0d148c 100644 --- a/common/src/generated/resources/data/jamd/worldgen/biome/nether.json +++ b/common/src/generated/resources/data/jamd/worldgen/biome/nether.json @@ -32,14 +32,7 @@ [], [], [], - [ - "minecraft:ore_gravel_nether", - "minecraft:ore_blackstone", - "minecraft:ore_gold_nether", - "minecraft:ore_quartz_nether", - "minecraft:ore_ancient_debris_large", - "minecraft:ore_debris_small" - ] + [] ], "has_precipitation": false, "spawn_costs": {}, diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java b/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java new file mode 100644 index 0000000..9783ec8 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java @@ -0,0 +1,12 @@ +package com.unrealdinnerbone.jamd; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import java.util.List; + +public record ConfigCodec(List ores) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.list(OresCodec.CODEC).fieldOf("ores").forGetter(ConfigCodec::ores) + ).apply(instance, ConfigCodec::new)); +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/DefaultConfig.java b/common/src/main/java/com/unrealdinnerbone/jamd/DefaultConfig.java deleted file mode 100644 index 0ecd558..0000000 --- a/common/src/main/java/com/unrealdinnerbone/jamd/DefaultConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -//package com.unrealdinnerbone.jamd; -// -//import net.minecraft.world.level.levelgen.GenerationStep; -// -//import java.util.ArrayList; -//import java.util.List; -// -//public class DefaultConfig -//{ -// public static final List CONFIGS = new ArrayList<>(); -// -// static { -// CONFIGS.add(ModConfig.builder("minecraft") -// .biome(JAMDRegistry.Keys.BIOME, builder -> builder -// .settings(GenerationStep.Decoration.UNDERGROUND_ORES, -// generation -> generation.values( -// "minecraft:ore_coal_upper", -// "minecraft:ore_coal_lower", -// "minecraft:ore_iron_upper", -// "minecraft:ore_iron_middle", -// "minecraft:ore_iron_small", -// "minecraft:ore_gold", -// "minecraft:ore_gold_lower", -// "minecraft:ore_redstone", -// "minecraft:ore_redstone_lower", -// "minecraft:ore_diamond", -// "minecraft:ore_diamond_large", -// "minecraft:ore_diamond_buried", -// "minecraft:ore_lapis", -// "minecraft:ore_lapis_buried", -// "minecraft:ore_copper", -// "minecraft:underwater_magma", -// "minecraft:ore_emerald", -// "minecraft:ore_copper_large", -// "minecraft:ore_tuff")) -// .settings(GenerationStep.Decoration.LOCAL_MODIFICATIONS, generation -> -// generation.values("minecraft:amethyst_geode")) -// ) -// .build()); -// } -//} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java b/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java index c41a9c0..c1e3ecd 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java @@ -1,16 +1,89 @@ package com.unrealdinnerbone.jamd; -import com.unrealdinnerbone.config.ConfigManager; -import com.unrealdinnerbone.trenzalore.api.config.ConfigManger; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import com.unrealdinnerbone.jamd.util.Transformers; +import com.unrealdinnerbone.trenzalore.api.platform.Services; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; public class JAMD { + private static final Logger LOGGER = LoggerFactory.getLogger(JAMD.class); + + public static final Path CONFIG_FOLDER = Services.PLATFORM.getConfigPath().resolve("jamd"); public static final String MOD_ID = "jamd"; - private static final ConfigManager CONFIG_MANAGER = ConfigManger.createConfigManager(MOD_ID); - public static final JamdConfig CONFIG = CONFIG_MANAGER.loadConfig("general", JamdConfig::new); + public static final Map, Map> REGISTERED_FEATURES = new HashMap<>(); + + + private static final List DIM_TYPES = Arrays.asList("mining", "nether", "end"); public static void init() { + try { + createFiles(); + }catch (IOException e) { + LOGGER.error("Failed to create config files", e); + return; + } + for (String dimType : DIM_TYPES) { + try { + String jsonString = Files.readString(CONFIG_FOLDER.resolve(dimType + ".json")); + JsonElement parse = new JsonParser().parse(jsonString); + DataResult data = ConfigCodec.CODEC.parse(JsonOps.INSTANCE, parse); + if(data.error().isPresent()) { + LOGGER.error("Failed to parse config: {}", data.error().get().message()); + return; + } + Optional result = data.result(); + if(result.isPresent()) { + Map placedFeatureMap = new HashMap<>(); + ConfigCodec configCodec = result.get(); + for (OresCodec ore : configCodec.ores()) { + if(placedFeatureMap.containsKey(ore.id())) { + LOGGER.error("Duplicate ore: {} found in config {}", ore.id(), dimType); + continue; + } + placedFeatureMap.put(ore.id(), Transformers.fromConfigCodec(ore)); + LOGGER.debug("Registered ore: {} for dim type: {}", ore.id(), dimType); + } + REGISTERED_FEATURES.put(ResourceKey.create(Registries.BIOME, new ResourceLocation(MOD_ID, dimType)), placedFeatureMap); + } + }catch (IOException e) { + LOGGER.error("Failed to load config for dim type: {}", dimType, e); + } + } } + private static void createFiles() throws IOException { + if(!Files.exists(CONFIG_FOLDER)) { + Files.createDirectories(CONFIG_FOLDER); + } + for (String dimType : DIM_TYPES) { + Path path = CONFIG_FOLDER.resolve(dimType + ".json"); + if(!Files.exists(path)) { + InputStream defaultConfig = JAMD.class.getResourceAsStream("/defaults/" + dimType + ".json"); + if(defaultConfig != null) { + Files.copy(defaultConfig, path); + }else { + throw new IOException("Failed to find default config for: " + dimType); + } + } + } + } + + } \ No newline at end of file diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java b/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java index 2e1f9b3..d47c326 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java @@ -22,6 +22,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.ApiStatus; import java.util.List; diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/JamdConfig.java b/common/src/main/java/com/unrealdinnerbone/jamd/JamdConfig.java deleted file mode 100644 index 934f1c9..0000000 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JamdConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.unrealdinnerbone.jamd; - -import com.unrealdinnerbone.config.ConfigCreator; -import com.unrealdinnerbone.config.config.BooleanConfig; -import com.unrealdinnerbone.config.config.ListConfig; - -public class JamdConfig { - - private final BooleanConfig dynamicOreAdditionConfig; - private final ListConfig blackListedOresConfig; - - private final ListConfig additionalOresConfig; - public JamdConfig(ConfigCreator configCreator) { - dynamicOreAdditionConfig = configCreator.createBoolean("dynamicOreAddition", true); - blackListedOresConfig = configCreator.createList("blackListedOres", new String[]{ - "minecraft:ore_gold_deltas", - "minecraft:ore_infested", - "minecraft:ore_magma", - "minecraft:ore_gravel", - "minecraft:ore_soul_sand", - "minecraft:ore_gold_extra", - "minecraft:ore_quartz_nether", - "minecraft:ore_gold_nether", - "minecraft:ore_quartz_deltas", - "minecraft:ore_gravel_nether", - "minecraft:ore_dirt", - "minecraft:ore_blackstone", - "minecraft:ore_andesite_upper", - "minecraft:ore_clay", - "enlightened_end:.*" - }, String[].class); - additionalOresConfig = configCreator.createList("additionalOres", new String[]{}, String[].class); - } - - public BooleanConfig getDynamicOreAdditionConfig() { - return dynamicOreAdditionConfig; - } - - public ListConfig getBlackListedOresConfig() { - return blackListedOresConfig; - } - - public ListConfig getAdditionalOresConfig() { - return additionalOresConfig; - } -} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/ModConfig.java b/common/src/main/java/com/unrealdinnerbone/jamd/ModConfig.java deleted file mode 100644 index 9831b3c..0000000 --- a/common/src/main/java/com/unrealdinnerbone/jamd/ModConfig.java +++ /dev/null @@ -1,94 +0,0 @@ -//package com.unrealdinnerbone.jamd; -// -//import net.minecraft.resources.ResourceKey; -//import net.minecraft.world.level.biome.Biome; -//import net.minecraft.world.level.levelgen.GenerationStep; -// -//import java.util.ArrayList; -//import java.util.Collections; -//import java.util.List; -//import java.util.function.Consumer; -// -//public record ModConfig(String modid, List dimensions) { -// public record DimensionSettings(String biome, List settings) { -// -// public record GenerationSettings(String decoration, List values) { -// -// public static GenerationSettings of(GenerationStep.Decoration decoration, List values) { -// return new GenerationSettings(decoration.name().toLowerCase(), values); -// } -// } -// } -// -// //create builder -// public static class Builder { -// private final String modid; -// private final List dimensions; -// -// public Builder(String modid) { -// this.modid = modid; -// this.dimensions = new ArrayList<>(); -// } -// -// public Builder biome(ResourceKey biomeResourceKey, Consumer builder) { -// BiomeSettingsBuilder dimensionSettingsBuilder = new BiomeSettingsBuilder(biomeResourceKey); -// builder.accept(dimensionSettingsBuilder); -// dimensions.add(dimensionSettingsBuilder.build()); -// return this; -// } -// -// public ModConfig build() { -// return new ModConfig(modid, dimensions); -// } -// -// } -// public static Builder builder(String modid) { -// return new Builder(modid); -// } -// -// public static class BiomeSettingsBuilder { -// private final String biome; -// private final List settings; -// -// public BiomeSettingsBuilder(ResourceKey biomeResourceKey) { -// this.biome = biomeResourceKey.location().toString(); -// this.settings = new ArrayList<>(); -// } -// -// public BiomeSettingsBuilder settings(GenerationStep.Decoration decoration, Consumer builder) { -// GenerationSettingsBuilder generationSettingsBuilder = new GenerationSettingsBuilder(decoration); -// builder.accept(generationSettingsBuilder); -// settings.add(generationSettingsBuilder.build()); -// return this; -// } -// -// public DimensionSettings build() { -// return new DimensionSettings(biome, settings); -// } -// -// } -// public static class GenerationSettingsBuilder { -// private final String decoration; -// private final List values; -// -// public GenerationSettingsBuilder(GenerationStep.Decoration decoration) { -// this.decoration = decoration.getSerializedName(); -// this.values = new ArrayList<>(); -// } -// -// public GenerationSettingsBuilder values(List values) { -// this.values.addAll(values); -// return this; -// } -// -// public GenerationSettingsBuilder values(String... values) { -// Collections.addAll(this.values, values); -// return this; -// } -// -// public DimensionSettings.GenerationSettings build() { -// return new DimensionSettings.GenerationSettings(decoration, values); -// } -// -// } -//} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java b/common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java new file mode 100644 index 0000000..9d1edf4 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java @@ -0,0 +1,52 @@ +package com.unrealdinnerbone.jamd; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.StringRepresentable; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +public record OresCodec( + String id, + int oreSize, + int oreAmount, + float discardChance, + Optional minY, + Optional maxY, + PlacementType placementType, + List targets) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.fieldOf("id").forGetter(OresCodec::id), + Codec.INT.fieldOf("ore_size").forGetter(OresCodec::oreSize), + Codec.INT.fieldOf("ore_amount").forGetter(OresCodec::oreAmount), + Codec.FLOAT.fieldOf("discard_on_air_chance").forGetter(OresCodec::discardChance), + Codec.INT.optionalFieldOf("min_y").forGetter(OresCodec::minY), + Codec.INT.optionalFieldOf("max_y").forGetter(OresCodec::maxY), + PlacementType.CODEC.fieldOf("placement_type").forGetter(OresCodec::placementType), + Codec.list(OreConfiguration.TargetBlockState.CODEC).fieldOf("targets").forGetter(OresCodec::targets) + ).apply(instance, OresCodec::new)); + + + public static enum PlacementType implements StringRepresentable { + UNIFORM("uniform"), + TRIANGLE("triangle"), + ; + + public static final Codec CODEC = StringRepresentable.fromEnum(PlacementType::values); + private final String name; + + PlacementType(String name) { + this.name = name; + } + + + @Override + @NotNull + public String getSerializedName() { + return name; + } + } +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java b/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java new file mode 100644 index 0000000..3ef825e --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java @@ -0,0 +1,135 @@ +package com.unrealdinnerbone.jamd.command; + +import com.google.gson.*; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.LiteralMessage; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import com.unrealdinnerbone.jamd.JAMD; +import com.unrealdinnerbone.jamd.OresCodec; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class JamdCommand { + + private static final Logger LOGGER = LoggerFactory.getLogger(JamdCommand.class); + private static final SimpleCommandExceptionType NO_FEATURES = new SimpleCommandExceptionType(() -> "Can't create placed feature lookup"); + + private static final DynamicCommandExceptionType INVALID_TARGET = new DynamicCommandExceptionType((s) -> new LiteralMessage("Can't parse targets: " + s)); + + private static final DynamicCommandExceptionType CANT_COVERT = new DynamicCommandExceptionType((s) -> new LiteralMessage("Can't convert ores to json: " + s)); + + private static final DynamicCommandExceptionType CANT_SAVE_FILE = new DynamicCommandExceptionType((s) -> new LiteralMessage("Can't save command.json: " + s)); + public static void register(CommandDispatcher commandDispatcher) { + commandDispatcher.register(Commands.literal("jamd") + .then(Commands.literal("export") + .executes(JamdCommand::export))); + + } + + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + private static int export(CommandContext source) throws CommandSyntaxException { + MinecraftServer server = source.getSource().getServer(); + HolderLookup.RegistryLookup lookup = server.registryAccess().lookup(Registries.PLACED_FEATURE).orElseThrow(NO_FEATURES::create); + List oresCodecs = new ArrayList<>(); + for (Holder.Reference placedFeatureReference : lookup.listElements().toList()) { + String id = placedFeatureReference.key().location().getPath(); + DataResult json = PlacedFeature.DIRECT_CODEC.encodeStart(JsonOps.INSTANCE, placedFeatureReference.value()); + if(json.result().isPresent()) { + try { + JsonElement jsonElement = json.result().get(); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + JsonObject feature = jsonObject.getAsJsonObject("feature"); + String featureType = GsonHelper.getAsString(feature, "type"); + if(featureType.equals("minecraft:ore")) { + JsonObject config = GsonHelper.getAsJsonObject(feature, "config"); + JsonArray targets = GsonHelper.getAsJsonArray(config, "targets"); + DataResult> result = Codec.list(OreConfiguration.TargetBlockState.CODEC).parse(JsonOps.INSTANCE, targets); + if(result.error().isPresent()) { + throw INVALID_TARGET.create(result.error().get().message()); + } + List targetBlockState = result.result().get(); + int size = GsonHelper.getAsInt(config, "size"); + int discord = GsonHelper.getAsInt(config, "discard_chance_on_air_exposure"); + JsonArray placement = GsonHelper.getAsJsonArray(jsonObject, "placement"); + Integer minY = null; + Integer maxY = null; + Integer count = null; + OresCodec.PlacementType placementType = null; + for (JsonElement element : placement) { + String type = GsonHelper.getAsString(element.getAsJsonObject(), "type"); + if(type.equals("minecraft:count")) { + count = GsonHelper.getAsInt(element.getAsJsonObject(), "count"); + } + if(type.equals("minecraft:height_range")) { + JsonObject height = GsonHelper.getAsJsonObject(element.getAsJsonObject(), "height"); + JsonObject asJsonObject = GsonHelper.getAsJsonObject(height, "min_inclusive"); + if(asJsonObject.has("absolute")) { + minY = GsonHelper.getAsInt(asJsonObject, "absolute"); + }else if(asJsonObject.has("above_bottom")) { + minY = GsonHelper.getAsInt(asJsonObject, "above_bottom"); + } + JsonObject asJsonObject1 = GsonHelper.getAsJsonObject(height, "max_inclusive"); + if(asJsonObject1.has("absolute")) { + maxY = GsonHelper.getAsInt(asJsonObject1, "absolute"); + } else if(asJsonObject1.has("below_top")) { + maxY = GsonHelper.getAsInt(asJsonObject1, "below_top"); + } + String placementTypeString = GsonHelper.getAsString(height, "type"); + if(placementTypeString.equals("minecraft:uniform")) { + placementType = OresCodec.PlacementType.UNIFORM; + }else if(placementTypeString.equals("minecraft:trapezoid")) { + placementType = OresCodec.PlacementType.TRIANGLE; + } + } + } + if(minY != null && maxY != null && count != null && placementType != null) { + oresCodecs.add(new OresCodec(id, size, count, discord, Optional.of(minY), Optional.of(maxY), placementType, targetBlockState)); + } + }else { + if(featureType.equals("minecraft:scattered_ore")) { + LOGGER.info("{}", featureType); + } + } + }catch (JsonSyntaxException e) { + LOGGER.error("Skipping ore: {} because of error: {}", id, e); + } + + } + } + DataResult result = Codec.list(OresCodec.CODEC).encodeStart(JsonOps.INSTANCE, oresCodecs); + if(result.result().isPresent()) { + try { + Files.writeString(JAMD.CONFIG_FOLDER.resolve("command.json"), GSON.toJson(result.result().get())); + source.getSource().sendSuccess(() -> Component.literal("Generated command.json"), true); + } catch (IOException e) { + throw CANT_SAVE_FILE.create(e.getMessage()); + } + }else { + throw CANT_COVERT.create(result.error().get().message()); + } + return 0; + } +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java b/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java new file mode 100644 index 0000000..9d7d6b4 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java @@ -0,0 +1,32 @@ +package com.unrealdinnerbone.jamd.util; + +import com.unrealdinnerbone.jamd.OresCodec; +import net.minecraft.core.Holder; +import net.minecraft.world.level.levelgen.VerticalAnchor; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import net.minecraft.world.level.levelgen.placement.*; + +import java.util.ArrayList; +import java.util.List; + +public class Transformers { + + public static PlacedFeature fromConfigCodec(OresCodec oresCodec) { + ConfiguredFeature> oreFeature = new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(oresCodec.targets(), oresCodec.oreSize(), oresCodec.discardChance())); + List placementModifiers = new ArrayList<>(); + placementModifiers.add(CountPlacement.of(oresCodec.oreAmount())); + placementModifiers.add(InSquarePlacement.spread()); + VerticalAnchor min = oresCodec.minY().isPresent() ? VerticalAnchor.absolute(oresCodec.minY().get()) : VerticalAnchor.bottom(); + VerticalAnchor max = oresCodec.maxY().isPresent() ? VerticalAnchor.absolute(oresCodec.maxY().get()) : VerticalAnchor.top(); + HeightRangePlacement modifier = switch (oresCodec.placementType()) { + case UNIFORM -> HeightRangePlacement.uniform(min, max); + case TRIANGLE -> HeightRangePlacement.triangle(min, max); + }; + placementModifiers.add(modifier); + + placementModifiers.add(BiomeFilter.biome()); + return new PlacedFeature(Holder.direct(oreFeature), placementModifiers); + } +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelGeneratorSettings.java b/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelGeneratorSettings.java new file mode 100644 index 0000000..debb9f8 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelGeneratorSettings.java @@ -0,0 +1,66 @@ +package com.unrealdinnerbone.jamd.world; + +import com.mojang.datafixers.kinds.Applicative; +import com.mojang.logging.LogUtils; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.unrealdinnerbone.jamd.JAMD; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.RegistryCodecs; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.placement.MiscOverworldPlacements; +import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.flat.FlatLayerInfo; +import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.structure.StructureSet; + +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class CustomFlatLevelGeneratorSettings extends FlatLevelGeneratorSettings { + + public static final Codec CODEC = RecordCodecBuilder.create((instance) -> + instance.group(Biome.CODEC + .fieldOf("biome") + .forGetter(FlatLevelGeneratorSettings::getBiome), + FlatLayerInfo.CODEC.listOf().fieldOf("layers").forGetter(CustomFlatLevelGeneratorSettings::getLayersInfo)) + .apply(instance, instance.stable(CustomFlatLevelGeneratorSettings::create))); + + public static CustomFlatLevelGeneratorSettings create(Holder holder, List layersInfo) { + return new CustomFlatLevelGeneratorSettings(holder, layersInfo); + } + + @Override + public BiomeGenerationSettings adjustGenerationSettings(Holder holder) { + if(!holder.equals(this.biome)) { + return holder.value().getGenerationSettings(); + } + BiomeGenerationSettings.PlainBuilder plainBuilder = new BiomeGenerationSettings.PlainBuilder(); + Optional> biomeResourceKey = this.biome.unwrapKey(); + if(biomeResourceKey.isPresent()) { + for (PlacedFeature registeredFeature : JAMD.REGISTERED_FEATURES.get(biomeResourceKey.get()).values()) { + plainBuilder.addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, Holder.direct(registeredFeature)); + } + } + return plainBuilder.build(); + } + + public CustomFlatLevelGeneratorSettings( Holder holder, List infos) { + super(Optional.empty(), holder, List.of()); + getLayersInfo().clear(); + getLayersInfo().addAll(infos); + updateLayers(); + } + +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelSource.java b/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelSource.java index 6a4bed7..da74706 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelSource.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelSource.java @@ -5,17 +5,27 @@ import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings; +import org.jetbrains.annotations.NotNull; public class CustomFlatLevelSource extends FlatLevelSource { + private final CustomFlatLevelGeneratorSettings mySettings; + public static final Codec CODEC = RecordCodecBuilder.create((instance) -> - instance.group(FlatLevelGeneratorSettings.CODEC + instance.group(CustomFlatLevelGeneratorSettings.CODEC .fieldOf("settings") .forGetter(CustomFlatLevelSource::settings)) .apply(instance, instance.stable(CustomFlatLevelSource::new))); - public CustomFlatLevelSource(FlatLevelGeneratorSettings settings) { + public CustomFlatLevelSource(CustomFlatLevelGeneratorSettings settings) { super(settings); + this.mySettings = settings; + } + + @Override + @NotNull + public CustomFlatLevelGeneratorSettings settings() { + return mySettings; } @Override diff --git a/common/src/main/resources/data/jamd/dimension/mining.json b/common/src/main/resources/data/jamd/dimension/mining.json index 1041c40..5df1ea9 100644 --- a/common/src/main/resources/data/jamd/dimension/mining.json +++ b/common/src/main/resources/data/jamd/dimension/mining.json @@ -4,8 +4,6 @@ "type": "jamd:mining", "settings": { "biome": "jamd:mining", - "lakes": false, - "features": true, "layers": [ { "block": "minecraft:bedrock", diff --git a/common/src/main/resources/defaults/end.json b/common/src/main/resources/defaults/end.json new file mode 100644 index 0000000..ec18392 --- /dev/null +++ b/common/src/main/resources/defaults/end.json @@ -0,0 +1,5 @@ +{ + "ores": [ + + ] +} \ No newline at end of file diff --git a/common/src/main/resources/defaults/mining.json b/common/src/main/resources/defaults/mining.json new file mode 100644 index 0000000..78793ef --- /dev/null +++ b/common/src/main/resources/defaults/mining.json @@ -0,0 +1,392 @@ +{ + "ores": [ + { + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:base_stone_overworld", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:andesite" + } + } + ], + "id": "ore_andesite_lower", + "ore_size": 64, + "ore_amount": 2, + "discard_on_air_chance": 0.0 + }, + { + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:base_stone_overworld", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:clay" + } + } + ], + "id": "ore_clay", + "ore_size": 33, + "ore_amount": 4, + "discard_on_air_chance": 0.0 + }, + { + "placement_type": "triangle", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:coal_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_coal_ore" + } + } + ], + "id": "ore_coal", + "ore_size": 17, + "ore_amount": 50, + "discard_on_air_chance": 0.0 + }, + { + "min_y": -16, + "max_y": 112, + "placement_type": "triangle", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:copper_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_copper_ore" + } + } + ], + "id": "ore_copper", + "ore_size": 10, + "ore_amount": 32, + "discard_on_air_chance": 0.0 + }, + { + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:base_stone_overworld", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:diorite" + } + } + ], + "id": "ore_diorite", + "ore_size": 64, + "ore_amount": 2, + "discard_on_air_chance": 0.0 + }, + { + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:base_stone_overworld", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:dirt" + } + } + ], + "id": "ore_dirt", + "ore_size": 33, + "ore_amount": 7, + "discard_on_air_chance": 0.0 + }, + { + "min_y": -16, + "placement_type": "triangle", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:emerald_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_emerald_ore" + } + } + ], + "id": "ore_emerald", + "ore_size": 3, + "ore_amount": 100, + "discard_on_air_chance": 0.0 + }, + { + "min_y": -64, + "max_y": 32, + "placement_type": "triangle", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:gold_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_gold_ore" + } + } + ], + "id": "ore_gold", + "ore_size": 9, + "ore_amount": 4, + "discard_on_air_chance": 0.0 + }, + { + "min_y": 0, + "max_y": 60, + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:base_stone_overworld", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:granite" + } + } + ], + "id": "ore_granite_lower", + "ore_size": 64, + "ore_amount": 2, + "discard_on_air_chance": 0.0 + }, + { + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:base_stone_overworld", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:gravel" + } + } + ], + "id": "ore_gravel", + "ore_size": 33, + "ore_amount": 14, + "discard_on_air_chance": 0.0 + }, + { + "min_y": -24, + "max_y": 56, + "placement_type": "triangle", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:iron_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_iron_ore" + } + } + ], + "id": "ore_iron_middle", + "ore_size": 9, + "ore_amount": 10, + "discard_on_air_chance": 0.0 + }, + { + "max_y": 72, + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:iron_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_iron_ore" + } + } + ], + "id": "ore_iron_small", + "ore_size": 4, + "ore_amount": 10, + "discard_on_air_chance": 0.0 + }, + { + "placement_type": "triangle", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:iron_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_iron_ore" + } + } + ], + "id": "ore_iron_upper", + "ore_size": 9, + "ore_amount": 90, + "discard_on_air_chance": 0.0 + }, + { + "min_y": -32, + "max_y": 64, + "placement_type": "triangle", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:lapis_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:deepslate_lapis_ore" + } + } + ], + "id": "ore_lapis", + "ore_size": 7, + "ore_amount": 6, + "discard_on_air_chance": 0.0 + }, + { + "max_y": 15, + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:stone_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Properties": { + "lit": "false" + }, + "Name": "minecraft:redstone_ore" + } + }, + { + "target": { + "tag": "minecraft:deepslate_ore_replaceables", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Properties": { + "lit": "false" + }, + "Name": "minecraft:deepslate_redstone_ore" + } + } + ], + "id": "ore_redstone", + "ore_size": 8, + "ore_amount": 4, + "discard_on_air_chance": 0.0 + }, + { + "placement_type": "uniform", + "targets": [ + { + "target": { + "tag": "minecraft:base_stone_overworld", + "predicate_type": "minecraft:tag_match" + }, + "state": { + "Name": "minecraft:tuff" + } + } + ], + "id": "ore_tuff", + "ore_size": 64, + "ore_amount": 2, + "discard_on_air_chance": 0.0 + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/defaults/nether.json b/common/src/main/resources/defaults/nether.json new file mode 100644 index 0000000..090d752 --- /dev/null +++ b/common/src/main/resources/defaults/nether.json @@ -0,0 +1,124 @@ +{ + "ores": [ + { + "min_y": 0, + "max_y": 128, + "placement_type": "uniform", + "targets": [ + { + "target": { + "block": "minecraft:netherrack", + "predicate_type": "minecraft:block_match" + }, + "state": { + "Name": "minecraft:glowstone" + } + } + ], + "id": "ore_blackstone", + "ore_size": 16, + "ore_amount": 8, + "discard_on_air_chance": 0.0 + }, + { + "min_y": 5, + "max_y": 220, + "placement_type": "uniform", + "targets": [ + { + "target": { + "block": "minecraft:netherrack", + "predicate_type": "minecraft:block_match" + }, + "state": { + "Name": "minecraft:blackstone" + } + } + ], + "id": "ore_blackstone", + "ore_size": 33, + "ore_amount": 2, + "discard_on_air_chance": 0.0 + }, + { + "min_y": 10, + "max_y": 255, + "placement_type": "uniform", + "targets": [ + { + "target": { + "block": "minecraft:netherrack", + "predicate_type": "minecraft:block_match" + }, + "state": { + "Name": "minecraft:nether_gold_ore" + } + } + ], + "id": "ore_gold_nether", + "ore_size": 10, + "ore_amount": 10, + "discard_on_air_chance": 0.0 + }, + { + "min_y": 27, + "max_y": 36, + "placement_type": "uniform", + "targets": [ + { + "target": { + "block": "minecraft:netherrack", + "predicate_type": "minecraft:block_match" + }, + "state": { + "Name": "minecraft:magma_block" + } + } + ], + "id": "ore_magma", + "ore_size": 33, + "ore_amount": 4, + "discard_on_air_chance": 0.0 + }, + { + "min_y": 10, + "max_y": 255, + "placement_type": "uniform", + "targets": [ + { + "target": { + "block": "minecraft:netherrack", + "predicate_type": "minecraft:block_match" + }, + "state": { + "Name": "minecraft:nether_quartz_ore" + } + } + ], + "id": "ore_quartz_nether", + "ore_size": 14, + "ore_amount": 16, + "discard_on_air_chance": 0.0 + }, + { + "min_y": 0, + "max_y": 31, + "placement_type": "uniform", + "targets": [ + { + "target": { + "block": "minecraft:netherrack", + "predicate_type": "minecraft:block_match" + }, + "state": { + "Name": "minecraft:soul_sand" + } + } + ], + "id": "ore_soul_sand", + "ore_size": 12, + "ore_amount": 12, + "discard_on_air_chance": 0.0 + } + ] +} \ No newline at end of file diff --git a/common/src/main/resources/jamd.accesswidener b/common/src/main/resources/jamd.accesswidener new file mode 100644 index 0000000..481e1f4 --- /dev/null +++ b/common/src/main/resources/jamd.accesswidener @@ -0,0 +1,6 @@ +accessWidener v1 named +accessible field net/minecraft/world/level/levelgen/flat/FlatLevelGeneratorSettings biome Lnet/minecraft/core/Holder; +accessible method net/minecraft/world/level/levelgen/feature/configurations/OreConfiguration$TargetBlockState (Lnet/minecraft/world/level/levelgen/structure/templatesystem/RuleTest;Lnet/minecraft/world/level/block/state/BlockState;)V +accessible field net/minecraft/world/level/levelgen/placement/HeightRangePlacement height Lnet/minecraft/world/level/levelgen/heightproviders/HeightProvider; +accessible field net/minecraft/world/level/levelgen/placement/CountPlacement count Lnet/minecraft/util/valueproviders/IntProvider; +accessible field net/minecraft/world/level/levelgen/heightproviders/ConstantHeight value Lnet/minecraft/world/level/levelgen/VerticalAnchor; \ No newline at end of file diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java index 81f3a59..0810dcb 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java @@ -1,10 +1,15 @@ package com.unrealdinnerbone.jamd; +import com.unrealdinnerbone.jamd.command.JamdCommand; +import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; public class JAMDFabric implements ModInitializer { + @Override public void onInitialize() { - JAMD.init(); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> JamdCommand.register(dispatcher)); } + } diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java index 00bd3ca..6a4b3a4 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java @@ -1,16 +1,22 @@ package com.unrealdinnerbone.jamd.data; +import com.unrealdinnerbone.jamd.JAMD; import com.unrealdinnerbone.jamd.JAMDRegistry; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; +import net.minecraft.core.Holder; import net.minecraft.core.HolderGetter; import net.minecraft.core.RegistrySetBuilder; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BiomeDefaultFeatures; import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.data.worldgen.biome.OverworldBiomes; +import net.minecraft.data.worldgen.features.OreFeatures; import net.minecraft.data.worldgen.placement.NetherPlacements; import net.minecraft.data.worldgen.placement.OrePlacements; +import net.minecraft.data.worldgen.placement.PlacementUtils; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Musics; import net.minecraft.sounds.SoundEvents; import net.minecraft.tags.BlockTags; @@ -19,7 +25,10 @@ import net.minecraft.world.level.dimension.BuiltinDimensionTypes; import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.VerticalAnchor; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.placement.HeightRangePlacement; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import java.util.OptionalLong; diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/ModelProvider.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/ModelProvider.java index f3e321d..53ddeb0 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/ModelProvider.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/ModelProvider.java @@ -5,6 +5,7 @@ import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider; import net.minecraft.data.models.BlockModelGenerators; import net.minecraft.data.models.ItemModelGenerators; +import net.minecraft.world.item.CreativeModeTab; public class ModelProvider extends FabricModelProvider { diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 6b4e2b3..7987d37 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ "environment": "*", "entrypoints": { "main": [ - "com.unrealdinnerbone.jamd.JAMD::init" + "com.unrealdinnerbone.jamd.JAMDFabric" ], "fabric-datagen": [ "com.unrealdinnerbone.jamd.data.JAMDData" diff --git a/forge/build.gradle b/forge/build.gradle index 77fd279..c23de93 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -15,6 +15,9 @@ repositories { maven { url "https://cursemaven.com" } + maven { + url "https://maven.nanite.dev/releases" + } } @@ -23,6 +26,9 @@ dependencies { transitive = true } minecraftLibrary ("com.unrealdinnerbone:UnRealConfig-gson:12.3.4") + runtimeOnly fg.deobf("com.sunekaer.mods:ToolKit-forge:3.0.2-build.23+mc1.20.1") + runtimeOnly fg.deobf("dev.architectury:architectury-forge:9.0.8") + } diff --git a/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java b/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java index 31334f9..12a645b 100644 --- a/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java +++ b/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java @@ -1,6 +1,12 @@ package com.unrealdinnerbone.jamd; +import com.unrealdinnerbone.jamd.command.JamdCommand; import com.unrealdinnerbone.trenzalore.api.config.ConfigManger; +import net.minecraft.server.packs.PackType; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.AddPackFindersEvent; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -9,6 +15,11 @@ public class JAMDForge { public JAMDForge() { JAMD.init(); - FMLJavaModLoadingContext.get().getModEventBus().addListener(JAMDDataForge::onData); + MinecraftForge.EVENT_BUS.addListener(this::onServerStart); } + + public void onServerStart(RegisterCommandsEvent event) { + JamdCommand.register(event.getDispatcher()); + } + } \ No newline at end of file diff --git a/forge/src/main/java/com/unrealdinnerbone/jamd/biome/JAMDBiomeModifier.java b/forge/src/main/java/com/unrealdinnerbone/jamd/biome/JAMDBiomeModifier.java index c70c55b..bfe2837 100644 --- a/forge/src/main/java/com/unrealdinnerbone/jamd/biome/JAMDBiomeModifier.java +++ b/forge/src/main/java/com/unrealdinnerbone/jamd/biome/JAMDBiomeModifier.java @@ -36,92 +36,14 @@ public class JAMDBiomeModifier implements BiomeModifier { - public static final JAMDBiomeModifier INSTANCE = new JAMDBiomeModifier(); - private static final Logger LOGGER = LogUtils.getLogger(); - private final List matches; - private final boolean dynamicOreAddition; - - private final List> placedFeatures; public JAMDBiomeModifier() { - try { - dynamicOreAddition = JAMD.CONFIG.getDynamicOreAdditionConfig().getExceptionally(); - matches = Arrays.stream(JAMD.CONFIG.getBlackListedOresConfig().getExceptionally()) - .filter(Objects::nonNull) - .map(Pattern::compile) - .toList(); - placedFeatures = new ArrayList<>(); - Arrays.stream(JAMD.CONFIG.getAdditionalOresConfig().getExceptionally()) - .filter(Objects::nonNull) - .forEach(resourceLocation -> { - try { - ResourceLocation p135787 = new ResourceLocation(resourceLocation); - ResourceKey key = ResourceKey.create(Registries.PLACED_FEATURE, p135787); - placedFeatures.add(key); - }catch (Exception e) { - LOGGER.error("Failed to create key for {} ", resourceLocation, e); - } - }); - } catch (ConfigException e) { - throw new RuntimeException("Failed to load config", e); - } + } @Override public void modify(Holder biome, Phase phase, ModifiableBiomeInfo.BiomeInfo.Builder builder) { - if(dynamicOreAddition) { - if (phase == Phase.ADD) { - if(biome.is(JAMDRegistry.Keys.OVERWORLD.biome())) { - HolderLookup.RegistryLookup placedFeatureRegistryLookup = ServerLifecycleHooks.getCurrentServer().registryAccess().lookup(Registries.PLACED_FEATURE).orElseThrow(); - handle(placedFeatureRegistryLookup, builder); - }else if(biome.is(JAMDRegistry.Keys.NETHER.biome())) { - HolderLookup.RegistryLookup placedFeatureRegistryLookup = ServerLifecycleHooks.getCurrentServer().registryAccess().lookup(Registries.PLACED_FEATURE).orElseThrow(); -// List strings = JAMD.CONFIG.get().blackListNether(); - handle(placedFeatureRegistryLookup, builder); - }else if(biome.is(JAMDRegistry.Keys.END.biome())) { - HolderLookup.RegistryLookup placedFeatureRegistryLookup = ServerLifecycleHooks.getCurrentServer().registryAccess().lookup(Registries.PLACED_FEATURE).orElseThrow(); -// List strings = JAMD.CONFIG.get().blackListEnd(); - handle(placedFeatureRegistryLookup, builder); - } - } - } - } - - private void handle(HolderLookup.RegistryLookup placedFeatureRegistryLookup, ModifiableBiomeInfo.BiomeInfo.Builder builder) { - - - for (ResourceKey placedFeature : placedFeatures) { - placedFeatureRegistryLookup.get(placedFeature).ifPresent(placedFeature1 -> { - List> features = builder.getGenerationSettings().getFeatures(GenerationStep.Decoration.UNDERGROUND_ORES); - if (features.stream().noneMatch(holder -> holder.is(placedFeature))) { - LOGGER.debug("Force Adding: " + placedFeature.location()); - builder.getGenerationSettings().addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, placedFeature1); - }else { - LOGGER.debug("Skipping Force Added as it already exists: " + placedFeature.location()); - } - }); - } - - placedFeatureRegistryLookup.listElements().forEach(placedFeature -> { - if (!matches(placedFeature.key().location().toString())) { - PlacedFeature s = placedFeature.get(); - boolean isOreFeature = s.feature().get().feature() instanceof OreFeature; - if (isOreFeature) { - LOGGER.debug("Adding: " + placedFeature.key().location()); - List> features = builder.getGenerationSettings().getFeatures(GenerationStep.Decoration.UNDERGROUND_ORES); - if (features.stream().noneMatch(holder -> holder.is(placedFeature.key()))) { - builder.getGenerationSettings().addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, placedFeature); - } - } - }else { - LOGGER.debug("Blacklisted: " + placedFeature.key().location()); - } - }); - } - - private boolean matches(String value) { - return matches.stream().anyMatch(pattern -> pattern.matcher(value).matches()); } diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..5af17e0 --- /dev/null +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,5 @@ +public net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings f_70353_ +public net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration$TargetBlockState (Lnet/minecraft/world/level/levelgen/structure/templatesystem/RuleTest;Lnet/minecraft/world/level/block/state/BlockState;)V +public net.minecraft.world.level.levelgen.placement.HeightRangePlacement f_191674_ +public net.minecraft.world.level.levelgen.placement.CountPlacement f_191624_ +public net.minecraft.world.level.levelgen.heightproviders.ConstantHeight f_161947_ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae0804..db9a6b8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 13afba7..062c3a4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,10 @@ pluginManagement { repositories { gradlePluginPortal() + maven { + name = 'Neo' + url = 'https://maven.neoforged.net/releases' + } maven { name = 'Creeperhost' url = 'https://maven.creeperhost.net/'