public void grow(World world, Random rand) { BlockPos binding = getBinding(); Block block = getBlockAtBinding(); if(block instanceof IGrowable) ((IGrowable) block).grow(world, rand, binding, world.getBlockState(binding)); }
private boolean growBlock(World world, BlockPos pos, IBlockState state) { if (state.getBlock() instanceof IGrowable) { IGrowable growable = (IGrowable) state.getBlock(); if (growable.canGrow(world, pos, state, world.isRemote)) { if (ServerHelper.isServerWorld(world)) { if (growable.canUseBonemeal(world, world.rand, pos, state)) { growable.grow(world, world.rand, pos, state); world.playEvent(2005, pos, 0); } } return true; } } return false; }
igrowable.grow(worldIn, worldIn.rand, target, iblockstate);
private boolean applyBonemeal(World worldIn, BlockPos target, EntityPlayer player, ItemStack sigilStack) { IBlockState iblockstate = worldIn.getBlockState(target); BonemealEvent event = new BonemealEvent(player, worldIn, target, iblockstate, EnumHand.MAIN_HAND, sigilStack); if (MinecraftForge.EVENT_BUS.post(event)) return false; else if (event.getResult() == Result.ALLOW) return true; if (iblockstate.getBlock() instanceof IGrowable) { IGrowable igrowable = (IGrowable) iblockstate.getBlock(); if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote)) { if (!worldIn.isRemote) { if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate)) igrowable.grow(worldIn, worldIn.rand, target, iblockstate); } return true; } } return false; } }
private boolean useBoneMeal(World world, BlockPos pos) { boolean result = false; for (BlockPos currentPos : BlockPos.getAllInBoxMutable(pos.add(-15, 0, -15), pos.add(15, 0, 15))) { IBlockState state = world.getBlockState(currentPos); Block crop = state.getBlock(); if (crop instanceof IGrowable) { IGrowable growable = (IGrowable) crop; if (growable.canUseBonemeal(world, world.rand, currentPos, state)) { if (!result) { result = true; } growable.grow(world, world.rand, currentPos.toImmutable(), state); } } } return result; }
@Override public void newDay(World world, BlockPos pos, IBlockState state) { Calendar calendar = HFTrackers.getCalendar(world); Weather weather = calendar.getTodaysWeather(); if (!weather.isSnow()) { if (calendar.getDate().getSeason() != Season.WINTER && world.rand.nextInt(3) < 2) { if (state.getBlock() == Blocks.SNOW_LAYER) { world.setBlockToAir(pos); //Destroy the snow layer //Attempt to grow some plants in spring, as we will have destroyed them in the winter if (world.rand.nextInt(32) == 0) { IBlockState down = world.getBlockState(pos.down()); if (down.getBlock() instanceof IGrowable) { IGrowable growable = ((IGrowable)down.getBlock()); if (growable.canGrow(world, pos.down(), down, false)) { if (growable.canUseBonemeal(world, world.rand, pos.down(), down)) { growable.grow(world, world.rand, pos.down(), down); } } } } } else world.setBlockState(pos, Blocks.WATER.getDefaultState()); } } else if (weather == Weather.BLIZZARD && state.getBlock() == Blocks.SNOW_LAYER) { int meta = state.getValue(LAYERS); if (meta < 5) { world.setBlockState(pos, state.withProperty(LAYERS, meta + 1), 2); } } }
@Override public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { if(!worldIn.isRemote) { if(state.getValue(HALF) == BlockHalf.UPPER) { IBlockState downState = worldIn.getBlockState(pos.down()); if(downState.getBlock() instanceof IGrowable) { ((IGrowable)downState.getBlock()).grow(worldIn, rand, pos.down(), downState); } return; } int age = state.getValue(AGE); if (age <= 2) { IBlockState newState = state.withProperty(AGE, MathHelper.clamp(++age, 0, 2)); worldIn.setBlockState(pos, newState); worldIn.setBlockState(pos.up(), newState.withProperty(HALF, BlockHalf.UPPER)); } } }
growable.grow(world, world.rand, currentPos, state);
@Override public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { if (world.isRemote) return; if (world.canBlockSeeSky(pos) && world.isDaytime()) { Triple<BlockPos, IBlockState, IGrowable> trip = firstBlock(world, pos); boolean once = false; if (trip != null) for (int i = 0; i < 3; i++) { IBlockState growState = i == 0 ? trip.getMiddle() : world.getBlockState(trip.getLeft()); if (growState.getBlock() == trip.getRight() && trip.getRight().canGrow(world, trip.getLeft(), growState, false)) { trip.getRight().grow(world, rand, trip.getLeft(), growState); once = true; } } if (once) world.playEvent(2005, trip.getMiddle().isOpaqueCube() ? trip.getLeft().up() : trip.getLeft(), 0); } }