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
|
|
@ -0,0 +1,50 @@
|
||||||
|
package xyz.alexcrea.cuanvil.config;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public enum WorkPenaltyType {
|
||||||
|
DEFAULT("default", true, true),
|
||||||
|
INCREASE("increase_only", true, false),
|
||||||
|
ADDITIVE("add_only", false, true),
|
||||||
|
DISABLED("disabled", false, false),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final boolean penaltyIncrease;
|
||||||
|
private final boolean penaltyAdditive;
|
||||||
|
|
||||||
|
WorkPenaltyType(String name, boolean penaltyIncrease, boolean penaltyAdditive) {
|
||||||
|
this.name = name;
|
||||||
|
this.penaltyIncrease = penaltyIncrease;
|
||||||
|
this.penaltyAdditive = penaltyAdditive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPenaltyIncreasing() {
|
||||||
|
return penaltyIncrease;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPenaltyAdditive() {
|
||||||
|
return penaltyAdditive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doRepresentThisType(String toTest){
|
||||||
|
return name.equalsIgnoreCase(toTest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static WorkPenaltyType fromString(@Nullable String toTest){
|
||||||
|
if(toTest == null) return DEFAULT;
|
||||||
|
|
||||||
|
// Test if it matches any of values
|
||||||
|
for (WorkPenaltyType value : values()) {
|
||||||
|
if(value.doRepresentThisType(toTest)){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use default if not found
|
||||||
|
return DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package io.delilaheve.util
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
import io.delilaheve.util.EnchantmentUtil.enchantmentName
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
|
import xyz.alexcrea.cuanvil.config.WorkPenaltyType
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,6 +34,8 @@ object ConfigOptions {
|
||||||
const val PERMISSION_NEEDED_FOR_COLOR = "permission_needed_for_color"
|
const val PERMISSION_NEEDED_FOR_COLOR = "permission_needed_for_color"
|
||||||
const val USE_OF_COLOR_COST = "use_of_color_cost"
|
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"
|
private const val DEFAULT_LIMIT_PATH = "default_limit"
|
||||||
|
|
||||||
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
||||||
|
|
@ -248,6 +251,17 @@ object ConfigOptions {
|
||||||
?: DEFAULT_USE_OF_COLOR_COST
|
?: 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
|
* Default enchantment limit
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -85,16 +85,21 @@ object AnvilXpUtil {
|
||||||
fun calculatePenalty(left: ItemStack, right: ItemStack?, result: ItemStack, unitRepair: Boolean): Int {
|
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 penaltyType = ConfigOptions.workPenaltyType;
|
||||||
|
val leftPenalty =
|
||||||
|
if(!penaltyType.isPenaltyAdditive) 0
|
||||||
|
else {
|
||||||
|
(left.itemMeta as? Repairable)?.repairCost ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
val rightPenalty =
|
val rightPenalty =
|
||||||
if (right == null) {
|
if (right == null || !penaltyType.isPenaltyAdditive) 0
|
||||||
0
|
else {
|
||||||
} else {
|
|
||||||
(right.itemMeta as? Repairable)?.repairCost ?: 0
|
(right.itemMeta as? Repairable)?.repairCost ?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase penalty on fusing or unit repair
|
// Increase penalty on fusing or unit repair
|
||||||
if(right != null || unitRepair){
|
if(penaltyType.isPenaltyIncreasing && (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
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,17 @@ permission_needed_for_color: true
|
||||||
# Valid values include 0 to 1000.
|
# Valid values include 0 to 1000.
|
||||||
use_of_color_cost: 0
|
use_of_color_cost: 0
|
||||||
|
|
||||||
|
# Every time an item is used on the anvil. item work penalty is added to the price and increase
|
||||||
|
# Vanilla work penalty formula can be represented as 2 * previous_penalty + 1. with start value equal to 0
|
||||||
|
# See https://minecraft.wiki/w/Anvil_mechanics#Anvil_uses for more detail
|
||||||
|
#
|
||||||
|
# Valid work penalty type is:
|
||||||
|
# - default: work penalty added and increased
|
||||||
|
# - increase_only: work penalty increased but not added
|
||||||
|
# - add_only: work penalty added but not increased
|
||||||
|
# - disabled: work penalty disabled
|
||||||
|
work_penalty_type: default
|
||||||
|
|
||||||
# Default limit to apply to any enchants missing from enchant_limits
|
# Default limit to apply to any enchants missing from enchant_limits
|
||||||
#
|
#
|
||||||
# Valid values include 1 to 1000
|
# Valid values include 1 to 1000
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue