Refactored so that ISpecialArmor items do not see the factor of 25 on the damage.

The value returned form ISpecialArmor.getProperties is now copied, so mod items are free to re-use there return values.
This commit is contained in:
LexManos 2012-02-14 11:12:16 -08:00
parent d230b379f9
commit c54ed32d2a
6 changed files with 53 additions and 42 deletions

View file

@ -41,11 +41,12 @@ public class ArmorProperties implements Comparable<ArmorProperties>
*/
public static int ApplyArmor(EntityLiving entity, ItemStack[] inventory, DamageSource source, double damage)
{
ArrayList<ArmorProperties> dmgVals = new ArrayList<ArmorProperties>();
if (DEBUG)
{
System.out.println("Start: " + damage);
System.out.println("Start: " + damage + " " + (damage * 25));
}
damage *= 25;
ArrayList<ArmorProperties> dmgVals = new ArrayList<ArmorProperties>();
for (int x = 0; x < inventory.length; x++)
{
ItemStack stack = inventory[x];
@ -57,13 +58,12 @@ public class ArmorProperties implements Comparable<ArmorProperties>
if (stack.getItem() instanceof ISpecialArmor)
{
ISpecialArmor armor = (ISpecialArmor)stack.getItem();
prop = armor.getProperties(entity, stack, source, damage, x);
prop = armor.getProperties(entity, stack, source, damage / 25D, x).copy();
}
else if (stack.getItem() instanceof ItemArmor && !source.isUnblockable())
{
ItemArmor armor = (ItemArmor)stack.getItem();
prop = new ArmorProperties(0, armor.damageReduceAmount / 25D,
armor.getMaxDamage() - stack.getItemDamage());
prop = new ArmorProperties(0, armor.damageReduceAmount / 25D, armor.getMaxDamage() + 1 - stack.getItemDamage());
}
if (prop != null)
{
@ -74,10 +74,9 @@ public class ArmorProperties implements Comparable<ArmorProperties>
if (dmgVals.size() > 0)
{
ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[0]);
StanderdizeList(props, damage);
StandardizeList(props, damage);
int level = props[0].Priority;
double ratio = 0;
double totalAbsorbed = 0;
for (ArmorProperties prop : props)
{
if (level != prop.Priority)
@ -92,17 +91,18 @@ public class ArmorProperties implements Comparable<ArmorProperties>
if (absorb > 0)
{
ItemStack stack = inventory[prop.Slot];
int itemDamage = (int)(absorb / 25D < 1 ? 1 : absorb / 25D);
if (stack.getItem() instanceof ISpecialArmor)
{
((ISpecialArmor)stack.getItem()).damageArmor(entity, stack, source, (int)(absorb < 1 ? 1 : (int)absorb), prop.Slot);
((ISpecialArmor)stack.getItem()).damageArmor(entity, stack, source, itemDamage, prop.Slot);
}
else
{
if (DEBUG)
{
System.out.println("Item: " + stack.toString() + " Absorbed: " + absorb + " Damaged: " + (int)(absorb < 1 ? 1 : (int)absorb));
System.out.println("Item: " + stack.toString() + " Absorbed: " + (absorb / 25D) + " Damaged: " + itemDamage);
}
stack.damageItem((int)(absorb < 1 ? 1 : (int)absorb), entity);
stack.damageItem(itemDamage, entity);
}
if (stack.stackSize <= 0)
{
@ -116,11 +116,13 @@ public class ArmorProperties implements Comparable<ArmorProperties>
}
damage -= (damage * ratio);
}
damage += entity.carryoverDamage;
if (DEBUG)
{
System.out.println("Return: " + (int)damage + " " + damage);
System.out.println("Return: " + (int)(damage / 25D) + " " + damage);
}
return (int)damage;
entity.carryoverDamage = (int)damage % 25;
return (int)(damage / 25D);
}
/**
@ -129,7 +131,7 @@ public class ArmorProperties implements Comparable<ArmorProperties>
* @param armor The armor information
* @param damage The total damage being received
*/
private static void StanderdizeList(ArmorProperties[] armor, double damage)
private static void StandardizeList(ArmorProperties[] armor, double damage)
{
Arrays.sort(armor);
@ -253,4 +255,9 @@ public class ArmorProperties implements Comparable<ArmorProperties>
{
return String.format("%d, %d, %f, %d", Priority, AbsorbMax, AbsorbRatio, (AbsorbRatio == 0 ? 0 : (int)(AbsorbMax * 100.0D / AbsorbRatio)));
}
public ArmorProperties copy()
{
return new ArmorProperties(Priority, AbsorbRatio, AbsorbMax);
}
}

View file

@ -22,8 +22,6 @@ public interface ISpecialArmor
{
/**
* Retrieves the modifiers to be used when calculating armor damage.
* Mods should return a new instance every time as the return values
* will be manipulated by the damage function.
*
* Armor will higher priority will have damage applied to them before
* lower priority ones. If there are multiple pieces of armor with the
@ -36,7 +34,7 @@ public interface ISpecialArmor
* properties based on the type or source of damage.
* @param damage The total damage being applied to the entity
* @param slot The armor slot the item is in.
*
* @return A ArmorProperties instance holding information about how the armor effects damage.
*/
public ArmorProperties getProperties(EntityLiving player, ItemStack armor, DamageSource source, double damage, int slot);

View file

@ -1,5 +1,14 @@
--- ../src_base/minecraft/net/minecraft/src/EntityLiving.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/EntityLiving.java 0000-00-00 00:00:00.000000000 -0000
@@ -29,7 +29,7 @@
public float swingProgress;
protected int health;
public int prevHealth;
- protected int carryoverDamage;
+ public int carryoverDamage;
private int livingSoundTime;
public int hurtTime;
public int maxHurtTime;
@@ -835,7 +835,13 @@
int i = MathHelper.floor_double(posX);
int j = MathHelper.floor_double(boundingBox.minY);

View file

@ -93,26 +93,20 @@
public boolean canHarvestBlock(Block block)
{
return inventory.canHarvestBlock(block);
@@ -768,8 +824,16 @@
@@ -768,7 +824,11 @@
{
i = 1 + i >> 1;
}
- i = applyArmorCalculations(damagesource, i);
- i = applyPotionDamageCalculations(damagesource, i);
+ int damage = ArmorProperties.ApplyArmor(this, inventory.armorInventory, damagesource, (double)i * 25) + carryoverDamage;
+
+ carryoverDamage = damage % 25;
+ damage /= 25;
+ if (damage <= 0)
+ i = ArmorProperties.ApplyArmor(this, inventory.armorInventory, damagesource, i);
+ if (i <= 0)
+ {
+ return;
+ }
+
+ i = applyPotionDamageCalculations(damagesource, damage);
i = applyPotionDamageCalculations(damagesource, i);
addExhaustion(damagesource.getHungerDamage());
health -= i;
}
@@ -815,7 +879,9 @@
@@ -815,7 +875,9 @@
public void destroyCurrentEquippedItem()
{
@ -122,7 +116,7 @@
}
public double getYOffset()
@@ -834,6 +900,11 @@
@@ -834,6 +896,11 @@
public void attackTargetEntityWithCurrentItem(Entity entity)
{
@ -134,7 +128,7 @@
int i = inventory.getDamageVsEntity(entity);
if (isPotionActive(Potion.damageBoost))
{
@@ -947,6 +1018,11 @@
@@ -947,6 +1014,11 @@
public EnumStatus sleepInBedAt(int i, int j, int k)
{

View file

@ -1,5 +1,14 @@
--- ../src_base/minecraft_server/net/minecraft/src/EntityLiving.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/EntityLiving.java 0000-00-00 00:00:00.000000000 -0000
@@ -29,7 +29,7 @@
public float swingProgress;
protected int health;
public int prevHealth;
- protected int carryoverDamage;
+ public int carryoverDamage;
private int livingSoundTime;
public int hurtTime;
public int maxHurtTime;
@@ -812,7 +812,9 @@
int i = MathHelper.floor_double(posX);
int j = MathHelper.floor_double(boundingBox.minY);

View file

@ -103,26 +103,20 @@
public boolean canHarvestBlock(Block block)
{
return inventory.canHarvestBlock(block);
@@ -711,8 +770,16 @@
@@ -711,7 +770,11 @@
{
i = 1 + i >> 1;
}
- i = applyArmorCalculations(damagesource, i);
- i = applyPotionDamageCalculations(damagesource, i);
+ int damage = ArmorProperties.ApplyArmor(this, inventory.armorInventory, damagesource, (double)i * 25) + carryoverDamage;
+
+ carryoverDamage = damage % 25;
+ damage /= 25;
+ if (damage <= 0)
+ i = ArmorProperties.ApplyArmor(this, inventory.armorInventory, damagesource, i);
+ if (i <= 0)
+ {
+ return;
+ }
+
+ i = applyPotionDamageCalculations(damagesource, damage);
i = applyPotionDamageCalculations(damagesource, i);
addExhaustion(damagesource.getHungerDamage());
health -= i;
}
@@ -758,7 +825,9 @@
@@ -758,7 +821,9 @@
public void destroyCurrentEquippedItem()
{
@ -132,7 +126,7 @@
}
public double getYOffset()
@@ -777,6 +846,11 @@
@@ -777,6 +842,11 @@
public void attackTargetEntityWithCurrentItem(Entity entity)
{
@ -144,7 +138,7 @@
int i = inventory.getDamageVsEntity(entity);
if (isPotionActive(Potion.damageBoost))
{
@@ -884,6 +958,11 @@
@@ -884,6 +954,11 @@
public EnumStatus sleepInBedAt(int i, int j, int k)
{