예제 #1
0
  /** Damages the item in the ItemStack */
  public void damageItem(int par1, EntityLivingBase par2EntityLivingBase) {
    if (!(par2EntityLivingBase instanceof EntityPlayer)
        || !((EntityPlayer) par2EntityLivingBase).capabilities.isCreativeMode) {
      if (this.isItemStackDamageable()) {
        if (this.attemptDamageItem(par1, par2EntityLivingBase.getRNG())) {
          par2EntityLivingBase.renderBrokenItemStack(this);
          --this.stackSize;

          if (par2EntityLivingBase instanceof EntityPlayer) {
            EntityPlayer entityplayer = (EntityPlayer) par2EntityLivingBase;
            entityplayer.addStat(
                StatList.objectBreakStats[Item.getIdFromItem(this.field_151002_e)], 1);

            if (this.stackSize == 0 && this.getItem() instanceof ItemBow) {
              entityplayer.destroyCurrentEquippedItem();
            }
          }

          if (this.stackSize < 0) {
            this.stackSize = 0;
          }

          this.itemDamage = 0;
        }
      }
    }
  }
예제 #2
0
 @SubscribeEvent
 public void teleportEvent(EnderTeleportEvent event) {
   if (EtFuturum.enableEndermite) {
     EntityLivingBase entity = event.entityLiving;
     if (entity instanceof EntityPlayerMP)
       if (entity.getRNG().nextFloat() < 0.05F
           && entity.worldObj.getGameRules().getGameRuleBooleanValue("doMobSpawning")) {
         EntityEndermite entityendermite = new EntityEndermite(entity.worldObj);
         entityendermite.setSpawnedByPlayer(true);
         entityendermite.setLocationAndAngles(
             entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
         entity.worldObj.spawnEntityInWorld(entityendermite);
       }
   }
 }
예제 #3
0
  public void func_151367_b(EntityLivingBase p_151367_1_, Entity p_151367_2_, int p_151367_3_) {
    Random random = p_151367_1_.getRNG();
    ItemStack itemstack = EnchantmentHelper.func_92099_a(Enchantment.thorns, p_151367_1_);

    if (func_92094_a(p_151367_3_, random)) {
      p_151367_2_.attackEntityFrom(
          DamageSource.causeThornsDamage(p_151367_1_), (float) func_92095_b(p_151367_3_, random));
      p_151367_2_.playSound("damage.thorns", 0.5F, 1.0F);

      if (itemstack != null) {
        itemstack.damageItem(3, p_151367_1_);
      }
    } else if (itemstack != null) {
      itemstack.damageItem(1, p_151367_1_);
    }
  }
예제 #4
0
  protected int applyArmorCalculations(
      EntityLivingBase entity, DamageSource source, float originalDamage) {
    ItemStack[] armor = entity.getLastActiveItems();
    int pierceRating = 0;
    int slashRating = 0;
    int crushRating = 0;

    EntityArmorCalcEvent eventPre =
        new EntityArmorCalcEvent(entity, originalDamage, EntityArmorCalcEvent.EventType.PRE);
    MinecraftForge.EVENT_BUS.post(eventPre);
    float damage = eventPre.incomingDamage;

    if (!source.isUnblockable() && armor != null) {
      // 1. Get Random Hit Location
      int location = getRandomSlot(entity.getRNG());

      // 2. Get Armor Rating for armor in hit Location
      if (armor[location] != null && armor[location].getItem() instanceof ItemTFCArmor) {
        pierceRating = ((ItemTFCArmor) armor[location].getItem()).armorTypeTFC.getPiercingAR();
        slashRating = ((ItemTFCArmor) armor[location].getItem()).armorTypeTFC.getSlashingAR();
        crushRating = ((ItemTFCArmor) armor[location].getItem()).armorTypeTFC.getCrushingAR();
        if (entity instanceof IInnateArmor) {
          pierceRating += ((IInnateArmor) entity).getPierceArmor();
          slashRating += ((IInnateArmor) entity).getSlashArmor();
          crushRating += ((IInnateArmor) entity).getCrushArmor();
        }

        // 3. Convert the armor rating to % damage reduction
        float pierceMult = getDamageReduction(pierceRating);
        float slashMult = getDamageReduction(slashRating);
        float crushMult = getDamageReduction(crushRating);

        // 4. Reduce incoming damage
        damage = processDamageSource(source, damage, pierceMult, slashMult, crushMult);

        // 5. Damage the armor that was hit
        armor[location].damageItem((int) processArmorDamage(armor[location], damage), entity);
      } else if (armor[location] == null
          || armor[location] != null && !(armor[location].getItem() instanceof ItemTFCArmor)) {
        if (entity instanceof IInnateArmor) {
          pierceRating += ((IInnateArmor) entity).getPierceArmor();
          slashRating += ((IInnateArmor) entity).getSlashArmor();
          crushRating += ((IInnateArmor) entity).getCrushArmor();
        }
        // 1. Convert the armor rating to % damage reduction
        float pierceMult = getDamageReduction(pierceRating);
        float slashMult = getDamageReduction(slashRating);
        float crushMult = getDamageReduction(crushRating);
        // 4. Reduce incoming damage
        damage = processDamageSource(source, damage, pierceMult, slashMult, crushMult);

        // a. If the attack hits an unprotected head, it does 75% more damage
        // b. If the attack hits unprotected feet, it applies a slow to the player
        if (location == 3) damage *= 1.75f;
        else if (location == 0)
          entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.getId(), 100, 1));
      }
      // 6. Apply the damage to the player
      EntityArmorCalcEvent eventPost =
          new EntityArmorCalcEvent(entity, damage, EntityArmorCalcEvent.EventType.POST);
      MinecraftForge.EVENT_BUS.post(eventPost);
      // TerraFirmaCraft.log.info(entity.getClass()+", "+eventPre.incomingDamage+",
      // "+eventPost.incomingDamage);
      float hasHealth = entity.getHealth();
      entity.setHealth(entity.getHealth() - eventPost.incomingDamage);
      entity.func_110142_aN().func_94547_a(source, hasHealth, eventPost.incomingDamage);
    }
    return 0;
  }