| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import com.google.common.base.Predicates;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Direction;
|
| 6 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 7 | import net.minecraft.world.level.BlockGetter;
|
| 8 | import net.minecraft.world.level.Level;
|
| 9 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 10 | import net.minecraft.world.level.block.state.BlockState;
|
| 11 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 12 | import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
| 13 | import net.minecraft.world.level.block.state.pattern.BlockPattern;
|
| 14 | import net.minecraft.world.level.block.state.pattern.BlockPatternBuilder;
|
| 15 | import net.minecraft.world.level.block.state.predicate.BlockStatePredicate;
|
| 16 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 17 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 18 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 19 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 20 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 21 | import net.minecraft.world.phys.shapes.Shapes;
|
| 22 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 23 | import org.jspecify.annotations.Nullable;
|
| 24 |
|
| 25 | public class EndPortalFrameBlock extends Block {
|
| 26 | public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
|
| 27 | public static final BooleanProperty HAS_EYE = BlockStateProperties.EYE;
|
| 28 | private static final VoxelShape SHAPE_EMPTY = Block.column(16.0, 0.0, 13.0);
|
| 29 | private static final VoxelShape SHAPE_FULL = Shapes.or(SHAPE_EMPTY, Block.column(8.0, 13.0, 16.0));
|
| 30 | private static @Nullable BlockPattern portalShape;
|
| 31 |
|
| 32 | public EndPortalFrameBlock(final BlockBehaviour.Properties properties) {
|
| 33 | super(properties);
|
| 34 | this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(HAS_EYE, false));
|
| 35 | }
|
| 36 |
|
| 37 | @Override
|
| 38 | protected boolean useShapeForLightOcclusion(final BlockState state) {
|
| 39 | return true;
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 44 | return state.getValue(HAS_EYE) ? SHAPE_FULL : SHAPE_EMPTY;
|
| 45 | }
|
| 46 |
|
| 47 | @Override
|
| 48 | public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 49 | return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(HAS_EYE, false);
|
| 50 | }
|
| 51 |
|
| 52 | @Override
|
| 53 | protected boolean hasAnalogOutputSignal(final BlockState state) {
|
| 54 | return true;
|
| 55 | }
|
| 56 |
|
| 57 | @Override
|
| 58 | protected int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction) {
|
| 59 | return state.getValue(HAS_EYE) ? 15 : 0;
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 64 | return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 69 | return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 74 | builder.add(FACING, HAS_EYE);
|
| 75 | }
|
| 76 |
|
| 77 | public static BlockPattern getOrCreatePortalShape() {
|
| 78 | if (portalShape == null) {
|
| 79 | portalShape = BlockPatternBuilder.start()
|
| 80 | .aisle("?vvv?", ">???<", ">???<", ">???<", "?^^^?")
|
| 81 | .where('?', BlockInWorld.hasState(BlockStatePredicate.ANY))
|
| 82 | .where(
|
| 83 | '^',
|
| 84 | BlockInWorld.hasState(
|
| 85 | BlockStatePredicate.forBlock(Blocks.END_PORTAL_FRAME).where(HAS_EYE, Predicates.equalTo(true)).where(FACING, Predicates.equalTo(Direction.SOUTH))
|
| 86 | )
|
| 87 | )
|
| 88 | .where(
|
| 89 | '>',
|
| 90 | BlockInWorld.hasState(
|
| 91 | BlockStatePredicate.forBlock(Blocks.END_PORTAL_FRAME).where(HAS_EYE, Predicates.equalTo(true)).where(FACING, Predicates.equalTo(Direction.WEST))
|
| 92 | )
|
| 93 | )
|
| 94 | .where(
|
| 95 | 'v',
|
| 96 | BlockInWorld.hasState(
|
| 97 | BlockStatePredicate.forBlock(Blocks.END_PORTAL_FRAME).where(HAS_EYE, Predicates.equalTo(true)).where(FACING, Predicates.equalTo(Direction.NORTH))
|
| 98 | )
|
| 99 | )
|
| 100 | .where(
|
| 101 | '<',
|
| 102 | BlockInWorld.hasState(
|
| 103 | BlockStatePredicate.forBlock(Blocks.END_PORTAL_FRAME).where(HAS_EYE, Predicates.equalTo(true)).where(FACING, Predicates.equalTo(Direction.EAST))
|
| 104 | )
|
| 105 | )
|
| 106 | .build();
|
| 107 | }
|
| 108 |
|
| 109 | return portalShape;
|
| 110 | }
|
| 111 |
|
| 112 | @Override
|
| 113 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 114 | return false;
|
| 115 | }
|
| 116 | }
|
| 117 |
|