private ItemStack getFishingResult() {
    float f = this.worldObj.rand.nextFloat();
    int i = EnchantmentHelper.getLuckOfSeaModifier(this.angler);
    int j = EnchantmentHelper.getLureModifier(this.angler);
    float f1 = 0.1F - (float) i * 0.025F - (float) j * 0.01F;
    float f2 = 0.05F + (float) i * 0.01F - (float) j * 0.01F;
    f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
    f2 = MathHelper.clamp_float(f2, 0.0F, 1.0F);

    if (f < f1) {
      this.angler.triggerAchievement(StatList.junkFishedStat);
      return ((WeightedRandomFishable) WeightedRandom.getRandomItem(this.rand, JUNK))
          .getItemStack(this.rand);
    } else {
      f = f - f1;

      if (f < f2) {
        this.angler.triggerAchievement(StatList.treasureFishedStat);
        return ((WeightedRandomFishable) WeightedRandom.getRandomItem(this.rand, TREASURE))
            .getItemStack(this.rand);
      } else {
        float f3 = f - f2;
        this.angler.triggerAchievement(StatList.fishCaughtStat);
        return ((WeightedRandomFishable) WeightedRandom.getRandomItem(this.rand, FISH))
            .getItemStack(this.rand);
      }
    }
  }
 public static ItemStack getGrassSeed(World world) {
   SeedEntry entry = (SeedEntry) WeightedRandom.getRandomItem(world.rand, seedList);
   if (entry == null || entry.seed == null) {
     return null;
   }
   return entry.seed.copy();
 }
 public static void plantGrass(World world, int x, int y, int z) {
   GrassEntry grass = (GrassEntry) WeightedRandom.getRandomItem(world.rand, grassList);
   if (grass == null || grass.block == null || !grass.block.canBlockStay(world, x, y, z)) {
     return;
   }
   world.setBlock(x, y, z, grass.block.blockID, grass.metadata, 3);
 }
  @Override
  public boolean generate(World world, Random rand, int x, int y, int z) {

    float f = rand.nextFloat() * (float) Math.PI;
    double d0 = x + 8 + MathHelper.sin(f) * genClusterSize / 8.0F;
    double d1 = x + 8 - MathHelper.sin(f) * genClusterSize / 8.0F;
    double d2 = z + 8 + MathHelper.cos(f) * genClusterSize / 8.0F;
    double d3 = z + 8 - MathHelper.cos(f) * genClusterSize / 8.0F;
    double d4 = y + rand.nextInt(3) - 2;
    double d5 = y + rand.nextInt(3) - 2;

    for (int l = 0; l <= genClusterSize; ++l) {
      double d6 = d0 + (d1 - d0) * l / genClusterSize;
      double d7 = d4 + (d5 - d4) * l / genClusterSize;
      double d8 = d2 + (d3 - d2) * l / genClusterSize;
      double d9 = rand.nextDouble() * genClusterSize / 16.0D;
      double d10 = (MathHelper.sin(l * (float) Math.PI / genClusterSize) + 1.0F) * d9 + 1.0D;
      double d11 = (MathHelper.sin(l * (float) Math.PI / genClusterSize) + 1.0F) * d9 + 1.0D;
      int i1 = MathHelper.floor_double(d6 - d10 / 2.0D);
      int j1 = MathHelper.floor_double(d7 - d11 / 2.0D);
      int k1 = MathHelper.floor_double(d8 - d10 / 2.0D);
      int l1 = MathHelper.floor_double(d6 + d10 / 2.0D);
      int i2 = MathHelper.floor_double(d7 + d11 / 2.0D);
      int j2 = MathHelper.floor_double(d8 + d10 / 2.0D);

      for (int k2 = i1; k2 <= l1; ++k2) {
        double d12 = (k2 + 0.5D - d6) / (d10 / 2.0D);

        if (d12 * d12 < 1.0D) {
          for (int l2 = j1; l2 <= i2; ++l2) {
            double d13 = (l2 + 0.5D - d7) / (d11 / 2.0D);

            if (d12 * d12 + d13 * d13 < 1.0D) {
              for (int i3 = k1; i3 <= j2; ++i3) {
                double d14 = (i3 + 0.5D - d8) / (d10 / 2.0D);

                Block block = Block.blocksList[world.getBlockId(k2, l2, i3)];
                if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D
                    && block != null
                    && block.isGenMineableReplaceable(world, k2, l2, i3, genBlockID)) {

                  WeightedRandomBlock ore =
                      (WeightedRandomBlock) WeightedRandom.getRandomItem(world.rand, cluster);
                  world.setBlock(k2, l2, i3, ore.blockId, ore.metadata, 1);
                }
              }
            }
          }
        }
      }
    }
    return true;
  }
  private void resetTimer() {
    if (this.maxSpawnDelay <= this.minSpawnDelay) {
      this.spawnDelay = this.minSpawnDelay;
    } else {
      int var10003 = this.maxSpawnDelay - this.minSpawnDelay;
      this.spawnDelay = this.minSpawnDelay + this.getSpawnerWorld().rand.nextInt(var10003);
    }

    if (this.minecartToSpawn != null && this.minecartToSpawn.size() > 0) {
      this.setRandomMinecart(
          (MobSpawnerBaseLogic.WeightedRandomMinecart)
              WeightedRandom.getRandomItem(this.getSpawnerWorld().rand, this.minecartToSpawn));
    }

    this.func_98267_a(1);
  }
  /** Generates the Dispenser contents. */
  public static void generateDispenserContents(
      Random par0Random,
      WeightedRandomChestContent[] par1ArrayOfWeightedRandomChestContent,
      TileEntityDispenser par2TileEntityDispenser,
      int par3) {
    for (int j = 0; j < par3; ++j) {
      WeightedRandomChestContent weightedrandomchestcontent =
          (WeightedRandomChestContent)
              WeightedRandom.getRandomItem(par0Random, par1ArrayOfWeightedRandomChestContent);
      ItemStack[] stacks =
          weightedrandomchestcontent.generateChestContent(par0Random, par2TileEntityDispenser);

      for (ItemStack item : stacks) {
        par2TileEntityDispenser.setInventorySlotContents(
            par0Random.nextInt(par2TileEntityDispenser.getSizeInventory()), item);
      }
    }
  }
 /**
  * Generates a number of random chest contents, placing them in the chest either completely at
  * random or only in empty slots, as designated by the parameters
  */
 public static void generateRandomChestContents(
     Random rand,
     WeightedRandomChestContent[] weightedContents,
     IInventory chest,
     int numItems,
     boolean atRandom) {
   for (int i = 0; i < numItems; ++i) {
     WeightedRandomChestContent weightedChest =
         (WeightedRandomChestContent) WeightedRandom.getRandomItem(rand, weightedContents);
     ItemStack[] stacks =
         ChestGenHooks.generateStacks(
             rand,
             weightedChest.theItemId,
             weightedChest.theMinimumChanceToGenerateItem,
             weightedChest.theMaximumChanceToGenerateItem);
     for (ItemStack item : stacks) {
       if (atRandom) {
         chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory()), item);
       } else {
         addItemToInventoryAtRandom(rand, item, chest, 3);
       }
     }
   }
 }
  @Override
  public boolean activateMachine() {
    _grindingWorld.cleanReferences();
    List<?> entities =
        worldObj.getEntitiesWithinAABB(
            EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());

    entityList:
    for (Object o : entities) {
      EntityLiving e = (EntityLiving) o;
      if (e instanceof EntityAgeable && ((EntityAgeable) e).getGrowingAge() < 0
          || e.isEntityInvulnerable()
          || e.getHealth() <= 0) {
        continue;
      }
      boolean processMob = false;
      processEntity:
      {
        if (MFRRegistry.getGrindables27().containsKey(e.getClass())) {
          IFactoryGrindable2 r = MFRRegistry.getGrindables27().get(e.getClass());
          List<MobDrop> drops = r.grind(e.worldObj, e, getRandom());
          if (drops != null && drops.size() > 0 && WeightedRandom.getTotalWeight(drops) > 0) {
            ItemStack drop = ((MobDrop) WeightedRandom.getRandomItem(_rand, drops)).getStack();
            doDrop(drop);
          }
          if (r instanceof IFactoryGrindable2) {
            if (((IFactoryGrindable2) r).processEntity(e)) {
              processMob = true;
              if (e.getHealth() <= 0) {
                continue entityList;
              }
              break processEntity;
            }
          } else {
            processMob = true;
            break processEntity;
          }
        }
        for (Class<?> t : MFRRegistry.getGrinderBlacklist()) {
          if (t.isInstance(e)) {
            continue entityList;
          }
        }
        if (!_grindingWorld.addEntityForGrinding(e)) {
          continue entityList;
        }
      }
      if (processMob && e.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot")) {
        try {
          e.worldObj.getGameRules().setOrCreateGameRule("doMobLoot", "false");
          damageEntity(e);
          if (e.getHealth() <= 0) {
            _tank.fill(LiquidDictionary.getLiquid("mobEssence", 100), true);
          }
        } finally {
          e.worldObj.getGameRules().setOrCreateGameRule("doMobLoot", "true");
          setIdleTicks(20);
        }
        return true;
      }
      damageEntity(e);
      if (e.getHealth() <= 0) {
        _tank.fill(LiquidDictionary.getLiquid("mobEssence", 100), true);
        setIdleTicks(20);
      } else {
        setIdleTicks(10);
      }
      return true;
    }
    setIdleTicks(getIdleTicksMax());
    return false;
  }
  /**
   * Create a list of random EnchantmentData (enchantments) that can be added together to the
   * ItemStack, the 3rd parameter is the total enchantability level.
   */
  public static List buildEnchantmentList(Random p_77513_0_, ItemStack p_77513_1_, int p_77513_2_) {
    Item item = p_77513_1_.getItem();
    int j = item.getItemEnchantability(p_77513_1_);

    if (j <= 0) {
      return null;
    } else {
      j /= 2;
      j = 1 + p_77513_0_.nextInt((j >> 1) + 1) + p_77513_0_.nextInt((j >> 1) + 1);
      int k = j + p_77513_2_;
      float f = (p_77513_0_.nextFloat() + p_77513_0_.nextFloat() - 1.0F) * 0.15F;
      int l = (int) ((float) k * (1.0F + f) + 0.5F);

      if (l < 1) {
        l = 1;
      }

      ArrayList arraylist = null;
      Map map = mapEnchantmentData(l, p_77513_1_);

      if (map != null && !map.isEmpty()) {
        EnchantmentData enchantmentdata =
            (EnchantmentData) WeightedRandom.getRandomItem(p_77513_0_, map.values());

        if (enchantmentdata != null) {
          arraylist = new ArrayList();
          arraylist.add(enchantmentdata);

          for (int i1 = l; p_77513_0_.nextInt(50) <= i1; i1 >>= 1) {
            Iterator iterator = map.keySet().iterator();

            while (iterator.hasNext()) {
              Integer integer = (Integer) iterator.next();
              boolean flag = true;
              Iterator iterator1 = arraylist.iterator();

              while (true) {
                if (iterator1.hasNext()) {
                  EnchantmentData enchantmentdata1 = (EnchantmentData) iterator1.next();

                  Enchantment e1 = enchantmentdata1.enchantmentobj;
                  Enchantment e2 = Enchantment.enchantmentsList[integer.intValue()];
                  if (e1.canApplyTogether(e2)
                      && e2.canApplyTogether(
                          e1)) // Forge BugFix: Let Both enchantments veto being together
                  {
                    continue;
                  }

                  flag = false;
                }

                if (!flag) {
                  iterator.remove();
                }

                break;
              }
            }

            if (!map.isEmpty()) {
              EnchantmentData enchantmentdata2 =
                  (EnchantmentData) WeightedRandom.getRandomItem(p_77513_0_, map.values());
              arraylist.add(enchantmentdata2);
            }
          }
        }
      }

      return arraylist;
    }
  }
  /**
   * Create a list of random EnchantmentData (enchantments) that can be added together to the
   * ItemStack, the 3rd parameter is the total enchantability level.
   */
  public static List buildEnchantmentList(Random par0Random, ItemStack par1ItemStack, int par2) {
    Item item = par1ItemStack.getItem();
    int j = item.getItemEnchantability();

    if (j <= 0) {
      return null;
    } else {
      j /= 2;
      j = 1 + par0Random.nextInt((j >> 1) + 1) + par0Random.nextInt((j >> 1) + 1);
      int k = j + par2;
      float f = (par0Random.nextFloat() + par0Random.nextFloat() - 1.0F) * 0.15F;
      int l = (int) ((float) k * (1.0F + f) + 0.5F);

      if (l < 1) {
        l = 1;
      }

      ArrayList arraylist = null;
      Map map = mapEnchantmentData(l, par1ItemStack);

      if (map != null && !map.isEmpty()) {
        EnchantmentData enchantmentdata =
            (EnchantmentData) WeightedRandom.getRandomItem(par0Random, map.values());

        if (enchantmentdata != null) {
          arraylist = new ArrayList();
          arraylist.add(enchantmentdata);

          for (int i1 = l; par0Random.nextInt(50) <= i1; i1 >>= 1) {
            Iterator iterator = map.keySet().iterator();

            while (iterator.hasNext()) {
              Integer integer = (Integer) iterator.next();
              boolean flag = true;
              Iterator iterator1 = arraylist.iterator();

              while (true) {
                if (iterator1.hasNext()) {
                  EnchantmentData enchantmentdata1 = (EnchantmentData) iterator1.next();

                  if (enchantmentdata1.enchantmentobj.canApplyTogether(
                      Enchantment.enchantmentsList[integer.intValue()])) {
                    continue;
                  }

                  flag = false;
                }

                if (!flag) {
                  iterator.remove();
                }

                break;
              }
            }

            if (!map.isEmpty()) {
              EnchantmentData enchantmentdata2 =
                  (EnchantmentData) WeightedRandom.getRandomItem(par0Random, map.values());
              arraylist.add(enchantmentdata2);
            }
          }
        }
      }

      return arraylist;
    }
  }