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

90 lines
3.9 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import javax.annotation.Nullable;
import net.minecraft.world.level.LevelReader;
import net.minecraft.core.Direction;
import net.minecraft.world.item.BlockPlaceContext;
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 Lantern extends Block {
public static final BooleanProperty HANGING;
protected static final VoxelShape AABB;
protected static final VoxelShape HANGING_AABB;
public Lantern(final Properties c) {
super(c);
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Boolean>setValue((Property<Comparable>)Lantern.HANGING, false));
}
@Nullable
@Override
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
for (final Direction fp6 : bcn.getNearestLookingDirections()) {
if (fp6.getAxis() == Direction.Axis.Y) {
final BlockState byg7 = ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)Lantern.HANGING, fp6 == Direction.UP);
if (byg7.canSurvive(bcn.getLevel(), bcn.getClickedPos())) {
return byg7;
}
}
}
return null;
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return byg.<Boolean>getValue((Property<Boolean>)Lantern.HANGING) ? Lantern.HANGING_AABB : Lantern.AABB;
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(Lantern.HANGING);
}
@Override
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
final Direction fp5 = getConnectedDirection(byg).getOpposite();
return Block.canSupportCenter(bjw, fk.relative(fp5), fp5.getOpposite());
}
protected static Direction getConnectedDirection(final BlockState byg) {
return byg.<Boolean>getValue((Property<Boolean>)Lantern.HANGING) ? Direction.DOWN : Direction.UP;
}
@Override
public PushReaction getPistonPushReaction(final BlockState byg) {
return PushReaction.DESTROY;
}
@Override
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
if (getConnectedDirection(byg1).getOpposite() == fp && !byg1.canSurvive(bju, fk5)) {
return Blocks.AIR.defaultBlockState();
}
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
}
@Override
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
return false;
}
static {
HANGING = BlockStateProperties.HANGING;
AABB = Shapes.or(Block.box(5.0, 0.0, 5.0, 11.0, 7.0, 11.0), Block.box(6.0, 7.0, 6.0, 10.0, 9.0, 10.0));
HANGING_AABB = Shapes.or(Block.box(5.0, 1.0, 5.0, 11.0, 8.0, 11.0), Block.box(6.0, 8.0, 6.0, 10.0, 10.0, 10.0));
}
}