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:
alexcrea 2024-06-22 14:59:56 +02:00
parent 19806773a6
commit 5e42bf3a90
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
5 changed files with 83 additions and 51 deletions

View file

@ -0,0 +1,34 @@
package xyz.alexcrea.cuanvil.enchant;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public interface AdditionalTestEnchantment {
/**
* Test if the provided enchantments can be compatible with this enchantment. only non-Custom Anvil conflict.
* @param enchantments Immutable map of validated enchantments for the item.
* @param itemMat Material of the tested item.
* @return If there is a conflict with the enchantments.
*/
boolean isEnchantConflict(
@NotNull Map<CAEnchantment, Integer> enchantments,
@NotNull Material itemMat);
/**
* Test if the provided item can be compatible with this enchantment. only non-Custom Anvil conflict.
* @param enchantments Immutable map of validated enchantments for the item.
* @param itemMat Material of the tested item.
* @param item Provide a new instance of the used item stack with the partial enchantment applied.
* @return If there is a conflict with the enchantment and the item.
*/
boolean isItemConflict(
@NotNull Map<CAEnchantment, Integer> enchantments,
@NotNull Material itemMat,
@NotNull ItemStack item);
}

View file

@ -89,19 +89,6 @@ public interface CAEnchantment {
*/
@NotNull Collection<EnchantConflictGroup> getConflicts();
/**
* Test if the provided item can be compatible with this enchantment. only non-Custom Anvil conflict.
* @param baseEnchantments Validated enchantments for the item.
* @param itemMat Material of the tested item.
* @param itemSupply Provide a new instance of used item stack but with baseEnchantments as enchantments.
* @return Type of conflict this enchantment has with the provided item.
*/
@NotNull
ConflictType testOtherConflicts(
@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply);
/**
* Get current level of the enchantment.
* @param item Item to search the level for.

View file

@ -112,12 +112,4 @@ public abstract class CAEnchantmentBase implements CAEnchantment {
return conflicts;
}
@Override
public @NotNull ConflictType testOtherConflicts(
@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply) {
return ConflictType.NO_CONFLICT;
}
}

View file

@ -7,12 +7,13 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment;
import xyz.alexcrea.cuanvil.group.ConflictType;
import java.util.Map;
import java.util.function.Supplier;
public class CAEcoEnchant extends CAVanillaEnchantment {
public class CAEcoEnchant extends CAVanillaEnchantment implements AdditionalTestEnchantment {
private final @NotNull EcoEnchant ecoEnchant;
@ -22,36 +23,37 @@ public class CAEcoEnchant extends CAVanillaEnchantment {
}
@Override
public @NotNull ConflictType testOtherConflicts(
@NotNull Map<CAEnchantment, Integer> baseEnchantments,
@NotNull Material itemMat,
@NotNull Supplier<ItemStack> itemSupply) {
if(!baseEnchantments.isEmpty()){
if(this.ecoEnchant.getConflictsWithEverything()){
return ConflictType.ENCHANTMENT_CONFLICT;
public boolean isEnchantConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat) {
if(!enchantments.isEmpty()) {
if (this.ecoEnchant.getConflictsWithEverything()) {
return true;
}
for (CAEnchantment other : baseEnchantments.keySet()) {
if(other instanceof CAVanillaEnchantment otherVanilla //TODO ISSUE FOUND: if vanilla is applied first conflcit is ignored. maybe export only enchantment conflict but keep target from ecoEnchant.
for (CAEnchantment other : enchantments.keySet()) {
if(other instanceof CAVanillaEnchantment otherVanilla
&& this.ecoEnchant.conflictsWith(otherVanilla.getEnchant())){
return ConflictType.ENCHANTMENT_CONFLICT;
return true;
}
}
}
return false;
}
// Allow enchanted book
@Override
public boolean isItemConflict(@NotNull Map<CAEnchantment, Integer> enchantments,
@NotNull Material itemMat,
@NotNull ItemStack item) {
if(Material.ENCHANTED_BOOK.equals(itemMat)){
return ConflictType.NO_CONFLICT;
return false;
}
ItemStack item = itemSupply.get();
for (EnchantmentTarget target : this.ecoEnchant.getTargets()) {
if(target.matches(item)){
return ConflictType.NO_CONFLICT;
return false;
}
}
return ConflictType.ITEM_CONFLICT;
return true;
}
}