diff --git a/CHANGELOG.md b/CHANGELOG.md index 248abb0..757a504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ -### 3.2.2 +### 3.3.0 -- Blacklist Enlightened End mod \ No newline at end of file +- Rewrite mod to better support modded / custom ores +- Added /jamd reload to reload the config +- Added configs jamd/overworld.json, jamd/nether.json, jamd/end.json +- Configs now completely controls the world generation +- Added support for ore multipliers +- Added Mekanism support \ No newline at end of file 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/worldgen/biome/mining.json b/common/src/generated/resources/data/jamd/worldgen/biome/mining.json index 6e6cba1..63dbe6e 100644 --- a/common/src/generated/resources/data/jamd/worldgen/biome/mining.json +++ b/common/src/generated/resources/data/jamd/worldgen/biome/mining.json @@ -36,7 +36,7 @@ "minecraft:ore_tuff" ] ], - "has_precipitation": true, + "has_precipitation": false, "spawn_costs": {}, "spawners": { "ambient": [], 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..e8f5a60 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java @@ -0,0 +1,13 @@ +package com.unrealdinnerbone.jamd; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import java.util.List; + +public record ConfigCodec(int oreMultiplier, List ores) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("oreMultiplier").forGetter(ConfigCodec::oreMultiplier), + 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..60576a0 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java @@ -1,16 +1,35 @@ package com.unrealdinnerbone.jamd; -import com.unrealdinnerbone.config.ConfigManager; -import com.unrealdinnerbone.trenzalore.api.config.ConfigManger; +import com.mojang.logging.LogUtils; +import com.unrealdinnerbone.jamd.api.FeatureTypeRegistry; +import com.unrealdinnerbone.jamd.compact.MinecraftOreCompact; +import com.unrealdinnerbone.jamd.util.OreRegistry; +import com.unrealdinnerbone.trenzalore.api.platform.Services; +import net.minecraft.server.MinecraftServer; +import org.slf4j.Logger; + +import java.io.IOException; +import java.nio.file.Path; public class JAMD { + private static final Logger LOGGER = LogUtils.getLogger(); + 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 void init() { + FeatureTypeRegistry.register("minecraft", MinecraftOreCompact::new); + } + public static void onServerStart(MinecraftServer server) { + OreRegistry.REGISTERED_FEATURES.clear(); + for (WorldType type : WorldType.TYPES) { + try { + type.exportIfNotExist(server); + } catch (IOException e) { + LOGGER.error("Failed to export config for world type: {}", type.getName(), e); + } + } } } \ 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..6795bd2 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java @@ -13,6 +13,8 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BiomeTags; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; @@ -22,6 +24,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; @@ -37,24 +40,21 @@ public class JAMDRegistry implements IRegistry { public static final RegistryEntry> CUSTOM_FLAT_LEVEL_SOURCE = CHUNK_GENERATORS.register("mining", () -> CustomFlatLevelSource.CODEC); - public static final RegistrySet OVERWORLD = RegistrySet.of("portal_block", "portal", OverworldPortalBlock::new, OverworldBlockEntity::new); - public static final RegistrySet NETHER = RegistrySet.of("nether_portal", NetherPortalBlock::new, NetherBlockEntity::new); + public static final WorldType OVERWORLD = of("mining", "portal_block", "portal", OverworldPortalBlock::new, OverworldBlockEntity::new, BiomeTags.IS_OVERWORLD); - public static final RegistrySet END = RegistrySet.of("end_portal", EndPortalBlock::new, EndBlockEntity::new); + public static final WorldType NETHER = of("nether", "nether_portal", "nether_portal", NetherPortalBlock::new, NetherBlockEntity::new, BiomeTags.IS_NETHER); + public static final WorldType END = of("end", "end_portal", "end_portal", EndPortalBlock::new, EndBlockEntity::new, BiomeTags.IS_END); - public static class Keys { - public static final KeySet OVERWORLD = KeySet.of(new ResourceLocation(JAMD.MOD_ID, "mining")); - - public static final KeySet NETHER = KeySet.of(new ResourceLocation(JAMD.MOD_ID, "nether")); - - public static final KeySet END = KeySet.of(new ResourceLocation(JAMD.MOD_ID, "end")); + private static WorldType of(String name, String blockName, String tileName, Supplier blockSupplier, BiFunction tileSupplier, TagKey biomeTagKey) { + RegistryEntry block = BLOCKS.register(blockName, blockSupplier); + return new WorldType(name, block, ITEMS.register(blockName, () -> new BlockItem(block.get(), new Item.Properties())), TILES.register(tileName, () -> Regeneration.createBlockEntityType(tileSupplier, block.get())), biomeTagKey); } @Override public void afterRegistered() { - Regeneration.addItemsToCreateTab(CreativeTabs.FUNCTIONAL_BLOCKS, List.of(OVERWORLD.item(), NETHER.item(), END.item())); + Regeneration.addItemsToCreateTab(CreativeTabs.FUNCTIONAL_BLOCKS, List.of(OVERWORLD.getItem(), NETHER.getItem(), END.getItem())); } @Override @@ -67,26 +67,5 @@ public String getModID() { return JAMD.MOD_ID; } - public record RegistrySet(RegistryEntry block, RegistryEntry item, RegistryEntry> blockEntity) { - private static RegistrySet of(String name, Supplier blockSupplier, BiFunction tileSupplier) { - return of(name, name, blockSupplier, tileSupplier); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "4.0.0") - private static RegistrySet of(String blockName, String tileName, Supplier blockSupplier, BiFunction tileSupplier) { - RegistryEntry block = BLOCKS.register(blockName, blockSupplier); - RegistryEntry itemBlock = ITEMS.register(blockName, () -> new BlockItem(block.get(), new Item.Properties())); - RegistryEntry> tile = TILES.register(tileName, () -> Regeneration.createBlockEntityType(tileSupplier, block.get())); - return new RegistrySet(block, itemBlock, tile); - } - } - - public record KeySet(ResourceKey level, ResourceKey dimensionType, ResourceKey biome) { - - private static KeySet of(ResourceLocation id) { - return new KeySet(ResourceKey.create(Registries.DIMENSION, id), ResourceKey.create(Registries.DIMENSION_TYPE, id), ResourceKey.create(Registries.BIOME, id)); - } - } } 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..89b5055 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java @@ -0,0 +1,21 @@ +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 net.minecraft.world.level.levelgen.placement.PlacementModifier; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +public record OresCodec(int oreSize, float discardChance, List modifiers, List targets) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("ore_size").forGetter(OresCodec::oreSize), + Codec.FLOAT.fieldOf("discard_on_air_chance").forGetter(OresCodec::discardChance), + Codec.list(PlacementModifier.CODEC).fieldOf("modifiers").forGetter(OresCodec::modifiers), + Codec.list(OreConfiguration.TargetBlockState.CODEC).fieldOf("targets").forGetter(OresCodec::targets) + ).apply(instance, OresCodec::new)); + +} \ No newline at end of file diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java b/common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java new file mode 100644 index 0000000..4c25311 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java @@ -0,0 +1,174 @@ +package com.unrealdinnerbone.jamd; + +import com.google.gson.*; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import com.unrealdinnerbone.jamd.api.FeatureTypeRegistry; +import com.unrealdinnerbone.jamd.block.base.PortalTileEntity; +import com.unrealdinnerbone.trenzalore.api.registry.RegistryEntry; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tags.TagKey; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.placement.PlacementModifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; + +public class WorldType { + + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + private static final Logger LOGGER = LoggerFactory.getLogger(WorldType.class); + + public static final List TYPES = new ArrayList<>(); + private final String name; + private final KeySet key; + private final RegistryEntry block; + private final RegistryEntry item; + private final RegistryEntry> blockEntity; + + private final Path configPath; + + private final TagKey biomeTag; + public WorldType(String name, RegistryEntry block, RegistryEntry item, RegistryEntry> blockEntity, TagKey biomeTag) { + this.name = name; + this.key = KeySet.of(new ResourceLocation(JAMD.MOD_ID, name)); + this.block = block; + this.item = item; + this.blockEntity = blockEntity; + this.biomeTag = biomeTag; + this.configPath = JAMD.CONFIG_FOLDER.resolve(name + ".json"); + TYPES.add(this); + } + + public RegistryEntry getBlock() { + return block; + } + + public RegistryEntry> getBlockEntity() { + return blockEntity; + } + + public RegistryEntry getItem() { + return item; + } + + public KeySet getKey() { + return key; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + WorldType worldType = (WorldType) o; + return Objects.equals(name, worldType.name); + } + + public String getName() { + return name; + } + + public TagKey getBiomeTag() { + return biomeTag; + } + + public Path getConfigPath() { + return configPath; + } + + public void exportIfNotExist(MinecraftServer server) throws IllegalStateException, IOException { + if (!Files.exists(configPath)) { + export(server); + } + } + + public void export(MinecraftServer server) throws IllegalStateException, IOException { + List oresCodecs = new ArrayList<>(); + List placedFeatures = getFeatures(server); + for (PlacedFeature placedFeature : placedFeatures) { + List placementModifiers = placedFeature.placement(); + for (PlacementModifier modifier : placementModifiers) { + DataResult dataResult = PlacementModifier.CODEC.encodeStart(JsonOps.INSTANCE, modifier); + Optional result = dataResult.result(); + if(result.isEmpty()) { + LOGGER.error("Failed to encode: {}", dataResult.error().get().message()); + } + } + DataResult json = PlacedFeature.DIRECT_CODEC.encodeStart(JsonOps.INSTANCE, placedFeature); + 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"); + FeatureTypeRegistry.getFeatureType(featureType).ifPresent(iFeatureTypeCompact -> { + try { + oresCodecs.add(iFeatureTypeCompact.getOreCodec(GsonHelper.getAsJsonObject(feature, "config"), placementModifiers)); + }catch (Exception e) { + LOGGER.error("Failed to parse ore", e); + } + }); + } catch (JsonSyntaxException e) { + LOGGER.error("Skipping ore", e); + } + + } + DataResult result = ConfigCodec.CODEC.encodeStart(JsonOps.INSTANCE, new ConfigCodec(1, oresCodecs)); + if (result.result().isPresent()) { + if(!Files.exists(JAMD.CONFIG_FOLDER)) { + Files.createDirectories(JAMD.CONFIG_FOLDER); + } + Files.writeString(configPath, GSON.toJson(result.result().get())); + } else { + throw new IllegalStateException(result.error().get().message()); + } + } + } + + + public List getFeatures(MinecraftServer server) { + List features = new ArrayList<>(); + HolderLookup.RegistryLookup biomeRegistryLookup = server.registryAccess().lookup(Registries.BIOME).orElseThrow(); + for (Holder.Reference biomeReference : biomeRegistryLookup.listElements().toList()) { + Set placedFeatures = biomeReference.value().getGenerationSettings().featureSet.get(); + for (PlacedFeature placedFeature : placedFeatures) { + if (biomeReference.is(biomeTag)) { + if (!features.contains(placedFeature)) { + features.add(placedFeature); + } + } + } + } + return features; + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + + public record KeySet(ResourceKey level, ResourceKey dimensionType, ResourceKey biome) { + + private static KeySet of(ResourceLocation id) { + return new KeySet(ResourceKey.create(Registries.DIMENSION, id), ResourceKey.create(Registries.DIMENSION_TYPE, id), ResourceKey.create(Registries.BIOME, id)); + } + } +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java b/common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java new file mode 100644 index 0000000..58f0fc8 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java @@ -0,0 +1,33 @@ +package com.unrealdinnerbone.jamd.api; + +import com.unrealdinnerbone.jamd.api.IFeatureTypeCompact; +import com.unrealdinnerbone.jamd.compact.MinecraftOreCompact; +import com.unrealdinnerbone.trenzalore.api.platform.Services; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Supplier; + +public class FeatureTypeRegistry +{ + private static final Logger LOGGER = LogManager.getLogger(); + public static final List> FEATURES = new ArrayList<>(); + + public static void register(String modId, Supplier> featureTypeCompact) { + if(Services.PLATFORM.isModLoaded(modId)) { + IFeatureTypeCompact iFeatureTypeCompact = featureTypeCompact.get(); + LOGGER.debug("Registering Feature {} for {}", iFeatureTypeCompact.getFeatureType(), modId); + FEATURES.add(iFeatureTypeCompact); + }else { + LOGGER.debug("Skipping Feature for {} as mod is not loaded", modId); + } + } + + public static Optional> getFeatureType(String id) { + return FEATURES.stream().filter(featureTypeCompact -> featureTypeCompact.getFeatureType().toString().equalsIgnoreCase(id)).findFirst(); + } + +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java b/common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java new file mode 100644 index 0000000..d8cc7f5 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java @@ -0,0 +1,41 @@ +package com.unrealdinnerbone.jamd.api; + +import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import com.unrealdinnerbone.jamd.OresCodec; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.placement.PlacementModifier; + +import java.util.List; + +public interface IFeatureTypeCompact +{ + + default OresCodec getOreCodec(JsonObject config, List modifiers) throws IllegalArgumentException { + DataResult parse = getCodec().parse(JsonOps.INSTANCE, config); + if(parse.error().isPresent()) { + throw new IllegalArgumentException(parse.error().get().message()); + } else { + return parse(parse.result().get(), modifiers); + } + } + + /** + * @return The ore config codec + */ + Codec getCodec(); + + /** + * @param value the parsed ore config codec + * @param placementModifiers the placement modifiers to create ore codec + * @return the ore codec + */ + OresCodec parse(T value, List placementModifiers); + + /** + * @return feature type id + */ + ResourceLocation getFeatureType(); +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/block/EndPortalBlock.java b/common/src/main/java/com/unrealdinnerbone/jamd/block/EndPortalBlock.java index ca118e1..134d672 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/block/EndPortalBlock.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/block/EndPortalBlock.java @@ -1,6 +1,7 @@ package com.unrealdinnerbone.jamd.block; import com.unrealdinnerbone.jamd.JAMDRegistry; +import com.unrealdinnerbone.jamd.WorldType; import com.unrealdinnerbone.jamd.block.base.PortalBlock; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity; @@ -10,14 +11,10 @@ public class EndPortalBlock extends PortalBlock { public EndPortalBlock() { - super(JAMDRegistry.Keys.END.level(), JAMDRegistry.END); + super(JAMDRegistry.END); } - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return JAMDRegistry.END.blockEntity().get().create(pos, state); - } + } diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/block/NetherPortalBlock.java b/common/src/main/java/com/unrealdinnerbone/jamd/block/NetherPortalBlock.java index fec31ac..b5f16ea 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/block/NetherPortalBlock.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/block/NetherPortalBlock.java @@ -10,14 +10,7 @@ public class NetherPortalBlock extends PortalBlock { public NetherPortalBlock() { - super(JAMDRegistry.Keys.NETHER.level(), JAMDRegistry.NETHER); + super(JAMDRegistry.NETHER); } - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return JAMDRegistry.NETHER.blockEntity().get().create(pos, state); - } - - } diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/block/OverworldPortalBlock.java b/common/src/main/java/com/unrealdinnerbone/jamd/block/OverworldPortalBlock.java index e229dd0..1330578 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/block/OverworldPortalBlock.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/block/OverworldPortalBlock.java @@ -10,14 +10,7 @@ public class OverworldPortalBlock extends PortalBlock { public OverworldPortalBlock() { - super(JAMDRegistry.Keys.OVERWORLD.level(), JAMDRegistry.OVERWORLD); + super(JAMDRegistry.OVERWORLD); } - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return JAMDRegistry.OVERWORLD.blockEntity().get().create(pos, state); - } - - } diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalBlock.java b/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalBlock.java index ce955ad..4170b8b 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalBlock.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalBlock.java @@ -1,6 +1,7 @@ package com.unrealdinnerbone.jamd.block.base; import com.unrealdinnerbone.jamd.JAMDRegistry; +import com.unrealdinnerbone.jamd.WorldType; import com.unrealdinnerbone.jamd.util.TelerportUtils; import com.unrealdinnerbone.trenzalore.api.registry.RegistryEntry; import net.minecraft.core.BlockPos; @@ -29,22 +30,26 @@ public abstract class PortalBlock extends Block implements EntityBlock { //Todo CONFIG private static final ResourceKey OVERWORLD = Level.OVERWORLD; - private final ResourceKey destinationLevel; - private final JAMDRegistry.RegistrySet registrySet; - public PortalBlock(ResourceKey destinationWorld, JAMDRegistry.RegistrySet registrySet) { + private final WorldType type; + public PortalBlock(WorldType type) { super(Properties.of().requiresCorrectToolForDrops().strength(5.0F, 6.0F).sound(SoundType.STONE).mapColor(MapColor.COLOR_BLUE)); - this.destinationLevel = destinationWorld; - this.registrySet = registrySet; + this.type = type; + } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return type.getBlockEntity().get().create(pos, state); } @Override public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (!level.isClientSide()) { - if(level.dimension().equals(destinationLevel)) { - TelerportUtils.teleport(player, OVERWORLD, pos, registrySet); + if(level.dimension().equals(type.getKey().level())) { + TelerportUtils.teleport(player, OVERWORLD, pos, type); }else if(level.dimension().equals(OVERWORLD)) { - TelerportUtils.teleport(player, destinationLevel, pos, registrySet); + TelerportUtils.teleport(player, type.getKey().level(), pos, type); }else { player.displayClientMessage(Component.literal("You can't teleport from this dimension"), true); } diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalTileEntity.java b/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalTileEntity.java index fe0592a..ff7e675 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalTileEntity.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/block/base/PortalTileEntity.java @@ -1,15 +1,14 @@ package com.unrealdinnerbone.jamd.block.base; -import com.unrealdinnerbone.jamd.JAMDRegistry; +import com.unrealdinnerbone.jamd.WorldType; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; public abstract class PortalTileEntity extends BlockEntity { - public PortalTileEntity(JAMDRegistry.RegistrySet registrySet, BlockPos blockPos, BlockState blockState) { - super(registrySet.blockEntity().get(), blockPos, blockState); + public PortalTileEntity(WorldType worldType, BlockPos blockPos, BlockState blockState) { + super(worldType.getBlockEntity().get(), blockPos, blockState); } } 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..f9b18e4 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java @@ -0,0 +1,26 @@ +package com.unrealdinnerbone.jamd.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.unrealdinnerbone.jamd.util.OreRegistry; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; + +public class JamdCommand { + + public static void register(CommandDispatcher commandDispatcher) { + commandDispatcher.register(Commands.literal("jamd") + .then(Commands.literal("reload") + .executes(JamdCommand::reload))); + + } + + private static int reload(CommandContext stackCommandContext) throws CommandSyntaxException { + OreRegistry.REGISTERED_FEATURES.clear(); + + stackCommandContext.getSource().sendSuccess(() -> Component.literal("Reloaded Biomes Data"), true); + return 0; + } +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftOreCompact.java b/common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftOreCompact.java new file mode 100644 index 0000000..7d026eb --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftOreCompact.java @@ -0,0 +1,30 @@ +package com.unrealdinnerbone.jamd.compact; + +import com.mojang.serialization.Codec; +import com.unrealdinnerbone.jamd.OresCodec; +import com.unrealdinnerbone.jamd.api.IFeatureTypeCompact; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import net.minecraft.world.level.levelgen.placement.PlacementModifier; + +import java.util.List; + +public class MinecraftOreCompact implements IFeatureTypeCompact { + + private static final ResourceLocation FEATURE_TYPE = new ResourceLocation("minecraft", "ore"); + + @Override + public OresCodec parse(OreConfiguration value, List placementModifiers) { + return new OresCodec(value.size, value.discardChanceOnAirExposure, placementModifiers, value.targetStates); + } + + @Override + public Codec getCodec() { + return OreConfiguration.CODEC; + } + + @Override + public ResourceLocation getFeatureType() { + return FEATURE_TYPE; + } +} diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/util/OreRegistry.java b/common/src/main/java/com/unrealdinnerbone/jamd/util/OreRegistry.java new file mode 100644 index 0000000..931b02f --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/util/OreRegistry.java @@ -0,0 +1,71 @@ +package com.unrealdinnerbone.jamd.util; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.mojang.logging.LogUtils; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import com.unrealdinnerbone.jamd.*; +import net.minecraft.core.Holder; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.slf4j.Logger; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; + +public class OreRegistry +{ + private static final Logger LOGGER = LogUtils.getLogger(); + + public static final Map> REGISTERED_FEATURES = new HashMap<>(); + + public static List getFeatures(Holder biomeHolder) { + if(biomeHolder.is(JAMDRegistry.OVERWORLD.getKey().biome())) { + return getFeatures(JAMDRegistry.OVERWORLD); + }else if(biomeHolder.is(JAMDRegistry.NETHER.getKey().biome())) { + return getFeatures(JAMDRegistry.NETHER); + }else if(biomeHolder.is(JAMDRegistry.END.getKey().biome())) { + return getFeatures(JAMDRegistry.END); + } + return Collections.emptyList(); + } + public static List getFeatures(WorldType type) { + if(!REGISTERED_FEATURES.containsKey(type)) { + try { + Path resolve = JAMD.CONFIG_FOLDER.resolve(type.getName() + ".json"); + if(!Files.exists(resolve)) { + return Collections.emptyList(); + } + String jsonString = Files.readString(resolve); + 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 Collections.emptyList(); + } + Optional result = data.result(); + if(result.isPresent()) { + List features = new ArrayList<>(); + ConfigCodec configCodec = result.get(); + for (int i = 0; i < configCodec.oreMultiplier(); i++) { + for (OresCodec ore : configCodec.ores()) { + features.add(Transformers.fromConfigCodec(ore)); + } + } + REGISTERED_FEATURES.put(type, features); + }else { + LOGGER.error("Failed to parse config: {}", "No result"); + return Collections.emptyList(); + } + }catch (IOException e) { + LOGGER.error("Failed to read config file", e); + } + } + return REGISTERED_FEATURES.get(type); + } + +} + diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/util/TelerportUtils.java b/common/src/main/java/com/unrealdinnerbone/jamd/util/TelerportUtils.java index 21c8120..d6d2a4a 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/util/TelerportUtils.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/util/TelerportUtils.java @@ -2,6 +2,7 @@ import com.unrealdinnerbone.jamd.JAMD; import com.unrealdinnerbone.jamd.JAMDRegistry; +import com.unrealdinnerbone.jamd.WorldType; import com.unrealdinnerbone.jamd.block.base.PortalTileEntity; import com.unrealdinnerbone.trenzalore.api.platform.Services; import net.minecraft.core.BlockPos; @@ -20,12 +21,12 @@ import java.util.Optional; public class TelerportUtils { - public static void teleport(Player playerEntity, ResourceKey toWorldKey, BlockPos blockPos, JAMDRegistry.RegistrySet registrySet) { + public static void teleport(Player playerEntity, ResourceKey toWorldKey, BlockPos blockPos, WorldType registrySet) { ServerLevel toWorld = playerEntity.getServer().getLevel(toWorldKey); if (toWorld != null) { findPortalLocation(toWorld, blockPos, registrySet).ifPresentOrElse(portalLocation -> { if (toWorld.getBlockState(portalLocation).isAir()) { - toWorld.setBlockAndUpdate(portalLocation, registrySet.block().get().defaultBlockState()); + toWorld.setBlockAndUpdate(portalLocation, registrySet.getBlock().get().defaultBlockState()); } Vec3 portalLocationVec = new Vec3(portalLocation.getX() + 0.5, portalLocation.getY() + 1, portalLocation.getZ() + 0.5); Services.PLATFORM.teleport(playerEntity, toWorld, new PortalInfo(portalLocationVec, playerEntity.getDeltaMovement(), playerEntity.getYRot(), playerEntity.getXRot())); }, @@ -37,8 +38,8 @@ public static void teleport(Player playerEntity, ResourceKey toWorldKey, } - private static Optional findPortalLocation(Level worldTo, BlockPos fromPos, JAMDRegistry.RegistrySet registrySet) { - if (worldTo.getBlockState(fromPos).is(registrySet.block().get()) && isSafeSpawnLocation(worldTo, fromPos)) { + private static Optional findPortalLocation(Level worldTo, BlockPos fromPos, WorldType registrySet) { + if (worldTo.getBlockState(fromPos).is(registrySet.getBlock().get()) && isSafeSpawnLocation(worldTo, fromPos)) { return Optional.of(fromPos.above()); } @@ -46,7 +47,7 @@ private static Optional findPortalLocation(Level worldTo, BlockPos fro return Optional.ofNullable(ChunkPos.rangeClosed(worldTo.getChunkAt(fromPos).getPos(), range) .map(chunkPos -> worldTo.getChunk(chunkPos.x, chunkPos.z).getBlockEntitiesPos()) .flatMap(Collection::stream).toList().stream() - .filter(pos -> worldTo.getBlockEntity(pos).getType().equals(registrySet.blockEntity().get())) + .filter(pos -> worldTo.getBlockEntity(pos).getType().equals(registrySet.getBlock().get())) .findFirst() .orElseGet(() -> { BlockPos heightmapPos = worldTo.getHeightmapPos(Heightmap.Types.WORLD_SURFACE_WG, fromPos); 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..1ce45e9 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java @@ -0,0 +1,20 @@ +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())); + return new PlacedFeature(Holder.direct(oreFeature), oresCodec.modifiers()); + } +} 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..9ef29dc --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelGeneratorSettings.java @@ -0,0 +1,50 @@ +package com.unrealdinnerbone.jamd.world; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.unrealdinnerbone.jamd.util.OreRegistry; +import net.minecraft.core.Holder; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeGenerationSettings; +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 java.util.List; +import java.util.Optional; + +@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(); + for (PlacedFeature registeredFeature : OreRegistry.getFeatures(holder)) { + 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/jamd.accesswidener b/common/src/main/resources/jamd.accesswidener new file mode 100644 index 0000000..7785392 --- /dev/null +++ b/common/src/main/resources/jamd.accesswidener @@ -0,0 +1,7 @@ +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; +accessible field net/minecraft/world/level/biome/BiomeGenerationSettings featureSet Ljava/util/function/Supplier; \ 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..c111417 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java @@ -1,10 +1,17 @@ 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; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; public class JAMDFabric implements ModInitializer { + @Override public void onInitialize() { - JAMD.init(); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> JamdCommand.register(dispatcher)); + ServerLifecycleEvents.SERVER_STARTING.register(JAMD::onServerStart); } + } diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/BlockTagProvider.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/BlockTagProvider.java index 9a9026c..96501bc 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/BlockTagProvider.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/BlockTagProvider.java @@ -19,13 +19,13 @@ public BlockTagProvider(FabricDataOutput output, CompletableFuture context) { HolderGetter placedFeatures = context.lookup(Registries.PLACED_FEATURE); HolderGetter> configuredWorldCarvers = context.lookup(Registries.CONFIGURED_CARVER); BiomeGenerationSettings.Builder builder = new BiomeGenerationSettings.Builder(placedFeatures, configuredWorldCarvers); - context.register(JAMDRegistry.Keys.END.biome(), new Biome.BiomeBuilder() + context.register(JAMDRegistry.END.getKey().biome(), new Biome.BiomeBuilder() .temperature(0.5f) .downfall(0.5f) .hasPrecipitation(false) @@ -77,7 +86,7 @@ static void bootstrapBiome(BootstapContext context) { } static void bootstrapDimensionType(BootstapContext context) { - context.register(JAMDRegistry.Keys.END.dimensionType(), new DimensionType(OptionalLong.of(6000), + context.register(JAMDRegistry.END.getKey().dimensionType(), new DimensionType(OptionalLong.of(6000), false, false, false, @@ -106,10 +115,10 @@ static void bootstrapBiome(BootstapContext context) { BiomeDefaultFeatures.addExtraEmeralds(builder); builder.addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, OrePlacements.ORE_COPPER_LARGE); builder.addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, OrePlacements.ORE_TUFF); - context.register(JAMDRegistry.Keys.OVERWORLD.biome(), new Biome.BiomeBuilder() + context.register(JAMDRegistry.OVERWORLD.getKey().biome(), new Biome.BiomeBuilder() .temperature(1) .downfall(0.4f) - .hasPrecipitation(true) + .hasPrecipitation(false) .temperatureAdjustment(Biome.TemperatureModifier.NONE) .specialEffects(new BiomeSpecialEffects.Builder() .skyColor(8103167) @@ -123,7 +132,7 @@ static void bootstrapBiome(BootstapContext context) { } static void bootstrapDimensionType(BootstapContext context) { - context.register(JAMDRegistry.Keys.OVERWORLD.dimensionType(), new DimensionType(OptionalLong.of(6000), + context.register(JAMDRegistry.OVERWORLD.getKey().dimensionType(), new DimensionType(OptionalLong.of(6000), true, false, false, @@ -149,7 +158,7 @@ static void bootstrapBiome(BootstapContext context) { HolderGetter> configuredWorldCarvers = context.lookup(Registries.CONFIGURED_CARVER); BiomeGenerationSettings.Builder builder = new BiomeGenerationSettings.Builder(placedFeatures, configuredWorldCarvers); BiomeDefaultFeatures.addNetherDefaultOres(builder); - context.register(JAMDRegistry.Keys.NETHER.biome(), new Biome.BiomeBuilder() + context.register(JAMDRegistry.NETHER.getKey().biome(), new Biome.BiomeBuilder() .hasPrecipitation(false) .temperature(2.0F) .downfall(0.0F) @@ -168,7 +177,7 @@ static void bootstrapBiome(BootstapContext context) { } static void bootstrapDimensionType(BootstapContext context) { - context.register(JAMDRegistry.Keys.NETHER.dimensionType(), new DimensionType(OptionalLong.of(18000), + context.register(JAMDRegistry.NETHER.getKey().dimensionType(), new DimensionType(OptionalLong.of(18000), false, false, true, diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LangProvider.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LangProvider.java index e6ead27..ff90207 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LangProvider.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LangProvider.java @@ -12,9 +12,9 @@ protected LangProvider(FabricDataOutput dataOutput) { @Override public void generateTranslations(TranslationBuilder translationBuilder) { - translationBuilder.add(JAMDRegistry.OVERWORLD.block().get(), "Mining Portal"); - translationBuilder.add(JAMDRegistry.NETHER.block().get(), "Nether Mining Portal"); - translationBuilder.add(JAMDRegistry.END.block().get(), "End Mining Portal"); + translationBuilder.add(JAMDRegistry.OVERWORLD.getBlock().get(), "Mining Portal"); + translationBuilder.add(JAMDRegistry.NETHER.getBlock().get(), "Nether Mining Portal"); + translationBuilder.add(JAMDRegistry.END.getBlock().get(), "End Mining Portal"); translationBuilder.add("jamd.invalid.world", "Unable to find world '%s'"); translationBuilder.add("jamd.invalid.pos", "Unable to find valid portal location"); translationBuilder.add("biome.jamd.mining", "Mining"); diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LootTableProvider.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LootTableProvider.java index b680b99..3a98ec0 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LootTableProvider.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/LootTableProvider.java @@ -12,8 +12,8 @@ protected LootTableProvider(FabricDataOutput dataOutput) { @Override public void generate() { - dropSelf(JAMDRegistry.OVERWORLD.block().get()); - dropSelf(JAMDRegistry.NETHER.block().get()); - dropSelf(JAMDRegistry.END.block().get()); + dropSelf(JAMDRegistry.OVERWORLD.getBlock().get()); + dropSelf(JAMDRegistry.NETHER.getBlock().get()); + dropSelf(JAMDRegistry.END.getBlock().get()); } } 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..3c95d24 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 { @@ -14,9 +15,9 @@ public ModelProvider(FabricDataOutput output) { @Override public void generateBlockStateModels(BlockModelGenerators generator) { - generator.createTrivialCube(JAMDRegistry.OVERWORLD.block().get()); - generator.createTrivialCube(JAMDRegistry.NETHER.block().get()); - generator.createTrivialCube(JAMDRegistry.END.block().get()); + generator.createTrivialCube(JAMDRegistry.OVERWORLD.getBlock().get()); + generator.createTrivialCube(JAMDRegistry.NETHER.getBlock().get()); + generator.createTrivialCube(JAMDRegistry.END.getBlock().get()); } @Override diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/RecipeProvider.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/RecipeProvider.java index 3034ca0..4d4c0e1 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/RecipeProvider.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/RecipeProvider.java @@ -20,7 +20,7 @@ public RecipeProvider(FabricDataOutput output) { @Override public void buildRecipes(Consumer exporter) { - ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, JAMDRegistry.OVERWORLD.block().get()) + ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, JAMDRegistry.OVERWORLD.getBlock().get()) .pattern("OOO") .pattern("OPO") .pattern("OOO") @@ -28,7 +28,7 @@ public void buildRecipes(Consumer exporter) { .define('P', Items.DIAMOND_PICKAXE) .unlockedBy("has_diamond_pick", has(Items.DIAMOND_PICKAXE)) .save(exporter, new ResourceLocation(JAMD.MOD_ID, "portal_block")); - ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, JAMDRegistry.NETHER.block().get()) + ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, JAMDRegistry.NETHER.getBlock().get()) .pattern("OOO") .pattern("OPO") .pattern("OOO") @@ -36,7 +36,7 @@ public void buildRecipes(Consumer exporter) { .define('P', Items.NETHERITE_PICKAXE) .unlockedBy("has_diamond_pick", has(Items.NETHERITE_PICKAXE)) .save(exporter, new ResourceLocation(JAMD.MOD_ID, "nether_portal_block")); - ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, JAMDRegistry.END.block().get()) + ShapedRecipeBuilder.shaped(RecipeCategory.TRANSPORTATION, JAMDRegistry.END.getBlock().get()) .pattern("OOO") .pattern("OPO") .pattern("OOO") 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..b76b42d 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" + } } @@ -22,7 +25,11 @@ dependencies { implementation (fg.deobf("com.unrealdinnerbone:trenzalore-forge:${project.property("trenzalore_version")}+mc${project.property("minecraft_version")}-SNAPSHOT")) { transitive = true } + implementation fg.deobf("mekanism:Mekanism:${mekanism_version}") 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..15a3d88 100644 --- a/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java +++ b/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java @@ -1,14 +1,33 @@ package com.unrealdinnerbone.jamd; -import com.unrealdinnerbone.trenzalore.api.config.ConfigManger; +import com.unrealdinnerbone.jamd.api.FeatureTypeRegistry; +import com.unrealdinnerbone.jamd.command.JamdCommand; +import com.unrealdinnerbone.jamd.compact.MekenismOreCompact; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @Mod(JAMD.MOD_ID) public class JAMDForge { - + public JAMDForge() { JAMD.init(); - FMLJavaModLoadingContext.get().getModEventBus().addListener(JAMDDataForge::onData); + MinecraftForge.EVENT_BUS.addListener(this::onRegisterCommands); + MinecraftForge.EVENT_BUS.addListener(this::onStart); + registerCompact(); + } + + public static void registerCompact() { + FeatureTypeRegistry.register("mekanism", MekenismOreCompact::new); + } + + public void onRegisterCommands(RegisterCommandsEvent event) { + JamdCommand.register(event.getDispatcher()); + } + + public void onStart(ServerStartingEvent event) { + JAMD.onServerStart(event.getServer()); } + } \ 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/java/com/unrealdinnerbone/jamd/compact/MekenismOreCompact.java b/forge/src/main/java/com/unrealdinnerbone/jamd/compact/MekenismOreCompact.java new file mode 100644 index 0000000..cedae57 --- /dev/null +++ b/forge/src/main/java/com/unrealdinnerbone/jamd/compact/MekenismOreCompact.java @@ -0,0 +1,30 @@ +package com.unrealdinnerbone.jamd.compact; + +import com.mojang.serialization.Codec; +import com.unrealdinnerbone.jamd.OresCodec; +import com.unrealdinnerbone.jamd.api.IFeatureTypeCompact; +import mekanism.common.world.ResizableOreFeatureConfig; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.placement.PlacementModifier; + +import java.util.List; + +public class MekenismOreCompact implements IFeatureTypeCompact { + + private static final ResourceLocation FEATURE_TYPE = new ResourceLocation("mekanism", "ore"); + + @Override + public OresCodec parse(ResizableOreFeatureConfig config, List placementModifiers) { + return new OresCodec(config.size().getAsInt(), config.discardChanceOnAirExposure().getAsFloat(), placementModifiers, config.targetStates()); + } + + @Override + public Codec getCodec() { + return ResizableOreFeatureConfig.CODEC; + } + + @Override + public ResourceLocation getFeatureType() { + return FEATURE_TYPE; + } +} 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..b51ff60 --- /dev/null +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,6 @@ +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_ +public net.minecraft.world.level.biome.BiomeGenerationSettings f_186648_ diff --git a/gradle.properties b/gradle.properties index 4f0eca6..903194b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project -mod_version=3.3.3 +mod_version=3.4.0 maven_group=com.unrealdinnerbone curse_id=422981 mod_name=JAMD @@ -18,8 +18,11 @@ fabric_version=0.83.1+1.20.1 fabric_loader_version=0.14.21 # Other -trenzalore_version=3.3.9 +trenzalore_version=3.3.10 # Gradle org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false + +#Compact +mekanism_version=1.20.1-10.4.0.14 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/'