User Tools

Site Tools


tutorial:blocks

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:blocks [2023/11/18 08:34] solidblocktutorial:blocks [2024/04/15 01:44] – update solidblock
Line 19: Line 19:
        You can find the stats of all vanilla blocks in the class `Blocks`, where you can also reference other blocks.        You can find the stats of all vanilla blocks in the class `Blocks`, where you can also reference other blocks.
     */     */
-    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); // fabric api version <= 0.77.0 +     
-    public static final Block EXAMPLE_BLOCK  = new Block(FabricBlockSettings.create().strength(4.0f));+    // For versions below 1.20: 
 +    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); 
 +    // For versions below 1.20.5: 
 +    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); 
 +    // For versions since 1.20.5: 
 +    public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); 
 +    
     @Override     @Override
     public void onInitialize() {     public void onInitialize() {
Line 37: Line 43:
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
-    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); // fabric api version <= 0.77.0 +    // For versions below 1.20: 
-    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f));+    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); 
 +    // For versions below 1.20.5: 
 +    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); 
 +    // For versions since 1.20.5: 
 +    public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f));
          
     @Override     @Override
Line 56: Line 66:
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
-    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); // fabric api version <= 0.77.0 +    // For versions below 1.20: 
-    public static final Block EXAMPLE_BLOCK  = new Block(FabricBlockSettings.create().strength(4.0f));+    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f)); 
 +    // For versions below 1.20.5: 
 +    // public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.create().strength(4.0f)); 
 +    // For versions since 1.20.5: 
 +    public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f));
          
     @Override     @Override
     public void onInitialize() {     public void onInitialize() {
         Registry.register(Registries.BLOCK, new Identifier("tutorial", "example_block"), EXAMPLE_BLOCK);         Registry.register(Registries.BLOCK, new Identifier("tutorial", "example_block"), EXAMPLE_BLOCK);
 +        // For versions below 1.20.5:
         Registry.register(Registries.ITEM, new Identifier("tutorial", "example_block"), new BlockItem(EXAMPLE_BLOCK, new FabricItemSettings()));         Registry.register(Registries.ITEM, new Identifier("tutorial", "example_block"), new BlockItem(EXAMPLE_BLOCK, new FabricItemSettings()));
 +        // For versions since 1.20.5:
 +        Registry.register(Registries.ITEM, new Identifier("tutorial", "example_block"), new BlockItem(EXAMPLE_BLOCK, new Item.Settings()));
     }     }
 } }
Line 164: Line 181:
 </code> </code>
  
-For the harvest level tags (''needs_stone_tool'', ''needs_iron_tool'' and ''needs_diamond_tool'') to take effect, add ''requiresTool()'' to the FabricBlockSettings in the block declaration:+For the harvest level tags (''needs_stone_tool'', ''needs_iron_tool'' and ''needs_diamond_tool'') to take effect, add ''requiresTool()'' to the ''Block.Settings'' in the block declaration (example of versions above 1.20.5):
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-    // public static final Block EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.of(Material.METAL).strength(4.0f).requiresTool()); // fabric api version <= 0.77.0 +    public static final Block EXAMPLE_BLOCK = new ExampleBlock(Block.Settings.create().strength(4.0f).requiresTool());
-    public static final Block EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.create().strength(4.0f).requiresTool());+
 </code> </code>
  
Line 193: Line 209:
     }     }
  
 +    // For versions below 1.20.5, the parameters should be "BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit"
     @Override     @Override
-    public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {+    public ActionResult onUse(World world, PlayerEntity player, BlockHitResult hit) {
         if (!world.isClient) {         if (!world.isClient) {
             player.sendMessage(Text.literal("Hello, world!"), false);             player.sendMessage(Text.literal("Hello, world!"), false);
tutorial/blocks.txt · Last modified: 2024/04/15 01:52 by solidblock