| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import java.util.Map;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Direction;
|
| 6 | import net.minecraft.util.RandomSource;
|
| 7 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 8 | import net.minecraft.world.level.BlockGetter;
|
| 9 | import net.minecraft.world.level.LevelReader;
|
| 10 | import net.minecraft.world.level.ScheduledTickAccess;
|
| 11 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 12 | import net.minecraft.world.level.block.state.BlockState;
|
| 13 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 14 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 15 | import net.minecraft.world.level.material.Fluids;
|
| 16 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 17 | import net.minecraft.world.phys.shapes.Shapes;
|
| 18 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 19 | import org.jspecify.annotations.Nullable;
|
| 20 |
|
| 21 | /**
|
| 22 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 23 | */
|
| 24 | public class BaseCoralWallFanBlock extends BaseCoralFanBlock {
|
| 25 | public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
|
| 26 | private static final Map<Direction, VoxelShape> SHAPES = Shapes.rotateHorizontal(Block.boxZ(16.0, 8.0, 5.0, 16.0));
|
| 27 |
|
| 28 | /**
|
| 29 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 30 | */
|
| 31 | public BaseCoralWallFanBlock(final BlockBehaviour.Properties properties) {
|
| 32 | super(properties);
|
| 33 | this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, true));
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 38 | return SHAPES.get(state.getValue(FACING));
|
| 39 | }
|
| 40 |
|
| 41 | @Override
|
| 42 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 43 | return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
| 44 | }
|
| 45 |
|
| 46 | @Override
|
| 47 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 48 | return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
| 49 | }
|
| 50 |
|
| 51 | @Override
|
| 52 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 53 | builder.add(FACING, WATERLOGGED);
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | protected BlockState updateShape(
|
| 58 | final BlockState state,
|
| 59 | final LevelReader level,
|
| 60 | final ScheduledTickAccess ticks,
|
| 61 | final BlockPos pos,
|
| 62 | final Direction directionToNeighbour,
|
| 63 | final BlockPos neighbourPos,
|
| 64 | final BlockState neighbourState,
|
| 65 | final RandomSource random
|
| 66 | ) {
|
| 67 | if (state.getValue(WATERLOGGED)) {
|
| 68 | ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
|
| 69 | }
|
| 70 |
|
| 71 | return directionToNeighbour.getOpposite() == state.getValue(FACING) && !state.canSurvive(level, pos) ? Blocks.AIR.defaultBlockState() : state;
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
|
| 76 | Direction facing = state.getValue(FACING);
|
| 77 | BlockPos relativePos = pos.relative(facing.getOpposite());
|
| 78 | BlockState relativeState = level.getBlockState(relativePos);
|
| 79 | return relativeState.isFaceSturdy(level, relativePos, facing);
|
| 80 | }
|
| 81 |
|
| 82 | @Override
|
| 83 | public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 84 | BlockState state = super.getStateForPlacement(context);
|
| 85 | LevelReader level = context.getLevel();
|
| 86 | BlockPos pos = context.getClickedPos();
|
| 87 | Direction[] directions = context.getNearestLookingDirections();
|
| 88 |
|
| 89 | for (Direction direction : directions) {
|
| 90 | if (direction.getAxis().isHorizontal()) {
|
| 91 | state = state.setValue(FACING, direction.getOpposite());
|
| 92 | if (state.canSurvive(level, pos)) {
|
| 93 | return state;
|
| 94 | }
|
| 95 | }
|
| 96 | }
|
| 97 |
|
| 98 | return null;
|
| 99 | }
|
| 100 | }
|
| 101 |
|