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

120 lines
5.4 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.block.state.StateDefinition;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.pathfinder.PathComputationType;
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.IntegerProperty;
public class SnowLayerBlock extends Block {
public static final IntegerProperty LAYERS;
protected static final VoxelShape[] SHAPE_BY_LAYER;
protected SnowLayerBlock(final Properties c) {
super(c);
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)SnowLayerBlock.LAYERS, 1));
}
@Override
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
switch (cqo) {
case LAND: {
return byg.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS) < 5;
}
case WATER: {
return false;
}
case AIR: {
return false;
}
default: {
return false;
}
}
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return SnowLayerBlock.SHAPE_BY_LAYER[byg.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS)];
}
@Override
public VoxelShape getCollisionShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return SnowLayerBlock.SHAPE_BY_LAYER[byg.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS) - 1];
}
@Override
public boolean useShapeForLightOcclusion(final BlockState byg) {
return true;
}
@Override
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
final BlockState byg2 = bjw.getBlockState(fk.below());
final Block bpe6 = byg2.getBlock();
return bpe6 != Blocks.ICE && bpe6 != Blocks.PACKED_ICE && bpe6 != Blocks.BARRIER && (bpe6 == Blocks.HONEY_BLOCK || bpe6 == Blocks.SOUL_SAND || Block.isFaceFull(byg2.getCollisionShape(bjw, fk.below()), Direction.UP) || (bpe6 == this && byg2.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS) == 8));
}
@Override
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
if (!byg1.canSurvive(bju, fk5)) {
return Blocks.AIR.defaultBlockState();
}
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
}
@Override
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
if (xd.getBrightness(LightLayer.BLOCK, fk) > 11) {
Block.dropResources(byg, xd, fk);
xd.removeBlock(fk, false);
}
}
@Override
public boolean canBeReplaced(final BlockState byg, final BlockPlaceContext bcn) {
final int integer4 = byg.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS);
if (bcn.getItemInHand().getItem() == this.asItem() && integer4 < 8) {
return !bcn.replacingClickedOnBlock() || bcn.getClickedFace() == Direction.UP;
}
return integer4 == 1;
}
@Nullable
@Override
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
final BlockState byg3 = bcn.getLevel().getBlockState(bcn.getClickedPos());
if (byg3.getBlock() == this) {
final int integer4 = byg3.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS);
return ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Integer>setValue((Property<Comparable>)SnowLayerBlock.LAYERS, Math.min(8, integer4 + 1));
}
return super.getStateForPlacement(bcn);
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(SnowLayerBlock.LAYERS);
}
static {
LAYERS = BlockStateProperties.LAYERS;
SHAPE_BY_LAYER = new VoxelShape[] { Shapes.empty(), Block.box(0.0, 0.0, 0.0, 16.0, 2.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 4.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 6.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 10.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 12.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 14.0, 16.0), Block.box(0.0, 0.0, 0.0, 16.0, 16.0, 16.0) };
}
}