| 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.BooleanProperty;
|
| 15 |
|
| 16 | public class HugeMushroomBlock extends Block {
|
| 17 | public static final BooleanProperty NORTH = PipeBlock.NORTH;
|
| 18 | public static final BooleanProperty EAST = PipeBlock.EAST;
|
| 19 | public static final BooleanProperty SOUTH = PipeBlock.SOUTH;
|
| 20 | public static final BooleanProperty WEST = PipeBlock.WEST;
|
| 21 | public static final BooleanProperty UP = PipeBlock.UP;
|
| 22 | public static final BooleanProperty DOWN = PipeBlock.DOWN;
|
| 23 | private static final Map<Direction, BooleanProperty> PROPERTY_BY_DIRECTION = PipeBlock.PROPERTY_BY_DIRECTION;
|
| 24 |
|
| 25 | public HugeMushroomBlock(final BlockBehaviour.Properties properties) {
|
| 26 | super(properties);
|
| 27 | this.registerDefaultState(
|
| 28 | this.stateDefinition.any().setValue(NORTH, true).setValue(EAST, true).setValue(SOUTH, true).setValue(WEST, true).setValue(UP, true).setValue(DOWN, true)
|
| 29 | );
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 34 | BlockGetter level = context.getLevel();
|
| 35 | BlockPos pos = context.getClickedPos();
|
| 36 | return this.defaultBlockState()
|
| 37 | .setValue(DOWN, !level.getBlockState(pos.below()).is(this))
|
| 38 | .setValue(UP, !level.getBlockState(pos.above()).is(this))
|
| 39 | .setValue(NORTH, !level.getBlockState(pos.north()).is(this))
|
| 40 | .setValue(EAST, !level.getBlockState(pos.east()).is(this))
|
| 41 | .setValue(SOUTH, !level.getBlockState(pos.south()).is(this))
|
| 42 | .setValue(WEST, !level.getBlockState(pos.west()).is(this));
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | protected BlockState updateShape(
|
| 47 | final BlockState state,
|
| 48 | final LevelReader level,
|
| 49 | final ScheduledTickAccess ticks,
|
| 50 | final BlockPos pos,
|
| 51 | final Direction directionToNeighbour,
|
| 52 | final BlockPos neighbourPos,
|
| 53 | final BlockState neighbourState,
|
| 54 | final RandomSource random
|
| 55 | ) {
|
| 56 | return neighbourState.is(this)
|
| 57 | ? state.setValue(PROPERTY_BY_DIRECTION.get(directionToNeighbour), false)
|
| 58 | : super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 63 | return state.setValue(PROPERTY_BY_DIRECTION.get(rotation.rotate(Direction.NORTH)), state.getValue(NORTH))
|
| 64 | .setValue(PROPERTY_BY_DIRECTION.get(rotation.rotate(Direction.SOUTH)), state.getValue(SOUTH))
|
| 65 | .setValue(PROPERTY_BY_DIRECTION.get(rotation.rotate(Direction.EAST)), state.getValue(EAST))
|
| 66 | .setValue(PROPERTY_BY_DIRECTION.get(rotation.rotate(Direction.WEST)), state.getValue(WEST))
|
| 67 | .setValue(PROPERTY_BY_DIRECTION.get(rotation.rotate(Direction.UP)), state.getValue(UP))
|
| 68 | .setValue(PROPERTY_BY_DIRECTION.get(rotation.rotate(Direction.DOWN)), state.getValue(DOWN));
|
| 69 | }
|
| 70 |
|
| 71 | @Override
|
| 72 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 73 | return state.setValue(PROPERTY_BY_DIRECTION.get(mirror.mirror(Direction.NORTH)), state.getValue(NORTH))
|
| 74 | .setValue(PROPERTY_BY_DIRECTION.get(mirror.mirror(Direction.SOUTH)), state.getValue(SOUTH))
|
| 75 | .setValue(PROPERTY_BY_DIRECTION.get(mirror.mirror(Direction.EAST)), state.getValue(EAST))
|
| 76 | .setValue(PROPERTY_BY_DIRECTION.get(mirror.mirror(Direction.WEST)), state.getValue(WEST))
|
| 77 | .setValue(PROPERTY_BY_DIRECTION.get(mirror.mirror(Direction.UP)), state.getValue(UP))
|
| 78 | .setValue(PROPERTY_BY_DIRECTION.get(mirror.mirror(Direction.DOWN)), state.getValue(DOWN));
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 83 | builder.add(UP, DOWN, NORTH, EAST, SOUTH, WEST);
|
| 84 | }
|
| 85 | }
|
| 86 |
|