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/06/14 00:58] – copy comments to bottom code block draylartutorial:blocks [2020/06/14 01:02] – more highlighting draylar
Line 27: Line 27:
 Blocks should be registered under the ''Block.REGISTRY'' registry. Call //Registry.register// and pass in the appropriate arguments. Blocks should be registered under the ''Block.REGISTRY'' registry. Call //Registry.register// and pass in the appropriate arguments.
  
-<code java [enable_line_numbers="true",highlight_lines_extra="8"]>+<code java [enable_line_numbers="true",highlight_lines_extra="11"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
Line 49: Line 49:
 In most cases, you want to be able to place your block using an item. To do this, you need to register a corresponding BlockItem in the item registry. You can do this by registering an instance of BlockItem under Registry.ITEM. The registry name of the item should usually be the same as the registry name of the block. In most cases, you want to be able to place your block using an item. To do this, you need to register a corresponding BlockItem in the item registry. You can do this by registering an instance of BlockItem under Registry.ITEM. The registry name of the item should usually be the same as the registry name of the block.
  
-<code java [enable_line_numbers="true",highlight_lines_extra="9"]>+<code java [enable_line_numbers="true",highlight_lines_extra="12"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
-    // an instance of our new block+    /* Declare and initialize our custom block instance. 
 +       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));     public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL));
          
Line 150: Line 153:
 You can override methods in the block class for custom functionality. Here's an implementation of the ''onUse'' method, which is called when you right-click the block. We check if the interaction is occurring on the server, and then send the player a message saying, //"Hello, world!"// You can override methods in the block class for custom functionality. Here's an implementation of the ''onUse'' method, which is called when you right-click the block. We check if the interaction is occurring on the server, and then send the player a message saying, //"Hello, world!"//
  
-<code java [enable_line_numbers="true"]>+<code java [enable_line_numbers="true",highlight_lines_extra="8,9,10,11,12,13,14,15"]>
 @Override @Override
 public class ExampleBlock extends Block { public class ExampleBlock extends Block {
Line 171: Line 174:
 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"]>+<code java [enable_line_numbers="true",highlight_lines_extra="7"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
tutorial/blocks.txt · Last modified: 2024/04/15 01:52 by solidblock