예제 #1
0
 /** 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());
 }
예제 #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);
  }
 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 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);
   }
 }
예제 #5
0
  /** Moves the entity based on the specified heading. */
  public void moveEntityWithHeading(float strafe, float forward) {
    Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);

    if (this.isBeingRidden() && this.canBeSteered()) {
      this.rotationYaw = entity.rotationYaw;
      this.prevRotationYaw = this.rotationYaw;
      this.rotationPitch = entity.rotationPitch * 0.5F;
      this.setRotation(this.rotationYaw, this.rotationPitch);
      this.renderYawOffset = this.rotationYaw;
      this.rotationYawHead = this.rotationYaw;
      this.stepHeight = 1.0F;
      this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;

      if (this.canPassengerSteer()) {
        float f =
            (float)
                    this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED)
                        .getAttributeValue()
                * 0.225F;

        if (this.boosting) {
          if (this.boostTime++ > this.totalBoostTime) {
            this.boosting = false;
          }

          f +=
              f
                  * 1.15F
                  * MathHelper.sin(
                      (float) this.boostTime / (float) this.totalBoostTime * (float) Math.PI);
        }

        this.setAIMoveSpeed(f);
        super.moveEntityWithHeading(0.0F, 1.0F);
      } else {
        this.motionX = 0.0D;
        this.motionY = 0.0D;
        this.motionZ = 0.0D;
      }

      this.prevLimbSwingAmount = this.limbSwingAmount;
      double d1 = this.posX - this.prevPosX;
      double d0 = this.posZ - this.prevPosZ;
      float f1 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;

      if (f1 > 1.0F) {
        f1 = 1.0F;
      }

      this.limbSwingAmount += (f1 - this.limbSwingAmount) * 0.4F;
      this.limbSwing += this.limbSwingAmount;
    } else {
      this.stepHeight = 0.5F;
      this.jumpMovementFactor = 0.02F;
      super.moveEntityWithHeading(strafe, forward);
    }
  }
 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());
       }
     }
   }
 }
예제 #7
0
  @SuppressWarnings("unchecked")
  @Override
  public void updateChest(IBetterChest chest, int tick, World world, ItemStack item) {
    if (tick == 63) {
      AxisAlignedBB bounds =
          AxisAlignedBB.getBoundingBox(
              chest.getXPos() - Reference.Conf.FEED_RADIUS / 2,
              chest.getYPos() - Reference.Conf.FEED_HEIGHT / 2,
              chest.getZPos() - Reference.Conf.FEED_RADIUS / 2,
              chest.getXPos() + Reference.Conf.FEED_RADIUS / 2,
              chest.getYPos() + Reference.Conf.FEED_HEIGHT / 2,
              chest.getZPos() + Reference.Conf.FEED_RADIUS / 2);
      List<EntityAnimal> list = world.getEntitiesWithinAABB(EntityAnimal.class, bounds);

      for (EntityAnimal entity : list) {
        if (!entity.isEntityAlive() || entity.isChild()) continue;
        if (entity instanceof IShearable && !(entity instanceof EntityMooshroom)) {
          IShearable sheep = (EntitySheep) entity;
          if (sheep.isShearable(
              null, world, entity.serverPosX, entity.serverPosY, entity.serverPosZ)) {
            // If I ever implement that it uses Shears, then this would be the place to damage it.
            ArrayList<ItemStack> items =
                sheep.onSheared(
                    null, world, entity.serverPosX, entity.serverPosY, entity.serverPosZ, 1);
            for (ItemStack wool : items) {
              if (InvUtil.putIntoFirstSlot(chest, wool, false) != null) break;
            }
          }
        } else if (entity instanceof EntityCow) {
          ItemStack bucket = InvUtil.getFirstItem(chest, new ItemStack(Items.bucket), true);
          if (bucket != null) {
            if (InvUtil.putIntoFirstSlot(chest, new ItemStack(Items.milk_bucket), false) == null) {
              InvUtil.getFirstItem(chest, new ItemStack(Items.bucket), false);
            }
          }
          if (entity instanceof EntityMooshroom) {
            ItemStack bowl = InvUtil.getFirstItem(chest, new ItemStack(Items.bowl), true);
            if (bowl != null) {
              if (InvUtil.putIntoFirstSlot(chest, new ItemStack(Items.mushroom_stew), false)
                  == null) {
                InvUtil.getFirstItem(chest, new ItemStack(Items.bowl), false);
              }
            }
          }
        }
      }
    }
  }
