2025-11-24 22:52:51 +03:00

144 lines
5.4 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.serialization.MapCodec
* org.jspecify.annotations.Nullable
*/
package net.minecraft.world.level.block;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.ScheduledTickAccess;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jspecify.annotations.Nullable;
public class SnowLayerBlock
extends Block {
public static final MapCodec<SnowLayerBlock> CODEC = SnowLayerBlock.simpleCodec(SnowLayerBlock::new);
public static final int MAX_HEIGHT = 8;
public static final IntegerProperty LAYERS = BlockStateProperties.LAYERS;
private static final VoxelShape[] SHAPES = Block.boxes(8, height -> Block.column(16.0, 0.0, height * 2));
public static final int HEIGHT_IMPASSABLE = 5;
public MapCodec<SnowLayerBlock> codec() {
return CODEC;
}
protected SnowLayerBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState((BlockState)((BlockState)this.stateDefinition.any()).setValue(LAYERS, 1));
}
@Override
protected boolean isPathfindable(BlockState state, PathComputationType type) {
if (type == PathComputationType.LAND) {
return state.getValue(LAYERS) < 5;
}
return false;
}
@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPES[state.getValue(LAYERS)];
}
@Override
protected VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPES[state.getValue(LAYERS) - 1];
}
@Override
protected VoxelShape getBlockSupportShape(BlockState state, BlockGetter level, BlockPos pos) {
return SHAPES[state.getValue(LAYERS)];
}
@Override
protected VoxelShape getVisualShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPES[state.getValue(LAYERS)];
}
@Override
protected boolean useShapeForLightOcclusion(BlockState state) {
return true;
}
@Override
protected float getShadeBrightness(BlockState state, BlockGetter level, BlockPos pos) {
return state.getValue(LAYERS) == 8 ? 0.2f : 1.0f;
}
@Override
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
BlockState belowState = level.getBlockState(pos.below());
if (belowState.is(BlockTags.SNOW_LAYER_CANNOT_SURVIVE_ON)) {
return false;
}
if (belowState.is(BlockTags.SNOW_LAYER_CAN_SURVIVE_ON)) {
return true;
}
return Block.isFaceFull(belowState.getCollisionShape(level, pos.below()), Direction.UP) || belowState.is(this) && belowState.getValue(LAYERS) == 8;
}
@Override
protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) {
if (!state.canSurvive(level, pos)) {
return Blocks.AIR.defaultBlockState();
}
return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
}
@Override
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
if (level.getBrightness(LightLayer.BLOCK, pos) > 11) {
SnowLayerBlock.dropResources(state, level, pos);
level.removeBlock(pos, false);
}
}
@Override
protected boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
int layers = state.getValue(LAYERS);
if (context.getItemInHand().is(this.asItem()) && layers < 8) {
if (context.replacingClickedOnBlock()) {
return context.getClickedFace() == Direction.UP;
}
return true;
}
return layers == 1;
}
@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
if (state.is(this)) {
int layers = state.getValue(LAYERS);
return (BlockState)state.setValue(LAYERS, Math.min(8, layers + 1));
}
return super.getStateForPlacement(context);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(LAYERS);
}
}