public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (stack.getItemDamage() == EnumItems.TIMEMEAL.ordinal() && player.canPlayerEdit(pos, facing, stack)) { Block crops = world.getBlockState(pos).getBlock(); if (crops != null && crops instanceof BlockCrops) { if (crops != UCBlocks.cropMerlinia) world.setBlockState(pos, ((BlockCrops)crops).withAge(0), 2); else if (crops == UCBlocks.cropMerlinia) ((Merlinia)crops).merliniaGrowth(world, pos, world.rand.nextInt(1) + 1); else if (crops instanceof BlockNetherWart) ((BlockNetherWart)crops).updateTick(world, pos, world.getBlockState(pos), world.rand); if (!player.capabilities.isCreativeMode && !player.worldObj.isRemote) stack.stackSize--; UCPacketHandler.sendToNearbyPlayers(world, pos, new PacketUCEffect(EnumParticleTypes.VILLAGER_HAPPY, pos.getX() - 0.5D, pos.getY(), pos.getZ() - 0.5D, 6)); return EnumActionResult.SUCCESS; } } return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ); }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if(ItemStackTools.isValid(stack) && stack.getMetadata() == BoneType.BONEMEAL.getMetadata()){ IBlockState state = world.getBlockState(pos); if(state.getBlock() == Blocks.NETHER_WART){ int i = state.getValue(BlockNetherWart.AGE).intValue(); if (i < 3 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(world, pos, state, true)) { state = state.withProperty(BlockNetherWart.AGE, Integer.valueOf(i + 1)); world.setBlockState(pos, state, 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(world, pos, state, world.getBlockState(pos)); if(!player.capabilities.isCreativeMode){ player.setHeldItem(hand, ItemUtil.consumeItem(stack)); } return EnumActionResult.SUCCESS; } } } return EnumActionResult.PASS; }
@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; }
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 isPlant(Block plantBlock, IBlockState state) { if (plantBlock instanceof IGrowable) return true; if (plantBlock instanceof BlockNetherWart) return true; if (plantBlock == Blocks.REEDS) return true; if (plantBlock == Blocks.CACTUS) return true; return false; }
@Override public boolean handleHarvest(IBetterChest chest, IBlockState state, World world, BlockPos pos) { if (state.getValue(BlockNetherWart.AGE) == 3) { PlantHarvestHelper.breakBlockHandleDrop(world, pos, state, chest); return true; } return false; }
@Override public boolean canBeHarvested(World world, BlockPos pos, IBlockState blockState) { return blockState.getBlock() instanceof BlockNetherWart && blockState.getValue(BlockNetherWart.AGE) >= 3; }
@Override public boolean canBeHarvested() { return this.state.getValue(BlockNetherWart.AGE) == 3; }
@Override public boolean canHandleHarvest(IBlockState state, World world, BlockPos pos) { return state.getPropertyKeys().contains(BlockNetherWart.AGE); }