예제 #8
0
  public void hatch() {
    if (!worldObj.isRemote) {
      worldObj.playAuxSFX(2001, xCoord, yCoord, zCoord, Block.getIdFromBlock(getBlockType()));
      worldObj.setBlockToAir(xCoord, yCoord, zCoord);

      EntityAnimal entity = null;

      float specialChance = 0.05F;
      if (Math.random() < specialChance) {
        int entityType = worldObj.rand.nextInt(3);
        switch (entityType) {
          case 0:
            entity = new EntityHorse(worldObj);
            break;
          case 1:
            entity = new EntityWolf(worldObj);
            break;
          case 2:
            entity = new EntityOcelot(worldObj);
            break;
        }
      } else {
        int entityType = worldObj.rand.nextInt(4);
        switch (entityType) {
          case 0:
            entity = new EntitySheep(worldObj);
            break;
          case 1:
            if (Math.random() < 0.01) entity = new EntityMooshroom(worldObj);
            else entity = new EntityCow(worldObj);
            break;
          case 2:
            entity = new EntityPig(worldObj);
            break;
          case 3:
            entity = new EntityChicken(worldObj);
            break;
        }
      }

      if (entity != null) {
        entity.setPosition(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
        entity.setGrowingAge(-24000);
        worldObj.spawnEntityInWorld(entity);
        entity.spawnExplosionParticle();
      }
    }
  }
예제 #9
0
  /** Drop the equipment for this entity. */
  protected void dropEquipment(boolean wasRecentlyHit, int lootingModifier) {
    super.dropEquipment(wasRecentlyHit, lootingModifier);

    if (this.getSaddled()) {
      this.dropItem(Items.SADDLE, 1);
    }
  }
 @Override
 protected void entityInit() {
   super.entityInit();
   dataWatcher.addObject(18, new Float(getHealth()));
   dataWatcher.addObject(19, new Byte((byte) 0));
   dataWatcher.addObject(20, new Byte((byte) BlockColored.func_150032_b(1)));
 }
예제 #11
0
  /**
   * Called frequently so the entity can update its state every tick as required. For example,
   * zombies and skeletons use this to react to sunlight and start to burn.
   */
  public void onLivingUpdate() {
    super.onLivingUpdate();
    this.field_70888_h = this.field_70886_e;
    this.field_70884_g = this.destPos;
    this.destPos = (float) ((double) this.destPos + (double) (this.onGround ? -1 : 4) * 0.3D);

    if (this.destPos < 0.0F) {
      this.destPos = 0.0F;
    }

    if (this.destPos > 1.0F) {
      this.destPos = 1.0F;
    }

    if (!this.onGround && this.field_70889_i < 1.0F) {
      this.field_70889_i = 1.0F;
    }

    this.field_70889_i = (float) ((double) this.field_70889_i * 0.9D);

    if (!this.onGround && this.motionY < 0.0D) {
      this.motionY *= 0.6D;
    }

    this.field_70886_e += this.field_70889_i * 2.0F;

    if (!this.isChild() && !this.worldObj.isRemote && --this.timeUntilNextEgg <= 0) {
      this.playSound(
          "mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
      this.dropItem(Item.egg.itemID, 1);
      this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
    }
  }
예제 #12
0
  /**
   * Called frequently so the entity can update its state every tick as required. For example,
   * zombies and skeletons use this to react to sunlight and start to burn.
   */
  public void onLivingUpdate() {
    if (this.worldObj.isRemote) {
      this.sheepTimer = Math.max(0, this.sheepTimer - 1);
    }

    super.onLivingUpdate();
  }
  /** Called when the mob's health reaches 0. */
  public void onDeath(DamageSource p_70645_1_) {
    super.onDeath(p_70645_1_);

    if (!this.worldObj.isRemote) {
      this.dropChestItems();
    }
  }
예제 #14
0
 @Override
 protected void applyEntityAttributes() {
   super.applyEntityAttributes();
   this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(10);
   this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
       .setAttribute(0.10000000298023224D);
 }
  /** (abstract) Protected helper method to read subclass entity data from NBT. */
  public void readEntityFromNBT(NBTTagCompound tagCompund) {
    super.readEntityFromNBT(tagCompund);
    this.setEatingHaystack(tagCompund.getBoolean("EatingHaystack"));
    this.func_110242_l(tagCompund.getBoolean("Bred"));
    this.setChested(tagCompund.getBoolean("ChestedHorse"));
    this.setHasReproduced(tagCompund.getBoolean("HasReproduced"));
    this.setHorseType(tagCompund.getInteger("Type"));
    this.setHorseVariant(tagCompund.getInteger("Variant"));
    this.setTemper(tagCompund.getInteger("Temper"));
    this.setHorseTamed(tagCompund.getBoolean("Tame"));

    if (tagCompund.hasKey("OwnerUUID", 8)) {
      this.func_152120_b(tagCompund.getString("OwnerUUID"));
    }

    IAttributeInstance iattributeinstance =
        this.getAttributeMap().getAttributeInstanceByName("Speed");

    if (iattributeinstance != null) {
      this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
          .setBaseValue(iattributeinstance.getBaseValue() * 0.25D);
    }

    if (this.isChested()) {
      NBTTagList nbttaglist = tagCompund.getTagList("Items", 10);
      this.func_110226_cD();

      for (int i = 0; i < nbttaglist.tagCount(); ++i) {
        NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
        int j = nbttagcompound1.getByte("Slot") & 255;

        if (j >= 2 && j < this.horseChest.getSizeInventory()) {
          this.horseChest.setInventorySlotContents(
              j, ItemStack.loadItemStackFromNBT(nbttagcompound1));
        }
      }
    }

    ItemStack itemstack;

    if (tagCompund.hasKey("ArmorItem", 10)) {
      itemstack = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("ArmorItem"));

      if (itemstack != null && func_146085_a(itemstack.getItem())) {
        this.horseChest.setInventorySlotContents(1, itemstack);
      }
    }

    if (tagCompund.hasKey("SaddleItem", 10)) {
      itemstack = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("SaddleItem"));

      if (itemstack != null && itemstack.getItem() == Items.saddle) {
        this.horseChest.setInventorySlotContents(0, itemstack);
      }
    } else if (tagCompund.getBoolean("Saddle")) {
      this.horseChest.setInventorySlotContents(0, new ItemStack(Items.saddle));
    }

    this.func_110232_cE();
  }
