I'm developing a mod for Minecraft 1.18.2 using Fabric. I'd like my mod to replace all the vanilla birch trees (or whatever) in the game with my custom ones (or whatever). To do this, I'm trying to override the vanilla configured feature minecraft:birch to my custom configured feature that I've prepared in advance.
NOTE: birch trees must be completely replaced in the game, not only during the world generation phase, but also in all other possible game events and situations (e.g. when growing a birch sapling). Therefore, the use of Fabric Biome Modifications API will not cover all the necessary game situations.
I've written some code examples, but none of them work. In the error message, Fabric suggests using the .set() method instead of the .register(), but this method does not exist in the net.minecraft.core.Registry class (Parchment mappings) or net.minecraft.util.registry.Registry class (Yarn mappings). So I have no clue what to do with this information.
Is there any way to solve this problem without using mixins or datapacks (if possible)?
NOTE: I'm looking for a compact, simple, clear solution, so I don't prioritize the use of mixins and datapacks. If there are no other ways, then I can use them.
Vanilla source code
NOTE: I'm using Minecraft 1.18.2 with Parchment mappings.
package net.minecraft.data.worldgen.features;
// ...
public class TreeFeatures {
// ...
public static final Holder<ConfiguredFeature<TreeConfiguration, ?>> BIRCH = FeatureUtils.register("birch", Feature.TREE, TreeFeatures.createBirch().build());
// ...
}
My code
NOTE: I'm using Minecraft 1.18.2 with Parchment mappings.
Way 1 (according to the vanilla source code)
️ Code
FeatureUtils.register("birch", Feature.TREE, MyCustomTreeFeatures.createMyCustomBirch().build());
❌ Error
Attempted to register ID ResourceKey[minecraft:worldgen/configured_feature / minecraft:birch] at different raw IDs (24, 184)! If you're trying to override an item, use .set(), not .register()!
Way 2 (according to Fabric Wiki tutorial)
️ Code
Registry.register(Registry.FEATURE, "birch", Feature.TREE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, "birch", new ConfiguredFeature<>(Feature.TREE, MyCustomTreeFeatures.createMyCustomBirch().build()));
❌ Error
Attempted to register object net.minecraft.world.level.levelgen.feature.TreeFeature@2aaa5122 twice! (at raw IDs 1 and 61 )
Way 3 (according to Fabric Wiki tutorial without first line)
️ Code
// Registry.register(Registry.FEATURE, "birch", Feature.TREE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, "birch", new ConfiguredFeature<>(Feature.TREE, MyCustomTreeFeatures.createMyCustomBirch().build()));
❌ Error
Attempted to register ID ResourceKey[minecraft:worldgen/configured_feature / minecraft:birch] at different raw IDs (24, 184)! If you're trying to override an item, use .set(), not .register()!
Way 4 (using datapack)
️ File added
File path: src/main/resources/pack.mcmeta
File content:
{
"pack": {
"pack_format": 9,
"description": "My mod resources."
}
}
️ File added
File path: src/main/resources/data/minecraft/worldgen/configured_feature/birch.json
File content: the original JSON code of the vanilla birch tree configured feature, but with a slight modification of the trunk height.
❌ Does not work
Changes are not applied, nothing happens. I think this is due to the fact that my mod's datapack has a lower priority than the vanilla datapack, but I don't know how to fix it.
My system Info
Minecraft version: 1.18.2
Mappings: Parchment
Parchment mappings version: 2022.11.06
Fabric API version: 0.76.0+1.18.2
Fabric loader version: 0.14.24
Fabric loom version: 1.4-SNAPSHOT
Java version: 17
Gradle version: 8.4
OS: Windows 10