From 3a657e12f3577c41e34a3e6627b4cbee285a5eac Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Tue, 7 Nov 2023 11:59:07 -0600 Subject: [PATCH] Finish Rewrite --- CHANGELOG.md | 9 +- .../data/jamd/recipes/end_portal_block.json | 21 + .../jamd/recipes/nether_portal_block.json | 21 + .../data/jamd/recipes/portal_block.json | 21 + .../data/jamd/worldgen/biome/mining.json | 24 +- .../unrealdinnerbone/jamd/ConfigCodec.java | 3 +- .../java/com/unrealdinnerbone/jamd/JAMD.java | 82 +--- .../unrealdinnerbone/jamd/JAMDRegistry.java | 40 +- .../com/unrealdinnerbone/jamd/OresCodec.java | 39 +- .../com/unrealdinnerbone/jamd/WorldType.java | 174 ++++++++ .../jamd/api/FeatureTypeRegistry.java | 33 ++ .../jamd/api/IFeatureTypeCompact.java | 41 ++ .../jamd/block/EndPortalBlock.java | 9 +- .../jamd/block/NetherPortalBlock.java | 9 +- .../jamd/block/OverworldPortalBlock.java | 9 +- .../jamd/block/base/PortalBlock.java | 21 +- .../jamd/block/base/PortalTileEntity.java | 7 +- .../jamd/command/JamdCommand.java | 121 +----- .../jamd/compact/MinecraftOreCompact.java | 30 ++ .../jamd/util/OreRegistry.java | 71 ++++ .../jamd/util/TelerportUtils.java | 11 +- .../jamd/util/Transformers.java | 14 +- .../CustomFlatLevelGeneratorSettings.java | 24 +- common/src/main/resources/defaults/end.json | 5 - .../src/main/resources/defaults/mining.json | 392 ------------------ .../src/main/resources/defaults/nether.json | 124 ------ common/src/main/resources/jamd.accesswidener | 3 +- .../com/unrealdinnerbone/jamd/JAMDFabric.java | 2 + .../jamd/data/BlockTagProvider.java | 12 +- .../unrealdinnerbone/jamd/data/JAMDData.java | 14 +- .../jamd/data/LangProvider.java | 6 +- .../jamd/data/LootTableProvider.java | 6 +- .../jamd/data/ModelProvider.java | 6 +- .../jamd/data/RecipeProvider.java | 6 +- forge/build.gradle | 1 + .../com/unrealdinnerbone/jamd/JAMDForge.java | 22 +- .../jamd/compact/MekenismOreCompact.java | 30 ++ .../resources/META-INF/accesstransformer.cfg | 1 + gradle.properties | 7 +- 39 files changed, 589 insertions(+), 882 deletions(-) create mode 100644 common/src/generated/resources/data/jamd/recipes/end_portal_block.json create mode 100644 common/src/generated/resources/data/jamd/recipes/nether_portal_block.json create mode 100644 common/src/generated/resources/data/jamd/recipes/portal_block.json create mode 100644 common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java create mode 100644 common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java create mode 100644 common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java create mode 100644 common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftOreCompact.java create mode 100644 common/src/main/java/com/unrealdinnerbone/jamd/util/OreRegistry.java delete mode 100644 common/src/main/resources/defaults/end.json delete mode 100644 common/src/main/resources/defaults/mining.json delete mode 100644 common/src/main/resources/defaults/nether.json create mode 100644 forge/src/main/java/com/unrealdinnerbone/jamd/compact/MekenismOreCompact.java 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/common/src/generated/resources/data/jamd/recipes/end_portal_block.json b/common/src/generated/resources/data/jamd/recipes/end_portal_block.json new file mode 100644 index 0000000..4dd61f9 --- /dev/null +++ b/common/src/generated/resources/data/jamd/recipes/end_portal_block.json @@ -0,0 +1,21 @@ +{ + "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 new file mode 100644 index 0000000..e3176f4 --- /dev/null +++ b/common/src/generated/resources/data/jamd/recipes/nether_portal_block.json @@ -0,0 +1,21 @@ +{ + "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 new file mode 100644 index 0000000..88de21a --- /dev/null +++ b/common/src/generated/resources/data/jamd/recipes/portal_block.json @@ -0,0 +1,21 @@ +{ + "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 231017d..63dbe6e 100644 --- a/common/src/generated/resources/data/jamd/worldgen/biome/mining.json +++ b/common/src/generated/resources/data/jamd/worldgen/biome/mining.json @@ -14,9 +14,29 @@ [], [], [], - [] + [ + "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, + "has_precipitation": false, "spawn_costs": {}, "spawners": { "ambient": [], diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java b/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java index 9783ec8..e8f5a60 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java @@ -5,8 +5,9 @@ import java.util.List; -public record ConfigCodec(List ores) { +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/JAMD.java b/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java index c1e3ecd..60576a0 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java @@ -1,89 +1,35 @@ package com.unrealdinnerbone.jamd; -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.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.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 net.minecraft.server.MinecraftServer; 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); - + 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"; - 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); - } - - } + FeatureTypeRegistry.register("minecraft", MinecraftOreCompact::new); } - 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); - } + 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 d47c326..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; @@ -38,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 @@ -68,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/OresCodec.java b/common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java index 9d1edf4..89b5055 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/OresCodec.java @@ -4,49 +4,18 @@ 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( - String id, - int oreSize, - int oreAmount, - float discardChance, - Optional minY, - Optional maxY, - PlacementType placementType, - List targets) { +public record OresCodec(int oreSize, float discardChance, List modifiers, 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(PlacementModifier.CODEC).fieldOf("modifiers").forGetter(OresCodec::modifiers), 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; - } - } -} +} \ 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 index 3ef825e..f9b18e4 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java @@ -1,135 +1,26 @@ 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 com.unrealdinnerbone.jamd.util.OreRegistry; 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))); + .then(Commands.literal("reload") + .executes(JamdCommand::reload))); } - 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); - } + private static int reload(CommandContext stackCommandContext) throws CommandSyntaxException { + OreRegistry.REGISTERED_FEATURES.clear(); - } - } - 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()); - } + 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 index 9d7d6b4..1ce45e9 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java @@ -15,18 +15,6 @@ 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); + 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 index debb9f8..9ef29dc 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelGeneratorSettings.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/world/CustomFlatLevelGeneratorSettings.java @@ -1,31 +1,18 @@ 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 com.unrealdinnerbone.jamd.util.OreRegistry; 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 { @@ -43,15 +30,12 @@ public static CustomFlatLevelGeneratorSettings create(Holder holder, List @Override public BiomeGenerationSettings adjustGenerationSettings(Holder holder) { - if(!holder.equals(this.biome)) { + 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)); - } + for (PlacedFeature registeredFeature : OreRegistry.getFeatures(holder)) { + plainBuilder.addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, Holder.direct(registeredFeature)); } return plainBuilder.build(); } diff --git a/common/src/main/resources/defaults/end.json b/common/src/main/resources/defaults/end.json deleted file mode 100644 index ec18392..0000000 --- a/common/src/main/resources/defaults/end.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "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 deleted file mode 100644 index 78793ef..0000000 --- a/common/src/main/resources/defaults/mining.json +++ /dev/null @@ -1,392 +0,0 @@ -{ - "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 deleted file mode 100644 index 090d752..0000000 --- a/common/src/main/resources/defaults/nether.json +++ /dev/null @@ -1,124 +0,0 @@ -{ - "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 index 481e1f4..7785392 100644 --- a/common/src/main/resources/jamd.accesswidener +++ b/common/src/main/resources/jamd.accesswidener @@ -3,4 +3,5 @@ accessible field net/minecraft/world/level/levelgen/flat/FlatLevelGeneratorSetti 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 +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 0810dcb..c111417 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/JAMDFabric.java @@ -4,12 +4,14 @@ 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() { 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) @@ -86,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, @@ -115,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) @@ -132,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, @@ -158,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) @@ -177,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 53ddeb0..3c95d24 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/ModelProvider.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/ModelProvider.java @@ -15,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/forge/build.gradle b/forge/build.gradle index c23de93..b76b42d 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -25,6 +25,7 @@ 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 12a645b..15a3d88 100644 --- a/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java +++ b/forge/src/main/java/com/unrealdinnerbone/jamd/JAMDForge.java @@ -1,25 +1,33 @@ package com.unrealdinnerbone.jamd; +import com.unrealdinnerbone.jamd.api.FeatureTypeRegistry; import com.unrealdinnerbone.jamd.command.JamdCommand; -import com.unrealdinnerbone.trenzalore.api.config.ConfigManger; -import net.minecraft.server.packs.PackType; +import com.unrealdinnerbone.jamd.compact.MekenismOreCompact; 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; @Mod(JAMD.MOD_ID) public class JAMDForge { - + public JAMDForge() { JAMD.init(); - MinecraftForge.EVENT_BUS.addListener(this::onServerStart); + MinecraftForge.EVENT_BUS.addListener(this::onRegisterCommands); + MinecraftForge.EVENT_BUS.addListener(this::onStart); + registerCompact(); + } + + public static void registerCompact() { + FeatureTypeRegistry.register("mekanism", MekenismOreCompact::new); } - public void onServerStart(RegisterCommandsEvent event) { + 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/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 index 5af17e0..b51ff60 100644 --- a/forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -3,3 +3,4 @@ public net.minecraft.world.level.levelgen.feature.configurations.OreConfiguratio 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