tutorial:directionalblock
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:directionalblock [2023/09/26 05:43] – Fix typo [Making a Directional Block] poopooracoocoo | tutorial:directionalblock [2024/12/08 14:04] (current) – [Influence path finding] typo solidblock | ||
---|---|---|---|
Line 6: | Line 6: | ||
{{: | {{: | ||
- | <code java> | + | < |
public class VerticalSlabBlock extends HorizontalFacingBlock { | public class VerticalSlabBlock extends HorizontalFacingBlock { | ||
+ | // the codec is required since 1.20.5 however not actually used in Minecraft yet. | ||
+ | public static final MapCodec< | ||
public VerticalSlabBlock(Settings settings) { | public VerticalSlabBlock(Settings settings) { | ||
super(settings); | super(settings); | ||
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, | setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected MapCodec<? | ||
+ | return CODEC; | ||
} | } | ||
Line 22: | Line 29: | ||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) { | public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) { | ||
Direction dir = state.get(FACING); | Direction dir = state.get(FACING); | ||
- | switch(dir) { | + | return |
- | case NORTH: | + | case NORTH -> VoxelShapes.cuboid(0.0f, |
- | return | + | case SOUTH -> VoxelShapes.cuboid(0.0f, |
- | case SOUTH: | + | case EAST -> VoxelShapes.cuboid(0.5f, |
- | return | + | case WEST -> VoxelShapes.cuboid(0.0f, |
- | case EAST: | + | default |
- | return | + | }; |
- | case WEST: | + | |
- | return | + | |
- | default: | + | |
- | return | + | |
- | } | + | |
} | } | ||
Line 43: | Line 45: | ||
} | } | ||
</ | </ | ||
- | <code java> | + | |
- | public class ExampleMod | + | and then register the block according to the method covered in [[blocks]]: |
- | public static final VerticalSlabBlock POLISHED_ANDESITE_VERTICAL_SLAB = Registry.register( | + | < |
- | Registries.BLOCK, | + | public |
- | new Identifier(" | + | [...] |
- | new VerticalSlabBlock(FabricBlockSettings.copyOf(Blocks.POLISHED_ANDESITE))); | + | |
+ | public static final VerticalSlabBlock POLISHED_ANDESITE_VERTICAL_SLAB = register(" | ||
+ | new VerticalSlabBlock(Block.Settings.copy(Blocks.POLISHED_ANDESITE))); | ||
} | } | ||
</ | </ | ||
Line 101: | Line 105: | ||
===== Defining rotation and mirroring of blocks ===== | ===== Defining rotation and mirroring of blocks ===== | ||
For directional blocks, you may have to override '' | For directional blocks, you may have to override '' | ||
+ | |||
+ | ===== 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 '' | ||
+ | <code java> | ||
+ | @Override | ||
+ | protected boolean canPathfindThrough(BlockState state, NavigationType type) { | ||
+ | return false; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 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, | ||
===== Next ===== | ===== Next ===== | ||
Try to make it [[waterloggable]]. | Try to make it [[waterloggable]]. |
tutorial/directionalblock.1695707005.txt.gz · Last modified: 2023/09/26 05:43 by poopooracoocoo