mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add merge level limit (#32)
Add merge level limit (aka "max before merge" or "disable merge over")
This commit is contained in:
parent
a915d5ad80
commit
a00bb919f4
5 changed files with 128 additions and 7 deletions
|
|
@ -41,6 +41,8 @@ object ConfigOptions {
|
|||
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
||||
const val ENCHANT_VALUES_ROOT = "enchant_values"
|
||||
|
||||
const val DISABLE_MERGE_OVER_ROOT = "disable-merge-over"
|
||||
|
||||
// Keys for specific enchantment values
|
||||
private const val KEY_BOOK = "book"
|
||||
private const val KEY_ITEM = "item"
|
||||
|
|
@ -110,6 +112,9 @@ object ConfigOptions {
|
|||
// Default value for an enchantment multiplier
|
||||
private const val DEFAULT_ENCHANT_VALUE = 0
|
||||
|
||||
// Default max before merge disabled (negative mean enabled)
|
||||
const val DEFAULT_MAX_BEFORE_MERGE_DISABLED = -1;
|
||||
|
||||
// -------------
|
||||
// Get methods
|
||||
// -------------
|
||||
|
|
@ -374,4 +379,33 @@ object ConfigOptions {
|
|||
return DEFAULT_ENCHANT_VALUE
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given [enchantmentName]'s level before merge is disabled
|
||||
* a negative value would mean never disabled
|
||||
*/
|
||||
fun maxBeforeMergeDisabled(enchantment: CAEnchantment): Int {
|
||||
return maxBeforeMergeDisabled(enchantment.enchantmentName)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given [enchantmentName]'s level before merge is disabled
|
||||
* a negative value would mean never disabled
|
||||
*/
|
||||
private fun maxBeforeMergeDisabled(enchantmentName: String) : Int {
|
||||
// find if set
|
||||
val path = "${DISABLE_MERGE_OVER_ROOT}.$enchantmentName"
|
||||
|
||||
val value = CustomAnvil.instance
|
||||
.config
|
||||
.getInt(path, DEFAULT_MAX_BEFORE_MERGE_DISABLED)
|
||||
.takeIf { it in ENCHANT_LIMIT_RANGE }
|
||||
?: DEFAULT_MAX_BEFORE_MERGE_DISABLED;
|
||||
|
||||
if((value == DEFAULT_MAX_BEFORE_MERGE_DISABLED) && (enchantmentName == "sweeping_edge")){
|
||||
return maxBeforeMergeDisabled("sweeping")
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,11 @@ object EnchantmentUtil {
|
|||
}
|
||||
// ... and they're the same level
|
||||
else {
|
||||
// try to increase the enchantment level by 1
|
||||
// We test if it is allowed to merge at this level
|
||||
val maxBeforeDisabled = ConfigOptions.maxBeforeMergeDisabled(enchantment)
|
||||
if((maxBeforeDisabled > 0) && (oldLevel >= maxBeforeDisabled)) return@forEach
|
||||
|
||||
// Now we increase the enchantment level by 1
|
||||
var newLevel = oldLevel + 1
|
||||
newLevel = max(min(newLevel, maxLevel), oldLevel)
|
||||
this[enchantment] = newLevel
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue