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 [2019/05/30 11:47] – [Introduction] Explain the use of placeholders jamieswhiteshirttutorial:blocks [2019/07/05 14:00] – [Registering a BlockItem] itemGroup() -> group() upcraftlp
Line 3: Line 3:
 ==== Introduction ==== ==== Introduction ====
  
-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. In this tutorial the "wikitut" namespace and the "example_block" name are used as placeholders, which should be replaced by the appropriate values for your mod and block.+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, as you can see here: +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
Line 19: Line 18:
 ==== Registering a Block ==== ==== Registering a Block ====
  
-We're going to register our block, just like you would an item or any other additionYou can call //Registry.register// to do this; the first parameter is the registry type, the second is the identifier for your registered subject, and the final is usually an instance of what you are registering.+Registering blocks is the same as registering itemsCall //Registry.register// and pass in the appropriate arguments.
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 30: Line 29:
     public void onInitialize()     public void onInitialize()
     {     {
-        Registry.register(Registry.BLOCK, new Identifier("wikitut", "example_block"), EXAMPLE_BLOCK);+        Registry.register(Registry.BLOCK, new Identifier("tutorial", "example_block"), EXAMPLE_BLOCK);
     }     }
 } }
 </code> </code>
  
-Your block will not be accessible as an item, but it can be seen in-game by using /setblock ~ ~ ~ modid:name.+Your block will //not// be accessible as an item, but it can be seen in-game by using /setblock ~ ~ ~ tutorial:example_block.
  
 ==== Registering a BlockItem ==== ==== Registering a BlockItem ====
Line 53: Line 52:
         [...]         [...]
                  
-        Registry.register(Registry.ITEM, new Identifier("wikitut", "example_block"), new BlockItem(EXAMPLE_BLOCK, new Item.Settings().itemGroup(ItemGroup.MISC)));+        Registry.register(Registry.ITEM, new Identifier("tutorial", "example_block"), new BlockItem(EXAMPLE_BLOCK, new Item.Settings().group(ItemGroup.MISC)));
     }     }
 } }
Line 62: Line 61:
 As you probably have noticed, the block is simply a purple and black checkerboard pattern in-game. This is Minecraft's way of showing you that the block has no model. Modeling a block is a little bit more difficult than modeling an item. You will need three files: A blockstate file, a block model file, and an item model file if the block has a BlockItem. Textures are also required if you don't use vanilla ones. The files should be located here: As you probably have noticed, the block is simply a purple and black checkerboard pattern in-game. This is Minecraft's way of showing you that the block has no model. Modeling a block is a little bit more difficult than modeling an item. You will need three files: A blockstate file, a block model file, and an item model file if the block has a BlockItem. Textures are also required if you don't use vanilla ones. The files should be located here:
  
-  Blockstate: src/main/resources/assets/wikitut/blockstates/example_block.json +  Blockstate: src/main/resources/assets/tutorial/blockstates/example_block.json 
-  Block Model: src/main/resources/assets/wikitut/models/block/example_block.json +  Block Model: src/main/resources/assets/tutorial/models/block/example_block.json 
-  Item Model: src/main/resources/assets/wikitut/models/item/example_block.json +  Item Model: src/main/resources/assets/tutorial/models/item/example_block.json 
-  Block Texture: src/main/resources/assets/wikitut/textures/block/example_block.png+  Block Texture: src/main/resources/assets/tutorial/textures/block/example_block.png
  
 The blockstate file determines which model that the block should use depending on it's blockstate. As our block has only one state, the file is a simple as this: The blockstate file determines which model that the block should use depending on it's blockstate. As our block has only one state, the file is a simple as this:
  
-<code JavaScript src/main/resources/assets/wikitut/blockstates/example_block.json>+<code JavaScript src/main/resources/assets/tutorial/blockstates/example_block.json>
 { {
   "variants": {   "variants": {
-    "": { "model": "wikitut:block/example_block" }+    "": { "model": "tutorial:block/example_block" }
   }   }
 } }
Line 79: Line 78:
 The block model file defines the shape and texture of your block. We will use block/cube_all, which will allow us to easily set the same texture on all sides of the block. The block model file defines the shape and texture of your block. We will use block/cube_all, which will allow us to easily set the same texture on all sides of the block.
  
-<code JavaScript src/main/resources/assets/wikitut/models/block/example_block.json>+<code JavaScript src/main/resources/assets/tutorial/models/block/example_block.json>
 { {
   "parent": "block/cube_all",   "parent": "block/cube_all",
   "textures": {   "textures": {
-    "all": "wikitut:block/example_block"+    "all": "tutorial:block/example_block"
   }   }
 } }
Line 90: Line 89:
 In most cases you want the block to look the same in hand. To do this, you can make an item file that inherits from the block model file: In most cases you want the block to look the same in hand. To do this, you can make an item file that inherits from the block model file:
  
-<code JavaScript src/main/resources/assets/wikitut/models/item/example_block.json>+<code JavaScript src/main/resources/assets/tutorial/models/item/example_block.json>
 { {
-  "parent": "wikitut:block/example_block"+  "parent": "tutorial:block/example_block"
 } }
 </code> </code>
Line 102: Line 101:
 The block must have a loot table for any items to drop when the block is broken. Assuming you have created an item for your block and registered it using the same name as the block, the following file will produce regular block drops ''src/main/resources/data/wikitut/loot_tables/blocks/example_block.json''. The block must have a loot table for any items to drop when the block is broken. Assuming you have created an item for your block and registered it using the same name as the block, the following file will produce regular block drops ''src/main/resources/data/wikitut/loot_tables/blocks/example_block.json''.
  
-<code JavaScript src/main/resources/data/wikitut/loot_tables/blocks/example_block.json>+<code JavaScript src/main/resources/data/tutorial/loot_tables/blocks/example_block.json>
 { {
   "type": "minecraft:block",   "type": "minecraft:block",
Line 111: Line 110:
         {         {
           "type": "minecraft:item",           "type": "minecraft:item",
-          "name": "wikitut:example_block"+          "name": "tutorial:example_block"
         }         }
       ],       ],
tutorial/blocks.txt · Last modified: 2024/04/15 01:52 by solidblock