mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-31 06:39:36 +01:00
Fixed Impact reducing durability of non-armor equipped blocks
This commit is contained in:
parent
56056797bc
commit
2fac0170e7
@ -30,6 +30,7 @@ Version 1.4.00-dev
|
||||
+ Added Shears, Buckets, Fishing Rods, Flint & Steel, Carrot Sticks, and Bows to the list of items that can be Salvaged
|
||||
+ Added the "wait" music disc to the default fishing treasures
|
||||
+ Added "Chinese (Taiwan)" localization files (zh_TW)
|
||||
= Fixed Impact reducing durability of non-armor equipped blocks
|
||||
= Fixed multiple commands not working properly on offline players
|
||||
= Fixed /mmoedit not giving feedback when modifying another players stats
|
||||
= Fixed the guide usage string showing up every time /skillname was called
|
||||
|
@ -49,10 +49,7 @@ public class AxeManager extends SkillManager {
|
||||
public void impact(EntityDamageByEntityEvent event, LivingEntity target) {
|
||||
ImpactEventHandler eventHandler = new ImpactEventHandler(this, event, target);
|
||||
|
||||
if (Misc.hasArmor(target)) {
|
||||
eventHandler.damageArmor();
|
||||
}
|
||||
else {
|
||||
if (!eventHandler.applyImpact()) {
|
||||
eventHandler.applyGreaterImpact();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.ItemChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
@ -16,38 +17,46 @@ public class ImpactEventHandler {
|
||||
private Player player;
|
||||
private EntityDamageByEntityEvent event;
|
||||
private short durabilityDamage = 1;
|
||||
private EntityEquipment equipment;
|
||||
private ItemStack[] armorContents;
|
||||
private EntityEquipment entityEquipment;
|
||||
protected LivingEntity defender;
|
||||
boolean impactApplied;
|
||||
|
||||
public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
|
||||
this.manager = manager;
|
||||
this.player = manager.getMcMMOPlayer().getPlayer();
|
||||
this.event = event;
|
||||
this.defender = defender;
|
||||
this.equipment = defender.getEquipment();
|
||||
this.armorContents = equipment.getArmorContents();
|
||||
this.entityEquipment = defender.getEquipment();
|
||||
}
|
||||
|
||||
protected void damageArmor() {
|
||||
protected boolean applyImpact() {
|
||||
// Every 50 Skill Levels you gain 1 durability damage (default values)
|
||||
durabilityDamage += (short) (manager.getSkillLevel() / Axes.impactIncreaseLevel);
|
||||
// getArmorContents.length can't be used because it's always equal to 4 (no armor = air block)
|
||||
boolean hasArmor = false;
|
||||
|
||||
for (ItemStack armor : armorContents) {
|
||||
if (Misc.getRandom().nextInt(100) > 75) {
|
||||
|
||||
for (int i = 0; i <= durabilityDamage; i++) {
|
||||
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
|
||||
handleDurabilityEnchantment(armor);
|
||||
}
|
||||
}
|
||||
|
||||
damageValidation(armor);
|
||||
armor.setDurability((short) (armor.getDurability() + durabilityDamage));
|
||||
for (ItemStack itemStack : entityEquipment.getArmorContents()) {
|
||||
if (ItemChecks.isArmor(itemStack)) {
|
||||
damageArmor(itemStack);
|
||||
hasArmor = true;
|
||||
}
|
||||
}
|
||||
|
||||
equipment.setArmorContents(armorContents);
|
||||
return hasArmor;
|
||||
}
|
||||
|
||||
private void damageArmor(ItemStack armor) {
|
||||
if (Misc.getRandom().nextInt(100) >= 25) {
|
||||
return;
|
||||
}
|
||||
|
||||
float modifier = 1;
|
||||
|
||||
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
|
||||
modifier /= armor.getEnchantmentLevel(Enchantment.DURABILITY) + 1;
|
||||
}
|
||||
|
||||
armor.setDurability((short) (durabilityDamage * modifier + armor.getDurability()));
|
||||
}
|
||||
|
||||
protected void applyGreaterImpact() {
|
||||
@ -73,20 +82,4 @@ public class ImpactEventHandler {
|
||||
((Player) defender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDurabilityEnchantment(ItemStack armor) {
|
||||
int enchantmentLevel = armor.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
|
||||
if (Misc.getRandom().nextInt(enchantmentLevel + 1) > 0) {
|
||||
durabilityDamage--;
|
||||
}
|
||||
}
|
||||
|
||||
private void damageValidation(ItemStack armor) {
|
||||
short maxDurability = (short) (armor.getType().getMaxDurability() * Axes.impactMaxDurabilityDamageModifier);
|
||||
|
||||
if (durabilityDamage > maxDurability) {
|
||||
durabilityDamage = maxDurability;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user