mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
add left item enchantment cost toggle
Some checks are pending
Java CI with Gradle / build (push) Waiting to run
Some checks are pending
Java CI with Gradle / build (push) Waiting to run
This commit is contained in:
parent
965ee33325
commit
7ea708ec14
4 changed files with 43 additions and 7 deletions
|
|
@ -75,6 +75,8 @@ object ConfigOptions {
|
|||
const val DISABLE_MERGE_OVER_ROOT = "disable-merge-over"
|
||||
|
||||
const val IMMUTABLE_ENCHANTMENT_LIST = "immutable_enchantments"
|
||||
|
||||
const val INCLUDE_LEFT_ENCHANTMENT_FOR_COST = "include_left_enchantment_for_cost"
|
||||
|
||||
// Monetary configs
|
||||
const val MONETARY_USAGE_ROOT = "monetary_cost"
|
||||
|
|
@ -110,6 +112,8 @@ object ConfigOptions {
|
|||
|
||||
const val DEFAULT_ENCHANT_COUNT_LIMIT = -1
|
||||
|
||||
const val DEFAULT_INCLUDE_LEFT_ENCHANTMENT_FOR_COST = false
|
||||
|
||||
// Color related config
|
||||
const val DEFAULT_ALLOW_COLOR_CODE = false
|
||||
const val DEFAULT_ALLOW_HEXADECIMAL_COLOR = false
|
||||
|
|
@ -434,6 +438,13 @@ object ConfigOptions {
|
|||
?: DEFAULT_ENCHANT_COUNT_LIMIT
|
||||
}
|
||||
|
||||
val includeLeftEnchantmentForCost: Boolean
|
||||
get() {
|
||||
return ConfigHolder.DEFAULT_CONFIG
|
||||
.config
|
||||
.getBoolean(INCLUDE_LEFT_ENCHANTMENT_FOR_COST, DEFAULT_INCLUDE_LEFT_ENCHANTMENT_FOR_COST)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to show debug logging
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ object AnvilMergeLogic {
|
|||
if (hasChanged) {
|
||||
resultItem.setEnchantmentsUnsafe(newEnchants)
|
||||
// Calculate enchantment cost
|
||||
AnvilXpUtil.getRightValues(second, resultItem, cost)
|
||||
AnvilXpUtil.getRightValues(first, second, resultItem, cost)
|
||||
}
|
||||
|
||||
// Calculate repair cost
|
||||
|
|
|
|||
|
|
@ -240,17 +240,21 @@ object AnvilXpUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* Function to calculate right enchantment values
|
||||
* Function to calculate enchantments values
|
||||
* it include enchantment placed on final item and conflicting enchantment
|
||||
*/
|
||||
fun getRightValues(right: ItemStack, result: ItemStack, cost: AnvilCost) {
|
||||
fun getRightValues(left: ItemStack, right: ItemStack, result: ItemStack, cost: AnvilCost) {
|
||||
// Calculate right value and illegal enchant penalty
|
||||
|
||||
val rightIsFormBook = right.isEnchantedBook()
|
||||
val rightEnchs = right.findEnchantments()
|
||||
val resultEnchs = result.findEnchantments()
|
||||
val resultEnchsKeys = HashMap(resultEnchs)
|
||||
|
||||
for (enchantment in right.findEnchantments()) {
|
||||
var rightValue = 0
|
||||
var leftValue = 0
|
||||
|
||||
for (enchantment in rightEnchs) {
|
||||
// count enchant as illegal enchant if it conflicts with another enchant or not in result
|
||||
if ((enchantment.key !in resultEnchsKeys)) {
|
||||
resultEnchsKeys[enchantment.key] = enchantment.value
|
||||
|
|
@ -272,13 +276,31 @@ object AnvilXpUtil {
|
|||
|
||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
|
||||
val value = resultLevel * enchantmentMultiplier
|
||||
CustomAnvil.log("Value for ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||
cost.enchantment += value
|
||||
CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||
rightValue += value
|
||||
|
||||
}
|
||||
if(ConfigOptions.includeLeftEnchantmentForCost) {
|
||||
val leftIsFormBook = left.isEnchantedBook()
|
||||
val leftEnchs = left.findEnchantments()
|
||||
for (enchantment in leftEnchs) {
|
||||
// Do not process enchantment that are present on the sacrifice
|
||||
if(rightEnchs.contains(enchantment.key)) continue
|
||||
|
||||
val resultLevel = resultEnchs.getOrDefault(enchantment.key, 0)
|
||||
|
||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, leftIsFormBook)
|
||||
val value = resultLevel * enchantmentMultiplier
|
||||
CustomAnvil.log("Value for left item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||
leftValue += value
|
||||
}
|
||||
}
|
||||
|
||||
cost.enchantment = rightValue + leftValue
|
||||
CustomAnvil.log(
|
||||
"Calculated right values: " +
|
||||
"rightValue: ${cost.enchantment}, " +
|
||||
"rightValue: ${rightValue}, " +
|
||||
"leftValue: ${leftValue}, " +
|
||||
"illegalPenalty: ${cost.illegalPenalty}"
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue