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 [2020/08/01 16:30] – update mappings for EntityContext draylartutorial:blocks [2021/02/27 07:51] – Fix misleading highlight siglong
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 150: Line 151:
  
 <code java [enable_line_numbers="true",highlight_lines_extra="8,9,10,11,12,13,14,15"]> <code java [enable_line_numbers="true",highlight_lines_extra="8,9,10,11,12,13,14,15"]>
-@Override 
 public class ExampleBlock extends Block { public class ExampleBlock extends Block {
  
Line 170: 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: 2024/04/15 01:52 by solidblock