Adds an option for toggling whether reforging removing enchantments
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
This commit is contained in:
parent
faff982585
commit
cb70874093
@ -160,11 +160,12 @@ All currently supported presets, and available filters for each preset:
|
|||||||
#### Configuration values
|
#### Configuration values
|
||||||
|
|
||||||
| Key | Value type | Description |
|
| Key | Value type | Description |
|
||||||
|------------------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|--------------------------------|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| dropItem | true/false | Whether the blacksmith should drop the repaired item on the ground (instead of putting it into the player's inventory). |
|
| dropItem | true/false | Whether the blacksmith should drop the repaired item on the ground (instead of putting it into the player's inventory). |
|
||||||
| disableCoolDown | true/false | Whether to completely disable the cool-down between repairs. |
|
| disableCoolDown | true/false | Whether to completely disable the cool-down between repairs. |
|
||||||
| disableDelay | true/false | Whether to completely disable the delay required to reforge an item. |
|
| disableDelay | true/false | Whether to completely disable the delay required to reforge an item. |
|
||||||
| failReforgeChance | 0-100 | The chance of the blacksmith failing to repair an item. |
|
| failReforgeChance | 0-100 | The chance of the blacksmith failing to repair an item (further damaging it, or just repairing it a bit), and either removing or downgrading all enchantments (if failReforgeRemovesEnchantments is true). |
|
||||||
|
| failReforgeRemovesEnchantments | true/false | Whether a failed reforge should remove or downgrade all enchantments on the item. |
|
||||||
| extraEnchantmentChance | 0-100 | The chance of the blacksmith adding an enchantment to an item. |
|
| extraEnchantmentChance | 0-100 | The chance of the blacksmith adding an enchantment to an item. |
|
||||||
| maxEnchantments | 0-10 | The maximum number of different enchantments a blacksmith can add. |
|
| maxEnchantments | 0-10 | The maximum number of different enchantments a blacksmith can add. |
|
||||||
| maxReforgeDelay | 0-3600 | The maximum number of seconds a player needs to wait for an item to be repaired. |
|
| maxReforgeDelay | 0-3600 | The maximum number of seconds a player needs to wait for an item to be repaired. |
|
||||||
|
@ -17,6 +17,12 @@ public enum NPCSetting {
|
|||||||
*/
|
*/
|
||||||
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
|
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setting for whether failing a reforging should downgrade/remove enchantments as well
|
||||||
|
*/
|
||||||
|
FAIL_REMOVE_ENCHANTMENTS("failReforgeRemovesEnchantments", SettingValueType.BOOLEAN, false,
|
||||||
|
"failReforgeRemovesEnchantments"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The setting for the chance of an additional enchantment being added
|
* The setting for the chance of an additional enchantment being added
|
||||||
*/
|
*/
|
||||||
|
@ -258,6 +258,15 @@ public class NPCSettings {
|
|||||||
return asInt(NPCSetting.FAIL_CHANCE);
|
return asInt(NPCSetting.FAIL_CHANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether a failed reforging should remove/downgrade enchantments
|
||||||
|
*
|
||||||
|
* @return <p>Whether enchantments should be removed</p>
|
||||||
|
*/
|
||||||
|
public boolean getFailRemovesEnchantments() {
|
||||||
|
return asBoolean(NPCSetting.FAIL_REMOVE_ENCHANTMENTS);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the chance for adding an extra enchantment to an item
|
* Gets the chance for adding an extra enchantment to an item
|
||||||
*
|
*
|
||||||
@ -282,7 +291,7 @@ public class NPCSettings {
|
|||||||
* @return <p>Whether to drop reforged items on the ground</p>
|
* @return <p>Whether to drop reforged items on the ground</p>
|
||||||
*/
|
*/
|
||||||
public boolean getDropItem() {
|
public boolean getDropItem() {
|
||||||
return ConfigHelper.asBoolean(getValue(NPCSetting.DROP_ITEM));
|
return asBoolean(NPCSetting.DROP_ITEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -318,7 +327,7 @@ public class NPCSettings {
|
|||||||
* @return <p>True if this blacksmith is able to repair anvils</p>
|
* @return <p>True if this blacksmith is able to repair anvils</p>
|
||||||
*/
|
*/
|
||||||
public boolean getRepairAnvils() {
|
public boolean getRepairAnvils() {
|
||||||
return ConfigHelper.asBoolean(getValue(NPCSetting.REPAIR_ANVILS));
|
return asBoolean(NPCSetting.REPAIR_ANVILS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -343,6 +352,16 @@ public class NPCSettings {
|
|||||||
return getValue(setting).toString();
|
return getValue(setting).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the boolean value of the given setting
|
||||||
|
*
|
||||||
|
* @param setting <p>The setting to get the value of</p>
|
||||||
|
* @return <p>The value of the given setting as a boolean</p>
|
||||||
|
*/
|
||||||
|
private boolean asBoolean(NPCSetting setting) {
|
||||||
|
return ConfigHelper.asBoolean(getValue(setting));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of a setting, using the default if not set
|
* Gets the value of a setting, using the default if not set
|
||||||
*
|
*
|
||||||
|
@ -133,14 +133,19 @@ public class ReforgeSession implements Runnable {
|
|||||||
itemToReforge.setType(Material.ANVIL);
|
itemToReforge.setType(Material.ANVIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add random enchantments
|
//See if a random roll (0-99) is less than extraEnchantmentChance, and add a random enchantment
|
||||||
int roll = random.nextInt(100);
|
int roll = random.nextInt(100);
|
||||||
if (!(roll < config.getExtraEnchantmentChance() &&
|
if (roll < config.getExtraEnchantmentChance() &&
|
||||||
itemToReforge.getEnchantments().keySet().size() < config.getMaxEnchantments())) {
|
itemToReforge.getEnchantments().keySet().size() < config.getMaxEnchantments() &&
|
||||||
// Abort if randomness isn't on our side, or if max enchantments has been reached
|
!ItemHelper.isAnvil(itemToReforge.getType(), false)) {
|
||||||
return;
|
addRandomEnchantment();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a random enchantment to the currently reforged item
|
||||||
|
*/
|
||||||
|
private void addRandomEnchantment() {
|
||||||
//Find usable enchantments first
|
//Find usable enchantments first
|
||||||
List<Enchantment> usableEnchantments = new ArrayList<>();
|
List<Enchantment> usableEnchantments = new ArrayList<>();
|
||||||
for (String enchantmentName : enchantments) {
|
for (String enchantmentName : enchantments) {
|
||||||
@ -176,16 +181,8 @@ public class ReforgeSession implements Runnable {
|
|||||||
* The method to run when a blacksmith fails re-forging an item
|
* The method to run when a blacksmith fails re-forging an item
|
||||||
*/
|
*/
|
||||||
private void failReforge() {
|
private void failReforge() {
|
||||||
// Remove or downgrade existing enchantments
|
if (config.getFailRemovesEnchantments()) {
|
||||||
for (Enchantment enchantment : itemToReforge.getEnchantments().keySet()) {
|
removeOrDowngradeEnchantments();
|
||||||
if (random.nextBoolean()) {
|
|
||||||
itemToReforge.removeEnchantment(enchantment);
|
|
||||||
} else {
|
|
||||||
if (itemToReforge.getEnchantmentLevel(enchantment) > 1) {
|
|
||||||
itemToReforge.removeEnchantment(enchantment);
|
|
||||||
itemToReforge.addEnchantment(enchantment, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Damage the item
|
//Damage the item
|
||||||
@ -200,6 +197,22 @@ public class ReforgeSession implements Runnable {
|
|||||||
updateDamage(itemToReforge, maxDurability - newDurability);
|
updateDamage(itemToReforge, maxDurability - newDurability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes or downgrades all enchantments for the currently reforged item
|
||||||
|
*/
|
||||||
|
private void removeOrDowngradeEnchantments() {
|
||||||
|
//Remove or downgrade existing enchantments
|
||||||
|
for (Enchantment enchantment : itemToReforge.getEnchantments().keySet()) {
|
||||||
|
//Completely remove the enchantment, downgrade it, or keep it if lucky and already level 1
|
||||||
|
if (random.nextBoolean()) {
|
||||||
|
itemToReforge.removeEnchantment(enchantment);
|
||||||
|
} else if (itemToReforge.getEnchantmentLevel(enchantment) > 1) {
|
||||||
|
itemToReforge.removeEnchantment(enchantment);
|
||||||
|
itemToReforge.addEnchantment(enchantment, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the damage done to an item
|
* Updates the damage done to an item
|
||||||
*
|
*
|
||||||
|
@ -51,6 +51,9 @@ defaults:
|
|||||||
# The chance to fail reforging an item, which only repairs the item a tiny bit or not at all (0-100)
|
# The chance to fail reforging an item, which only repairs the item a tiny bit or not at all (0-100)
|
||||||
failReforgeChance: 10 # Default = 10%
|
failReforgeChance: 10 # Default = 10%
|
||||||
|
|
||||||
|
# Whether failed reforging should remove or downgrade the item's enchantments
|
||||||
|
failReforgeRemovesEnchantments: false # Default = false
|
||||||
|
|
||||||
# The chance that an enchantment will be added to the reforged item (0-100)
|
# The chance that an enchantment will be added to the reforged item (0-100)
|
||||||
extraEnchantmentChance: 5 # Default = 5%
|
extraEnchantmentChance: 5 # Default = 5%
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user