Better system for handling 1.20.5 sweeping edge.

This commit is contained in:
alexcrea 2024-04-28 04:02:03 +02:00
parent 45401edbf4
commit 32b535efda
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
2 changed files with 48 additions and 10 deletions

View file

@ -39,6 +39,7 @@ public enum EnchantmentProperties {
SOUL_SPEED(EnchantmentRarity.VERY_RARE),
SWIFT_SNEAK(EnchantmentRarity.VERY_RARE),
SWEEPING(EnchantmentRarity.RARE),
SWEEPING_EDGE(EnchantmentRarity.RARE),
THORNS(EnchantmentRarity.VERY_RARE),
UNBREAKING(EnchantmentRarity.UNCOMMON),
VANISHING_CURSE(EnchantmentRarity.VERY_RARE);

View file

@ -217,12 +217,32 @@ object ConfigOptions {
* Get the given [enchantment]'s limit
*/
fun enchantLimit(enchantment: Enchantment): Int {
val path = "${ENCHANT_LIMIT_ROOT}.${getEnchantKey(enchantment)}"
return enchantLimit(enchantment.enchantmentName)
}
/**
* Get the given [enchantmentName]'s limit
*/
private fun enchantLimit(enchantmentName: String): Int {
val default = getDefaultLevel(enchantmentName)
val path = "${ENCHANT_LIMIT_ROOT}.$enchantmentName"
return CustomAnvil.instance
.config
.getInt(path, defaultEnchantLimit)
.getInt(path, default)
.takeIf { it in ENCHANT_LIMIT_RANGE }
?: defaultEnchantLimit
?: default
}
/**
* Get default value if enchantment do not exist on config
*/
private fun getDefaultLevel(enchantmentName: String, // compatibility with 1.20.5. TODO better update system
) : Int {
if(enchantmentName == "sweeping_edge"){
return enchantLimit("sweeping")
}
return defaultEnchantLimit
}
/**
@ -233,22 +253,39 @@ object ConfigOptions {
enchantment: Enchantment,
isFromBook: Boolean
): Int {
return enchantmentValue(enchantment.enchantmentName, isFromBook)
}
/**
* Get the appropriate [enchantmentName]'s value dependent on whether
* it's source [isFromBook]
*/
private fun enchantmentValue(
enchantmentName: String,
isFromBook: Boolean
): Int {
val default = getDefaultValue(enchantmentName, isFromBook)
val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM
val path = "${ENCHANT_VALUES_ROOT}.${getEnchantKey(enchantment)}.$typeKey"
val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey"
return CustomAnvil.instance
.config
.getInt(path, DEFAULT_ENCHANT_VALUE)
.getInt(path, default)
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
?: DEFAULT_ENCHANT_VALUE
}
fun getEnchantKey(enchantment: Enchantment) : String{
val enchantKey = enchantment.enchantmentName
if(enchantKey == "sweeping_edge"){ // compatibility with 1.20.5. TODO better update system
return "sweeping"
/**
* Get default value if enchantment do not exist on config
*/
private fun getDefaultValue(enchantmentName: String, // compatibility with 1.20.5. TODO better update system
isFromBook: Boolean) : Int {
if(enchantmentName == "sweeping_edge"){
return enchantmentValue("sweeping", isFromBook)
}
return enchantKey
return DEFAULT_ENCHANT_VALUE
}
/**
* Get an array of key of basic config options
*/