mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Fix unit repair not increasing penalty and version up.
This was caused by previous fix fixing renaming increasing penalty.
This commit is contained in:
parent
44367d0ced
commit
056892ee1e
3 changed files with 13 additions and 5 deletions
|
|
@ -13,7 +13,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "xyz.alexcrea"
|
group = "xyz.alexcrea"
|
||||||
version = "1.5.4"
|
version = "1.5.4-fix"
|
||||||
|
|
||||||
java {
|
java {
|
||||||
disableAutoTargetJvm()
|
disableAutoTargetJvm()
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
|
||||||
anvilCost += repairAmount * ConfigOptions.unitRepairCost
|
anvilCost += repairAmount * ConfigOptions.unitRepairCost
|
||||||
}
|
}
|
||||||
// We do not care about right item penalty for unit repair
|
// 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.
|
// Test/stop if nothing changed.
|
||||||
if (first == resultItem) {
|
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
|
* 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 {
|
||||||
|
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
|
// Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation
|
||||||
// Calculate work penalty
|
// Calculate work penalty
|
||||||
val leftPenalty = (left.itemMeta as? Repairable)?.repairCost ?: 0
|
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
|
(right.itemMeta as? Repairable)?.repairCost ?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set work penalty for the result item only if right item not null
|
// Increase penalty on fusing or unit repair
|
||||||
if(right != null){
|
if(right != null || unitRepair){
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
main: io.delilaheve.CustomAnvil
|
main: io.delilaheve.CustomAnvil
|
||||||
name: CustomAnvil
|
name: CustomAnvil
|
||||||
prefix: "Custom Anvil"
|
prefix: "Custom Anvil"
|
||||||
version: 1.5.4
|
version: 1.5.4-fix
|
||||||
description: Allow to customise anvil mechanics
|
description: Allow to customise anvil mechanics
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue