better log

This commit is contained in:
alexcrea 2025-04-30 16:42:37 +02:00
parent f9da8ad6ef
commit 41f785a6f6
No known key found for this signature in database
GPG key ID: 027DD67D2D3280C5

View file

@ -31,8 +31,9 @@ class EnchantConflictManager {
// 1.20.5 compatibility TODO better update system // 1.20.5 compatibility TODO better update system
private val SWEEPING_EDGE_ENCHANT = Collections.singletonList<CAEnchantment>( private val SWEEPING_EDGE_ENCHANT = Collections.singletonList<CAEnchantment>(
CAEnchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) ?: CAEnchantment.getByKey(NamespacedKey.minecraft("sweeping_edge"))
CAEnchantment.getByKey(Enchantment.SWEEPING_EDGE.key)) ?: CAEnchantment.getByKey(Enchantment.SWEEPING_EDGE.key)
)
} }
@ -169,22 +170,31 @@ class EnchantConflictManager {
return group return group
} }
fun isConflicting(appliedEnchants: Map<CAEnchantment, Int>, item: ItemStack, newEnchant: CAEnchantment): ConflictType { fun isConflicting(
appliedEnchants: Map<CAEnchantment, Int>,
item: ItemStack,
newEnchant: CAEnchantment
): ConflictType {
val mat = item.type val mat = item.type
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}") CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}")
val conflictList = newEnchant.conflicts val conflictList = newEnchant.conflicts
var result = ConflictType.NO_CONFLICT var result = ConflictType.NO_CONFLICT
for (conflict in conflictList) { for (conflict in conflictList) {
CustomAnvil.verboseLog("Is against $conflict") val isBigConflict = conflict.getEnchants().size > 1
if (result == ConflictType.ITEM_CONFLICT && !isBigConflict) {
CustomAnvil.verboseLog("skipping small conflict ${conflict.name}")
continue
}
val allowed = conflict.allowed(appliedEnchants.keys, mat) val allowed = conflict.allowed(appliedEnchants.keys, mat)
CustomAnvil.verboseLog("Was against $conflict and conflicting: ${!allowed} ") CustomAnvil.verboseLog("Was against $conflict and conflicting: ${!allowed} ")
if (!allowed) { if (!allowed) {
if (conflict.getEnchants().size <= 1) { if (conflict.getEnchants().size <= 1) {
result = ConflictType.ITEM_CONFLICT result = ConflictType.ITEM_CONFLICT
CustomAnvil.verboseLog("Small conflict, continuing") CustomAnvil.verboseLog("Small conflict (${conflict.name}), continuing")
} else { } else {
CustomAnvil.verboseLog("Big conflict, probably stoping") CustomAnvil.verboseLog("Big conflict (${conflict.name}), stopping")
return ConflictType.ENCHANTMENT_CONFLICT return ConflictType.ENCHANTMENT_CONFLICT
} }
} }
@ -195,6 +205,7 @@ class EnchantConflictManager {
if (appliedEnchant is AdditionalTestEnchantment) { if (appliedEnchant is AdditionalTestEnchantment) {
val doConflict = appliedEnchant.isEnchantConflict(immutableEnchants, mat) val doConflict = appliedEnchant.isEnchantConflict(immutableEnchants, mat)
if (doConflict) { if (doConflict) {
CustomAnvil.verboseLog("Big conflict by additional test, stopping")
return ConflictType.ENCHANTMENT_CONFLICT return ConflictType.ENCHANTMENT_CONFLICT
} }
@ -217,8 +228,8 @@ class EnchantConflictManager {
val newItem = item.clone() val newItem = item.clone()
CAEnchantment.clearEnchants(newItem) CAEnchantment.clearEnchants(newItem)
enchantments.forEach{ enchantments.forEach { enchantment ->
enchantment -> enchantment.key.addEnchantmentUnsafe(newItem, enchantment.value) enchantment.key.addEnchantmentUnsafe(newItem, enchantment.value)
} }
return newItem return newItem