From 0cad9414293aa077b8ced7dfc6771c9b2cd1b29a Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Fri, 1 Mar 2024 08:11:01 -0600 Subject: [PATCH] Rewrite Feature mapping --- CHANGELOG.md | 4 +- .../12b48ce80665160388e37efcbe6ffc9c320247a7 | 2 - .../1d8aa9c5d04d534625d05e0315fa2dfc314eb45b | 10 ---- .../2a895680709e271705f445e2c6f6dbca16550c92 | 7 --- .../3803046a7d7b7ce0a060be8ae0299aa98c17094c | 3 - .../4b9da48b48cbb77fa11342e113f8c9a9cb9c99c1 | 7 --- .../e360e4cfe8a52d2933ccfa99feb357854d82856f | 4 -- .../e579368e5ce100f0caf83470459223110b73fa16 | 2 - .../resources/assets/jamd/lang/en_us.json | 1 + .../advancements/enter_mining_dimension.json | 1 + .../worldgen/configured_feature/mining.json | 6 ++ .../unrealdinnerbone/jamd/ConfigCodec.java | 4 +- .../java/com/unrealdinnerbone/jamd/JAMD.java | 7 +-- .../unrealdinnerbone/jamd/JAMDRegistry.java | 3 - .../com/unrealdinnerbone/jamd/WorldType.java | 57 +++++++++---------- .../jamd/api/FeatureTypeRegistry.java | 20 ++++--- .../jamd/api/IFeatureTypeCompact.java | 24 +------- .../jamd/command/JamdCommand.java | 11 ++-- .../jamd/compact/MinecraftScatteredOre.java | 30 ---------- .../{ => minecraft}/MinecraftOreCompact.java | 15 +---- .../jamd/util/OreRegistry.java | 2 +- .../jamd/util/Transformers.java | 4 +- .../jamd/data/FeatureTagProvider.java | 28 +++++++++ .../unrealdinnerbone/jamd/data/JAMDData.java | 1 + gradle.properties | 2 +- .../unrealdinnerbone/jamd/neo/JAMDNeo.java | 4 +- .../jamd/neo/compact/IECompact.java | 11 +--- .../jamd/neo/compact/MekenismOreCompact.java | 12 ---- .../resources/META-INF/accesstransformer.cfg | 2 - 29 files changed, 101 insertions(+), 183 deletions(-) delete mode 100644 common/src/generated/resources/.cache/12b48ce80665160388e37efcbe6ffc9c320247a7 delete mode 100644 common/src/generated/resources/.cache/1d8aa9c5d04d534625d05e0315fa2dfc314eb45b delete mode 100644 common/src/generated/resources/.cache/2a895680709e271705f445e2c6f6dbca16550c92 delete mode 100644 common/src/generated/resources/.cache/3803046a7d7b7ce0a060be8ae0299aa98c17094c delete mode 100644 common/src/generated/resources/.cache/4b9da48b48cbb77fa11342e113f8c9a9cb9c99c1 delete mode 100644 common/src/generated/resources/.cache/e360e4cfe8a52d2933ccfa99feb357854d82856f delete mode 100644 common/src/generated/resources/.cache/e579368e5ce100f0caf83470459223110b73fa16 create mode 100644 common/src/generated/resources/data/jamd/tags/worldgen/configured_feature/mining.json delete mode 100644 common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftScatteredOre.java rename common/src/main/java/com/unrealdinnerbone/jamd/compact/{ => minecraft}/MinecraftOreCompact.java (62%) create mode 100644 fabric/src/main/java/com/unrealdinnerbone/jamd/data/FeatureTagProvider.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd9c2c..898127b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -### 4.1.0 +### 4.2.0 -- Add Support for Mekanism and Immersive Engineering ores +- Rewrite Features to support complex features diff --git a/common/src/generated/resources/.cache/12b48ce80665160388e37efcbe6ffc9c320247a7 b/common/src/generated/resources/.cache/12b48ce80665160388e37efcbe6ffc9c320247a7 deleted file mode 100644 index a659f66..0000000 --- a/common/src/generated/resources/.cache/12b48ce80665160388e37efcbe6ffc9c320247a7 +++ /dev/null @@ -1,2 +0,0 @@ -// 1.20.4 2023-12-31T21:15:52.9836649 Just Another Mining Dimension/Language (en_us) -d18e932526fabcfa1f61561fb911af2af2e722d2 assets\jamd\lang\en_us.json diff --git a/common/src/generated/resources/.cache/1d8aa9c5d04d534625d05e0315fa2dfc314eb45b b/common/src/generated/resources/.cache/1d8aa9c5d04d534625d05e0315fa2dfc314eb45b deleted file mode 100644 index e7bfaca..0000000 --- a/common/src/generated/resources/.cache/1d8aa9c5d04d534625d05e0315fa2dfc314eb45b +++ /dev/null @@ -1,10 +0,0 @@ -// 1.20.4 2023-12-31T21:15:52.9863671 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 -6048ff3f9c71f641213c1d7aa6d605d9b23fed72 assets\jamd\models\block\end_portal.json -76633e08f2190391221ca5bc14b6536cda1b87a9 assets\jamd\models\item\nether_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 deleted file mode 100644 index af4c09a..0000000 --- a/common/src/generated/resources/.cache/2a895680709e271705f445e2c6f6dbca16550c92 +++ /dev/null @@ -1,7 +0,0 @@ -// 1.20.4 2023-12-31T21:15:52.9851725 Just Another Mining Dimension/JAMD World Data -e022cecafe8e7e93c9e3e503c46197cf1fb33450 data\jamd\dimension_type\mining.json -9493a2c0221f086efbb4263f171937a72c6d6992 data\jamd\worldgen\biome\end.json -ef6de3478b3faf584bda19d292e42bf38c666765 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 deleted file mode 100644 index 614ebb0..0000000 --- a/common/src/generated/resources/.cache/3803046a7d7b7ce0a060be8ae0299aa98c17094c +++ /dev/null @@ -1,3 +0,0 @@ -// 1.20.4 2023-12-31T21:15:52.9866822 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 deleted file mode 100644 index e2004bb..0000000 --- a/common/src/generated/resources/.cache/4b9da48b48cbb77fa11342e113f8c9a9cb9c99c1 +++ /dev/null @@ -1,7 +0,0 @@ -// 1.20.4 2023-12-31T21:15:52.9871834 Just Another Mining Dimension/Recipes -4d6b8136d5ff79eb4469ecbc72396d94fd25af20 data\jamd\advancements\recipes\transportation\nether_portal_block.json -20e233e25e1b3488c1d968a1230f04ef41f4e97a data\jamd\advancements\recipes\transportation\end_portal_block.json -f956a1ca3452cba931d99b28820a4e0e73ad2624 data\jamd\recipes\portal_block.json -79a197aae235dfbca7663473a2ad3e7483842e94 data\jamd\recipes\nether_portal_block.json -6893e3a682595a9cf169036ba333467142cab2ff data\jamd\recipes\end_portal_block.json -98ed8e49a380927bcf6b3bf26ccc62a8389b53e6 data\jamd\advancements\recipes\transportation\portal_block.json diff --git a/common/src/generated/resources/.cache/e360e4cfe8a52d2933ccfa99feb357854d82856f b/common/src/generated/resources/.cache/e360e4cfe8a52d2933ccfa99feb357854d82856f deleted file mode 100644 index 698ad3d..0000000 --- a/common/src/generated/resources/.cache/e360e4cfe8a52d2933ccfa99feb357854d82856f +++ /dev/null @@ -1,4 +0,0 @@ -// 1.20.4 2023-12-31T21:15:52.9846687 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/.cache/e579368e5ce100f0caf83470459223110b73fa16 b/common/src/generated/resources/.cache/e579368e5ce100f0caf83470459223110b73fa16 deleted file mode 100644 index c8b9001..0000000 --- a/common/src/generated/resources/.cache/e579368e5ce100f0caf83470459223110b73fa16 +++ /dev/null @@ -1,2 +0,0 @@ -// 1.20.4 2023-12-31T21:15:52.9856762 Just Another Mining Dimension/Advancements -f34c43720484aabd95e66cd03d741a74ddc92be3 data\jamd\advancements\enter_mining_dimension.json diff --git a/common/src/generated/resources/assets/jamd/lang/en_us.json b/common/src/generated/resources/assets/jamd/lang/en_us.json index 1caaa54..7250c82 100644 --- a/common/src/generated/resources/assets/jamd/lang/en_us.json +++ b/common/src/generated/resources/assets/jamd/lang/en_us.json @@ -7,6 +7,7 @@ "block.jamd.end_portal": "End Mining Portal", "block.jamd.nether_portal": "Nether Mining Portal", "block.jamd.portal_block": "Mining Portal", + "jamd.argument.world_type.invalid": "Invalid World Type '%s'", "jamd.invalid.pos": "Unable to find valid portal location", "jamd.invalid.world": "Unable to find world '%s'" } \ No newline at end of file diff --git a/common/src/generated/resources/data/jamd/advancements/enter_mining_dimension.json b/common/src/generated/resources/data/jamd/advancements/enter_mining_dimension.json index 6a0ecf1..f8eb087 100644 --- a/common/src/generated/resources/data/jamd/advancements/enter_mining_dimension.json +++ b/common/src/generated/resources/data/jamd/advancements/enter_mining_dimension.json @@ -11,6 +11,7 @@ "description": { "translate": "advancements.jamd.mining.description" }, + "hidden": true, "icon": { "item": "jamd:portal_block" }, diff --git a/common/src/generated/resources/data/jamd/tags/worldgen/configured_feature/mining.json b/common/src/generated/resources/data/jamd/tags/worldgen/configured_feature/mining.json new file mode 100644 index 0000000..38d47bb --- /dev/null +++ b/common/src/generated/resources/data/jamd/tags/worldgen/configured_feature/mining.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "minecraft:ore_infested" + ] +} \ No newline at end of file diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java b/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java index e8f5a60..3cc7b0e 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/ConfigCodec.java @@ -4,10 +4,12 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.List; +import java.util.Optional; -public record ConfigCodec(int oreMultiplier, List ores) { +public record ConfigCodec(int oreMultiplier, Boolean ignoreAirChance, List ores) { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.INT.fieldOf("oreMultiplier").forGetter(ConfigCodec::oreMultiplier), + Codec.BOOL.optionalFieldOf("ignoreAirChance", false).forGetter(ConfigCodec::ignoreAirChance), 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 d311d14..9022be4 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/JAMD.java @@ -2,8 +2,7 @@ import com.mojang.logging.LogUtils; import com.unrealdinnerbone.jamd.api.FeatureTypeRegistry; -import com.unrealdinnerbone.jamd.compact.MinecraftOreCompact; -import com.unrealdinnerbone.jamd.compact.MinecraftScatteredOre; +import com.unrealdinnerbone.jamd.compact.minecraft.MinecraftOreCompact; import com.unrealdinnerbone.jamd.util.OreRegistry; import com.unrealdinnerbone.trenzalore.api.platform.Services; import net.minecraft.server.MinecraftServer; @@ -19,8 +18,8 @@ public class JAMD { public static final String MOD_ID = "jamd"; public static void init() { - FeatureTypeRegistry.register("minecraft", MinecraftOreCompact::new); - FeatureTypeRegistry.register("minecraft", MinecraftScatteredOre::new); + FeatureTypeRegistry.register("minecraft", "ore", MinecraftOreCompact::new); + FeatureTypeRegistry.register("minecraft", "scattered_ore", MinecraftOreCompact::new); } public static void onServerStart(MinecraftServer server) { diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java b/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java index 1396c5c..c8fe435 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/JAMDRegistry.java @@ -34,11 +34,8 @@ public class JAMDRegistry implements IRegistry { private static final RegistryObjects BLOCKS = Regeneration.create(Registries.BLOCK); private static final RegistryObjects ITEMS = Regeneration.create(Registries.ITEM); private static final RegistryObjects> TILES = Regeneration.create(Registries.BLOCK_ENTITY_TYPE); - - private static final RegistryObjects> ARG_TYPE = Regeneration.create(Registries.COMMAND_ARGUMENT_TYPE); private static final RegistryObjects> CHUNK_GENERATORS = Regeneration.create(Registries.CHUNK_GENERATOR); - public static final RegistryEntry> CUSTOM_FLAT_LEVEL_SOURCE = CHUNK_GENERATORS.register("mining", () -> CustomFlatLevelSource.CODEC); public static final WorldType OVERWORLD = of("mining", "portal_block", "portal", OverworldPortalBlock::new, OverworldBlockEntity::new, BiomeTags.IS_OVERWORLD); diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java b/common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java index 1fa0c9e..d6d7d41 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/WorldType.java @@ -8,21 +8,22 @@ import com.unrealdinnerbone.trenzalore.api.registry.RegistryEntry; import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; +import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.features.OreFeatures; 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.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import net.minecraft.world.level.levelgen.placement.PlacementModifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,6 +45,7 @@ public class WorldType { private final RegistryEntry item; private final RegistryEntry> blockEntity; + private final TagKey> ingoredFeatures; private final Path configPath; private final TagKey biomeTag; @@ -55,6 +57,7 @@ public WorldType(String name, RegistryEntry block, RegistryEntry> getIgnoredFeatures() { + return ingoredFeatures; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -102,41 +109,33 @@ public void exportIfNotExist(MinecraftServer server) throws IllegalStateExceptio } public void export(MinecraftServer server) throws IllegalStateException, IOException { + List loggedTypes = new ArrayList<>(); 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()); - } - } - //Todo better way to do this - if (!placedFeature.feature().is(OreFeatures.ORE_INFESTED)) { - DataResult json = PlacedFeature.DIRECT_CODEC.encodeStart(JsonOps.INSTANCE, placedFeature); - if (json.result().isPresent()) { + if (!placedFeature.feature().is(ingoredFeatures)) { + RegistryAccess.Frozen frozen = server.registryAccess(); + ConfiguredFeature configuredFeatureReference = placedFeature.feature().value(); + Feature feature1 = configuredFeatureReference.feature(); + ResourceLocation key1 = frozen.registryOrThrow(Registries.FEATURE).getKey(feature1); + FeatureTypeRegistry.getFeatureType(key1).ifPresentOrElse(iFeatureTypeCompact -> { 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); + oresCodecs.add(iFeatureTypeCompact.getOreCodec(configuredFeatureReference.config(), placedFeature.placement())); + } catch (ClassCastException e) { + LOGGER.error("Failed to parse ore Wrong Ore Config?", e); + } catch (Exception e) { + LOGGER.error("Failed to parse ore", e); } - } + }, () -> { + if (!loggedTypes.contains(key1.toString())) { + loggedTypes.add(key1.toString()); + LOGGER.debug("No Feature Mapping for: {}", key1); + } + }); } - DataResult result = ConfigCodec.CODEC.encodeStart(JsonOps.INSTANCE, new ConfigCodec(1, oresCodecs)); + DataResult result = ConfigCodec.CODEC.encodeStart(JsonOps.INSTANCE, new ConfigCodec(1, false, oresCodecs)); if (result.result().isPresent()) { if (!Files.exists(JAMD.CONFIG_FOLDER)) { Files.createDirectories(JAMD.CONFIG_FOLDER); diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java b/common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java index e2684ee..eaf3d2b 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/api/FeatureTypeRegistry.java @@ -1,30 +1,32 @@ package com.unrealdinnerbone.jamd.api; import com.unrealdinnerbone.trenzalore.api.platform.Services; +import net.minecraft.resources.ResourceLocation; 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.*; import java.util.function.Supplier; public class FeatureTypeRegistry { private static final Logger LOGGER = LogManager.getLogger(); - public static final List> FEATURES = new ArrayList<>(); + public static final Map> FEATURES = new HashMap<>(); - public static void register(String modId, Supplier> featureTypeCompact) { + public static void register(String modId, String id, Supplier> featureTypeCompact) { + register(modId, new ResourceLocation(modId, id), featureTypeCompact); + } + public static void register(String modId, ResourceLocation id, Supplier> featureTypeCompact) { if (Services.PLATFORM.isModLoaded(modId)) { IFeatureTypeCompact iFeatureTypeCompact = featureTypeCompact.get(); - LOGGER.debug("Registering Feature {} for {}", iFeatureTypeCompact.getFeatureType(), modId); - FEATURES.add(iFeatureTypeCompact); + LOGGER.debug("Registering Feature {} for {}", id, modId); + FEATURES.put(id, 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(); + public static Optional> getFeatureType(ResourceLocation id) { + return Optional.ofNullable(FEATURES.get(id)); } } diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java b/common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java index 5a7d61a..067024e 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/api/IFeatureTypeCompact.java @@ -1,31 +1,17 @@ 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.feature.configurations.FeatureConfiguration; 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); - } + default OresCodec getOreCodec(FeatureConfiguration feature, List modifiers) throws IllegalArgumentException { + return parse((T) feature, modifiers); } - /** - * @return The ore config codec - */ - Codec getCodec(); - /** * @param value the parsed ore config codec * @param placementModifiers the placement modifiers to create ore codec @@ -33,8 +19,4 @@ default OresCodec getOreCodec(JsonObject config, List modifie */ OresCodec parse(T value, List placementModifiers); - /** - * @return feature type id - */ - ResourceLocation getFeatureType(); } 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 543726d..c0886e1 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/command/JamdCommand.java @@ -27,12 +27,13 @@ public class JamdCommand { public static void register(CommandDispatcher commandDispatcher) { commandDispatcher.register(Commands.literal("jamd") - .then(Commands.literal("export") - .then(Commands.argument("type", StringArgumentType.string()) - .suggests((context, builder) -> SharedSuggestionProvider.suggest(WorldType.TYPES.stream().map(WorldType::getName), builder)) - .executes(JamdCommand::export) + .requires((commandSourceStack) -> commandSourceStack.hasPermission(Commands.LEVEL_GAMEMASTERS)) + .then(Commands.literal("export") + .then(Commands.argument("type", StringArgumentType.string()) + .suggests((context, builder) -> SharedSuggestionProvider.suggest(WorldType.TYPES.stream().map(WorldType::getName), builder)) + .executes(JamdCommand::export))) .then(Commands.literal("reload") - .executes(JamdCommand::reload))))); + .executes(JamdCommand::reload))); } diff --git a/common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftScatteredOre.java b/common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftScatteredOre.java deleted file mode 100644 index 4d1f614..0000000 --- a/common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftScatteredOre.java +++ /dev/null @@ -1,30 +0,0 @@ -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 MinecraftScatteredOre implements IFeatureTypeCompact { - - private static final ResourceLocation FEATURE_TYPE = new ResourceLocation("minecraft", "scattered_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/compact/MinecraftOreCompact.java b/common/src/main/java/com/unrealdinnerbone/jamd/compact/minecraft/MinecraftOreCompact.java similarity index 62% rename from common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftOreCompact.java rename to common/src/main/java/com/unrealdinnerbone/jamd/compact/minecraft/MinecraftOreCompact.java index 7d026eb..968b8ae 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/compact/MinecraftOreCompact.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/compact/minecraft/MinecraftOreCompact.java @@ -1,6 +1,5 @@ -package com.unrealdinnerbone.jamd.compact; +package com.unrealdinnerbone.jamd.compact.minecraft; -import com.mojang.serialization.Codec; import com.unrealdinnerbone.jamd.OresCodec; import com.unrealdinnerbone.jamd.api.IFeatureTypeCompact; import net.minecraft.resources.ResourceLocation; @@ -10,21 +9,9 @@ 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 index 5318b10..b45f074 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/util/OreRegistry.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/util/OreRegistry.java @@ -52,7 +52,7 @@ public static List getFeatures(WorldType type) { ConfigCodec configCodec = result.get(); for (int i = 0; i < configCodec.oreMultiplier(); i++) { for (OresCodec ore : configCodec.ores()) { - features.add(Transformers.fromConfigCodec(ore)); + features.add(Transformers.fromConfigCodec(ore, configCodec.ignoreAirChance())); } } REGISTERED_FEATURES.put(type, features); 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 2d4a79e..3981e74 100644 --- a/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java +++ b/common/src/main/java/com/unrealdinnerbone/jamd/util/Transformers.java @@ -9,8 +9,8 @@ public class Transformers { - public static PlacedFeature fromConfigCodec(OresCodec oresCodec) { - ConfiguredFeature> oreFeature = new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(oresCodec.targets(), oresCodec.oreSize(), oresCodec.discardChance())); + public static PlacedFeature fromConfigCodec(OresCodec oresCodec, boolean ignoreAirChance) { + ConfiguredFeature> oreFeature = new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(oresCodec.targets(), oresCodec.oreSize(), ignoreAirChance ? 0 : oresCodec.discardChance())); return new PlacedFeature(Holder.direct(oreFeature), oresCodec.modifiers()); } } diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/FeatureTagProvider.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/FeatureTagProvider.java new file mode 100644 index 0000000..21f05d1 --- /dev/null +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/FeatureTagProvider.java @@ -0,0 +1,28 @@ +package com.unrealdinnerbone.jamd.data; + +import com.unrealdinnerbone.jamd.JAMDRegistry; +import com.unrealdinnerbone.jamd.WorldType; +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.features.OreFeatures; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; + +import java.util.concurrent.CompletableFuture; + +public class FeatureTagProvider extends FabricTagProvider> { + public FeatureTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, Registries.CONFIGURED_FEATURE, registriesFuture); + } + + @Override + protected void addTags(HolderLookup.Provider arg) { + getOrCreateTagBuilder(JAMDRegistry.OVERWORLD.getIgnoredFeatures()) + .add(OreFeatures.ORE_INFESTED); + + } +} diff --git a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java index 3af290b..7ac5f26 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java +++ b/fabric/src/main/java/com/unrealdinnerbone/jamd/data/JAMDData.java @@ -35,6 +35,7 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { pack.addProvider(RecipeProvider::new); pack.addProvider(LootTableProvider::new); pack.addProvider(AdvancementProvider::new); + pack.addProvider(FeatureTagProvider::new); } @Override diff --git a/gradle.properties b/gradle.properties index 19c76c1..cb23a79 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project -mod_version=4.1.0 +mod_version=4.2.0 maven_group=com.unrealdinnerbone curse_id=422981 mod_name=JAMD diff --git a/neo/src/main/java/com/unrealdinnerbone/jamd/neo/JAMDNeo.java b/neo/src/main/java/com/unrealdinnerbone/jamd/neo/JAMDNeo.java index 108c359..d324ca0 100644 --- a/neo/src/main/java/com/unrealdinnerbone/jamd/neo/JAMDNeo.java +++ b/neo/src/main/java/com/unrealdinnerbone/jamd/neo/JAMDNeo.java @@ -21,8 +21,8 @@ public JAMDNeo() { } public static void registerCompact() { - FeatureTypeRegistry.register("mekanism", MekenismOreCompact::new); - FeatureTypeRegistry.register("immersiveengineering", IECompact::new); + FeatureTypeRegistry.register("mekanism", "ore", MekenismOreCompact::new); + FeatureTypeRegistry.register("immersiveengineering", "ie_ore", IECompact::new); } public void onRegisterCommands(RegisterCommandsEvent event) { diff --git a/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/IECompact.java b/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/IECompact.java index 2790499..c9fe8b7 100644 --- a/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/IECompact.java +++ b/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/IECompact.java @@ -11,21 +11,12 @@ public class IECompact implements IFeatureTypeCompact { - private static final ResourceLocation LOCATION = new ResourceLocation("immersiveengineering", "ie_ore"); - @Override - public Codec getCodec() { - return IEOreFeature.IEOreFeatureConfig.CODEC; - } + public static final ResourceLocation ID = new ResourceLocation("immersiveengineering", "ie_ore"); @Override public OresCodec parse(IEOreFeature.IEOreFeatureConfig value, List placementModifiers) { return new OresCodec(value.getSize(), (float) value.getAirExposure(), placementModifiers, value.targetList()); } - @Override - public ResourceLocation getFeatureType() { - return LOCATION; - } - } diff --git a/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/MekenismOreCompact.java b/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/MekenismOreCompact.java index 8fb23ba..9c2223b 100644 --- a/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/MekenismOreCompact.java +++ b/neo/src/main/java/com/unrealdinnerbone/jamd/neo/compact/MekenismOreCompact.java @@ -1,6 +1,5 @@ package com.unrealdinnerbone.jamd.neo.compact; -import com.mojang.serialization.Codec; import com.unrealdinnerbone.jamd.OresCodec; import com.unrealdinnerbone.jamd.api.IFeatureTypeCompact; import mekanism.common.world.ResizableOreFeatureConfig; @@ -11,20 +10,9 @@ 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/neo/src/main/resources/META-INF/accesstransformer.cfg b/neo/src/main/resources/META-INF/accesstransformer.cfg index 6348532..83f2979 100644 --- a/neo/src/main/resources/META-INF/accesstransformer.cfg +++ b/neo/src/main/resources/META-INF/accesstransformer.cfg @@ -4,5 +4,3 @@ public net.minecraft.world.level.levelgen.placement.HeightRangePlacement height public net.minecraft.world.level.levelgen.placement.CountPlacement count public net.minecraft.world.level.levelgen.heightproviders.ConstantHeight value public net.minecraft.world.level.biome.BiomeGenerationSettings featureSet - -public net.minecraft.world.item.crafting.S