tutorial:directionalblock
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:directionalblock [2021/08/11 02:53] – use auto uv and uvlock solidblock | tutorial:directionalblock [2024/12/08 14:04] (current) – [Influence path finding] typo solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== Directional | + | ====== Making a Directional |
Making blocks directional (facing into certain directions) is also done using block states. | Making blocks directional (facing into certain directions) is also done using block states. | ||
Line 7: | Line 6: | ||
{{: | {{: | ||
- | <code java> | + | < |
- | public class PolishedAndesiteSideBlock | + | public class VerticalSlabBlock |
+ | // the codec is required since 1.20.5 however not actually used in Minecraft yet. | ||
+ | public static final MapCodec< | ||
- | public | + | public |
super(settings); | super(settings); | ||
- | setDefaultState(this.stateManager.getDefaultState().with(Properties.HORIZONTAL_FACING, | + | setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, |
} | } | ||
@Override | @Override | ||
- | protected | + | protected |
- | stateManager.add(Properties.HORIZONTAL_FACING); | + | return CODEC; |
} | } | ||
@Override | @Override | ||
- | public VoxelShape getOutlineShape(BlockState state, BlockView | + | protected void appendProperties(StateManager.Builder< |
+ | builder.add(Properties.HORIZONTAL_FACING); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public VoxelShape getOutlineShape(BlockState state, BlockView | ||
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 | + | |
- | } | + | |
} | } | ||
+ | @Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
- | return | + | return |
} | } | ||
Line 44: | Line 46: | ||
</ | </ | ||
+ | and then register the block according to the method covered in [[blocks]]: | ||
+ | <code java TutorialBlocks.java> | ||
+ | public final class TutorialBlocks implements ModInitializer { | ||
+ | [...] | ||
+ | | ||
+ | public static final VerticalSlabBlock POLISHED_ANDESITE_VERTICAL_SLAB = register(" | ||
+ | new VerticalSlabBlock(Block.Settings.copy(Blocks.POLISHED_ANDESITE))); | ||
+ | } | ||
+ | </ | ||
- | ==== Defining Blockstate ==== | + | ===== Defining Blockstate |
- | polished_andesite_side_block.json | + | < |
- | < | + | |
{ | { | ||
" | " | ||
- | " | + | " |
- | " | + | " |
- | " | + | " |
- | " | + | " |
} | } | ||
} | } | ||
</ | </ | ||
+ | ===== Defining Block Models ===== | ||
- | ==== Defining Block Models ==== | + | < |
- | + | ||
- | + | ||
- | side.json | + | |
- | < | + | |
{ " | { " | ||
" | " | ||
Line 85: | Line 92: | ||
</ | </ | ||
- | polished_andesite_side_block.json | + | < |
- | < | + | |
{ | { | ||
- | " | + | " |
" | " | ||
" | " | ||
Line 96: | Line 102: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Defining rotation and mirroring of blocks ===== | ||
+ | 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 ===== | ||
+ | Try to make it [[waterloggable]]. |
tutorial/directionalblock.1628650383.txt.gz · Last modified: 2021/08/11 02:53 by solidblock