User Tools

Site Tools


tutorial:directionalblock

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
tutorial:directionalblock [2024/08/24 14:03] – [Making a Directional Block] solidblocktutorial:directionalblock [2024/12/08 14:04] (current) – [Influence path finding] typo solidblock
Line 45: Line 45:
 } }
 </code> </code>
-<code java ExampleMod.java> + 
-public class ExampleMod implements ModInitializer { +and then register the block according to the method covered in [[blocks]]: 
-    public static final VerticalSlabBlock POLISHED_ANDESITE_VERTICAL_SLAB = Registry.register( +<code java TutorialBlocks.java> 
-        Registries.BLOCK, +public final class TutorialBlocks implements ModInitializer { 
-        Identifier.of("tutorial", "polished_andesite_vertical_slab")+    [...] 
-        new VerticalSlabBlock(FabricBlockSettings.copyOf(Blocks.POLISHED_ANDESITE)));+     
 +    public static final VerticalSlabBlock POLISHED_ANDESITE_VERTICAL_SLAB = register("polished_andesite_vertical_slab",  
 +        new VerticalSlabBlock(Block.Settings.copy(Blocks.POLISHED_ANDESITE)));
 } }
 </code> </code>
Line 103: Line 105:
 ===== Defining rotation and mirroring of blocks ===== ===== Defining rotation and mirroring of blocks =====
 For directional blocks, you may have to override ''rotate'' and ''mirror'' methods, so that in structure blocks, they can be correctly rotated or mirrored. However, in this case, the ''HorizontalFacingBlock'' class has already done it for you. For directional blocks, you may have to override ''rotate'' and ''mirror'' methods, so that in structure blocks, they can be correctly rotated or mirrored. However, in this case, the ''HorizontalFacingBlock'' class has already done it for you.
 +
 +===== Influence path finding =====
 +If you place these blocks in game, you may find the issue that, the mobs when trying to find paths, will try to cross the blocks, as if the blocks did not exist, ending up being blocked by the blocks. That's because mobs treat such non-full-cube blocks as those not blocking their path. To modify this path-finding behavior, you need to override ''canPathfindThrough'' method:
 +<code java>
 +  @Override
 +  protected boolean canPathfindThrough(BlockState state, NavigationType type) {
 +    return false;
 +  }
 +</code>
 +
 +In vanilla, some blocks have different path node types. For example, mobs will avoid some dangerous blocks, such as magma block, wither rose and cactus. You can also make mobs treat your blocks differently, by modifying path node types, via ''LandPathNodeTypesRegistry'' of Fabric API.
  
 ===== Next ===== ===== Next =====
 Try to make it [[waterloggable]]. Try to make it [[waterloggable]].
tutorial/directionalblock.1724508198.txt.gz · Last modified: 2024/08/24 14:03 by solidblock