Hacky fix for 1.20.5.

Also:
- version up
- metric fix (expected as config was changed)
- Prepared for long term update system
This commit is contained in:
alexcrea 2024-04-28 03:20:32 +02:00
parent 2861238f58
commit 46ff34deea
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
7 changed files with 43 additions and 11 deletions

View file

@ -217,7 +217,7 @@ object ConfigOptions {
* Get the given [enchantment]'s limit
*/
fun enchantLimit(enchantment: Enchantment): Int {
val path = "${ENCHANT_LIMIT_ROOT}.${enchantment.enchantmentName}"
val path = "${ENCHANT_LIMIT_ROOT}.${getEnchantKey(enchantment)}"
return CustomAnvil.instance
.config
.getInt(path, defaultEnchantLimit)
@ -234,7 +234,7 @@ object ConfigOptions {
isFromBook: Boolean
): Int {
val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM
val path = "${ENCHANT_VALUES_ROOT}.${enchantment.enchantmentName}.$typeKey"
val path = "${ENCHANT_VALUES_ROOT}.${getEnchantKey(enchantment)}.$typeKey"
return CustomAnvil.instance
.config
.getInt(path, DEFAULT_ENCHANT_VALUE)
@ -242,6 +242,13 @@ object ConfigOptions {
?: 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"
}
return enchantKey
}
/**
* Get an array of key of basic config options
*/

View file

@ -24,6 +24,12 @@ class EnchantConflictManager {
// Default name for a joining group
private const val DEFAULT_GROUP_NAME = "joinedGroup"
// 1.20.5 compatibility TODO better update system
private val SWEEPING_EDGE_ENCHANT =
Enchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) ?:
Enchantment.SWEEPING_EDGE
}
private lateinit var conflictMap: HashMap<Enchantment, ArrayList<EnchantConflictGroup>>
@ -76,8 +82,7 @@ class EnchantConflictManager {
// Read and add enchantment to conflict
val enchantList = section.getStringList(ENCH_LIST_PATH)
for (enchantName in enchantList) {
val enchantKey = NamespacedKey.minecraft(enchantName)
val enchant = Enchantment.getByKey(enchantKey)
val enchant = getEnchantByName(enchantName);
if (enchant == null) {
if (!futureUse) {
CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName")
@ -95,6 +100,20 @@ class EnchantConflictManager {
return conflict
}
private fun getEnchantByName(enchantName: String): Enchantment? {
// Teporary solution for 1.20.5
when(enchantName){
"sweeping", "sweeping_edge" -> {
return SWEEPING_EDGE_ENCHANT
}
}
val enchantKey = NamespacedKey.minecraft(enchantName)
return Enchantment.getByKey(enchantKey);
}
private fun createConflictObject(
section: ConfigurationSection,
itemManager: ItemGroupManager,

View file

@ -8,9 +8,9 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
object MetricsUtil {
private const val baseConfigHash = -1592940914
private const val enchantLimitsConfigHash = -1014133828
private const val enchantValuesConfigHash = 1072574774
private const val enchantConflictConfigHash = 1406650190
private const val enchantLimitsConfigHash = -275034280
private const val enchantValuesConfigHash = -17048020
private const val enchantConflictConfigHash = 546475833
private const val itemGroupsConfigHash = 1406650190
private const val unitRepairItemConfigHash = 536871958
private const val customAnvilCraftConfigHash = 0

View file

@ -72,6 +72,7 @@ enchant_limits:
fire_aspect: 2
looting: 3
sweeping: 3
sweeping_edge: 3
efficiency: 5
unbreaking: 3
fortune: 3
@ -208,6 +209,9 @@ enchant_values:
sweeping:
item: 4
book: 2
sweeping_edge:
item: 4
book: 2
thorns:
item: 8
book: 4
@ -223,3 +227,5 @@ debug_log: false
# Whether to show verbose debug logging
debug_log_verbose: false
configVersion: 1.4.3

View file

@ -147,8 +147,8 @@ restriction_soul_speed:
enchantments: [ soul_speed ]
notAffectedGroups: [ enchanted_book, boots ]
restriction_sweeping:
enchantments: [ sweeping ]
restriction_sweeping_edge:
enchantments: [ sweeping, sweeping_edge ]
notAffectedGroups: [ enchanted_book, swords ]
# Do not exist in 1.18, that mean useInFuture will be set to true

View file

@ -1,7 +1,7 @@
main: io.delilaheve.CustomAnvil
name: CustomAnvil
prefix: "Custom Anvil"
version: 1.4.2a
version: 1.4.3a
description: Allow to customise anvil mechanics
api-version: 1.18
load: POSTWORLD