增加对 Unbreakable 属性的支持

This commit is contained in:
zhangyuheng 2024-10-06 20:25:53 +08:00
parent 0c3c0e0726
commit bda0f8dee7
2 changed files with 11 additions and 5 deletions

View File

@ -91,9 +91,11 @@ public class Job {
} }
// 如果耐久小于10提示玩家 // 如果耐久小于10提示玩家
pickaxe_damage = (Damageable) pickaxe_meta; pickaxe_damage = (Damageable) pickaxe_meta;
if (pickaxe_damage.getDamage() >= 2031 - 10) { if (!pickaxe_meta.isUnbreakable()) {
LoggerX.debug(index + " 下界合金镐耐久太低!"); if (pickaxe_damage.getDamage() >= 2031 - 10) {
continue; LoggerX.debug(index + " 下界合金镐耐久太低!");
continue;
}
} }
pickaxe = p; pickaxe = p;
break; break;
@ -104,9 +106,13 @@ public class Job {
public static ItemStack useNetherPickaxe(ItemStack pickaxe) { public static ItemStack useNetherPickaxe(ItemStack pickaxe) {
int durability = pickaxe.getEnchantmentLevel(Enchantment.DURABILITY); int durability = pickaxe.getEnchantmentLevel(Enchantment.DURABILITY);
double random = Math.random(); double random = Math.random();
Damageable pickaxe_damage = (Damageable) pickaxe.getItemMeta();
if (pickaxe_damage.isUnbreakable()) {
// 无限耐久则不损坏
return pickaxe;
}
if (random < 1.0 / (durability + 1)) { if (random < 1.0 / (durability + 1)) {
// 扣除耐久 // 扣除耐久
Damageable pickaxe_damage = (Damageable) pickaxe.getItemMeta();
pickaxe_damage.setDamage(pickaxe_damage.getDamage() + 1); pickaxe_damage.setDamage(pickaxe_damage.getDamage() + 1);
pickaxe.setItemMeta(pickaxe_damage); pickaxe.setItemMeta(pickaxe_damage);
} }

View File

@ -34,7 +34,7 @@ public class Remove extends Job {
} }
// 获取玩家背包中的下届合金镐 // 获取玩家背包中的下届合金镐
HashMap<Integer, ?> pickaxes = getNetherPickaxes(_creator); HashMap<Integer, ?> pickaxes = getNetherPickaxes(_creator);
if (pickaxes.size() == 0) { if (pickaxes.isEmpty()) {
return JobErrCode.NO_PICKAXE; return JobErrCode.NO_PICKAXE;
} }
ItemStack pickaxe = getUsableNetherPickaxe(pickaxes, _creator); ItemStack pickaxe = getUsableNetherPickaxe(pickaxes, _creator);