minecraft-source/src/net/minecraft/world/level/block/WallBlock.java

108 lines
7.1 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.tags.BlockTags;
import net.minecraft.core.Direction;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
public class WallBlock extends CrossCollisionBlock {
public static final BooleanProperty UP;
private final VoxelShape[] shapeWithPostByIndex;
private final VoxelShape[] collisionShapeWithPostByIndex;
public WallBlock(final Properties c) {
super(0.0f, 3.0f, 0.0f, 14.0f, 24.0f, c);
this.registerDefaultState((((((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)WallBlock.UP, true)).setValue((Property<Comparable>)WallBlock.NORTH, false)).setValue((Property<Comparable>)WallBlock.EAST, false)).setValue((Property<Comparable>)WallBlock.SOUTH, false)).setValue((Property<Comparable>)WallBlock.WEST, false)).<Comparable, Boolean>setValue((Property<Comparable>)WallBlock.WATERLOGGED, false));
this.shapeWithPostByIndex = this.makeShapes(4.0f, 3.0f, 16.0f, 0.0f, 14.0f);
this.collisionShapeWithPostByIndex = this.makeShapes(4.0f, 3.0f, 24.0f, 0.0f, 24.0f);
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
if (byg.<Boolean>getValue((Property<Boolean>)WallBlock.UP)) {
return this.shapeWithPostByIndex[this.getAABBIndex(byg)];
}
return super.getShape(byg, bjd, fk, cvn);
}
@Override
public VoxelShape getCollisionShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
if (byg.<Boolean>getValue((Property<Boolean>)WallBlock.UP)) {
return this.collisionShapeWithPostByIndex[this.getAABBIndex(byg)];
}
return super.getCollisionShape(byg, bjd, fk, cvn);
}
@Override
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
return false;
}
private boolean connectsTo(final BlockState byg, final boolean boolean2, final Direction fp) {
final Block bpe5 = byg.getBlock();
final boolean boolean3 = bpe5.is(BlockTags.WALLS) || (bpe5 instanceof FenceGateBlock && FenceGateBlock.connectsToDirection(byg, fp));
return (!Block.isExceptionForConnection(bpe5) && boolean2) || boolean3;
}
@Override
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
final LevelReader bjw3 = bcn.getLevel();
final BlockPos fk4 = bcn.getClickedPos();
final FluidState cog5 = bcn.getLevel().getFluidState(bcn.getClickedPos());
final BlockPos fk5 = fk4.north();
final BlockPos fk6 = fk4.east();
final BlockPos fk7 = fk4.south();
final BlockPos fk8 = fk4.west();
final BlockState byg10 = bjw3.getBlockState(fk5);
final BlockState byg11 = bjw3.getBlockState(fk6);
final BlockState byg12 = bjw3.getBlockState(fk7);
final BlockState byg13 = bjw3.getBlockState(fk8);
final boolean boolean14 = this.connectsTo(byg10, byg10.isFaceSturdy(bjw3, fk5, Direction.SOUTH), Direction.SOUTH);
final boolean boolean15 = this.connectsTo(byg11, byg11.isFaceSturdy(bjw3, fk6, Direction.WEST), Direction.WEST);
final boolean boolean16 = this.connectsTo(byg12, byg12.isFaceSturdy(bjw3, fk7, Direction.NORTH), Direction.NORTH);
final boolean boolean17 = this.connectsTo(byg13, byg13.isFaceSturdy(bjw3, fk8, Direction.EAST), Direction.EAST);
final boolean boolean18 = (!boolean14 || boolean15 || !boolean16 || boolean17) && (boolean14 || !boolean15 || boolean16 || !boolean17);
return (((((((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)WallBlock.UP, boolean18 || !bjw3.isEmptyBlock(fk4.above()))).setValue((Property<Comparable>)WallBlock.NORTH, boolean14)).setValue((Property<Comparable>)WallBlock.EAST, boolean15)).setValue((Property<Comparable>)WallBlock.SOUTH, boolean16)).setValue((Property<Comparable>)WallBlock.WEST, boolean17)).<Comparable, Boolean>setValue((Property<Comparable>)WallBlock.WATERLOGGED, cog5.getType() == Fluids.WATER);
}
@Override
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
if (byg1.<Boolean>getValue((Property<Boolean>)WallBlock.WATERLOGGED)) {
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
}
if (fp == Direction.DOWN) {
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
}
final Direction fp2 = fp.getOpposite();
final boolean boolean9 = (fp == Direction.NORTH) ? this.connectsTo(byg3, byg3.isFaceSturdy(bju, fk6, fp2), fp2) : byg1.<Boolean>getValue((Property<Boolean>)WallBlock.NORTH);
final boolean boolean10 = (fp == Direction.EAST) ? this.connectsTo(byg3, byg3.isFaceSturdy(bju, fk6, fp2), fp2) : byg1.<Boolean>getValue((Property<Boolean>)WallBlock.EAST);
final boolean boolean11 = (fp == Direction.SOUTH) ? this.connectsTo(byg3, byg3.isFaceSturdy(bju, fk6, fp2), fp2) : byg1.<Boolean>getValue((Property<Boolean>)WallBlock.SOUTH);
final boolean boolean12 = (fp == Direction.WEST) ? this.connectsTo(byg3, byg3.isFaceSturdy(bju, fk6, fp2), fp2) : byg1.<Boolean>getValue((Property<Boolean>)WallBlock.WEST);
final boolean boolean13 = (!boolean9 || boolean10 || !boolean11 || boolean12) && (boolean9 || !boolean10 || boolean11 || !boolean12);
return ((((((AbstractStateHolder<O, BlockState>)byg1).setValue((Property<Comparable>)WallBlock.UP, boolean13 || !bju.isEmptyBlock(fk5.above()))).setValue((Property<Comparable>)WallBlock.NORTH, boolean9)).setValue((Property<Comparable>)WallBlock.EAST, boolean10)).setValue((Property<Comparable>)WallBlock.SOUTH, boolean11)).<Comparable, Boolean>setValue((Property<Comparable>)WallBlock.WEST, boolean12);
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(WallBlock.UP, WallBlock.NORTH, WallBlock.EAST, WallBlock.WEST, WallBlock.SOUTH, WallBlock.WATERLOGGED);
}
static {
UP = BlockStateProperties.UP;
}
}