99 lines
3.5 KiB
Java
99 lines
3.5 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
import java.util.function.ToIntFunction;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.ScheduledTickAccess;
|
|
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;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
|
|
public class GlowLichenBlock extends MultifaceBlock implements BonemealableBlock, SimpleWaterloggedBlock {
|
|
public static final MapCodec<GlowLichenBlock> CODEC = simpleCodec(GlowLichenBlock::new);
|
|
private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
private final MultifaceSpreader spreader = new MultifaceSpreader(this);
|
|
|
|
@Override
|
|
public MapCodec<GlowLichenBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
public GlowLichenBlock(BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.registerDefaultState(this.defaultBlockState().setValue(WATERLOGGED, false));
|
|
}
|
|
|
|
public static ToIntFunction<BlockState> emission(int light) {
|
|
return blockState -> MultifaceBlock.hasAnyFace(blockState) ? light : 0;
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
super.createBlockStateDefinition(builder);
|
|
builder.add(WATERLOGGED);
|
|
}
|
|
|
|
@Override
|
|
protected BlockState updateShape(
|
|
BlockState blockState,
|
|
LevelReader levelReader,
|
|
ScheduledTickAccess scheduledTickAccess,
|
|
BlockPos blockPos,
|
|
Direction direction,
|
|
BlockPos blockPos2,
|
|
BlockState blockState2,
|
|
RandomSource randomSource
|
|
) {
|
|
if ((Boolean)blockState.getValue(WATERLOGGED)) {
|
|
scheduledTickAccess.scheduleTick(blockPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelReader));
|
|
}
|
|
|
|
return super.updateShape(blockState, levelReader, scheduledTickAccess, blockPos, direction, blockPos2, blockState2, randomSource);
|
|
}
|
|
|
|
@Override
|
|
protected boolean canBeReplaced(BlockState state, BlockPlaceContext useContext) {
|
|
return !useContext.getItemInHand().is(Items.GLOW_LICHEN) || super.canBeReplaced(state, useContext);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) {
|
|
return Direction.stream().anyMatch(direction -> this.spreader.canSpreadInAnyDirection(state, level, pos, direction.getOpposite()));
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) {
|
|
this.spreader.spreadFromRandomFaceTowardRandomDirection(state, level, pos, random);
|
|
}
|
|
|
|
@Override
|
|
protected FluidState getFluidState(BlockState state) {
|
|
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
|
|
}
|
|
|
|
@Override
|
|
protected boolean propagatesSkylightDown(BlockState blockState) {
|
|
return blockState.getFluidState().isEmpty();
|
|
}
|
|
|
|
@Override
|
|
public MultifaceSpreader getSpreader() {
|
|
return this.spreader;
|
|
}
|
|
}
|