mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Fix enchantment being applied to the left item when trying to combine.
Fix conflict not being applied on some situation.
This commit is contained in:
parent
19806773a6
commit
5e42bf3a90
5 changed files with 83 additions and 51 deletions
|
|
@ -5,9 +5,11 @@ import org.bukkit.NamespacedKey
|
|||
import org.bukkit.configuration.ConfigurationSection
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||
import java.util.function.Supplier
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class EnchantConflictManager {
|
||||
|
||||
|
|
@ -166,23 +168,38 @@ class EnchantConflictManager {
|
|||
}
|
||||
}
|
||||
|
||||
// Test conflict with other conflict system.
|
||||
val otherConflict = newEnchant.testOtherConflicts(appliedEnchants, mat, reEnchantSupplier(item, appliedEnchants))
|
||||
val immutableEnchants = Collections.unmodifiableMap(appliedEnchants)
|
||||
for (appliedEnchant in appliedEnchants) {
|
||||
if(appliedEnchant is AdditionalTestEnchantment){
|
||||
val doConflict = appliedEnchant.isEnchantConflict(immutableEnchants, mat)
|
||||
if(doConflict){
|
||||
return ConflictType.ENCHANTMENT_CONFLICT
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return result.getWorstConflict(otherConflict)
|
||||
if((result != ConflictType.ITEM_CONFLICT) && (newEnchant is AdditionalTestEnchantment)){
|
||||
val partialItem = createPartialResult(item, immutableEnchants)
|
||||
|
||||
if(newEnchant.isItemConflict(immutableEnchants, mat, partialItem)){
|
||||
return ConflictType.ITEM_CONFLICT
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private fun reEnchantSupplier(item: ItemStack, enchantments: Map<CAEnchantment, Int>): Supplier<ItemStack> {
|
||||
return Supplier {
|
||||
val newItem = item.clone()
|
||||
private fun createPartialResult(item: ItemStack, enchantments: Map<CAEnchantment, Int>): ItemStack {
|
||||
val newItem = item.clone()
|
||||
|
||||
CAEnchantment.clearEnchants(newItem)
|
||||
enchantments.forEach{//TODO maybe bulk add if possible
|
||||
enchantment -> enchantment.key.addEnchantmentUnsafe(item, enchantment.value)
|
||||
}
|
||||
|
||||
return@Supplier newItem
|
||||
CAEnchantment.clearEnchants(newItem)
|
||||
enchantments.forEach{//TODO maybe bulk add if possible
|
||||
enchantment -> enchantment.key.addEnchantmentUnsafe(newItem, enchantment.value)
|
||||
}
|
||||
|
||||
return newItem
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue