96 lines
4.1 KiB
Java
96 lines
4.1 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
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 BaseCoralPlantTypeBlock extends Block implements SimpleWaterloggedBlock {
|
|
public static final BooleanProperty WATERLOGGED;
|
|
private static final VoxelShape AABB;
|
|
|
|
protected BaseCoralPlantTypeBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Boolean>setValue((Property<Comparable>)BaseCoralPlantTypeBlock.WATERLOGGED, true));
|
|
}
|
|
|
|
protected void tryScheduleDieTick(final BlockState byg, final LevelAccessor bju, final BlockPos fk) {
|
|
if (!scanForWater(byg, bju, fk)) {
|
|
bju.getBlockTicks().scheduleTick(fk, this, 60 + bju.getRandom().nextInt(40));
|
|
}
|
|
}
|
|
|
|
protected static boolean scanForWater(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
|
|
if (byg.<Boolean>getValue((Property<Boolean>)BaseCoralPlantTypeBlock.WATERLOGGED)) {
|
|
return true;
|
|
}
|
|
for (final Direction fp7 : Direction.values()) {
|
|
if (bjd.getFluidState(fk.relative(fp7)).is(FluidTags.WATER)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
final FluidState cog3 = bcn.getLevel().getFluidState(bcn.getClickedPos());
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)BaseCoralPlantTypeBlock.WATERLOGGED, cog3.is(FluidTags.WATER) && cog3.getAmount() == 8);
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return BaseCoralPlantTypeBlock.AABB;
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (byg1.<Boolean>getValue((Property<Boolean>)BaseCoralPlantTypeBlock.WATERLOGGED)) {
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
|
}
|
|
if (fp == Direction.DOWN && !this.canSurvive(byg1, bju, fk5)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
final BlockPos fk2 = fk.below();
|
|
return bjw.getBlockState(fk2).isFaceSturdy(bjw, fk2, Direction.UP);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(BaseCoralPlantTypeBlock.WATERLOGGED);
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(final BlockState byg) {
|
|
if (byg.<Boolean>getValue((Property<Boolean>)BaseCoralPlantTypeBlock.WATERLOGGED)) {
|
|
return Fluids.WATER.getSource(false);
|
|
}
|
|
return super.getFluidState(byg);
|
|
}
|
|
|
|
static {
|
|
WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
AABB = Block.box(2.0, 0.0, 2.0, 14.0, 4.0, 14.0);
|
|
}
|
|
}
|