zh_cn:tutorial:directionalblock
This is an old revision of the document!
带有方向的方块
使方块带有方向(朝向特定的方向)也是通过方块状态完成的。 这个例子介绍了垂直版的安山岩台阶。
public class PolishedAndesiteSideBlock extends HorizontalFacingBlock { public PolishedAndesiteSideBlock(Settings settings) { super(settings); setDefaultState(this.stateManager.getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH)); } @Override protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) { stateManager.add(Properties.HORIZONTAL_FACING); } @Override public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext ctx) { Direction dir = state.get(FACING); switch(dir) { case NORTH: return VoxelShapes.cuboid(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f); case SOUTH: return VoxelShapes.cuboid(0.0f, 0.0f, 0.5f, 1.0f, 1.0f, 1.0f); case EAST: return VoxelShapes.cuboid(0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); case WEST: return VoxelShapes.cuboid(0.0f, 0.0f, 0.0f, 0.5f, 1.0f, 1.0f); default: return VoxelShapes.fullCube(); } } public BlockState getPlacementState(ItemPlacementContext ctx) { return (BlockState)this.getDefaultState().with(FACING, ctx.getPlayerFacing()); } }
定义方块状态
- src/main/resources/assets/tutorial/blockstates/polished_andesite_side_block.json
{ "variants": { "facing=north": { "model": "bitmod:block/polished_andesite_side_block", "uvlock": true }, "facing=east": { "model": "bitmod:block/polished_andesite_side_block", "y": 90, "uvlock": true }, "facing=south": { "model": "bitmod:block/polished_andesite_side_block", "y": 180, "uvlock": true }, "facing=west": { "model": "bitmod:block/polished_andesite_side_block", "y": 270, "uvlock": true } } }
定义方块模型
- src/main/resources/assets/tutorial/models/block/side.json
{ "parent": "block/block", "textures": { "particle": "#side" }, "elements": [ { "from": [ 0, 0, 0 ], "to": [ 16, 16, 8 ], "faces": { "down": { "texture": "#bottom", "cullface": "down" }, "up": { "texture": "#top", "cullface": "up" }, "north": { "texture": "#side", "cullface": "north" }, "south": { "texture": "#side", "cullface": "south" }, "west": { "texture": "#side", "cullface": "west" }, "east": { "texture": "#side", "cullface": "east" } } } ] }
- src/main/resources/assets/tutorial/models/block/polished_andesite_side_block.json
{ "parent": "tutorial:block/side", "textures": { "bottom": "block/polished_andesite", "top": "block/polished_andesite", "side": "block/polished_andesite" } }
zh_cn/tutorial/directionalblock.1646009763.txt.gz · Last modified: 2022/02/28 00:56 by solidblock