50 lines
1.9 KiB
Java
50 lines
1.9 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
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.BooleanProperty;
|
|
|
|
public class SnowyDirtBlock extends Block {
|
|
public static final MapCodec<SnowyDirtBlock> CODEC = simpleCodec(SnowyDirtBlock::new);
|
|
public static final BooleanProperty SNOWY = BlockStateProperties.SNOWY;
|
|
|
|
@Override
|
|
protected MapCodec<? extends SnowyDirtBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
protected SnowyDirtBlock(BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(SNOWY, false));
|
|
}
|
|
|
|
@Override
|
|
protected BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) {
|
|
return direction == Direction.UP
|
|
? state.setValue(SNOWY, isSnowySetting(neighborState))
|
|
: super.updateShape(state, direction, neighborState, level, pos, neighborPos);
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
|
BlockState blockState = context.getLevel().getBlockState(context.getClickedPos().above());
|
|
return this.defaultBlockState().setValue(SNOWY, isSnowySetting(blockState));
|
|
}
|
|
|
|
private static boolean isSnowySetting(BlockState state) {
|
|
return state.is(BlockTags.SNOW);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(SNOWY);
|
|
}
|
|
}
|