Prevents an exception caused by enchantment start level being higher than enchantment max level
This commit is contained in:
parent
348a404066
commit
b16bb933e2
@ -93,7 +93,12 @@ class ReforgeSession implements Runnable {
|
||||
if (roll < config.getExtraEnchantmentChance() && itemToReforge.getEnchantments().keySet().size() < config.getMaxEnchantments()) {
|
||||
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.fromString(enchantments[random.nextInt(enchantments.length)]));
|
||||
if (Objects.requireNonNull(enchantment).canEnchantItem(itemToReforge)) {
|
||||
itemToReforge.addEnchantment(enchantment, random.nextInt(enchantment.getMaxLevel() - enchantment.getStartLevel()) + enchantment.getStartLevel());
|
||||
int randomBound = enchantment.getMaxLevel() - enchantment.getStartLevel();
|
||||
//A workaround for the random method's bound sometimes being negative
|
||||
if (randomBound >= 0) {
|
||||
itemToReforge.addEnchantment(enchantment, random.nextInt(randomBound) +
|
||||
enchantment.getStartLevel());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user