How to prevent plant from growing under certain conditions #1268
-
Hello there, I'm currently porting Oceancraft to 1.16 and want to implement seaweed (for now an almost 1:1 copy of vanilla kelp). I don't want it to grow to the very top water source block of the sea/ocean, so in My code: public class SeaweedPlantBlockBase extends AbstractPlantStemBlock implements FluidFillable {
public SeaweedPlantBlockBase(VoxelShape bounds) {
super(FabricBlockSettings.copy(Blocks.KELP_PLANT).nonOpaque(), Direction.UP, bounds, true, 0.14D);
}
protected boolean chooseStemState(BlockState state) {
return state.isOf(Blocks.WATER);
}
protected Block getPlant() {
return this.asBlock();
}
protected boolean canAttachTo(Block block) {
return block != Blocks.MAGMA_BLOCK;
}
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
return false;
}
public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
return false;
}
protected int method_26376(Random random) {
return 1;
}
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
Block topBlock = ctx.getWorld().getBlockState(ctx.getBlockPos().up(1)).getBlock();
return fluidState.isIn(FluidTags.WATER) && fluidState.getLevel() == 8 && topBlock == Blocks.WATER ? super.getPlacementState(ctx) : null;
}
public FluidState getFluidState(BlockState state) {
return Fluids.WATER.getStill(false);
}
} In the original source code (Forge 1.8) it was solved with the public boolean canBlockStay(World p_149718_1_, BlockPos pos) {
return p_149718_1_.getBlockState(pos.up(1)).getBlock() == Blocks.water;
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I fixed it by overriding the @Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
Block topBlock = world.getBlockState(pos.up(2)).getBlock();
if (topBlock == Blocks.WATER) {
super.randomTick(state, world, pos, random);
}
} Thanks to |
Beta Was this translation helpful? Give feedback.
I fixed it by overriding the
randomTick
function:Thanks to
lolad#1000
on Discord!