Merged in the change to ISpecialArmor to introduce the DamageSource argument.

As well as the concept of damage absorption vs reduction.
This commit is contained in:
LexManos 2012-02-10 04:02:32 -08:00
parent 2ea1775224
commit 408d2a9d62
4 changed files with 135 additions and 45 deletions

View file

@ -5,16 +5,23 @@
package net.minecraft.src.forge; package net.minecraft.src.forge;
public class ArmorProperties { public class ArmorProperties
public int damageRemove = 0; {
public boolean allowRegularComputation = false; public double damageReduce = 0;
public int damageAbsorb = 0;
public ArmorProperties () { public ArmorProperties () {}
/**
} * Create an ArmorProperties describing the damage reduction.
*
public ArmorProperties (int damageRemove, boolean allowRegularCompuation) { * @param absorb Damage absorption. Removed from damage before damage
this.damageRemove = damageRemove; * reduction computation is applied.
this.allowRegularComputation = allowRegularCompuation; * @param reduce Damage reduction, percentage of damage absorbed by
* armor where 1.0 =100%. A full set of diamond armor is 80%.
*/
public ArmorProperties (int absorb, double reduce)
{
damageReduce = reduce;
damageAbsorb = absorb;
} }
} }

View file

@ -5,8 +5,10 @@
package net.minecraft.src.forge; package net.minecraft.src.forge;
import net.minecraft.src.DamageSource;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemArmor; import net.minecraft.src.ItemArmor;
import net.minecraft.src.ItemStack;
/** /**
* This interface is to be implemented by ItemArmor classes. It will allow to * This interface is to be implemented by ItemArmor classes. It will allow to
@ -15,11 +17,32 @@ import net.minecraft.src.ItemArmor;
* *
* @see ItemArmor * @see ItemArmor
*/ */
public interface ISpecialArmor { public interface ISpecialArmor
{
/**
* Apply an armor effect to incoming damage. This should both compute
* the damage reduction properties of the armor against the incoming
* damage, and reduce the armor durability if appropriate. If the
* armor is destroyed, decrement the stack size of the ItemStack. It
* will then be cleaned up automatically.
*
* @param player The player wearing the armor.
* @param damageSource The source of the damage, which can be used to alter armor
* properties based on the type or source of damage.
* @param armor The ItemStack of the armor item itself. If you should
* need the index in damageArmor, use the armorType field in the item.
* @param damage The damage being applied to the armor.
*
*/
public ArmorProperties getProperties(EntityPlayer player, DamageSource damageSource, ItemStack armor, int damage);
/** /**
* Return extra properties for the armor * Get the displayed effective armor.
*/ *
public ArmorProperties getProperties(EntityPlayer player, * @param player The player wearing the armor.
int intitialDamage, int currentDamage); * @param armor The ItemStack of the armor item itself. If you should
* need the index in damageArmor, use the armorType field in the item.
* @return The number of armor points for display, 2 per shield.
*/
public abstract int getArmorDisplay(EntityPlayer player, ItemStack armor);
} }

View file

