Fixed very specific anvil edge case

This commit is contained in:
Auxilor 2022-09-05 17:38:41 +01:00
parent 27b351858f
commit cbdaf0bccd

View File

@ -17,7 +17,6 @@ import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.Damageable import org.bukkit.inventory.meta.Damageable
import org.bukkit.inventory.meta.EnchantmentStorageMeta import org.bukkit.inventory.meta.EnchantmentStorageMeta
import org.jetbrains.annotations.NotNull
import java.util.* import java.util.*
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
@ -90,15 +89,24 @@ class AnvilSupport(
val oldLeft = event.inventory.getItem(0) val oldLeft = event.inventory.getItem(0)
if (result == FAIL) {
return@run
}
if (oldLeft == null || oldLeft.type != outItem.type) { if (oldLeft == null || oldLeft.type != outItem.type) {
return@run return@run
} }
if (result == FAIL || left == old) { if (left == old) {
return@run return@run
} }
val cost = oldCost + price var cost = oldCost + price
// Unbelievably specific edge case
if (oldCost == -price) {
cost = price
}
// Cost could be less than zero at times, so I include that here. // Cost could be less than zero at times, so I include that here.
if (cost <= 0) { if (cost <= 0) {