MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"my custom sugarcane/cactus blocks just continues to grow instead of stopping at 3"
-- To limit the growth of your custom sugarcane/cactus block to 3, you need to override the randomTick method and add a condition to check the height of the plant before allowing it to grow. public class CustomSugarcaneCactusBlock extends Block { public CustomSugarcaneCactusBlock(AbstractBlock.Properties props) { super(props); } @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { if (world.isEmptyBlock(pos.above())) { int height; for (height = 1; world.getBlockState(pos.below(height)).getBlock() == this; ++height) { } if (height < 3) { int age = state.getValue(BlockStateProperties.AGE_15); if (age == 15) { world.setBlock(pos.above(), this.defaultBlockState(), 3); world.setBlock(pos, state.setValue(BlockStateProperties.AGE_15, Integer.valueOf(0)), 4); } else { world.setBlock(pos, state.setValue(BlockStateProperties.AGE_15, Integer.valueOf(age + 1)), 4); } } } } }