@Override public void safeImpact(BlockPos pos, @Nullable EnumFacing side, World world, int amplifier) { int box = 1 + (int) ((float) amplifier / 2F); BlockPos posI = pos.add(box, box, box); BlockPos posF = pos.add(-box, -box, -box); Iterable<BlockPos> spots = BlockPos.getAllInBox(posI, posF); for (BlockPos spot : spots) { IBlockState state = world.getBlockState(spot); boolean place = amplifier > 2 || world.rand.nextBoolean(); if (place && state.getBlock() instanceof IGrowable) { IGrowable crop = (IGrowable) state.getBlock(); if (crop.canGrow(world, spot, state, false)) crop.grow(world, world.rand, spot, state); } } }
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target) { IBlockState iblockstate = worldIn.getBlockState(target); 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); } --stack.stackSize; } return true; } } return false; }
private boolean isCorrectBlock(BlockPos pos) { Block block = WBlock.getBlock(pos); if(!(block instanceof IGrowable) || block instanceof BlockGrass || !((IGrowable)block).canGrow(WMinecraft.getWorld(), pos, WBlock.getState(pos), false)) return false; if(block instanceof BlockSapling) return saplings.isChecked(); else if(block instanceof BlockCrops) return crops.isChecked(); else if(block instanceof BlockStem) return stems.isChecked(); else if(block instanceof BlockCocoa) return cocoa.isChecked(); else return other.isChecked(); }
private void enderlilyTele(World world, BlockPos pos, IBlockState state, int age) { if (world.getLightFromNeighbors(pos.up()) >= 9) { if (age < ((BlockCrops)state.getBlock()).getMaxAge()) { Iterable<BlockPos> getBox = BlockPos.getAllInBox(pos.add(-4, 0, -4), pos.add(4, 0, 4)); Iterator it = getBox.iterator(); while (it.hasNext()) { BlockPos looppos = (BlockPos)it.next(); Block loopblock = world.getBlockState(looppos).getBlock(); if (loopblock != null && (world.isAirBlock(looppos) || (loopblock instanceof IGrowable && loopblock != this))) { IBlockState savestate = world.getBlockState(looppos); if (world.getBlockState(looppos.add(0, -1, 0)).getBlock() == Blocks.FARMLAND && world.rand.nextInt(7) == 0) { world.setBlockState(looppos, ((BlockCrops)state.getBlock()).withAge(age + 1), 2); world.setBlockState(pos, savestate); UCPacketHandler.sendToNearbyPlayers(world, looppos, new PacketUCEffect(EnumParticleTypes.PORTAL, looppos.getX(), looppos.getY(), looppos.getZ(), 6)); UCPacketHandler.sendToNearbyPlayers(world, pos, new PacketUCEffect(EnumParticleTypes.PORTAL, pos.getX(), pos.getY(), pos.getZ(), 6)); return; } } } } } }
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target) { IBlockState iblockstate = worldIn.getBlockState(target); 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); } stack.func_190918_g(1); } return true; } } return false; }
public static boolean isNormalCrop(World world, BlockPos pos) { if (world.isAirBlock(pos)) { return false; } boolean found = false; IBlockState state = world.getBlockState(pos); Block bi = state.getBlock(); for (int a = 0; a < 16; a++) { if ((getCrops(CropType.NORMAL).contains(bi.getUnlocalizedName() + a))) { found = true; break; } } int md = bi.getMetaFromState(state); if ((((bi instanceof IGrowable)) && (!(bi instanceof BlockStem))) || (((bi instanceof BlockCrops)) && (!found)) || ((bi == Blocks.NETHER_WART)) || ((bi == Blocks.COCOA)) || (getCrops(CropType.NORMAL).contains(bi.getUnlocalizedName() + md))) { return true; } return false; }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); IBlockState state = world.getBlockState(pos); if (state.getBlock() instanceof IGrowable) { NBTTagList nbtList = stack.getEnchantmentTagList(); for (NBTBase nbt : nbtList) { if (((NBTTagCompound) nbt).getInteger("id") == Enchantment.getEnchantmentID(GSEnchantment.BONE_RAIN)) { if (applyBonemeal(stack, world, pos, state, player, hand)) { if (!world.isRemote) { world.playEvent(2005, pos, 0); } return EnumActionResult.SUCCESS; } break; } } } return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ); }
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, @javax.annotation.Nullable EnumHand hand) { if (!(state.getBlock() instanceof BlockGrass) || player.isSneaking()) { int hook = net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(player, worldIn, pos, state, stack, hand); if (hook != 0) return hook > 0; IGrowable igrowable = (IGrowable) state.getBlock(); if (igrowable.canGrow(worldIn, pos, state, worldIn.isRemote)) { if (!worldIn.isRemote) { if (igrowable.canUseBonemeal(worldIn, worldIn.rand, pos, state)) { igrowable.grow(worldIn, worldIn.rand, pos, state); } stack.damageItem(1, player); } return true; } } return false; }
private boolean applyUnko(ItemStack stack, World worldIn, BlockPos pos, EntityPlayer player) { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (block instanceof IGrowable) { IGrowable igrowable = (IGrowable)block; if (igrowable.isStillGrowing(worldIn, pos, iblockstate, worldIn.isRemote)) { if (!worldIn.isRemote) { if (igrowable.canUseBonemeal(worldIn, worldIn.rand, pos, iblockstate)) { igrowable.grow(worldIn, worldIn.rand, pos, iblockstate); } --stack.stackSize; } return true; } } return false; }
@SuppressWarnings({ "NumericCastThatLosesPrecision", "MethodMayBeStatic" }) @SubscribeEvent public void onItemExpire(ItemExpireEvent event) { if (Settings.INSTANCE.doPlantGrowable()) { final Item item = event.entityItem.getEntityItem().getItem(); final Block block = Block.getBlockFromItem(item); if (block instanceof IGrowable) { final World world = event.entityItem.worldObj; final int x = (int) event.entityItem.posX; final int y = (int) event.entityItem.posY; final int z = (int) event.entityItem.posZ; final int metadata = event.entityItem.getEntityItem().getItemDamage(); plantGrowable(world, x, y, z, block, metadata); } } }
/** * Gives a bonemeal growth effect to the plant in question. Does not work on BlockBush because they appear to pop off on tall pushes. * @param world * @param pos * @return */ public static boolean growPlantAtBlock(World world, BlockPos pos) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(block instanceof IGrowable && !(block instanceof BlockBush)) { ((IGrowable)block).grow(world, rand, pos, state); // block.updateTick(world, pos, state, world.rand); return true; } return false; }
public static boolean func_150919_a(ItemStack p_150919_0_, World p_150919_1_, int p_150919_2_, int p_150919_3_, int p_150919_4_) { Block var5 = p_150919_1_.getBlock(p_150919_2_, p_150919_3_, p_150919_4_); if (var5 instanceof IGrowable) { IGrowable var6 = (IGrowable)var5; if (var6.func_149851_a(p_150919_1_, p_150919_2_, p_150919_3_, p_150919_4_, p_150919_1_.isClient)) { if (!p_150919_1_.isClient) { if (var6.func_149852_a(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_)) { var6.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); } --p_150919_0_.stackSize; } return true; } } return false; }
@Override public void onUpdateTick(ItemStack stack, World world, Entity entity, IPlayerSession session, int par4, boolean par5, int boost, int cost, boolean bool) { if (entity != null && entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entity; if (++tick >= 140) { tick = 0; for (int x = -(1 + boost); x < (2 + boost); x++) for (int z = -(1 + boost); z < (2 + boost); z++) { if (session.hasEnoughMana(cost())) { int blkX = (int) player.posX + x, blkY = (int) player.posY, blkZ = (int) player.posZ + z; Block blk = world.getBlock(blkX, blkY, blkZ); if (blk != null && !world.isAirBlock(blkX, blkY, blkZ)) { if (blk instanceof IGrowable) { if (((IGrowable) blk).func_149851_a(world, blkX, blkY, blkZ, world.isRemote)) { if (!world.isRemote) blk.updateTick(world, blkX, blkY, blkZ, world.rand); session.adjustMana(-cost(), false); } } } } else break; } } } }
private void init () { registerCompostMaterial(new ItemStack(Blocks.melon_block), defaultMaterial); registerCompostMaterial(new ItemStack(Blocks.pumpkin), defaultMaterial); registerCompostMaterial(new ItemStack(Blocks.hay_block), defaultMaterial); registerCompostMaterial(new ItemStack(Items.string), new StandardCompostMaterial(100, 0.0625f)); registerCompostMaterial(new ItemStack(Items.wheat), new StandardCompostMaterial(100, 0.125f)); registerCompostMaterial(new ItemStack(Items.reeds), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial(new ItemStack(Items.feather), new StandardCompostMaterial(50, 0.0625f)); registerCompostMaterial(new ItemStack(Items.rotten_flesh), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial(new ItemStack(Items.leather), new StandardCompostMaterial(150, 0.125f)); registerCompostMaterial("treeWood", new StandardCompostMaterial(300, 0.25f)); registerCompostMaterial("logWood", new StandardCompostMaterial(300, 0.25f)); registerCompostMaterial("treeLeaves", defaultMaterial); registerCompostMaterial("treeSapling", defaultMaterial); registerCompostMaterial("stickWood", defaultMaterial); registerCompostMaterial(IPlantable.class, defaultMaterial); registerCompostMaterial(IGrowable.class, defaultMaterial); registerCompostMaterial(BlockLeavesBase.class, defaultMaterial); registerCompostMaterial(BlockVine.class, defaultMaterial); registerCompostMaterial(ItemFood.class, defaultMaterial); }
@Override public boolean isGrown(Point3I plantPoint, Block plantBlock, IBlockState state, World worldObj) { int metadata = plantBlock.getMetaFromState(state); //check pumpkins and mellons first if (plantBlock instanceof BlockStem) { for (EnumFacing facing : EnumFacing.Plane.HORIZONTAL) { Block testBlock = worldObj.getBlockState(plantPoint.toPosition().offset(facing)).getBlock(); if ( (testBlock == Blocks.MELON_BLOCK) || (testBlock == Blocks.PUMPKIN) ) return true; } } else if (plantBlock instanceof IGrowable) { return !((IGrowable)plantBlock).canGrow(worldObj, plantPoint.toPosition(), state, true); } else if (plantBlock instanceof BlockNetherWart) { //nether wart return (metadata >= 3); } else if (plantBlock == Blocks.REEDS) { // sugar cane return (worldObj.getBlockState(plantPoint.toPosition().up()).getBlock() == Blocks.REEDS); } else if (plantBlock == Blocks.CACTUS) { //cactus return (worldObj.getBlockState(plantPoint.toPosition().up()).getBlock() == Blocks.CACTUS); } return false; }
/** Increases the drops of plants/crops if they are within a certain distance of a block of ichor */ @SubscribeEvent public void onPlantHarvest(BlockEvent.HarvestDropsEvent e) { // If its not growable (a crop) then we don't need to do anything if (!(e.block instanceof IGrowable)) return; Block ichorBlock = null; for (int x = e.x - BlockIchorFluid.ENRICH_RADIUS; x <= e.x + BlockIchorFluid.ENRICH_RADIUS; x++) { for (int y = e.y - 1; y < e.y; y++) { for (int z = e.z - BlockIchorFluid.ENRICH_RADIUS; z <= e.z + BlockIchorFluid.ENRICH_RADIUS; z++) { ichorBlock = e.world.getBlock(x, y, z); if (ichorBlock instanceof BlockIchorFluid) { //increase drops for (ItemStack stack : e.drops) { if (e.world.rand.nextFloat() <= .2F) { ItemStack copy = stack.copy(); e.drops.add(copy); } } return; } } } } }
@Override public float work() { if (WorkUtils.isDisabled(this.getBlockType())) return 0; if (ItemStackUtils.isInventoryFull(outItems)) return 0; hasWorked = false; List<BlockPos> blockPos = BlockUtils.getBlockPosInAABB(getWorkingArea()); if (pointer >= blockPos.size()) pointer = 0; if (pointer < blockPos.size() && BlockUtils.canBlockBeBroken(this.world, blockPos.get(pointer))) { BlockPos pos = blockPos.get(pointer); if (this.world.getBlockState(pos).getBlock() instanceof IGrowable) { FakePlayer player = IndustrialForegoing.getFakePlayer(this.world, pos.up()); player.inventory.clear(); WORKING_TILES.add(this); this.world.getBlockState(pos).getBlock().onBlockActivated(this.world, pos, this.world.getBlockState(pos), player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, EnumFacing.UP, new Vec3d(0, 0, 0)); for (ItemStack stack : player.inventory.mainInventory) { if (!stack.isEmpty()) { ItemHandlerHelper.insertItem(outItems, stack, false); sludge.fill(new FluidStack(FluidsRegistry.SLUDGE, 10 * stack.getCount()), true); hasWorked = true; } } player.inventory.clear(); WORKING_TILES.remove(this); } } ++pointer; return hasWorked ? 1 : 0.1f; }
@Override public float work() { if (WorkUtils.isDisabled(this.getBlockType())) return 0; List<BlockPos> blockPosList = BlockUtils.getBlockPosInAABB(getWorkingArea()); boolean hasWorked = false; for (BlockPos pos : blockPosList) { if (world.getBlockState(pos).getBlock() instanceof IGrowable) { world.getBlockState(pos).getBlock().randomTick(world, pos, world.getBlockState(pos), world.rand); hasWorked = true; } } return hasWorked ? 1 : 0; }
@SideOnly(Side.CLIENT) @Override public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) { super.randomDisplayTick(stateIn, worldIn, pos, rand); for (BlockPos pos1 : BlockPos.getAllInBoxMutable(pos.add(-2, 0, -2), pos.add(2, 0, 2))) { if (worldIn.getBlockState(pos1).getBlock() instanceof IGrowable && rand.nextBoolean() && rand.nextBoolean() && rand.nextBoolean()) { worldIn.spawnParticle(EnumParticleTypes.WATER_WAKE, pos1.getX() + rand.nextDouble(), pos1.getY(), pos1.getZ() + rand.nextDouble(), 0.0D, 0.0D, 0.0D); } } }
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target, EntityPlayer player) { IBlockState iblockstate = worldIn.getBlockState(target); int hook = net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(player, worldIn, target, iblockstate, stack); if (hook != 0) return hook > 0; 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); } --stack.stackSize; } return true; } } return false; }
public static boolean isGrownCrop(World world, BlockPos pos) { if (world.isAirBlock(pos)) { return false; } boolean found = false; IBlockState state = world.getBlockState(pos); Block bi = state.getBlock(); for (int a = 0; a < 16; a++) { if ((getCrops(CropType.NORMAL).contains(bi.getUnlocalizedName() + a)) || (getCrops(CropType.STACKED).contains(bi.getUnlocalizedName() + a)) || (getCrops(CropType.CLICKABLE).contains(bi.getUnlocalizedName() + a))) { found = true; break; } } Block biB = world.getBlockState(pos.down()).getBlock(); int md = bi.getMetaFromState(state); if ((((bi instanceof IGrowable)) && (!((IGrowable)bi).canGrow(world, pos, state, world.isRemote)) && (!(bi instanceof BlockStem))) || (((bi instanceof BlockCrops)) && ((BlockCrops)bi).isMaxAge(state) && (!found)) || ((bi == Blocks.NETHER_WART) && (state.getValue(BlockNetherWart.AGE).intValue() >= 3)) || ((bi == Blocks.COCOA) && (state.getValue(BlockCocoa.AGE).intValue() >= 2)) || (getCrops(CropType.NORMAL).contains(bi.getUnlocalizedName() + md)) || (getCrops(CropType.STACKED).contains(bi.getUnlocalizedName() + md)) || ((getCrops(CropType.CLICKABLE).contains(bi.getUnlocalizedName() + md)) && (biB == bi))) { return true; } return false; }
@Override public boolean run(@Nonnull SpellData spell) { World world = spell.world; BlockPos targetPos = spell.getData(BLOCK_HIT); Entity targetEntity = spell.getData(ENTITY_HIT); Entity caster = spell.getData(CASTER); Vec3d pos = spell.getData(TARGET_HIT); if (pos != null) spell.world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1); if (targetEntity instanceof EntityLivingBase) { double strength = getModifier(spell, Attributes.POTENCY, 3, 20) / 10.0; if (!tax(this, spell)) return false; ((EntityLivingBase) targetEntity).heal((float) strength); } if (targetPos != null) { if (world.getBlockState(targetPos).getBlock() instanceof IGrowable) { if (!tax(this, spell)) return false; if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster))) ItemDye.applyBonemeal(new ItemStack(Items.DYE), world, targetPos); } else if (world.getBlockState(targetPos).getBlock() instanceof IPlantable) { IBlockState state = world.getBlockState(targetPos); Block block = state.getBlock(); if (!tax(this, spell)) return false; if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster))) { while (world.getBlockState(targetPos.up()).getBlock() == block) { targetPos = targetPos.up(); state = world.getBlockState(targetPos); block = state.getBlock(); } world.immediateBlockTick(targetPos, state, RandUtil.random); } } } return true; }
@Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ); if (this.getMaterialName() == zivicioToolMaterial.toString() && PrimordialConfig.enableZivicioHoeSpeedup) { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (block != null && block instanceof IGrowable) { IGrowable igrowable = (IGrowable) block; if (igrowable.canGrow(worldIn, pos, iblockstate, worldIn.isRemote)) { if (!worldIn.isRemote) { if (igrowable.canUseBonemeal(worldIn, worldIn.rand, pos, iblockstate)) { //igrowable.grow(worldIn, worldIn.rand, pos, iblockstate); // no client side update //iblockstate.getBlock().updateTick(worldIn, pos, iblockstate, worldIn.rand); // no client side update //LogHelper.info("update"); worldIn.scheduleUpdate(pos, block, 1); } } else { //LogHelper.info("spawn" + igrowable.toString()); spawnBonemealParticles(worldIn, pos, 5); } } } } return EnumActionResult.PASS; }
public static IPlantWrapper getPlantWrapper(World world, BlockPos pos) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if (block.getClass().getName().startsWith("com.infinityraider.agricraft.blocks")) { return new AgricraftPlantWrapper(block, state, world, pos); } if ((block == Blocks.MELON_STEM) || (block == Blocks.PUMPKIN_STEM)) { return new VanillaMelonPlant(block, state, world, pos); } if (block == Blocks.REEDS) { return new VanillaTallPlant(block, state, world, pos); } if (block == Blocks.CACTUS) { return new VanillaCactusPlant(block, state, world, pos); } if (block == Blocks.NETHER_WART) { return new VanillaNetherWartPlant(state, world, pos); } if (block instanceof IGrowable) { return new VanillaGenericPlant(block, state, world, pos); } return null; }
@Override public boolean canUseFertilizer() { if (this.block instanceof IGrowable) { return ((IGrowable)this.block).canGrow(this.world, this.pos, this.state, false); } return false; }
private void sprinkle() { EnvironmentData environment = EnvironmentData.getEnvironmentData(getWorld()); GameData data = environment.getData(); boolean dirty = false; int xCoord = getPos().getX(); int yCoord = getPos().getY(); int zCoord = getPos().getZ(); for (int x = xCoord-4 ; x <= xCoord+4; x++) { for (int y = yCoord-1 ; y <= yCoord+2; y++) { for (int z = zCoord-4 ; z <= zCoord+4; z++) { BlockPos pos = new BlockPos(x, y, z); IBlockState blockState = getWorld().getBlockState(pos); Block block = blockState.getBlock(); if (!getWorld().isAirBlock(pos)) { spawnParticles(EnumParticleTypes.WATER_SPLASH, 10, x, y+1, z); // splash, dripWater } if (block == ModBlocks.customFarmLand) { byte moistness = data.get(getWorld().provider.getDimension(), pos); if (moistness < MAX_MOISTNESS) { moistness++; data.set(getWorld().provider.getDimension(), pos, moistness); dirty = true; } } else if (block instanceof IGrowable) { if (random.nextInt(2) == 0) { block.updateTick(getWorld(), pos, blockState, random); } // if (random.nextInt(10) == 5) { // ((IGrowable) block).grow(getWorld(), random, pos, blockState); // } } } } } if (dirty) { environment.save(getWorld()); } }
private void killPlant(World world, BlockPos pos) { Block block = world.getBlockState(pos.up()).getBlock(); if (block == Blocks.CARROTS) { world.setBlockState(pos.up(), ModBlocks.deadCarrot.getDefaultState(), 3); } else if (block == Blocks.WHEAT) { world.setBlockState(pos.up(), ModBlocks.deadWheat.getDefaultState(), 3); } else if (block instanceof IGrowable) { world.setBlockState(pos.up(), ModBlocks.deadWheat.getDefaultState(), 3); } }
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target, EntityPlayer player) { IBlockState iblockstate = worldIn.getBlockState(target); int hook = net.minecraftforge.event.ForgeEventFactory .onApplyBonemeal(player, worldIn, target, iblockstate, stack); if (hook != 0) return hook > 0; 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); } stack.damageItem(10, player); } return true; } } return false; }
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target, EntityPlayer player) { IBlockState iblockstate = worldIn.getBlockState(target); int hook = net.minecraftforge.event.ForgeEventFactory .onApplyBonemeal(player, worldIn, target, iblockstate, stack); if (hook != 0) return hook > 0; 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); } --stack.stackSize; } return true; } } return false; }
@Override public void onWornTick(ItemStack itemstack, EntityLivingBase player) { if(player instanceof EntityPlayer && !((EntityPlayer) player).worldObj.isRemote) { if (player.getActivePotionEffect(Potion.moveSlowdown) != null) player.removePotionEffect(Potion.moveSlowdown.id); player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, Integer.MAX_VALUE, 1, true)); } if(growth = true) { int range = 3; int verticalRange = 2; int posX = (int) Math.round(player.posX - 0.5F); int posY = (int) player.posY; int posZ = (int) Math.round(player.posZ - 0.5F); for (int ix = posX - range; ix <= posZ + range; ix++) { for (int iz = posZ - range; iz <= posZ + range; iz++) { for (int iy = posY - verticalRange; iy <= posY + verticalRange; iy++) { Block block = player.worldObj.getBlock(ix, iy, iz); if (block instanceof IPlantable || block instanceof IGrowable) { if (player.worldObj.rand.nextInt(50) == 0) { block.updateTick(player.worldObj, ix, iy, iz, player.worldObj.rand); } } } } } } }
/** * This method will search through a vertical column of positions, starting from the top. * It will stop searching any lower once it hits anything other than air or plants. * Any plant found has an independant chance for a growth tick. That percentage is controlled by AgriCraftConfig. * Farmland also ends the search, but it first has its moisture set to max (7) if it isn't already. * The lowest position is special: a plant this far away is not helped. Only farmland is currently. */ private void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) { for (int targetY = highestY; targetY >= lowestY; targetY -= 1) { BlockPos target = new BlockPos(targetX, targetY, targetZ); IBlockState state = this.getWorld().getBlockState(target); Block block = state.getBlock(); // Option A: Skip empty/air blocks. // TODO: Is there a way to use isSideSolid to ignore minor obstructions? (Farmland isn't solid.) if (block.isAir(state, this.getWorld(), target)) { continue; } // Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too. if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) { if (this.getRandom().nextInt(100) < AgriCraftConfig.sprinklerGrowthChance) { block.updateTick(this.getWorld(), target, state, this.getRandom()); } continue; } // Option C: Dry farmland gets set as moist. if (block instanceof BlockFarmland) { if (state.getValue(BlockFarmland.MOISTURE) < 7) { this.getWorld().setBlockState(target, state.withProperty(BlockFarmland.MOISTURE, 7), 2); } break; // Explicitly expresses the intent to stop. } // Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop. break; } }
@Override public boolean useOnBlock(World world, EntityPlayer player, IPlayerSession session, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int boost, int cost) { for (int j = -(1 + boost); j < (2 + boost); j++) for (int k = -(1 + boost); k < (2 + boost); k++) { if (session.hasEnoughMana(cost())) { Block blk = world.getBlock(x + j, y, z + k); if (blk != null && !world.isAirBlock(x + j, y, z + k)) { BonemealEvent event = new BonemealEvent(player, world, blk, x + j, y, z + k); if (MinecraftForge.EVENT_BUS.post(event)) return false; if (blk instanceof IGrowable) { IGrowable grow = (IGrowable) blk; if (grow.func_149851_a(world, x + j, y, z + k, world.isRemote)) { world.spawnParticle("happyVillager", x + j + 0.5, y + 0.5, z + k + 0.5, world.rand.nextDouble() + 2, world.rand.nextDouble() + 2, world.rand.nextDouble() + 2); if (!world.isRemote) { if (grow.func_149852_a(world, world.rand, x + j, y, z + k)) { session.adjustMana(-cost(), false); //blk.updateTick(world, x + j, y, z + k, world.rand); grow.func_149853_b(world, world.rand, x + j, y, z + k); } } } } } } else break; } return false; }
@Override public boolean matchesFilter(ItemStack item) { if(item == null) return false; if (item.getItem() instanceof IPlantable) return true; if(item.getItem() instanceof ItemBlock){ Block b = ((ItemBlock)item.getItem()).getBlock(); if(b instanceof IPlantable) return true; if(b instanceof IGrowable) return true; } return false; }
public static boolean applyBonemeal(ItemStack itemstack, World world, int x, int y, int z, EntityPlayer player) { Block block = world.getBlock(x, y, z); BonemealEvent event = new BonemealEvent(player, world, block, x, y, z); if (MinecraftForge.EVENT_BUS.post(event)) { return false; } if (event.getResult() == Result.ALLOW) { if (!world.isRemote) { itemstack.stackSize--; } return true; } if (block instanceof IGrowable) { IGrowable igrowable = (IGrowable) block; if (igrowable.func_149851_a(world, x, y, z, world.isRemote)) { if (!world.isRemote) { if (igrowable.func_149852_a(world, world.rand, x, y, z)) { igrowable.func_149853_b(world, world.rand, x, y, z); } } return true; } } return false; }
public static boolean applyBonemeal(ItemStack p_150919_0_, World p_150919_1_, int p_150919_2_, int p_150919_3_, int p_150919_4_, EntityPlayer player) { Block block = p_150919_1_.getBlock(p_150919_2_, p_150919_3_, p_150919_4_); if (block instanceof IGrowable) { IGrowable igrowable = (IGrowable) block; if (igrowable.func_149851_a(p_150919_1_, p_150919_2_, p_150919_3_, p_150919_4_, p_150919_1_.isRemote)) { if (!p_150919_1_.isRemote) { if (igrowable.func_149852_a(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_)) { if (StringUtils.isShiftKeyDown()) { igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_ - 1, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_ + 1, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_ - 1); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_ + 1); } else { igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); } } // --p_150919_0_.stackSize; } return true; } } return false; }
public static boolean applyBonemeal(ItemStack p_150919_0_, World p_150919_1_, int p_150919_2_, int p_150919_3_, int p_150919_4_, EntityPlayer player, boolean superStrength) { Block block = p_150919_1_.getBlock(p_150919_2_, p_150919_3_, p_150919_4_); if (block instanceof IGrowable) { IGrowable igrowable = (IGrowable) block; if (igrowable.func_149851_a(p_150919_1_, p_150919_2_, p_150919_3_, p_150919_4_, p_150919_1_.isRemote)) { if (!p_150919_1_.isRemote) { if (igrowable.func_149852_a(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_)) { if (superStrength) { igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); }else{ igrowable.func_149853_b(p_150919_1_, p_150919_1_.rand, p_150919_2_, p_150919_3_, p_150919_4_); } } // --p_150919_0_.stackSize; } return true; } } return false; }