zh_cn:tutorial:waterloggable
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| zh_cn:tutorial:waterloggable [2022/03/20 13:43] – created solidblock | zh_cn:tutorial:waterloggable [2024/10/27 14:59] (current) – solidblock | ||
|---|---|---|---|
| Line 17: | Line 17: | ||
| public VerticalSlabBlock(Settings settings) { | public VerticalSlabBlock(Settings settings) { | ||
| super(settings); | super(settings); | ||
| - | setDefaultState(this.stateManager.getDefaultState() | + | setDefaultState(getDefaultState() |
| .with(Properties.HORIZONTAL_FACING, | .with(Properties.HORIZONTAL_FACING, | ||
| - | .with(WATERLOGGED, | + | .with(WATERLOGGED, |
| } | } | ||
| | | ||
| // 让方块认识这个属性,否则设置该属性将会抛出异常。 | // 让方块认识这个属性,否则设置该属性将会抛出异常。 | ||
| @Override | @Override | ||
| - | protected void appendProperties(StateManager.Builder< | + | protected void appendProperties(StateManager.Builder< |
| - | | + | |
| } | } | ||
| </ | </ | ||
| Line 33: | Line 33: | ||
| @Override | @Override | ||
| public BlockState getPlacementState(ItemPlacementContext ctx) { | public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
| - | return | + | return this.getDefaultState() |
| - | .with(Properties.HORIZONTAL_FACING, | + | .with(Properties.HORIZONTAL_FACING, |
| .with(WATERLOGGED, | .with(WATERLOGGED, | ||
| } | } | ||
| </ | </ | ||
| - | |||
| 覆盖 '' | 覆盖 '' | ||
| Line 49: | Line 48: | ||
| 覆盖 '' | 覆盖 '' | ||
| - | <code java> | + | |
| + | //1.21.2 之前的版本,请这么写:// | ||
| + | <yarncode | ||
| @Override | @Override | ||
| public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, | public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, | ||
| if (state.get(WATERLOGGED)) { | if (state.get(WATERLOGGED)) { | ||
| - | // 1.17 之前是这么写的:world.getFluidTickScheduler().schedule(pos, | + | // 对于 |
| - | world.createAndScheduleFluidTick(pos, Fluids.WATER, | + | // world.getFluidTickScheduler().schedule(pos, |
| + | // 对于 1.18 之后、1.21.2 之前的版本: | ||
| + | world.method_39281(pos, Fluids.WATER, | ||
| } | } | ||
| return super.getStateForNeighborUpdate(state, | return super.getStateForNeighborUpdate(state, | ||
| } | } | ||
| - | </code> | + | </yarncode> |
| + | |||
| + | //1.21.2 以及更高的版本,请这么写:// | ||
| + | < | ||
| + | @Override | ||
| + | public BlockState getStateForNeighborUpdate(BlockState state, WorldView world, ScheduledTickView tickView, BlockPos pos, Direction direction, BlockPos neighborPos, | ||
| + | if (state.get(WATERLOGGED)) { | ||
| + | // For versions since 1.21.2: | ||
| + | tickView.scheduleFluidTick(pos, | ||
| + | } | ||
| + | |||
| + | return super.getStateForNeighborUpdate(state, | ||
| + | } | ||
| + | </ | ||
| 现在方块可含水了,并且与水有关的功能都能正常运作。 | 现在方块可含水了,并且与水有关的功能都能正常运作。 | ||
zh_cn/tutorial/waterloggable.1647783804.txt.gz · Last modified: 2022/03/20 13:43 by solidblock