From 9859404a97dbb6d40263266694ce8e757fa388ce Mon Sep 17 00:00:00 2001 From: AlsoSomeoneElse <64546452+AlsoSomeoneElse@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:06:22 +0100 Subject: [PATCH] [1.20.4] Port feature mod element (#4570) * Ported datapack feature templates * Ported some feature blocks * Port feature to NeoForge (without structure feature) * Port holder set feature blocks (used by structure feature) * Port structure feature, with cleaner config code --- .../datapack-1.20.4}/feature.definition.yaml | 0 .../features/_mcitemblock.json.ftl | 0 .../features/block_holderset_list.json.ftl | 0 .../features/block_holderset_tag.json.ftl | 0 .../features/feature_lake.json.ftl | 0 .../features/feature_no_op.json.ftl | 0 .../features/feature_simple_block.json.ftl | 0 .../features/placement_biome_filter.json.ftl | 0 .../features/placement_heightmap.json.ftl | 0 .../features/placement_in_square.json.ftl | 0 .../datapack-1.20.4/mappings/features.yaml | 22 +++++++++++++++++++ .../feature/configured_feature.json.ftl | 0 .../templates/feature/placed_feature.json.ftl | 0 .../neoforge-1.20.4}/common.features.yaml | 0 .../neoforge-1.20.4}/feature.definition.yaml | 2 +- .../feature_custom_structure.json.ftl | 0 .../templates/elementinits/features.java.ftl | 8 +++---- .../templates/feature/feature.java.ftl | 1 - .../feature/structure_feature.java.ftl | 10 ++++----- .../structure_feature_configuration.java.ftl | 20 +++++++---------- .../json/feature_biome_modifier.json.ftl | 4 ++-- .../templates/modbase/mod.java.ftl | 2 ++ 22 files changed, 44 insertions(+), 25 deletions(-) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/feature.definition.yaml (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/_mcitemblock.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/block_holderset_list.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/block_holderset_tag.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/feature_lake.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/feature_no_op.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/feature_simple_block.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/placement_biome_filter.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/placement_heightmap.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/features/placement_in_square.json.ftl (100%) create mode 100644 plugins/generator-1.20.4/datapack-1.20.4/mappings/features.yaml rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/templates/feature/configured_feature.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-datapack-1.20.1 => generator-1.20.4/datapack-1.20.4}/templates/feature/placed_feature.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/common.features.yaml (100%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/feature.definition.yaml (91%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/features/feature_custom_structure.json.ftl (100%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/templates/elementinits/features.java.ftl (83%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/templates/feature/feature.java.ftl (96%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/templates/feature/structure_feature.java.ftl (84%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/templates/feature/structure_feature_configuration.java.ftl (70%) rename plugins/{generator-reference-1.20.1/ref-forge-1.20.1 => generator-1.20.4/neoforge-1.20.4}/templates/json/feature_biome_modifier.json.ftl (84%) diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/feature.definition.yaml b/plugins/generator-1.20.4/datapack-1.20.4/feature.definition.yaml similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/feature.definition.yaml rename to plugins/generator-1.20.4/datapack-1.20.4/feature.definition.yaml diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/_mcitemblock.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/_mcitemblock.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/_mcitemblock.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/_mcitemblock.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/block_holderset_list.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/block_holderset_list.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/block_holderset_list.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/block_holderset_list.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/block_holderset_tag.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/block_holderset_tag.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/block_holderset_tag.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/block_holderset_tag.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/feature_lake.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/feature_lake.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/feature_lake.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/feature_lake.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/feature_no_op.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/feature_no_op.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/feature_no_op.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/feature_no_op.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/feature_simple_block.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/feature_simple_block.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/feature_simple_block.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/feature_simple_block.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/placement_biome_filter.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/placement_biome_filter.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/placement_biome_filter.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/placement_biome_filter.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/placement_heightmap.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/placement_heightmap.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/placement_heightmap.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/placement_heightmap.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/placement_in_square.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/features/placement_in_square.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/features/placement_in_square.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/features/placement_in_square.json.ftl diff --git a/plugins/generator-1.20.4/datapack-1.20.4/mappings/features.yaml b/plugins/generator-1.20.4/datapack-1.20.4/mappings/features.yaml new file mode 100644 index 00000000000..ab15916bafd --- /dev/null +++ b/plugins/generator-1.20.4/datapack-1.20.4/mappings/features.yaml @@ -0,0 +1,22 @@ +_default: + - NoOpFeature + - NoneFeatureConfiguration + - "minecraft:no_op" +feature_no_op: + - NoOpFeature + - NoneFeatureConfiguration + - "minecraft:no_op" +feature_lake: + - LakeFeature + - LakeFeature.Configuration + - "minecraft:lake" +feature_simple_block: + - SimpleBlockFeature + - SimpleBlockConfiguration + - "minecraft:simple_block" + +# Custom NBT-based feature, not present in vanilla +feature_custom_structure: + - StructureFeature + - StructureFeatureConfiguration + - "@modid:structure_feature" \ No newline at end of file diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/templates/feature/configured_feature.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/templates/feature/configured_feature.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/templates/feature/configured_feature.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/templates/feature/configured_feature.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-datapack-1.20.1/templates/feature/placed_feature.json.ftl b/plugins/generator-1.20.4/datapack-1.20.4/templates/feature/placed_feature.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-datapack-1.20.1/templates/feature/placed_feature.json.ftl rename to plugins/generator-1.20.4/datapack-1.20.4/templates/feature/placed_feature.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/common.features.yaml b/plugins/generator-1.20.4/neoforge-1.20.4/common.features.yaml similarity index 100% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/common.features.yaml rename to plugins/generator-1.20.4/neoforge-1.20.4/common.features.yaml diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/feature.definition.yaml b/plugins/generator-1.20.4/neoforge-1.20.4/feature.definition.yaml similarity index 91% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/feature.definition.yaml rename to plugins/generator-1.20.4/neoforge-1.20.4/feature.definition.yaml index ec5dd7af62d..526de7f0d52 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/feature.definition.yaml +++ b/plugins/generator-1.20.4/neoforge-1.20.4/feature.definition.yaml @@ -4,7 +4,7 @@ templates: condition: hasGenerationConditions() - template: json/feature_biome_modifier.json.ftl writer: json - name: "@MODDATAROOT/forge/biome_modifier/@registryname_biome_modifier.json" + name: "@MODDATAROOT/neoforge/biome_modifier/@registryname_biome_modifier.json" - template: feature/configured_feature.json.ftl # loaded from datapack generator writer: json name: "@MODDATAROOT/worldgen/configured_feature/@registryname.json" diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/features/feature_custom_structure.json.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/features/feature_custom_structure.json.ftl similarity index 100% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/features/feature_custom_structure.json.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/features/feature_custom_structure.json.ftl diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/elementinits/features.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/elementinits/features.java.ftl similarity index 83% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/elementinits/features.java.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/templates/elementinits/features.java.ftl index 3a69180b0d9..06371799692 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/elementinits/features.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/elementinits/features.java.ftl @@ -1,7 +1,7 @@ <#-- # MCreator (https://mcreator.net/) # Copyright (C) 2012-2020, Pylo - # Copyright (C) 2020-2023, Pylo, opensource contributors + # Copyright (C) 2020-2024, Pylo, opensource contributors # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,12 +36,12 @@ package ${package}.init; -@Mod.EventBusSubscriber public class ${JavaModName}Features { +public class ${JavaModName}Features { - public static final DeferredRegister> REGISTRY = DeferredRegister.create(ForgeRegistries.FEATURES, ${JavaModName}.MODID); + public static final DeferredRegister> REGISTRY = DeferredRegister.create(Registries.FEATURE, ${JavaModName}.MODID); <#list features as feature> - public static final RegistryObject> ${feature.getModElement().getRegistryNameUpper()} = + public static final DeferredHolder, Feature> ${feature.getModElement().getRegistryNameUpper()} = REGISTRY.register("${feature.getModElement().getRegistryName()}", ${feature.getModElement().getName()}Feature::new); diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/feature.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/feature.java.ftl similarity index 96% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/feature.java.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/feature.java.ftl index a3bd5ade25d..1cd3501cc99 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/feature.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/feature.java.ftl @@ -30,7 +30,6 @@ <#-- @formatter:off --> <#include "../procedures.java.ftl"> -<#include "../mcitems.ftl"> package ${package}.world.features; diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/structure_feature.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/structure_feature.java.ftl similarity index 84% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/structure_feature.java.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/structure_feature.java.ftl index 7915c7e2f14..c61c37f3b6f 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/structure_feature.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/structure_feature.java.ftl @@ -1,7 +1,7 @@ <#-- # MCreator (https://mcreator.net/) # Copyright (C) 2012-2020, Pylo - # Copyright (C) 2020-2023, Pylo, opensource contributors + # Copyright (C) 2020-2024, Pylo, opensource contributors # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,9 +32,9 @@ package ${package}.world.features; <#compress> -@Mod.EventBusSubscriber public class StructureFeature extends Feature { - public static final DeferredRegister> REGISTRY = DeferredRegister.create(ForgeRegistries.FEATURES, ${JavaModName}.MODID); - public static final RegistryObject> STRUCTURE_FEATURE = REGISTRY.register("structure_feature", () -> new StructureFeature(StructureFeatureConfiguration.CODEC)); +public class StructureFeature extends Feature { + public static final DeferredRegister> REGISTRY = DeferredRegister.create(Registries.FEATURE, ${JavaModName}.MODID); + public static final DeferredHolder, StructureFeature> STRUCTURE_FEATURE = REGISTRY.register("structure_feature", () -> new StructureFeature(StructureFeatureConfiguration.CODEC)); public StructureFeature(Codec codec) { super(codec); @@ -51,7 +51,7 @@ package ${package}.world.features; StructureTemplateManager structureManager = worldGenLevel.getLevel().getServer().getStructureManager(); StructureTemplate template = structureManager.getOrCreate(config.structure()); StructurePlaceSettings placeSettings = (new StructurePlaceSettings()).setRotation(rotation).setMirror(mirror).setRandom(random).setIgnoreEntities(false) - .addProcessor(new BlockIgnoreProcessor(config.ignoredBlocks().stream().map(Holder::get).toList())); + .addProcessor(new BlockIgnoreProcessor(config.ignoredBlocks().stream().map(Holder::value).toList())); template.placeInWorld(worldGenLevel, placePos, placePos, placeSettings, random, 4); return true; } diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/structure_feature_configuration.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/structure_feature_configuration.java.ftl similarity index 70% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/structure_feature_configuration.java.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/structure_feature_configuration.java.ftl index 4b4073e47cd..59b3c7bc658 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/feature/structure_feature_configuration.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/feature/structure_feature_configuration.java.ftl @@ -1,7 +1,7 @@ <#-- # MCreator (https://mcreator.net/) # Copyright (C) 2012-2020, Pylo - # Copyright (C) 2020-2023, Pylo, opensource contributors + # Copyright (C) 2020-2024, Pylo, opensource contributors # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,17 +33,13 @@ package ${package}.world.features.configurations; public record StructureFeatureConfiguration(ResourceLocation structure, boolean randomRotation, boolean randomMirror, HolderSet ignoredBlocks, Vec3i offset) implements FeatureConfiguration { public static final Codec CODEC = RecordCodecBuilder.create(builder -> { - return builder.group(ResourceLocation.CODEC.fieldOf("structure").forGetter(config -> { - return config.structure; - }), Codec.BOOL.fieldOf("random_rotation").orElse(false).forGetter(config -> { - return config.randomRotation; - }), Codec.BOOL.fieldOf("random_mirror").orElse(false).forGetter(config -> { - return config.randomMirror; - }), RegistryCodecs.homogeneousList(Registries.BLOCK).fieldOf("ignored_blocks").forGetter(config -> { - return config.ignoredBlocks; - }), Vec3i.offsetCodec(48).optionalFieldOf("offset", Vec3i.ZERO).forGetter(config -> { - return config.offset; - })).apply(builder, StructureFeatureConfiguration::new); + return builder.group( + ResourceLocation.CODEC.fieldOf("structure").forGetter(StructureFeatureConfiguration::structure), + Codec.BOOL.fieldOf("random_rotation").orElse(false).forGetter(StructureFeatureConfiguration::randomRotation), + Codec.BOOL.fieldOf("random_mirror").orElse(false).forGetter(StructureFeatureConfiguration::randomMirror), + RegistryCodecs.homogeneousList(Registries.BLOCK).fieldOf("ignored_blocks").forGetter(StructureFeatureConfiguration::ignoredBlocks), + Vec3i.offsetCodec(48).optionalFieldOf("offset", Vec3i.ZERO).forGetter(StructureFeatureConfiguration::offset) + ).apply(builder, StructureFeatureConfiguration::new); }); } <#-- @formatter:on --> diff --git a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/json/feature_biome_modifier.json.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/json/feature_biome_modifier.json.ftl similarity index 84% rename from plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/json/feature_biome_modifier.json.ftl rename to plugins/generator-1.20.4/neoforge-1.20.4/templates/json/feature_biome_modifier.json.ftl index 60dbb280bce..27250a919f0 100644 --- a/plugins/generator-reference-1.20.1/ref-forge-1.20.1/templates/json/feature_biome_modifier.json.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/json/feature_biome_modifier.json.ftl @@ -1,6 +1,6 @@ <#assign spawnBiomes = w.filterBrokenReferences(data.restrictionBiomes)> { - "type": "forge:add_features", + "type": "neoforge:add_features", <#if spawnBiomes?size == 1> "biomes": "${spawnBiomes?first}", <#elseif spawnBiomes?size gt 1> @@ -9,7 +9,7 @@ ], <#else> "biomes": { - "type": "forge:any" + "type": "neoforge:any" }, "features": "${modid}:${registryname}", diff --git a/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl b/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl index 48df5c72391..7173e21ae12 100644 --- a/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl +++ b/plugins/generator-1.20.4/neoforge-1.20.4/templates/modbase/mod.java.ftl @@ -31,6 +31,8 @@ import org.apache.logging.log4j.Logger; <#if w.hasSounds()>${JavaModName}Sounds.REGISTRY.register(modEventBus); <#if w.hasVariables()>${JavaModName}Variables.ATTACHMENT_TYPES.register(modEventBus); + <#if w.hasElementsOfBaseType("feature")>${JavaModName}Features.REGISTRY.register(modEventBus); + <#if w.getElementsOfType("feature")?filter(e -> e.getMetadata("has_nbt_structure")??)?size != 0>StructureFeature.REGISTRY.register(modEventBus); <#if w.hasElementsOfType("painting")>${JavaModName}Paintings.REGISTRY.register(modEventBus); <#if w.hasElementsOfType("potion")>${JavaModName}Potions.REGISTRY.register(modEventBus); <#if w.hasElementsOfType("potioneffect")>${JavaModName}MobEffects.REGISTRY.register(modEventBus);