mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Fix anvil repair cost being increased for renaming.
This commit is contained in:
parent
f72d3622ca
commit
904e7a769a
1 changed files with 9 additions and 6 deletions
|
|
@ -256,7 +256,7 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
|
||||||
|
|
||||||
var numberOfChanges = 0
|
var numberOfChanges = 0
|
||||||
var startIndex = 0
|
var startIndex = 0
|
||||||
CustomAnvil.log("${matcher.find(startIndex)} $builder")
|
|
||||||
while(matcher.find(startIndex)){
|
while(matcher.find(startIndex)){
|
||||||
startIndex = matcher.start()
|
startIndex = matcher.start()
|
||||||
if(startIndex >= builder.length - endOffset) break
|
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
|
* 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 {
|
private fun calculatePenalty(left: ItemStack, right: ItemStack?, result: ItemStack): Int {
|
||||||
// Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation
|
// 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
|
(right.itemMeta as? Repairable)?.repairCost ?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set work penalty for the result item
|
// Try to set work penalty for the result item only if right item not null
|
||||||
|
if(right != null){
|
||||||
result.itemMeta?.let {
|
result.itemMeta?.let {
|
||||||
(it as? Repairable)?.repairCost = leftPenalty * 2 + 1
|
(it as? Repairable)?.repairCost = leftPenalty * 2 + 1
|
||||||
result.itemMeta = it
|
result.itemMeta = it
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomAnvil.log(
|
CustomAnvil.log(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue