public class VerticalSlabBlock extends HorizontalFacingBlock { // codec 从 1.20.5 开始是必需的,但是还没有在 Minecraft 中实际使用。 public static final MapCodec CODEC = Block.createCodec(VerticalSlabBlock::new); public VerticalSlabBlock(Settings settings) { super(settings); setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH)); } @Override protected MapCodec getCodec() { return CODEC; } @Override protected void appendProperties(StateManager.Builder builder) { builder.add(Properties.HORIZONTAL_FACING); } @Override public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) { Direction dir = state.get(FACING); return switch (dir) { case NORTH -> VoxelShapes.cuboid(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f); case SOUTH -> VoxelShapes.cuboid(0.0f, 0.0f, 0.5f, 1.0f, 1.0f, 1.0f); case EAST -> VoxelShapes.cuboid(0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); case WEST -> VoxelShapes.cuboid(0.0f, 0.0f, 0.0f, 0.5f, 1.0f, 1.0f); default -> VoxelShapes.fullCube(); }; } @Override public BlockState getPlacementState(ItemPlacementContext ctx) { return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite()); } }