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 revisionBoth sides next revision
tutorial:blocks [2023/10/23 09:29] – Fix typo mattidragontutorial:blocks [2023/11/18 08:26] solidblock
Line 1: Line 1:
 ====== Adding a Block ====== ====== Adding a Block ======
  
-Adding blocks to your mod follows a similar process to [[tutorial:items|adding an item]]. You can create an instance of ''Block'' or a custom class, and then register it under ''Registries.BLOCK'' (for 1.19.3 and above) or ''Registry.BLOCK'' (for 1.19.2 and below). You also need to provide a texture and blockstate/model file to give your block visuals. For more information on the block model format, view the [[https://minecraft.gamepedia.com/Model|Minecraft Wiki Model page]].+Adding blocks to your mod follows a similar process to [[tutorial:items|adding an item]]. You can create an instance of ''Block'' or a custom class, and then register it under ''Registries.BLOCK'' (for 1.19.3 and above) or ''Registry.BLOCK'' (for 1.19.2 and below). You also need to provide a texture and blockstate/model file to give your block visuals. For more information on the block model format, view the [[https://minecraft.wiki/Model|Minecraft Wiki Model page]].
  
 ===== Creating a Block ===== ===== Creating a Block =====
Line 47: Line 47:
 </code> </code>
  
-Your custom block will //not// be accessible as an item yet, but it can be seen in-game by using the command ''/setblock tutorial:example_block''.+Your custom block will //not// be accessible as an item yet, but it can be seen in-game by using the command ''/setblock <position> tutorial:example_block''.
  
 ==== Registering an Item for your Block ==== ==== Registering an Item for your Block ====
Line 77: Line 77:
 The files should be located here: The files should be located here:
  
-  Blockstate: src/main/resources/assets/tutorial/blockstates/example_block.json +  Blockstate: ''src/main/resources/assets/tutorial/blockstates/example_block.json'' 
-  Block Model: src/main/resources/assets/tutorial/models/block/example_block.json +  Block Model: ''src/main/resources/assets/tutorial/models/block/example_block.json'' 
-  Item Model: src/main/resources/assets/tutorial/models/item/example_block.json +  Item Model: ''src/main/resources/assets/tutorial/models/item/example_block.json'' 
-  Block Texture: src/main/resources/assets/tutorial/textures/block/example_block.png+  Block Texture: ''src/main/resources/assets/tutorial/textures/block/example_block.png''
  
 The blockstate file determines which model a block should use depending on its blockstate. Our block doesn't have any potential states, so we cover everything with ''""'' The blockstate file determines which model a block should use depending on its blockstate. Our block doesn't have any potential states, so we cover everything with ''""''
Line 138: Line 138:
 } }
 </code> </code>
 +
 +The condition ''minecraft:survives_explosion'' means that, if the block is destroyed in an explosion with decay (such as creeper explosion, not TNT explosion), it //may not// drop. If there is no this condition, the block always drops in explosions with decay.
  
 In minecraft 1.17, there has been a change for breaking blocks. Now, to define harvest tools and harvest levels, we need to use tags. Read about tags at: [[tutorial:tags|Tags Tutorial]]. The tags that we need to add the block to are: In minecraft 1.17, there has been a change for breaking blocks. Now, to define harvest tools and harvest levels, we need to use tags. Read about tags at: [[tutorial:tags|Tags Tutorial]]. The tags that we need to add the block to are:
  
-  Harvest tool: src/main/resources/data/minecraft/tags/blocks/mineable/<tooltype>.json, Where 'tooltype' can be any of: 'axe', 'pickaxe', 'shovel' or 'hoe' + Harvest tool: ''src/main/resources/data/minecraft/tags/blocks/mineable/<tooltype>.json''where ''<tooltype>'' can be any of: ''axe'', ''pickaxe'', ''shovel'' or ''hoe'
-  Harvest level: src/main/resources/data/minecraft/tags/blocks/needs_<tier>_tool.json, Where 'tier' can be any of: 'stone', 'iron' or 'diamond'+ Harvest level: ''src/main/resources/data/minecraft/tags/blocks/needs_<tier>_tool.json''where ''<tier>'' can be any of: ''stone'', ''iron'' or ''diamond'' (//not including// ''netherite'')
  
 <code JavaScript src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json> <code JavaScript src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json>
Line 162: Line 164:
 </code> </code>
  
-For the harvest level tags (needs_stone_tool, needs_iron_tool and needs_diamond_tool) to take effect, add requiresTool() to the FabricToolSettings in the block declaration: +For the harvest level tags (''needs_stone_tool''''needs_iron_tool'' and ''needs_diamond_tool'') to take effect, add ''requiresTool()'' to the FabricBlockSettings in the block declaration:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 195: Line 196:
     public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {     public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
         if (!world.isClient) {         if (!world.isClient) {
-            player.sendMessage(Text.of("Hello, world!"), false);+            player.sendMessage(Text.literal("Hello, world!"), false);
         }         }
  
tutorial/blocks.txt · Last modified: 2024/04/15 01:52 by solidblock