Fixes some savage fail problems
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
Fixes item not being returned when salvage fails Removes some redundancy when giving back items Makes extended salvage return 50% of the salvage (no items if only one item would be returned) Adds a better message when failing to salvage extended salvage items Fixes a bug in the caching of smith presets
This commit is contained in:
@@ -34,7 +34,6 @@ public class ReforgeSession extends Session implements Runnable {
|
||||
private final ItemStack itemToReforge;
|
||||
private final BlacksmithNPCSettings config;
|
||||
private static List<String> enchantments = null;
|
||||
private static final Random random = new Random();
|
||||
|
||||
/**
|
||||
* Instantiates a new session
|
||||
@@ -123,17 +122,8 @@ public class ReforgeSession extends Session implements Runnable {
|
||||
* Gives the reforged item back to the player
|
||||
*/
|
||||
private void giveReforgedItem() {
|
||||
if (this.config.getMaxReforgeDelay() > 0) {
|
||||
//If the player isn't online, or the player cannot fit the item, drop the item to prevent it from disappearing
|
||||
if (this.config.getDropItem() || !this.player.isOnline() || this.player.getInventory().firstEmpty() == -1) {
|
||||
this.player.getWorld().dropItemNaturally(this.npc.getEntity().getLocation(), this.itemToReforge);
|
||||
} else {
|
||||
this.player.getInventory().addItem(this.itemToReforge);
|
||||
}
|
||||
} else {
|
||||
//It can be assumed as this happens instantly, that the player still has the item's previous slot selected
|
||||
this.player.getInventory().setItemInMainHand(this.itemToReforge);
|
||||
}
|
||||
giveResultingItem(this.config.getMaxReforgeDelay() > 0, this.config.getDropItem(), this.npc,
|
||||
this.itemToReforge);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +146,10 @@ public class ReforgeSession extends Session implements Runnable {
|
||||
*/
|
||||
private void succeedReforge() {
|
||||
// Remove any damage done to the item
|
||||
updateDamage(this.itemToReforge, 0);
|
||||
if (ItemHelper.updateDamage(this.itemToReforge, 0)) {
|
||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to update damage for " +
|
||||
this.itemToReforge);
|
||||
}
|
||||
|
||||
//Replace damaged anvils with a normal anvil
|
||||
if (ItemHelper.isAnvil(this.itemToReforge.getType(), true)) {
|
||||
@@ -216,15 +209,7 @@ public class ReforgeSession extends Session implements Runnable {
|
||||
}
|
||||
|
||||
//Damage the item
|
||||
short currentItemDurability = ItemHelper.getDurability(this.itemToReforge);
|
||||
short newDurability = (short) (currentItemDurability + (currentItemDurability * random.nextInt(8)));
|
||||
short maxDurability = this.itemToReforge.getType().getMaxDurability();
|
||||
if (newDurability <= 0) {
|
||||
newDurability = (short) (maxDurability / 3);
|
||||
} else if (currentItemDurability + newDurability > maxDurability) {
|
||||
newDurability = (short) (maxDurability - random.nextInt(maxDurability - 25));
|
||||
}
|
||||
updateDamage(this.itemToReforge, maxDurability - newDurability);
|
||||
damageItemRandomly(this.itemToReforge);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,16 +228,4 @@ public class ReforgeSession extends Session implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the damage done to an item
|
||||
*
|
||||
* @param item <p>The item to update damage for</p>
|
||||
* @param newDamage <p>The new damage done</p>
|
||||
*/
|
||||
private void updateDamage(ItemStack item, int newDamage) {
|
||||
if (!ItemHelper.updateDamage(item, newDamage)) {
|
||||
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to change damage of " + item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user