57 lines
2.0 KiB
Java
57 lines
2.0 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import java.util.Random;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class CoralBlock extends Block {
|
|
private final Block deadBlock;
|
|
|
|
public CoralBlock(final Block bpe, final Properties c) {
|
|
super(c);
|
|
this.deadBlock = bpe;
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
if (!this.scanForWater(xd, fk)) {
|
|
xd.setBlock(fk, this.deadBlock.defaultBlockState(), 2);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (!this.scanForWater(bju, fk5)) {
|
|
bju.getBlockTicks().scheduleTick(fk5, this, 60 + bju.getRandom().nextInt(40));
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
protected boolean scanForWater(final BlockGetter bjd, final BlockPos fk) {
|
|
for (final Direction fp7 : Direction.values()) {
|
|
final FluidState cog8 = bjd.getFluidState(fk.relative(fp7));
|
|
if (cog8.is(FluidTags.WATER)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
if (!this.scanForWater(bcn.getLevel(), bcn.getClickedPos())) {
|
|
bcn.getLevel().getBlockTicks().scheduleTick(bcn.getClickedPos(), this, 60 + bcn.getLevel().getRandom().nextInt(40));
|
|
}
|
|
return this.defaultBlockState();
|
|
}
|
|
}
|