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
|
|
@ -76,6 +76,8 @@ object ConfigOptions {
|
||||||
|
|
||||||
const val IMMUTABLE_ENCHANTMENT_LIST = "immutable_enchantments"
|
const val IMMUTABLE_ENCHANTMENT_LIST = "immutable_enchantments"
|
||||||
|
|
||||||
|
const val INCLUDE_LEFT_ENCHANTMENT_FOR_COST = "include_left_enchantment_for_cost"
|
||||||
|
|
||||||
// Monetary configs
|
// Monetary configs
|
||||||
const val MONETARY_USAGE_ROOT = "monetary_cost"
|
const val MONETARY_USAGE_ROOT = "monetary_cost"
|
||||||
const val SHOULD_USE_MONEY = "$MONETARY_USAGE_ROOT.enabled"
|
const val SHOULD_USE_MONEY = "$MONETARY_USAGE_ROOT.enabled"
|
||||||
|
|
@ -110,6 +112,8 @@ object ConfigOptions {
|
||||||
|
|
||||||
const val DEFAULT_ENCHANT_COUNT_LIMIT = -1
|
const val DEFAULT_ENCHANT_COUNT_LIMIT = -1
|
||||||
|
|
||||||
|
const val DEFAULT_INCLUDE_LEFT_ENCHANTMENT_FOR_COST = false
|
||||||
|
|
||||||
// Color related config
|
// Color related config
|
||||||
const val DEFAULT_ALLOW_COLOR_CODE = false
|
const val DEFAULT_ALLOW_COLOR_CODE = false
|
||||||
const val DEFAULT_ALLOW_HEXADECIMAL_COLOR = false
|
const val DEFAULT_ALLOW_HEXADECIMAL_COLOR = false
|
||||||
|
|
@ -434,6 +438,13 @@ object ConfigOptions {
|
||||||
?: DEFAULT_ENCHANT_COUNT_LIMIT
|
?: 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
|
* Whether to show debug logging
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ object AnvilMergeLogic {
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
resultItem.setEnchantmentsUnsafe(newEnchants)
|
resultItem.setEnchantmentsUnsafe(newEnchants)
|
||||||
// Calculate enchantment cost
|
// Calculate enchantment cost
|
||||||
AnvilXpUtil.getRightValues(second, resultItem, cost)
|
AnvilXpUtil.getRightValues(first, second, resultItem, cost)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate repair 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
|
* 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
|
// Calculate right value and illegal enchant penalty
|
||||||
|
|
||||||
val rightIsFormBook = right.isEnchantedBook()
|
val rightIsFormBook = right.isEnchantedBook()
|
||||||
|
val rightEnchs = right.findEnchantments()
|
||||||
val resultEnchs = result.findEnchantments()
|
val resultEnchs = result.findEnchantments()
|
||||||
val resultEnchsKeys = HashMap(resultEnchs)
|
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
|
// count enchant as illegal enchant if it conflicts with another enchant or not in result
|
||||||
if ((enchantment.key !in resultEnchsKeys)) {
|
if ((enchantment.key !in resultEnchsKeys)) {
|
||||||
resultEnchsKeys[enchantment.key] = enchantment.value
|
resultEnchsKeys[enchantment.key] = enchantment.value
|
||||||
|
|
@ -272,13 +276,31 @@ object AnvilXpUtil {
|
||||||
|
|
||||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
|
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
|
||||||
val value = resultLevel * enchantmentMultiplier
|
val value = resultLevel * enchantmentMultiplier
|
||||||
CustomAnvil.log("Value for ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||||
cost.enchantment += value
|
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(
|
CustomAnvil.log(
|
||||||
"Calculated right values: " +
|
"Calculated right values: " +
|
||||||
"rightValue: ${cost.enchantment}, " +
|
"rightValue: ${rightValue}, " +
|
||||||
|
"leftValue: ${leftValue}, " +
|
||||||
"illegalPenalty: ${cost.illegalPenalty}"
|
"illegalPenalty: ${cost.illegalPenalty}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,9 @@ permission_needed_for_dialog_rename: false
|
||||||
# For practical reason. this only work when dialog rename is enabled
|
# For practical reason. this only work when dialog rename is enabled
|
||||||
dialog_rename_keep_user_text: true
|
dialog_rename_keep_user_text: true
|
||||||
|
|
||||||
|
# Also count left item enchantments for the final price
|
||||||
|
include_left_enchantment_for_cost: false
|
||||||
|
|
||||||
# Override limits for specific enchants
|
# Override limits for specific enchants
|
||||||
#
|
#
|
||||||
# Enchantments not listed here will use the value of default_limit
|
# Enchantments not listed here will use the value of default_limit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue