Example #1
0
  public static ItemStack chargeHealth(
      ItemStack stack, World world, EntityPlayer player, String tag) {
    if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound());

    NBTTagCompound nbtData = stack.getTagCompound();
    if (nbtData == null) {
      stack.getTagCompound().setInteger(tag, 0);
    }
    if (player.isSneaking()) {
      int points = stack.getTagCompound().getInteger(tag);
      if (points != 0) {
        int current = (int) player.getHealth();
        int max = (int) player.getMaxHealth();
        if (current != max & (current < max)) {
          int used = max - current;
          if (!(points - used < 0)) {
            nbtData.setInteger(tag, points - used);
            player.setHealth(player.getMaxHealth());
          } else if ((points - used < 0)) {
            nbtData.setInteger(tag, 0);
            player.setHealth(nbtData.getInteger(tag) + current);
          }
        }
      }
    } else {
      FontHelper.sendMessage(
          FontHelper.translate("points.health") + ": " + stack.getTagCompound().getInteger(tag),
          world,
          player);
    }
    return stack;
  }
 @Override
 public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
   float current = player.getHealth();
   if ((current >= 0.0F) && (current < 20.0F)) {
     player.setHealth(current + this.healAmount);
     stack.damageItem(1, player);
     world.playSoundAtEntity(player, Sounds.heal.getPrefixedName(), 1, 1);
   }
   return super.onItemRightClick(stack, world, player);
 }
  @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();
          }
        }
      }
    }
  }
 @Override
 public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
   if (!entity.worldObj.isRemote && entity instanceof EntityPlayer) {
     EntityPlayer victim = (EntityPlayer) entity;
     if (victim.capabilities.isCreativeMode
         && !victim.isDead
         && victim.getHealth() > 0
         && !LudicrousItems.isInfinite(victim)) {
       victim
           .func_110142_aN()
           .func_94547_a(
               new DamageSourceInfinitySword(player), victim.getHealth(), victim.getHealth());
       victim.setHealth(0);
       victim.onDeath(new EntityDamageSource("infinity", player));
       player.addStat(Achievements.creative_kill, 1);
       return true;
     }
   }
   return false;
 }
 @Override
 public boolean onItemUse(
     ItemStack par1ItemStack,
     EntityPlayer par2EntityPlayer,
     World par3World,
     int par4,
     int par5,
     int par6,
     int par7,
     float par8,
     float par9,
     float par10) {
   EntityPlayer player = par2EntityPlayer;
   ExtendedPlayer props = ExtendedPlayer.get(player);
   if (!player.capabilities.isCreativeMode) {
     float maxHealth = player.getMaxHealth();
     IAttributeInstance attrMaxHealth =
         player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
     if (attrMaxHealth.getAttributeValue() < dblMaxHealthLimit
         && props.getMaxHealth() < dblMaxHealthLimit) {
       maxHealth += healthIncreaseAmount;
       player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(maxHealth);
       player.setHealth(maxHealth);
       props.setMaxHealth(maxHealth);
       par1ItemStack.damageItem(2, par2EntityPlayer);
       if (!player.worldObj.isRemote) {
         ZollernHelper.addChatMessage(
             player,
             EnumChatFormatting.GOLD
                 + "+"
                 + this.healthIncreaseAmount
                 + " Max Health! Total: "
                 + props.getMaxHealth());
       }
     } else {
       ZollernHelper.addChatMessage(player, "Max health cannot exceed " + dblMaxHealthLimit + ".");
     }
   }
   return true;
 }
 @Override
 public void runForPlayer(EntityPlayer player) {
   player.setHealth(player.getMaxHealth());
   player.addChatMessage(notice);
 }