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/04/15 22:32] – Fixed loot table directory darthjaketutorial:blocks [2020/06/14 00:13] – block formatting changes + 1.16 draylar
Line 4: Line 4:
  
 To add a block to your mod, you will need to register a new instance of the Block class. For more control over your block, you can create a custom block class. We'll also look at adding a block model.  To add a block to your mod, you will need to register a new instance of the Block class. For more control over your block, you can create a custom block class. We'll also look at adding a block model. 
 +
 ==== Creating a Block ==== ==== Creating a Block ====
  
 To start, create an instance of Block in your main mod class. Block's constructor uses the FabricBlockSettings builder to set up basic properties of the block, such as hardness and resistance: To start, create an instance of Block in your main mod class. Block's constructor uses the FabricBlockSettings builder to set up basic properties of the block, such as hardness and resistance:
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public class ExampleMod implements ModInitializer +public class ExampleMod implements ModInitializer { 
-{+
     // an instance of our new block     // an instance of our new block
-    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).build()); +    public static final Block EXAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL)); 
-    [...]+     
 +    @Override 
 +    public void onInitialize() { 
 +         
 +    }
 } }
 </code> </code>
Line 21: Line 26:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public class ExampleMod implements ModInitializer +public class ExampleMod implements ModInitializer { 
-+ 
-    // block creation +    // an instance of our new block 
-    [...]+    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);
     }     }
Line 142: Line 146:
 If you want your block to be transparent, in your client mod initializer code, do: If you want your block to be transparent, in your client mod initializer code, do:
 <code java> <code java>
-    BlockRenderLayerMap.putBlock(/* your block */, RenderLayer.getTranslucent());+    BlockRenderLayerMap.INSTANCE.putBlock(EXAMPLE_BLOCK, RenderLayer.getTranslucent());
 </code> </code>
  
tutorial/blocks.txt · Last modified: 2024/04/15 01:52 by solidblock