@ -93,34 +93,64 @@
public boolean canHarvestBlock(Block block) public boolean canHarvestBlock(Block block)
{ {
return inventory.canHarvestBlock(block); return inventory.canHarvestBlock(block);
@@ -768,7 +824,25 @@ @@ -768,8 +824,54 @@
{ {
i = 1 + i >> 1; i = 1 + i >> 1;
} }
- i = applyArmorCalculations(damagesource, i); - i = applyArmorCalculations(damagesource, i);
- i = applyPotionDamageCalculations(damagesource, i);
+ +
+ boolean doRegularComputation = true; + int absorb = 0;
+ int initialDamage = i; + int reduce = 0;
+ +
+ for (ItemStack stack : inventory.armorInventory) + for (int x = 0; x < inventory.armorInventory.length; x++)
+ { + {
+ if (stack != null && stack.getItem() instanceof ISpecialArmor) + ItemStack stack = inventory.armorInventory[x];
+ if (stack == null)
+ {
+ continue;
+ }
+
+ if (stack.getItem() instanceof ISpecialArmor)
+ { + {
+ ISpecialArmor armor = (ISpecialArmor)stack.getItem(); + ISpecialArmor armor = (ISpecialArmor)stack.getItem();
+ ArmorProperties props = armor.getProperties(this, initialDamage, i); + ArmorProperties props = armor.getProperties(this, damagesource, stack, i);
+ i = i - props.damageRemove; + absorb += props.damageAbsorb;
+ doRegularComputation = doRegularComputation && props.allowRegularComputation; + reduce += props.damageReduce;
+ }
+ else if (stack.getItem() instanceof ItemArmor && !damagesource.isUnblockable())
+ {
+ reduce += ((ItemArmor)stack.getItem()).damageReduceAmount / 25.0;
+ stack.damageItem((i / 4 == 0 ? 1 : i / 4), this);
+ }
+
+ if (inventory.armorInventory[x] != null)
+ {
+ stack.onItemDestroyedByUse(this);
+ inventory.armorInventory[x] = null;
+ } + }
+ } + }
+ +
+ if (doRegularComputation) + i -= absorb;
+ if (i <= 0)
+ { + {
+ i = applyArmorCalculations(damagesource, i); + return;
+ } + }
i = applyPotionDamageCalculations(damagesource, i); +
+ reduce = Math.min(25, 25 * reduce);
+ int damage = i * (25 - reduce) + carryoverDamage;
+ carryoverDamage = damage % 25;
+ damage /= 25;
+ if (damage <= 0)
+ {
+ return;
+ }
+
+ i = applyPotionDamageCalculations(damagesource, damage);
addExhaustion(damagesource.getHungerDamage()); addExhaustion(damagesource.getHungerDamage());
health -= i; health -= i;
@@ -815,7 +889,9 @@ }
@@ -815,7 +917,9 @@
public void destroyCurrentEquippedItem() public void destroyCurrentEquippedItem()
{ {
@ -130,7 +160,7 @@
} }
public double getYOffset() public double getYOffset()
@@ -947,6 +1023,11 @@ @@ -947,6 +1051,11 @@
public EnumStatus sleepInBedAt(int i, int j, int k) public EnumStatus sleepInBedAt(int i, int j, int k)
{ {

View file

@ -103,34 +103,64 @@
public boolean canHarvestBlock(Block block) public boolean canHarvestBlock(Block block)
{ {
return inventory.canHarvestBlock(block); return inventory.canHarvestBlock(block);
@@ -711,7 +770,25 @@ @@ -711,8 +770,54 @@
{ {
i = 1 + i >> 1; i = 1 + i >> 1;
} }
- i = applyArmorCalculations(damagesource, i); - i = applyArmorCalculations(damagesource, i);
- i = applyPotionDamageCalculations(damagesource, i);
+ +
+ boolean doRegularComputation = true; + int absorb = 0;
+ int initialDamage = i; + int reduce = 0;
+ +
+ for (ItemStack stack : inventory.armorInventory) + for (int x = 0; x < inventory.armorInventory.length; x++)
+ { + {
+ if (stack != null && stack.getItem() instanceof ISpecialArmor) + ItemStack stack = inventory.armorInventory[x];
+ if (stack == null)
+ {
+ continue;
+ }
+
+ if (stack.getItem() instanceof ISpecialArmor)
+ { + {
+ ISpecialArmor armor = (ISpecialArmor)stack.getItem(); + ISpecialArmor armor = (ISpecialArmor)stack.getItem();
+ ArmorProperties props = armor.getProperties(this, initialDamage, i); + ArmorProperties props = armor.getProperties(this, damagesource, stack, i);
+ i = i - props.damageRemove; + absorb += props.damageAbsorb;
+ doRegularComputation = doRegularComputation && props.allowRegularComputation; + reduce += props.damageReduce;
+ }
+ else if (stack.getItem() instanceof ItemArmor && !damagesource.isUnblockable())
+ {
+ reduce += ((ItemArmor)stack.getItem()).damageReduceAmount / 25.0;
+ stack.damageItem((i / 4 == 0 ? 1 : i / 4), this);
+ }
+
+ if (inventory.armorInventory[x] != null)
+ {
+ stack.onItemDestroyedByUse(this);
+ inventory.armorInventory[x] = null;
+ } + }
+ } + }
+ +
+ if (doRegularComputation) + i -= absorb;
+ if (i <= 0)
+ { + {
+ i = applyArmorCalculations(damagesource, i); + return;
+ } + }
i = applyPotionDamageCalculations(damagesource, i); +
+ reduce = Math.min(25, 25 * reduce);
+ int damage = i * (25 - reduce) + carryoverDamage;
+ carryoverDamage = damage % 25;
+ damage /= 25;
+ if (damage <= 0)
+ {
+ return;
+ }
+
+ i = applyPotionDamageCalculations(damagesource, damage);
addExhaustion(damagesource.getHungerDamage()); addExhaustion(damagesource.getHungerDamage());
health -= i; health -= i;
@@ -758,7 +835,9 @@ }
@@ -758,7 +863,9 @@
public void destroyCurrentEquippedItem() public void destroyCurrentEquippedItem()
{ {
@ -140,7 +170,7 @@
} }
public double getYOffset() public double getYOffset()
@@ -884,6 +963,11 @@ @@ -884,6 +991,11 @@
public EnumStatus sleepInBedAt(int i, int j, int k) public EnumStatus sleepInBedAt(int i, int j, int k)
{ {