diff --git a/build.gradle.kts b/build.gradle.kts index 2b8dba8..30163cb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.5.4" +version = "1.5.4-fix" java { disableAutoTargetJvm() diff --git a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt index 7c6ca2a..1aa0013 100644 --- a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt +++ b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt @@ -145,7 +145,7 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener { anvilCost += repairAmount * ConfigOptions.unitRepairCost } // We do not care about right item penalty for unit repair - anvilCost += calculatePenalty(first, null, resultItem) + anvilCost += calculatePenalty(first, null, resultItem, true) // Test/stop if nothing changed. if (first == resultItem) { @@ -506,6 +506,14 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener { * Also change result work penalty if right item is not null */ private fun calculatePenalty(left: ItemStack, right: ItemStack?, result: ItemStack): Int { + return calculatePenalty(left, right, result, false) + } + + /** + * Function to calculate work penalty of anvil work + * Also change result work penalty if right item is not null + */ + private fun calculatePenalty(left: ItemStack, right: ItemStack?, result: ItemStack, unitRepair: Boolean): Int { // Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation // Calculate work penalty val leftPenalty = (left.itemMeta as? Repairable)?.repairCost ?: 0 @@ -516,8 +524,8 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener { (right.itemMeta as? Repairable)?.repairCost ?: 0 } - // Try to set work penalty for the result item only if right item not null - if(right != null){ + // Increase penalty on fusing or unit repair + if(right != null || unitRepair){ result.itemMeta?.let { (it as? Repairable)?.repairCost = leftPenalty * 2 + 1 result.itemMeta = it diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 690c2b2..0ba9ff9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ main: io.delilaheve.CustomAnvil name: CustomAnvil prefix: "Custom Anvil" -version: 1.5.4 +version: 1.5.4-fix description: Allow to customise anvil mechanics api-version: 1.16 load: POSTWORLD