User Tools

Site Tools


tutorial:features

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:features [2023/12/17 14:20] solidblocktutorial:features [2023/12/18 01:12] – [Creating a feature] updat ecode solidblock
Line 20: Line 20:
 <yarncode java> <yarncode java>
 public class ExampleFeature extends class_3031<ExampleFeatureConfig> { public class ExampleFeature extends class_3031<ExampleFeatureConfig> {
-  public ExampleFeature(Codec<class_3111> configCodec) { +  public ExampleFeature(Codec<FeatureConfig> configCodec) { 
-    smethod_10086er(configCodec);+    super(configCodec);
   }   }
  
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 blockID = config.blockID();+        class_2960 blockId = config.blockId();
  
-        class_2680 blockState = class_7923.field_41175.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 + " could not be parsed to a valid block identifier!");+        if (blockState == null) throw new IllegalStateException(blockId + " could not be parsed to a valid block identifier!");
  
         // 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+                        // create a simple pillar of blocks
                         world.method_8501(testPos, blockState, 0x10);                         world.method_8501(testPos, blockState, 0x10);
                         testPos = testPos.method_10086();                         testPos = testPos.method_10086();
Line 61: Line 61:
             }             }
         }         }
-//        the game couldn't find a place to put the pillar+       // the game couldn't find a place to put the pillar
         return false;         return false;
     }     }
Line 71: Line 71:
 public record ExampleFeatureConfig(int number, Identifier blockId) implements FeatureConfig { public record ExampleFeatureConfig(int number, Identifier blockId) implements FeatureConfig {
     public static Codec<ExampleFeatureConfig> CODEC = RecordCodecBuilder.create(     public static Codec<ExampleFeatureConfig> CODEC = RecordCodecBuilder.create(
-        instance -> +        instance -> instance.group(
-                instance.group(+
                         // 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("number").forGetter(ExampleFeatureConfig::number),                         Codecs.POSITIVE_INT.fieldOf("number").forGetter(ExampleFeatureConfig::number),
Line 83: Line 82:
  
 <code java> <code java>
-public class FeatureExampleMod implements ModInitializer {+public class ExampleMod implements ModInitializer {
     public static final Identifier EXAMPLE_FEATURE_ID = new Identifier("tutorial", "example_feature");     public static final Identifier EXAMPLE_FEATURE_ID = new Identifier("tutorial", "example_feature");
-    public static Feature<ExampleFeatureConfig> EXAMPLE_FEATURE = new ExampleFeature(ExampleFeatureConfig.CODEC);+    public static final Feature<ExampleFeatureConfig> EXAMPLE_FEATURE = new ExampleFeature(ExampleFeatureConfig.CODEC);
  
     @Override     @Override
     public void onInitialize() {     public void onInitialize() {
-        Registry.register(Registry.FEATURE, EXAMPLE_FEATURE_ID, EXAMPLE_FEATURE);+        Registry.register(Registries.FEATURE, EXAMPLE_FEATURE_ID, EXAMPLE_FEATURE);
     }     }
 } }
tutorial/features.txt · Last modified: 2023/12/18 01:19 by solidblock