Slightly simplify DurabilityManager
- Added a simple DurabilityManager#isBroken methods. This allows hiding the getMaxDurability method and move any isBroken logic out of the classes where it was previously used.
This commit is contained in:
parent
d6bd4feb68
commit
294f4d1cf3
@ -96,7 +96,7 @@ public class EventHandlers implements Listener
|
||||
// Even when we don't subtract durability, we still want to update the durability, so just subtract 0.
|
||||
final int durabilityLoss = removeDurability ? (int) Math.max(1, e.getDamage() / 4) : 0;
|
||||
final int newDurability = durabilityManager.removeDurability(elytra, durabilityLoss, armorTier);
|
||||
if (newDurability >= durabilityManager.getMaxDurability(armorTier))
|
||||
if (durabilityManager.isBroken(newDurability, armorTier))
|
||||
Util.moveChestplateToInventory(p);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class FlyDurabilityHandler implements Listener
|
||||
return;
|
||||
|
||||
final int newDurability = durabilityManager.removeDurability(e.getItem(), e.getDamage(), armorTier);
|
||||
if (newDurability >= durabilityManager.getMaxDurability(armorTier))
|
||||
if (durabilityManager.isBroken(newDurability, armorTier))
|
||||
Util.moveChestplateToInventory(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
@ -226,13 +226,40 @@ public class DurabilityManager
|
||||
return ArmorTier.getMaxDurability(armorTier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an armored elytra should be considered 'broken'.
|
||||
*
|
||||
* @param durability The current 'real' durability. See {@link #getRealDurability(ItemStack, ArmorTier)}.
|
||||
* @param armorTier The armor tier for which to check.
|
||||
* @return True if the provided durability should be considered 'broken' for the provided armor tier.
|
||||
*/
|
||||
public boolean isBroken(int durability, ArmorTier armorTier)
|
||||
{
|
||||
return durability >= getMaxDurability(armorTier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an armored elytra should be considered 'broken'.
|
||||
*
|
||||
* @param armoredElytra The armored elytra to check.
|
||||
* @param armorTier The armor tier for which to check.
|
||||
* @return True if the provided armored elytra should be considered 'broken'.
|
||||
*/
|
||||
public boolean isBroken(ItemStack armoredElytra, @Nullable ArmorTier armorTier)
|
||||
{
|
||||
final int realDurability = getRealDurability(armoredElytra, armorTier);
|
||||
if (realDurability == 0)
|
||||
return false;
|
||||
return isBroken(realDurability, armorTier == null ? nbtEditor.getArmorTier(armoredElytra) : armorTier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum durability for a given armor tier.
|
||||
*
|
||||
* @param armorTier The armor tier for which to get the maximum durability.
|
||||
* @return The maximum durability of the given armor tier.
|
||||
*/
|
||||
public int getMaxDurability(ArmorTier armorTier)
|
||||
private int getMaxDurability(ArmorTier armorTier)
|
||||
{
|
||||
return maxDurabilities[armorTier.ordinal()];
|
||||
}
|
||||
@ -243,7 +270,7 @@ public class DurabilityManager
|
||||
* @param armorTier The armor tier.
|
||||
* @return The amount of durability restored per repair step for the given armor tier.
|
||||
*/
|
||||
public int getRepairAmount(ArmorTier armorTier)
|
||||
private int getRepairAmount(ArmorTier armorTier)
|
||||
{
|
||||
return repairAmounts[armorTier.ordinal()];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user