76 lines
2.8 KiB
Java
76 lines
2.8 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.material.Fluid;
|
|
import net.minecraft.world.level.ItemLike;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import java.util.Random;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class KelpPlantBlock extends Block implements LiquidBlockContainer {
|
|
private final KelpBlock top;
|
|
|
|
protected KelpPlantBlock(final KelpBlock bsd, final Properties c) {
|
|
super(c);
|
|
this.top = bsd;
|
|
}
|
|
|
|
@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);
|
|
}
|
|
super.tick(byg, xd, fk, random);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (fp == Direction.DOWN && !byg1.canSurvive(bju, fk5)) {
|
|
bju.getBlockTicks().scheduleTick(fk5, this, 1);
|
|
}
|
|
if (fp == Direction.UP) {
|
|
final Block bpe8 = byg3.getBlock();
|
|
if (bpe8 != this && bpe8 != this.top) {
|
|
return this.top.getStateForPlacement(bju);
|
|
}
|
|
}
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
|
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();
|
|
final BlockState byg2 = bjw.getBlockState(fk2);
|
|
final Block bpe7 = byg2.getBlock();
|
|
return bpe7 != Blocks.MAGMA_BLOCK && (bpe7 == this || byg2.isFaceSturdy(bjw, fk2, Direction.UP));
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getCloneItemStack(final BlockGetter bjd, final BlockPos fk, final BlockState byg) {
|
|
return new ItemStack(Blocks.KELP);
|
|
}
|
|
|
|
@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;
|
|
}
|
|
}
|