/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.MapCodec * com.mojang.serialization.codecs.RecordCodecBuilder */ package net.minecraft.world.level.block; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.math.OctahedralGroup; import com.mojang.math.Quadrant; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.Map; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.ScheduledTickAccess; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.Half; import net.minecraft.world.level.block.state.properties.StairsShape; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; public class StairBlock extends Block implements SimpleWaterloggedBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)BlockState.CODEC.fieldOf("base_state").forGetter(b -> b.baseState), StairBlock.propertiesCodec()).apply((Applicative)i, StairBlock::new)); public static final EnumProperty FACING = HorizontalDirectionalBlock.FACING; public static final EnumProperty HALF = BlockStateProperties.HALF; public static final EnumProperty SHAPE = BlockStateProperties.STAIRS_SHAPE; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; private static final VoxelShape SHAPE_OUTER = Shapes.or(Block.column(16.0, 0.0, 8.0), Block.box(0.0, 8.0, 0.0, 8.0, 16.0, 8.0)); private static final VoxelShape SHAPE_STRAIGHT = Shapes.or(SHAPE_OUTER, Shapes.rotate(SHAPE_OUTER, OctahedralGroup.fromXYAngles(Quadrant.R0, Quadrant.R90))); private static final VoxelShape SHAPE_INNER = Shapes.or(SHAPE_STRAIGHT, Shapes.rotate(SHAPE_STRAIGHT, OctahedralGroup.fromXYAngles(Quadrant.R0, Quadrant.R90))); private static final Map SHAPE_BOTTOM_OUTER = Shapes.rotateHorizontal(SHAPE_OUTER); private static final Map SHAPE_BOTTOM_STRAIGHT = Shapes.rotateHorizontal(SHAPE_STRAIGHT); private static final Map SHAPE_BOTTOM_INNER = Shapes.rotateHorizontal(SHAPE_INNER); private static final Map SHAPE_TOP_OUTER = Shapes.rotateHorizontal(Shapes.rotate(SHAPE_OUTER, OctahedralGroup.INVERT_Y)); private static final Map SHAPE_TOP_STRAIGHT = Shapes.rotateHorizontal(Shapes.rotate(SHAPE_STRAIGHT, OctahedralGroup.INVERT_Y)); private static final Map SHAPE_TOP_INNER = Shapes.rotateHorizontal(Shapes.rotate(SHAPE_INNER, OctahedralGroup.INVERT_Y)); private final Block base; protected final BlockState baseState; public MapCodec codec() { return CODEC; } protected StairBlock(BlockState baseState, BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(FACING, Direction.NORTH)).setValue(HALF, Half.BOTTOM)).setValue(SHAPE, StairsShape.STRAIGHT)).setValue(WATERLOGGED, false)); this.base = baseState.getBlock(); this.baseState = baseState; } @Override protected boolean useShapeForLightOcclusion(BlockState state) { return true; } @Override protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { boolean isBottom = state.getValue(HALF) == Half.BOTTOM; Direction facing = state.getValue(FACING); return (switch (state.getValue(SHAPE)) { default -> throw new MatchException(null, null); case StairsShape.STRAIGHT -> { if (isBottom) { yield SHAPE_BOTTOM_STRAIGHT; } yield SHAPE_TOP_STRAIGHT; } case StairsShape.INNER_RIGHT, StairsShape.INNER_LEFT -> { if (isBottom) { yield SHAPE_BOTTOM_INNER; } yield SHAPE_TOP_INNER; } case StairsShape.OUTER_LEFT, StairsShape.OUTER_RIGHT -> isBottom ? SHAPE_BOTTOM_OUTER : SHAPE_TOP_OUTER; }).get(switch (state.getValue(SHAPE)) { default -> throw new MatchException(null, null); case StairsShape.STRAIGHT, StairsShape.OUTER_LEFT, StairsShape.INNER_RIGHT -> facing; case StairsShape.INNER_LEFT -> facing.getCounterClockWise(); case StairsShape.OUTER_RIGHT -> facing.getClockWise(); }); } @Override public float getExplosionResistance() { return this.base.getExplosionResistance(); } @Override public BlockState getStateForPlacement(BlockPlaceContext context) { Direction clickedFace = context.getClickedFace(); BlockPos pos = context.getClickedPos(); FluidState replacedFluidState = context.getLevel().getFluidState(pos); BlockState state = (BlockState)((BlockState)((BlockState)this.defaultBlockState().setValue(FACING, context.getHorizontalDirection())).setValue(HALF, clickedFace == Direction.DOWN || clickedFace != Direction.UP && context.getClickLocation().y - (double)pos.getY() > 0.5 ? Half.TOP : Half.BOTTOM)).setValue(WATERLOGGED, replacedFluidState.getType() == Fluids.WATER); return (BlockState)state.setValue(SHAPE, StairBlock.getStairsShape(state, context.getLevel(), pos)); } @Override protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) { if (state.getValue(WATERLOGGED).booleanValue()) { ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } if (directionToNeighbour.getAxis().isHorizontal()) { return (BlockState)state.setValue(SHAPE, StairBlock.getStairsShape(state, level, pos)); } return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random); } private static StairsShape getStairsShape(BlockState state, BlockGetter level, BlockPos pos) { Direction frontFacing; Direction behindFacing; Direction facing = state.getValue(FACING); BlockState behindState = level.getBlockState(pos.relative(facing)); if (StairBlock.isStairs(behindState) && state.getValue(HALF) == behindState.getValue(HALF) && (behindFacing = behindState.getValue(FACING)).getAxis() != state.getValue(FACING).getAxis() && StairBlock.canTakeShape(state, level, pos, behindFacing.getOpposite())) { if (behindFacing == facing.getCounterClockWise()) { return StairsShape.OUTER_LEFT; } return StairsShape.OUTER_RIGHT; } BlockState frontState = level.getBlockState(pos.relative(facing.getOpposite())); if (StairBlock.isStairs(frontState) && state.getValue(HALF) == frontState.getValue(HALF) && (frontFacing = frontState.getValue(FACING)).getAxis() != state.getValue(FACING).getAxis() && StairBlock.canTakeShape(state, level, pos, frontFacing)) { if (frontFacing == facing.getCounterClockWise()) { return StairsShape.INNER_LEFT; } return StairsShape.INNER_RIGHT; } return StairsShape.STRAIGHT; } private static boolean canTakeShape(BlockState state, BlockGetter level, BlockPos pos, Direction neighbour) { BlockState neighborState = level.getBlockState(pos.relative(neighbour)); return !StairBlock.isStairs(neighborState) || neighborState.getValue(FACING) != state.getValue(FACING) || neighborState.getValue(HALF) != state.getValue(HALF); } public static boolean isStairs(BlockState state) { return state.getBlock() instanceof StairBlock; } @Override protected BlockState rotate(BlockState state, Rotation rotation) { return (BlockState)state.setValue(FACING, rotation.rotate(state.getValue(FACING))); } @Override protected BlockState mirror(BlockState state, Mirror mirror) { Direction direction = state.getValue(FACING); StairsShape shape = state.getValue(SHAPE); switch (mirror) { case LEFT_RIGHT: { if (direction.getAxis() != Direction.Axis.Z) break; switch (shape) { case INNER_LEFT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_RIGHT); } case INNER_RIGHT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_LEFT); } case OUTER_LEFT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_RIGHT); } case OUTER_RIGHT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_LEFT); } } return state.rotate(Rotation.CLOCKWISE_180); } case FRONT_BACK: { if (direction.getAxis() != Direction.Axis.X) break; switch (shape) { case INNER_LEFT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_LEFT); } case INNER_RIGHT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_RIGHT); } case OUTER_LEFT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_RIGHT); } case OUTER_RIGHT: { return (BlockState)state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_LEFT); } case STRAIGHT: { return state.rotate(Rotation.CLOCKWISE_180); } } break; } } return super.mirror(state, mirror); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, HALF, SHAPE, WATERLOGGED); } @Override protected FluidState getFluidState(BlockState state) { if (state.getValue(WATERLOGGED).booleanValue()) { return Fluids.WATER.getSource(false); } return super.getFluidState(state); } @Override protected boolean isPathfindable(BlockState state, PathComputationType type) { return false; } }