mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Fixed issue about level in fusing.
when fusing item with enchant above level limit there was some strange uncapped cases. Also fix a typo.
This commit is contained in:
parent
32b535efda
commit
adaba63d5e
2 changed files with 18 additions and 19 deletions
|
|
@ -30,10 +30,17 @@ object EnchantmentUtil {
|
||||||
) = mutableMapOf<Enchantment, Int>().apply {
|
) = mutableMapOf<Enchantment, Int>().apply {
|
||||||
putAll(this@combineWith)
|
putAll(this@combineWith)
|
||||||
other.forEach { (enchantment, level) ->
|
other.forEach { (enchantment, level) ->
|
||||||
|
// Get max level or 255 if player can bypass
|
||||||
|
val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission))
|
||||||
|
{ 255 } else
|
||||||
|
{ ConfigOptions.enchantLimit(enchantment) }
|
||||||
|
|
||||||
|
val cappedLevel = min(level, maxLevel)
|
||||||
|
|
||||||
// Enchantment not yet in result list
|
// Enchantment not yet in result list
|
||||||
if (!containsKey(enchantment)) {
|
if (!containsKey(enchantment)) {
|
||||||
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
||||||
this[enchantment] = level
|
this[enchantment] = cappedLevel
|
||||||
val conflictType =
|
val conflictType =
|
||||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||||
if (!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
if (!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
||||||
|
|
@ -46,6 +53,8 @@ object EnchantmentUtil {
|
||||||
}
|
}
|
||||||
// Enchantment already in result list
|
// Enchantment already in result list
|
||||||
else {
|
else {
|
||||||
|
val oldLevel = this[enchantment]!! // should be true, see the comment above
|
||||||
|
|
||||||
// ... and they are conflicting
|
// ... and they are conflicting
|
||||||
val conflictType =
|
val conflictType =
|
||||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||||
|
|
@ -57,28 +66,18 @@ object EnchantmentUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... and they're not the same level
|
// ... and they're not the same level
|
||||||
if (this[enchantment] != other[enchantment]) {
|
if (oldLevel != cappedLevel) {
|
||||||
val newLevel = max(this[enchantment] ?: 0, other[enchantment] ?: 0)
|
// apply the greater of the two or left one if right is above max
|
||||||
// apply the greater of the two if non-zero
|
this[enchantment] = max(oldLevel, cappedLevel)
|
||||||
|
|
||||||
if (newLevel > 0) {
|
|
||||||
this[enchantment] = newLevel
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// ... and they're the same level
|
// ... and they're the same level
|
||||||
else {
|
else {
|
||||||
// try to increase the enchantment level by 1
|
// try to increase the enchantment level by 1
|
||||||
var newLevel = this[enchantment]!! + 1
|
var newLevel = oldLevel + 1
|
||||||
// Get max level or 255 if player can bypass
|
newLevel = max(min(newLevel, maxLevel), oldLevel)
|
||||||
val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission)) {
|
|
||||||
255
|
|
||||||
} else {
|
|
||||||
ConfigOptions.enchantLimit(enchantment)
|
|
||||||
}
|
|
||||||
newLevel = min(newLevel, maxLevel)
|
|
||||||
if (newLevel > 0) {
|
|
||||||
this[enchantment] = newLevel
|
this[enchantment] = newLevel
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ class EnchantConflictManager {
|
||||||
|
|
||||||
private fun getEnchantByName(enchantName: String): Enchantment? {
|
private fun getEnchantByName(enchantName: String): Enchantment? {
|
||||||
|
|
||||||
// Teporary solution for 1.20.5
|
// Temporary solution for 1.20.5
|
||||||
when(enchantName){
|
when(enchantName){
|
||||||
"sweeping", "sweeping_edge" -> {
|
"sweeping", "sweeping_edge" -> {
|
||||||
return SWEEPING_EDGE_ENCHANT
|
return SWEEPING_EDGE_ENCHANT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue