131 lines
6.0 KiB
Java
131 lines
6.0 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 javax.annotation.Nullable;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.LevelReader;
|
|
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.core.Direction;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
|
|
public class LadderBlock extends Block implements SimpleWaterloggedBlock {
|
|
public static final DirectionProperty FACING;
|
|
public static final BooleanProperty WATERLOGGED;
|
|
protected static final VoxelShape EAST_AABB;
|
|
protected static final VoxelShape WEST_AABB;
|
|
protected static final VoxelShape SOUTH_AABB;
|
|
protected static final VoxelShape NORTH_AABB;
|
|
|
|
protected LadderBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)LadderBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)LadderBlock.WATERLOGGED, false));
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
switch (byg.<Direction>getValue((Property<Direction>)LadderBlock.FACING)) {
|
|
case NORTH: {
|
|
return LadderBlock.NORTH_AABB;
|
|
}
|
|
case SOUTH: {
|
|
return LadderBlock.SOUTH_AABB;
|
|
}
|
|
case WEST: {
|
|
return LadderBlock.WEST_AABB;
|
|
}
|
|
default: {
|
|
return LadderBlock.EAST_AABB;
|
|
}
|
|
}
|
|
}
|
|
|
|
private boolean canAttachTo(final BlockGetter bjd, final BlockPos fk, final Direction fp) {
|
|
final BlockState byg5 = bjd.getBlockState(fk);
|
|
return !byg5.isSignalSource() && byg5.isFaceSturdy(bjd, fk, fp);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
final Direction fp5 = byg.<Direction>getValue((Property<Direction>)LadderBlock.FACING);
|
|
return this.canAttachTo(bjw, fk.relative(fp5.getOpposite()), fp5);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (fp.getOpposite() == byg1.<Direction>getValue((Property<Direction>)LadderBlock.FACING) && !byg1.canSurvive(bju, fk5)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
if (byg1.<Boolean>getValue((Property<Boolean>)LadderBlock.WATERLOGGED)) {
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
if (!bcn.replacingClickedOnBlock()) {
|
|
final BlockState byg3 = bcn.getLevel().getBlockState(bcn.getClickedPos().relative(bcn.getClickedFace().getOpposite()));
|
|
if (byg3.getBlock() == this && byg3.<Comparable>getValue((Property<Comparable>)LadderBlock.FACING) == bcn.getClickedFace()) {
|
|
return null;
|
|
}
|
|
}
|
|
BlockState byg3 = this.defaultBlockState();
|
|
final LevelReader bjw4 = bcn.getLevel();
|
|
final BlockPos fk5 = bcn.getClickedPos();
|
|
final FluidState cog6 = bcn.getLevel().getFluidState(bcn.getClickedPos());
|
|
for (final Direction fp10 : bcn.getNearestLookingDirections()) {
|
|
if (fp10.getAxis().isHorizontal()) {
|
|
byg3 = ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Direction>setValue((Property<Comparable>)LadderBlock.FACING, fp10.getOpposite());
|
|
if (byg3.canSurvive(bjw4, fk5)) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Boolean>setValue((Property<Comparable>)LadderBlock.WATERLOGGED, cog6.getType() == Fluids.WATER);
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public BlockState rotate(final BlockState byg, final Rotation btr) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)LadderBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)LadderBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
public BlockState mirror(final BlockState byg, final Mirror bsr) {
|
|
return byg.rotate(bsr.getRotation(byg.<Direction>getValue((Property<Direction>)LadderBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(LadderBlock.FACING, LadderBlock.WATERLOGGED);
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(final BlockState byg) {
|
|
if (byg.<Boolean>getValue((Property<Boolean>)LadderBlock.WATERLOGGED)) {
|
|
return Fluids.WATER.getSource(false);
|
|
}
|
|
return super.getFluidState(byg);
|
|
}
|
|
|
|
static {
|
|
FACING = HorizontalDirectionalBlock.FACING;
|
|
WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
EAST_AABB = Block.box(0.0, 0.0, 0.0, 3.0, 16.0, 16.0);
|
|
WEST_AABB = Block.box(13.0, 0.0, 0.0, 16.0, 16.0, 16.0);
|
|
SOUTH_AABB = Block.box(0.0, 0.0, 0.0, 16.0, 16.0, 3.0);
|
|
NORTH_AABB = Block.box(0.0, 0.0, 13.0, 16.0, 16.0, 16.0);
|
|
}
|
|
}
|