コード例 #1
0
  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;
  }
コード例 #2
0
  private void feedBaby(EntityAnimal animal, EntityPlayer player, ItemStack stack) {
    int currentAge = animal.getGrowingAge();
    int age = (int) (-currentAge * 0.1F);
    animal.setGrowingAge(currentAge + age);
    player.swingItem();

    Random itemRand = animal.worldObj.rand;
    for (int i = 0; i < 3; i++) {
      double d0 = itemRand.nextGaussian() * 0.02D;
      double d1 = itemRand.nextGaussian() * 0.02D;
      double d2 = itemRand.nextGaussian() * 0.02D;
      animal.worldObj.spawnParticle(
          "happyVillager",
          animal.posX + itemRand.nextFloat() * 0.5,
          animal.posY + 0.5 + itemRand.nextFloat() * 0.5,
          animal.posZ + itemRand.nextFloat() * 0.5,
          d0,
          d1,
          d2);
    }

    if (!player.capabilities.isCreativeMode)
      if (--stack.stackSize <= 0)
        player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
  }
コード例 #3
0
 private void scanForCows(List<EntityAnimal> animals) {
   scanForAnimals(animals, cowsToBreed, maxCowCount);
   for (EntityAnimal animal : animals) {
     if (animal.getGrowingAge() >= 0) {
       cowsToMilk.add(animal.getEntityId());
     }
   }
 }
コード例 #4
0
  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--;
        }
      }
    }
  }
コード例 #5
0
 private void scanForSheep(List<EntityAnimal> sheep) {
   scanForAnimals(sheep, sheepToBreed, maxSheepCount);
   for (EntityAnimal animal : sheep) {
     if (animal.getGrowingAge() >= 0) {
       EntitySheep sheep1 = (EntitySheep) animal;
       if (!sheep1.getSheared()) {
         sheepToShear.add(sheep1.getEntityId());
       }
     }
   }
 }