Camellias_

Untitled

Aug 12th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.01 KB | None | 0 0
  1.         public static float applyArmor(EntityLivingBase entity, NonNullList<ItemStack> inventory, DamageSource source, double damage)
  2.         {
  3.             if (DEBUG)
  4.             {
  5.                 System.out.println("Start: " + damage);
  6.             }
  7.            
  8.             double totalArmor = entity.getTotalArmorValue();
  9.             double totalToughness = entity.getEntityAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getAttributeValue();
  10.  
  11.             if (source.isUnblockable())
  12.             {
  13.                 totalArmor = 0;
  14.                 totalToughness = 0;
  15.             }
  16.  
  17.             ArrayList<ArmorProperties> dmgVals = new ArrayList<ArmorProperties>();
  18.             for (int slot = 0; slot < inventory.size(); slot++)
  19.             {
  20.                 ItemStack stack = inventory.get(slot);
  21.                
  22.                 if (stack.isEmpty())
  23.                 {
  24.                     continue;
  25.                 }
  26.                
  27.                 ArmorProperties prop = null;
  28.                 if (stack.getItem() instanceof ISpecialArmor)
  29.                 {
  30.                     if (!source.isUnblockable() || ((ISpecialArmor) stack.getItem()).handleUnblockableDamage(entity, stack, source, damage, slot)) {
  31.                         ISpecialArmor armor = (ISpecialArmor)stack.getItem();
  32.                         prop = armor.getProperties(entity, stack, source, damage, slot).copy();
  33.                         totalArmor += prop.Armor;
  34.                         totalToughness += prop.Toughness;
  35.                     }
  36.                 }
  37.                 else if (stack.getItem() instanceof ItemArmor && !source.isUnblockable())
  38.                 {
  39.                     ItemArmor armor = (ItemArmor)stack.getItem();
  40.                     prop = new ArmorProperties(0, 0, Integer.MAX_VALUE);
  41.                     prop.Armor = armor.damageReduceAmount;
  42.                     prop.Toughness = armor.toughness;
  43.                 }
  44.                 if (prop != null)
  45.                 {
  46.                     prop.Slot = slot;
  47.                     dmgVals.add(prop);
  48.                 }
  49.             }
  50.             if (dmgVals.size() > 0)
  51.             {
  52.                 ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[dmgVals.size()]);
  53.                 StandardizeList(props, damage);
  54.                 int level = props[0].Priority;
  55.                 double ratio = 0;
  56.                 for (ArmorProperties prop : props)
  57.                 {
  58.                     if (level != prop.Priority)
  59.                     {
  60.                         damage -= (damage * ratio);
  61.                         ratio = 0;
  62.                         level = prop.Priority;
  63.                     }
  64.                     ratio += prop.AbsorbRatio;
  65.  
  66.                     double absorb = damage * prop.AbsorbRatio;
  67.                     if (absorb > 0)
  68.                     {
  69.                         ItemStack stack = inventory.get(prop.Slot);
  70.                         int itemDamage = (int)Math.max(1, absorb);
  71.                         if (stack.getItem() instanceof ISpecialArmor)
  72.                         {
  73.                             ((ISpecialArmor)stack.getItem()).damageArmor(entity, stack, source, itemDamage, prop.Slot);
  74.                         }
  75.                         else
  76.                         {
  77.                             if (DEBUG)
  78.                             {
  79.                                 System.out.println("Item: " + stack.toString() + " Absorbed: " + absorb + " Damaged: " + itemDamage);
  80.                             }
  81.                             stack.damageItem(itemDamage, entity);
  82.                         }
  83.                         if (stack.isEmpty())
  84.                         {
  85.                             /*if (entity instanceof EntityPlayer)
  86.                             {
  87.                                 stack.onItemDestroyedByUse((EntityPlayer)entity);
  88.                             }*/
  89.                             inventory.set(prop.Slot, ItemStack.EMPTY);
  90.                         }
  91.                     }
  92.                 }
  93.                 damage -= (damage * ratio);
  94.             }
  95.             if (damage > 0 && (totalArmor > 0 || totalToughness > 0))
  96.             {
  97.                 double armorDamage = Math.max(1.0F, damage / 4.0F);
  98.                
  99.                 for (int i = 0; i < inventory.size(); i++)
  100.                 {
  101.                     if (inventory.get(i).getItem() instanceof ItemArmor)
  102.                     {
  103.                         inventory.get(i).damageItem((int)armorDamage, entity);
  104.                        
  105.                         if (inventory.get(i).getCount() == 0)
  106.                         {
  107.                             inventory.set(i, ItemStack.EMPTY);
  108.                         }
  109.                     }
  110.                 }
  111.                 damage = CombatRules.getDamageAfterAbsorb((float)damage, (float)totalArmor, (float)totalToughness);
  112.             }
  113.             if (DEBUG)
  114.             {
  115.                 System.out.println("Return: " + (int)(damage) + " " + damage);
  116.             }
  117.             return (float)(damage);
  118.         }
Advertisement
Add Comment
Please, Sign In to add comment