Fix anvil repair cost being increased for renaming.

This commit is contained in:
alexcrea 2024-07-26 20:12:58 +02:00
parent f72d3622ca
commit 904e7a769a
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F

View file

@ -256,7 +256,7 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
var numberOfChanges = 0
var startIndex = 0
CustomAnvil.log("${matcher.find(startIndex)} $builder")
while(matcher.find(startIndex)){
startIndex = matcher.start()
if(startIndex >= builder.length - endOffset) break
@ -503,7 +503,7 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
/**
* Function to calculate work penalty of anvil work
* Also change result work penalty
* Also change result work penalty if right item is not null
*/
private fun calculatePenalty(left: ItemStack, right: ItemStack?, result: ItemStack): Int {
// Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation
@ -516,10 +516,13 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
(right.itemMeta as? Repairable)?.repairCost ?: 0
}
// Try to set work penalty for the result item
result.itemMeta?.let {
(it as? Repairable)?.repairCost = leftPenalty * 2 + 1
result.itemMeta = it
// Try to set work penalty for the result item only if right item not null
if(right != null){
result.itemMeta?.let {
(it as? Repairable)?.repairCost = leftPenalty * 2 + 1
result.itemMeta = it
}
}
CustomAnvil.log(