private boolean tryCulling(List<Integer> targets) { int entityId; Entity entity; EntityAnimal animal; int fortune = getUpgrades().contains(WorksiteUpgrade.ENCHANTED_TOOLS_1) ? 1 : getUpgrades().contains(WorksiteUpgrade.ENCHANTED_TOOLS_2) ? 2 : 0; while (!targets.isEmpty()) { entityId = targets.remove(0); entity = worldObj.getEntityByID(entityId); if (entity instanceof EntityAnimal) { animal = (EntityAnimal) entity; if (animal.isInLove() || animal.getGrowingAge() < 0) { continue; } animal.captureDrops = true; animal.captureDrops = true; animal.arrowHitTimer = 10; animal.attackEntityFrom(DamageSource.generic, animal.getHealth() + 1); ItemStack stack; for (EntityItem item : animal.capturedDrops) { stack = item.getEntityItem(); if (fortune > 0) { stack.stackSize += worldObj.rand.nextInt(fortune); } this.addStackToInventory(stack, RelativeSide.TOP); item.setDead(); } return true; } } return false; }
/** Returns true if the mob is currently able to mate with the specified mob. */ public boolean canMateWith(EntityAnimal p_70878_1_) { return p_70878_1_ == this ? false : (p_70878_1_.getClass() != this.getClass() ? false : this.isInLove() && p_70878_1_.isInLove()); }
private void scanForAnimals(List<EntityAnimal> animals, List<EntityPair> targets, int maxCount) { EntityAnimal animal1; EntityAnimal animal2; EntityPair breedingPair; int age; for (int i = 0; i < animals.size(); i++) { animal1 = animals.get(i); age = animal1.getGrowingAge(); if (age != 0 || animal1.isInLove()) { continue; } // unbreedable first-target, skip while (i + 1 < animals.size()) // loop through remaining animals to find a breeding partner { i++; animal2 = animals.get(i); age = animal2.getGrowingAge(); if (age == 0 && !animal2 .isInLove()) // found a second breedable animal, add breeding pair, exit to outer // loop { breedingPair = new EntityPair(animal1, animal2); targets.add(breedingPair); break; } } } int grownCount = 0; for (EntityAnimal animal : animals) { if (animal.getGrowingAge() >= 0) { grownCount++; } } if (grownCount > maxCount) { for (int i = 0, cullCount = grownCount - maxCount; i < animals.size() && cullCount > 0; i++) { if (animals.get(i).getGrowingAge() >= 0) { entitiesToCull.add(animals.get(i).getEntityId()); cullCount--; } } } }
private void setAnimalInLove(EntityAnimal animal, EntityPlayer player, ItemStack stack) { if (!animal.isInLove()) { animal.func_146082_f(player); if (!player.capabilities.isCreativeMode) if (--stack.stackSize <= 0) player.inventory.setInventorySlotContents(player.inventory.currentItem, null); } }