From 408d2a9d622e91be4faf769d4491ac88d4542d2b Mon Sep 17 00:00:00 2001 From: LexManos Date: Fri, 10 Feb 2012 04:02:32 -0800 Subject: [PATCH] Merged in the change to ISpecialArmor to introduce the DamageSource argument. As well as the concept of damage absorption vs reduction. --- .../minecraft/src/forge/ArmorProperties.java | 27 +++++---- .../minecraft/src/forge/ISpecialArmor.java | 37 +++++++++--- .../net/minecraft/src/EntityPlayer.java.patch | 56 +++++++++++++---- .../net/minecraft/src/EntityPlayer.java.patch | 60 ++++++++++++++----- 4 files changed, 135 insertions(+), 45 deletions(-) diff --git a/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java b/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java index 0a12b754f7..37bccbfdaf 100755 --- a/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java +++ b/forge/forge_common/net/minecraft/src/forge/ArmorProperties.java @@ -5,16 +5,23 @@ package net.minecraft.src.forge; -public class ArmorProperties { - public int damageRemove = 0; - public boolean allowRegularComputation = false; +public class ArmorProperties +{ + public double damageReduce = 0; + public int damageAbsorb = 0; - public ArmorProperties () { - - } - - public ArmorProperties (int damageRemove, boolean allowRegularCompuation) { - this.damageRemove = damageRemove; - this.allowRegularComputation = allowRegularCompuation; + public ArmorProperties () {} + /** + * Create an ArmorProperties describing the damage reduction. + * + * @param absorb Damage absorption. Removed from damage before damage + * reduction computation is applied. + * @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; } } diff --git a/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java b/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java index d6dbfa0268..f6a824d82b 100755 --- a/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java +++ b/forge/forge_common/net/minecraft/src/forge/ISpecialArmor.java @@ -5,8 +5,10 @@ package net.minecraft.src.forge; +import net.minecraft.src.DamageSource; import net.minecraft.src.EntityPlayer; import net.minecraft.src.ItemArmor; +import net.minecraft.src.ItemStack; /** * This interface is to be implemented by ItemArmor classes. It will allow to @@ -15,11 +17,32 @@ import net.minecraft.src.ItemArmor; * * @see ItemArmor */ -public interface ISpecialArmor { - - /** - * Return extra properties for the armor - */ - public ArmorProperties getProperties(EntityPlayer player, - int intitialDamage, int currentDamage); +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); + + /** + * Get the displayed effective armor. + * + * @param player The player wearing the armor. + * @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); } diff --git a/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch b/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch index 410dc27ab8..9771be5540 100644 --- a/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch @@ -93,34 +93,64 @@ public boolean canHarvestBlock(Block block) { return inventory.canHarvestBlock(block); -@@ -768,7 +824,25 @@ +@@ -768,8 +824,54 @@ { i = 1 + i >> 1; } - i = applyArmorCalculations(damagesource, i); +- i = applyPotionDamageCalculations(damagesource, i); + -+ boolean doRegularComputation = true; -+ int initialDamage = i; ++ int absorb = 0; ++ 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(); -+ ArmorProperties props = armor.getProperties(this, initialDamage, i); -+ i = i - props.damageRemove; -+ doRegularComputation = doRegularComputation && props.allowRegularComputation; ++ ArmorProperties props = armor.getProperties(this, damagesource, stack, i); ++ absorb += props.damageAbsorb; ++ 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()); health -= i; -@@ -815,7 +889,9 @@ + } +@@ -815,7 +917,9 @@ public void destroyCurrentEquippedItem() { @@ -130,7 +160,7 @@ } public double getYOffset() -@@ -947,6 +1023,11 @@ +@@ -947,6 +1051,11 @@ public EnumStatus sleepInBedAt(int i, int j, int k) { diff --git a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch index b737bdbe70..ca06958222 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch @@ -103,34 +103,64 @@ public boolean canHarvestBlock(Block block) { return inventory.canHarvestBlock(block); -@@ -711,7 +770,25 @@ +@@ -711,8 +770,54 @@ { i = 1 + i >> 1; } - i = applyArmorCalculations(damagesource, i); +- i = applyPotionDamageCalculations(damagesource, i); + -+ boolean doRegularComputation = true; -+ int initialDamage = i; ++ int absorb = 0; ++ 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) + { -+ ISpecialArmor armor = (ISpecialArmor)stack.getItem(); -+ ArmorProperties props = armor.getProperties(this, initialDamage, i); -+ i = i - props.damageRemove; -+ doRegularComputation = doRegularComputation && props.allowRegularComputation; ++ continue; ++ } ++ ++ if (stack.getItem() instanceof ISpecialArmor) ++ { ++ ISpecialArmor armor = (ISpecialArmor)stack.getItem(); ++ ArmorProperties props = armor.getProperties(this, damagesource, stack, i); ++ absorb += props.damageAbsorb; ++ 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()); health -= i; -@@ -758,7 +835,9 @@ + } +@@ -758,7 +863,9 @@ public void destroyCurrentEquippedItem() { @@ -140,7 +170,7 @@ } public double getYOffset() -@@ -884,6 +963,11 @@ +@@ -884,6 +991,11 @@ public EnumStatus sleepInBedAt(int i, int j, int k) {