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 revisionBoth sides next revision
tutorial:blocks [2020/08/16 17:09] – who tf wrote this section? java 101 when leocth2tutorial:blocks [2021/01/30 12:04] – updating to latest mappings and fixing continuity errors leocth2
Line 11: Line 11:
  
     /* Declare and initialize our custom block instance.     /* Declare and initialize our custom block instance.
-       We set our block material to METAL, which requires a pickaxe to efficiently break. +       We set our block material to `METAL`, which requires a pickaxe to efficiently break
-       Hardness represents how long the break takes to break. Stone has a hardness of 1.5f, while Obsidian has a hardness of 50.0f.+        
 +       `strength` sets both the hardness and the resistance of a block to the same value
 +       Hardness determines how long the block takes to break, and resistance determines how strong the block is against blast damage (e.g. explosions). 
 +       Stone has a hardness of 1.5f and a resistance of 6.0f, while Obsidian has a hardness of 50.0f and a resistance of 1200.0f. 
 +        
 +       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).hardness(4.0f));+    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f));
          
     @Override     @Override
Line 25: Line 30:
 ==== Registering your Block ==== ==== Registering your Block ====
  
-Blocks should be registered under the ''Block.REGISTRY'' registry. Call //Registry.register// and pass in the appropriate arguments.+Blocks should be registered under the ''Registry.BLOCK'' registry. Call //Registry.register// and pass in the appropriate arguments.
  
 <code java [enable_line_numbers="true",highlight_lines_extra="11"]> <code java [enable_line_numbers="true",highlight_lines_extra="11"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
-    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).hardness(4.0f));+    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f));
          
     @Override     @Override
Line 48: Line 53:
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
-    /* Declare and initialize our custom block instance. +    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).strength(4.0f));
-       We set out block material to METAL, which requires a pickaxe to efficiently break. +
-       Hardness represents how long the break takes to break. Stone has a hardness of 1.5f, while Obsidian has a hardness of 50.0f. +
-    */ +
-    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL));+
          
     @Override     @Override
     public void onInitialize() {     public void onInitialize() {
         Registry.register(Registry.BLOCK, new Identifier("tutorial", "example_block"), EXAMPLE_BLOCK);         Registry.register(Registry.BLOCK, new Identifier("tutorial", "example_block"), EXAMPLE_BLOCK);
-        Registry.register(Registry.ITEM, new Identifier("tutorial", "example_block"), new BlockItem(EXAMPLE_BLOCK, new Item.Settings().group(ItemGroup.MISC)));+        Registry.register(Registry.ITEM, new Identifier("tutorial", "example_block"), new BlockItem(EXAMPLE_BLOCK, new FabricItemSettings().group(ItemGroup.MISC)));
     }     }
 } }
tutorial/blocks.txt · Last modified: 2023/11/18 08:34 by solidblock