114 lines
4.7 KiB
Java
114 lines
4.7 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.material.Fluid;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import java.util.Random;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
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 KelpBlock extends Block implements LiquidBlockContainer {
|
|
public static final IntegerProperty AGE;
|
|
protected static final VoxelShape SHAPE;
|
|
|
|
protected KelpBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)KelpBlock.AGE, 0));
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return KelpBlock.SHAPE;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
final FluidState cog3 = bcn.getLevel().getFluidState(bcn.getClickedPos());
|
|
if (cog3.is(FluidTags.WATER) && cog3.getAmount() == 8) {
|
|
return this.getStateForPlacement(bcn.getLevel());
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public BlockState getStateForPlacement(final LevelAccessor bju) {
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)KelpBlock.AGE, bju.getRandom().nextInt(25));
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(final BlockState byg) {
|
|
return Fluids.WATER.getSource(false);
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
if (!byg.canSurvive(xd, fk)) {
|
|
xd.destroyBlock(fk, true);
|
|
return;
|
|
}
|
|
final BlockPos fk2 = fk.above();
|
|
final BlockState byg2 = xd.getBlockState(fk2);
|
|
if (byg2.getBlock() == Blocks.WATER && byg.<Integer>getValue((Property<Integer>)KelpBlock.AGE) < 25 && random.nextDouble() < 0.14) {
|
|
xd.setBlockAndUpdate(fk2, ((AbstractStateHolder<O, BlockState>)byg).<Comparable>cycle((Property<Comparable>)KelpBlock.AGE));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
final BlockPos fk2 = fk.below();
|
|
final BlockState byg2 = bjw.getBlockState(fk2);
|
|
final Block bpe7 = byg2.getBlock();
|
|
return bpe7 != Blocks.MAGMA_BLOCK && (bpe7 == this || bpe7 == Blocks.KELP_PLANT || byg2.isFaceSturdy(bjw, fk2, Direction.UP));
|
|
}
|
|
|
|
@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)) {
|
|
if (fp == Direction.DOWN) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
bju.getBlockTicks().scheduleTick(fk5, this, 1);
|
|
}
|
|
if (fp == Direction.UP && byg3.getBlock() == this) {
|
|
return Blocks.KELP_PLANT.defaultBlockState();
|
|
}
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(KelpBlock.AGE);
|
|
}
|
|
|
|
@Override
|
|
public boolean canPlaceLiquid(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final Fluid cof) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean placeLiquid(final LevelAccessor bju, final BlockPos fk, final BlockState byg, final FluidState cog) {
|
|
return false;
|
|
}
|
|
|
|
static {
|
|
AGE = BlockStateProperties.AGE_25;
|
|
SHAPE = Block.box(0.0, 0.0, 0.0, 16.0, 9.0, 16.0);
|
|
}
|
|
}
|