예제 #16
0
  @Override
  protected void func_110147_ax() {
    super.func_110147_ax();

    func_110148_a(SharedMonsterAttributes.field_111263_d).func_111128_a(0.4); // moveSpeed
    func_110148_a(SharedMonsterAttributes.field_111267_a).func_111128_a(9); // maxHealth
  }
예제 #17
0
 public void handleHealthUpdate(byte par1) {
   if (par1 == 10) {
     this.sheepTimer = 40;
   } else {
     super.handleHealthUpdate(par1);
   }
 }
 protected void applyEntityAttributes() {
   super.applyEntityAttributes();
   this.getAttributeMap().registerAttribute(horseJumpStrength);
   this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(53.0D);
   this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
       .setBaseValue(0.22499999403953552D);
 }
예제 #19
0
 public void handleHealthUpdate(byte value) {
   if (value == 10) {
     this.sheepTimer = 40;
   } else {
     super.handleHealthUpdate(value);
   }
 }
 protected void entityInit() {
   super.entityInit();
   this.dataWatcher.addObject(16, Integer.valueOf(0));
   this.dataWatcher.addObject(19, Byte.valueOf((byte) 0));
   this.dataWatcher.addObject(20, Integer.valueOf(0));
   this.dataWatcher.addObject(21, String.valueOf(""));
   this.dataWatcher.addObject(22, Integer.valueOf(0));
 }
