mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add work penalty type
This commit is contained in:
parent
98172a11c9
commit
519ab1853c
4 changed files with 85 additions and 5 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue