@SubscribeEvent
  public void onEntityHurt(LivingHurtEvent event) {
    EntityLivingBase entity = event.entityLiving;
    if (entity instanceof EntityPlayer) {
      float curMaxHealth =
          (float)
              ((EntityPlayer) entity)
                  .getEntityAttribute(SharedMonsterAttributes.maxHealth)
                  .getAttributeValue();
      float newMaxHealth = FoodStatsTFC.getMaxHealth((EntityPlayer) entity);
      float h = ((EntityPlayer) entity).getHealth();
      if (newMaxHealth != curMaxHealth)
        ((EntityPlayer) entity)
            .getEntityAttribute(SharedMonsterAttributes.maxHealth)
            .setBaseValue(newMaxHealth);
      if (newMaxHealth < h) ((EntityPlayer) entity).setHealth(newMaxHealth);
    }

    if (event.source == DamageSource.onFire) {
      event.ammount = 50;
    } else if (event.source == DamageSource.fall) {
      float healthMod = TFC_Core.getEntityMaxHealth(entity) / 1000f;
      event.ammount *= 80 * healthMod;
    } else if (event.source == DamageSource.drown) {
      event.ammount = 50;
    } else if (event.source == DamageSource.lava) {
      event.ammount = 100;
    } else if (event.source == DamageSource.inWall) {
      event.ammount = 100;
    } else if (event.source == DamageSource.fallingBlock) {
      event.ammount = 100;
    } else if (event.source.isExplosion()) {
      event.ammount *= 30;
    } else if (event.source == DamageSource.magic && entity.getHealth() > 25) {
      event.ammount = 25;
    } else if ("player".equals(event.source.damageType)
        || "mob".equals(event.source.damageType)
        || "arrow".equals(event.source.damageType)) {
      event.ammount = applyArmorCalculations(entity, event.source, event.ammount);
      if ("arrow".equals(event.source.damageType)) {
        Entity e = ((EntityDamageSourceIndirect) event.source).getSourceOfDamage();
        if (e instanceof EntityJavelin) {
          ((EntityJavelin) e).setDamageTaken((short) (((EntityJavelin) e).damageTaken + 10));
          if (((EntityJavelin) e).damageTaken >= ((EntityJavelin) e).pickupItem.getMaxDamage()) {
            e.setDead();
          }
        }
      }
    }
  }
Esempio n. 2
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.
   */
  @Override
  public void onLivingUpdate() {
    // Handle Hunger ticking
    if (hunger > 168000) {
      hunger = 168000;
    }
    if (hunger > 0) {
      hunger--;
    }

    syncData();
    if (isAdult()) {
      setGrowingAge(0);
    } else {
      setGrowingAge(-1);
    }

    roosterCrow();

    // Make sure that the vanilla egg timer is never after to reach 0 but always setting it back to
    // 9999
    this.timeUntilNextEgg = 9999;
    /** This Cancels out the changes made to growingAge by EntityAgeable */
    TFC_Core.PreventEntityDataUpdate = true;
    if (getGender() == GenderEnum.MALE) {
      nextEgg = 10000;
    }

    super.onLivingUpdate();
    TFC_Core.PreventEntityDataUpdate = false;

    if (hunger > 144000
        && rand.nextInt(100) == 0
        && getHealth() < TFC_Core.getEntityMaxHealth(this)
        && !isDead) {
      this.heal(1);
    }
  }