예제 #21
0
  @SubscribeEvent
  public void interactEntityEvent(EntityInteractEvent event) {
    ItemStack stack = event.entityPlayer.getCurrentEquippedItem();
    if (stack == null) return;
    if (!(event.target instanceof EntityAnimal)) return;

    EntityAnimal animal = (EntityAnimal) event.target;
    if (!animal.isChild()) {
      if (animal instanceof EntityPig) {
        if (stack.getItem() == ModItems.beetroot && EtFuturum.enableBeetroot)
          setAnimalInLove(animal, event.entityPlayer, stack);
      } else if (animal instanceof EntityChicken)
        if (stack.getItem() == ModItems.beetroot_seeds && EtFuturum.enableBeetroot)
          setAnimalInLove(animal, event.entityPlayer, stack);
    } else if (EtFuturum.enableBabyGrowthBoost && isFoodItem(animal, stack))
      feedBaby(animal, event.entityPlayer, stack);
  }
 private boolean tryBreeding(List<EntityPair> targets) {
   Entity animalA;
   Entity animalB;
   EntityPair pair;
   if (!targets.isEmpty()) {
     pair = targets.remove(0);
     animalA = pair.getEntityA(worldObj);
     animalB = pair.getEntityB(worldObj);
     if (!(animalA instanceof EntityAnimal) || !(animalB instanceof EntityAnimal)) {
       return false;
     }
     ((EntityAnimal) animalA).func_146082_f(null); // setInLove(EntityPlayer breeder)
     ((EntityAnimal) animalB).func_146082_f(null); // setInLove(EntityPlayer breeder)
     return true;
   }
   return false;
 }
  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;
  }
예제 #24
0
  public void fall(float distance, float damageMultiplier) {
    super.fall(distance, damageMultiplier);

    if (distance > 5.0F) {
      for (EntityPlayer entityplayer : this.getRecursivePassengersByType(EntityPlayer.class)) {
        entityplayer.addStat(AchievementList.FLY_PIG);
      }
    }
  }
예제 #25
0
 private boolean isFoodItem(EntityAnimal animal, ItemStack food) {
   if (animal.isBreedingItem(food)) return true;
   else if (animal instanceof EntityPig
       && food.getItem() == ModItems.beetroot
       && EtFuturum.enableBeetroot) return true;
   else if (animal instanceof EntityChicken
       && food.getItem() == ModItems.beetroot_seeds
       && EtFuturum.enableBeetroot) return true;
   else return false;
 }
 @SideOnly(Side.CLIENT)
 public void handleHealthUpdate(byte p_70103_1_) {
   if (p_70103_1_ == 7) {
     this.spawnHorseParticles(true);
   } else if (p_70103_1_ == 6) {
     this.spawnHorseParticles(false);
   } else {
     super.handleHealthUpdate(p_70103_1_);
   }
 }
  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--;
        }
      }
    }
  }
  /** Returns true if the mob is currently able to mate with the specified mob. */
  public boolean canMateWith(EntityAnimal p_70878_1_) {
    if (p_70878_1_ == this) {
      return false;
    } else if (p_70878_1_.getClass() != this.getClass()) {
      return false;
    } else {
      EntityHorse entityhorse = (EntityHorse) p_70878_1_;

      if (this.canMate() && entityhorse.canMate()) {
        int i = this.getHorseType();
        int j = entityhorse.getHorseType();
        return i == j || i == 0 && j == 1 || i == 1 && j == 0;
      } else {
        return false;
      }
    }
  }
  /** Called to update the entity's position/logic. */
  @Override
  public void onUpdate() {
    super.onUpdate();
    if (func_70922_bv()) {
      field_70926_e += (1.0F - field_70926_e) * 0.4F;
    } else {
      field_70926_e += (0.0F - field_70926_e) * 0.4F;
    }

    if (func_70922_bv()) {
      numTicksToChaseTarget = 10;
    }

    if (isWet()) {
      // can do special things if in water (or in rain)
    } else {
    }
  }
  public void updateRiderPosition() {
    super.updateRiderPosition();

    if (this.prevRearingAmount > 0.0F) {
      float f = MathHelper.sin(this.renderYawOffset * (float) Math.PI / 180.0F);
      float f1 = MathHelper.cos(this.renderYawOffset * (float) Math.PI / 180.0F);
      float f2 = 0.7F * this.prevRearingAmount;
      float f3 = 0.15F * this.prevRearingAmount;
      this.riddenByEntity.setPosition(
          this.posX + (double) (f2 * f),
          this.posY + this.getMountedYOffset() + this.riddenByEntity.getYOffset() + (double) f3,
          this.posZ - (double) (f2 * f1));

      if (this.riddenByEntity instanceof EntityLivingBase) {
        ((EntityLivingBase) this.riddenByEntity).renderYawOffset = this.renderYawOffset;
      }
    }
  }