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 revision Previous revision
Next revision
Previous revision
tutorial:blocks [2021/06/17 13:56]
redgrapefruit Fix typo
tutorial:blocks [2022/04/29 09:57] (current)
solidblock [Custom VoxelShape]
Line 30: Line 30:
 ==== Registering your Block ==== ==== Registering your Block ====
  
-Blocks should be registered under the ''​Registry.BLOCK''​ 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. You can either register the block in ''​onInitialize''​ method or directly when creating the block instance in the static context, as the ''​register''​ method returns the block instance as well.
  
 <code java [enable_line_numbers="​true",​highlight_lines_extra="​11"​]>​ <code java [enable_line_numbers="​true",​highlight_lines_extra="​11"​]>​
Line 133: Line 133:
   ]   ]
 } }
 +</​code>​
 +
 +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'​ ore '​hoe'​
 +  Harvest level: src/​main/​resources/​data/​minecraft/​tags/​blocks/​needs_<​tier>​_tool.json,​ Where '​tier'​ can be any of: '​stone',​ '​iron'​ or '​diamond'​
 +
 +<code JavaScript src/​main/​resources/​data/​minecraft/​tags/​blocks/​mineable/​pickaxe.json>​
 +{
 +  "​replace":​ false,
 +  "​values":​ [
 +    "​tutorial:​example_block"​
 +  ]
 +}
 +</​code>​
 +
 +<code JavaScript src/​main/​resources/​data/​minecraft/​tags/​blocks/​needs_stone_tool.json>​
 +{
 +  "​replace":​ false,
 +  "​values":​ [
 +    "​tutorial:​example_block"​
 +  ]
 +}
 +</​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:​
 +
 +
 +<code java [enable_line_numbers="​true"​]>​
 +    public static final Block EXAMPLE_BLOCK = new ExampleBlock(FabricBlockSettings.of(Material.METAL).strength(4.0f).requiresTool());​
 </​code>​ </​code>​
  
Line 191: Line 221:
 To fix this, we have to define the ''​VoxelShape''​ of the new block: To fix this, we have to define the ''​VoxelShape''​ of the new block:
  
-<​code>​ +<​code ​java
- ​@Override +public class ExambleBlock extends Block { 
- ​public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) { +    [...] 
-     ​return VoxelShapes.cuboid(0f,​ 0f, 0f, 1f, 1.0f, 0.5f); +    ​@Override 
- }+    public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) { 
 +        return VoxelShapes.cuboid(0f,​ 0f, 0f, 1f, 1.0f, 0.5f); 
 +    } 
 +}
 </​code>​ </​code>​
  
Line 206: Line 239:
  
 [[tutorial:​blockentity|Giving blocks a block entity so they can have advanced state like inventories]]. Also needed for many things like GUI and custom block rendering. [[tutorial:​blockentity|Giving blocks a block entity so they can have advanced state like inventories]]. Also needed for many things like GUI and custom block rendering.
 +
 +To make your block flammable (that is, can be burned in fire), you may use ''​FlammableBlockRegistry''​.
tutorial/blocks.1623938181.txt.gz · Last modified: 2021/06/17 13:56 by redgrapefruit