Add work penalty type

This commit is contained in:
alexcrea 2024-08-31 15:09:04 +02:00
parent 98172a11c9
commit 519ab1853c
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
4 changed files with 85 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package io.delilaheve.util
import io.delilaheve.CustomAnvil
import io.delilaheve.util.EnchantmentUtil.enchantmentName
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.config.WorkPenaltyType
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
/**
@ -33,6 +34,8 @@ object ConfigOptions {
const val PERMISSION_NEEDED_FOR_COLOR = "permission_needed_for_color"
const val USE_OF_COLOR_COST = "use_of_color_cost"
const val WORK_PENALTY_TYPE = "work_penalty_type"
private const val DEFAULT_LIMIT_PATH = "default_limit"
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
@ -248,6 +251,17 @@ object ConfigOptions {
?: DEFAULT_USE_OF_COLOR_COST
}
/**
* How many xp should use of color should cost
*/
val workPenaltyType: WorkPenaltyType
get() {
return WorkPenaltyType.fromString(
ConfigHolder.DEFAULT_CONFIG
.config
.getString(WORK_PENALTY_TYPE));
}
/**
* Default enchantment limit
*/

View file

@ -85,16 +85,21 @@ object AnvilXpUtil {
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
val penaltyType = ConfigOptions.workPenaltyType;
val leftPenalty =
if(!penaltyType.isPenaltyAdditive) 0
else {
(left.itemMeta as? Repairable)?.repairCost ?: 0
}
val rightPenalty =
if (right == null) {
0
} else {
if (right == null || !penaltyType.isPenaltyAdditive) 0
else {
(right.itemMeta as? Repairable)?.repairCost ?: 0
}
// Increase penalty on fusing or unit repair
if(right != null || unitRepair){
if(penaltyType.isPenaltyIncreasing && (right != null || unitRepair)){
result.itemMeta?.let {
(it as? Repairable)?.repairCost = leftPenalty * 2 + 1
result.itemMeta = it