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 a maximum height of 3, you can override the tick method and check the height before allowing it to grow. Here's an example implementation: */ public class CustomSugarcaneCactusBlock extends Block { public CustomSugarcaneCactusBlock(AbstractBlock.Properties properties) { super(properties); } @Override public void tick(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 (ForgeHooks.onCropsGrowPre(world, pos, state, random.nextInt(5) == 0)) { world.setBlock(pos.above(), this.defaultBlockState().setValue(BlockStateProperties.AGE_15, Integer.valueOf(age)), 3); ForgeHooks.onCropsGrowPost(world, pos, state); } } } } } /* This custom block will now stop growing after reaching a height of 3. Make sure to replace CustomSugarcaneCactusBlock with the name of your custom block class. */