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 revision Previous revision
Next revision
Previous revision
tutorial:blocks [2020/08/16 17:09]
leocth2 who tf wrote this section? java 101 when
tutorial:blocks [2021/02/27 07:51]
siglong Fix misleading highlight
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)));​
     }     }
 } }
Line 169: Line 170:
 To use your custom block class, replace //new Block// with //new ExampleBlock//:​ To use your custom block class, replace //new Block// with //new ExampleBlock//:​
  
-<code java [enable_line_numbers="​true",​highlight_lines_extra="​7"]>+<code java [enable_line_numbers="​true",​highlight_lines_extra="​3"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
tutorial/blocks.txt · Last modified: 2021/02/27 07:51 by siglong