tutorial:features
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:features [2022/09/03 23:28] – add github link miir | tutorial:features [2024/10/28 17:58] (current) – Fix new identifier vs Identifier.of cassiancc | ||
---|---|---|---|
Line 20: | Line 20: | ||
< | < | ||
public class ExampleFeature extends class_3031< | public class ExampleFeature extends class_3031< | ||
- | public | + | public |
- | | + | |
} | } | ||
Line 36: | Line 36: | ||
// don't worry about where these come from-- we'll implement these methods soon | // don't worry about where these come from-- we'll implement these methods soon | ||
int number = config.number(); | int number = config.number(); | ||
- | class_2960 | + | class_2960 |
- | class_2680 blockState = class_2378.field_11146.get(blockID).method_9564(); | + | class_2680 blockState = class_7923.field_41175.get(blockId).method_9564(); |
- | // ensure the ID is okay | + | // ensure the ID is okay |
- | if (blockState == null) throw new IllegalStateException(blockID | + | if (blockState == null) throw new IllegalStateException(blockId |
// find the surface of the world | // find the surface of the world | ||
Line 50: | Line 50: | ||
if (world.method_8320(testPos.method_10086()).isOf(class_2246.field_10124)) { | if (world.method_8320(testPos.method_10086()).isOf(class_2246.field_10124)) { | ||
for (int i = 0; i < number; i++) { | for (int i = 0; i < number; i++) { | ||
- | // create a simple pillar of blocks | + | |
world.method_8501(testPos, | world.method_8501(testPos, | ||
testPos = testPos.method_10086(); | testPos = testPos.method_10086(); | ||
Line 61: | Line 61: | ||
} | } | ||
} | } | ||
- | // the game couldn' | + | // the game couldn' |
return false; | return false; | ||
} | } | ||
Line 69: | Line 69: | ||
Now, we need to implement that '' | Now, we need to implement that '' | ||
< | < | ||
- | public record ExampleFeatureConfig(int number, Identifier | + | public record ExampleFeatureConfig(int number, Identifier |
- | public ExampleFeatureConfig(int number, Identifier blockID) { | + | public static |
- | this.blockID = blockID; | + | instance -> instance.group( |
- | this.number = number; | + | |
- | } | + | |
- | + | ||
- | public static Codec< | + | |
- | instance -> | + | |
- | | + | |
// you can add as many of these as you want, one for each parameter | // you can add as many of these as you want, one for each parameter | ||
Codecs.POSITIVE_INT.fieldOf(" | Codecs.POSITIVE_INT.fieldOf(" | ||
- | Identifier.CODEC.fieldOf(" | + | Identifier.CODEC.fieldOf(" |
.apply(instance, | .apply(instance, | ||
- | + | } | |
- | public int number() { | + | |
- | return number; | + | |
- | } | + | |
- | public Identifier blockID() { | + | |
- | return blockID; | + | |
- | | + | |
</ | </ | ||
Line 94: | Line 82: | ||
<code java> | <code java> | ||
- | public class FeatureExampleMod | + | public class ExampleMod |
- | public static final Identifier EXAMPLE_FEATURE_ID = new Identifier(" | + | public static final Identifier EXAMPLE_FEATURE_ID = Identifier.of("tutorial", " |
- | public static | + | public static |
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
- | Registry.register(Registry.FEATURE, EXAMPLE_FEATURE_ID, | + | Registry.register(Registries.FEATURE, EXAMPLE_FEATURE_ID, |
} | } | ||
} | } | ||
Line 113: | Line 101: | ||
public class FeatureExampleMod implements ModInitializer { | public class FeatureExampleMod implements ModInitializer { | ||
- | public static final Identifier EXAMPLE_FEATURE_ID = new Identifier(" | + | public static final Identifier EXAMPLE_FEATURE_ID = Identifier.of("tutorial", " |
- | public static | + | public static |
- | public static ConfiguredFeature< | + | public static |
- | | + | EXAMPLE_FEATURE, |
- | new ExampleFeatureConfig(10, | + | new ExampleFeatureConfig(10, |
); | ); | ||
Line 129: | Line 117: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | FIXME The last line has to be updated | ||
==== Adding a configured feature to a biome ==== | ==== Adding a configured feature to a biome ==== | ||
Line 135: | Line 125: | ||
Our final initializer class looks like this: | Our final initializer class looks like this: | ||
< | < | ||
- | public class FeatureExampleMod | + | public class ExampleMod |
- | public static final Identifier EXAMPLE_FEATURE_ID = new Identifier(" | + | public static final Identifier EXAMPLE_FEATURE_ID = Identifier.of("tutorial", " |
- | public static | + | public static |
- | public static ConfiguredFeature< | + | public static |
- | | + | EXAMPLE_FEATURE, |
- | new ExampleFeatureConfig(10, | + | new ExampleFeatureConfig(10, |
); | ); | ||
// our PlacedFeature. this is what gets passed to the biome modification API to add to the biome. | // our PlacedFeature. this is what gets passed to the biome modification API to add to the biome. | ||
Line 147: | Line 137: | ||
RegistryEntry.of( | RegistryEntry.of( | ||
EXAMPLE_FEATURE_CONFIGURED | EXAMPLE_FEATURE_CONFIGURED | ||
- | // the SquarePlacementModifier makes the feature generate a cluster of pillars each time | + | |
), List.of(SquarePlacementModifier.of()) | ), List.of(SquarePlacementModifier.of()) | ||
); | ); | ||
Line 153: | Line 143: | ||
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
- | // register the features | + | |
- | Registry.register(Registry.FEATURE, EXAMPLE_FEATURE_ID, | + | Registry.register(class_7923.field_41144, EXAMPLE_FEATURE_ID, |
- | Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, | + | |
- | Registry.register(BuiltinRegistries.PLACED_FEATURE, | + | |
- | // add it to overworld biomes using FAPI | + | |
BiomeModifications.addFeature( | BiomeModifications.addFeature( | ||
BiomeSelectors.foundInOverworld(), | BiomeSelectors.foundInOverworld(), | ||
// the feature is to be added while flowers and trees are being generated | // the feature is to be added while flowers and trees are being generated | ||
GenerationStep.Feature.VEGETAL_DECORATION, | GenerationStep.Feature.VEGETAL_DECORATION, | ||
- | RegistryKey.of(Registry.PLACED_FEATURE_KEY, EXAMPLE_FEATURE_ID)); | + | RegistryKey.of(RegistryKeys.PLACED_FEATURE, EXAMPLE_FEATURE_ID)); |
} | } | ||
} | } |
tutorial/features.1662247736.txt.gz · Last modified: 2022/09/03 23:28 by miir