9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-04 15:41:38 +00:00
This commit is contained in:
XiaoMoMi
2025-09-04 20:59:51 +08:00
parent 16f1ed54e1
commit c71fe99395
5 changed files with 169 additions and 51 deletions

View File

@@ -424,6 +424,7 @@ public class ComponentItemFactory1_20_5 extends BukkitItemFactory<ComponentItemW
@Override
protected Optional<Enchantment> getEnchantment(ComponentItemWrapper item, Key key) {
Object enchant = item.getComponentExact(ComponentTypes.ENCHANTMENTS);
if (enchant == null) return Optional.empty();
try {
Map<String, Integer> map = EnchantmentUtils.toMap(enchant);
Integer level = map.get(key.toString());

View File

@@ -4,6 +4,7 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflect
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public final class EnchantmentUtils {
@@ -11,6 +12,7 @@ public final class EnchantmentUtils {
@SuppressWarnings("unchecked")
public static Map<String, Integer> toMap(Object itemEnchantments) throws ReflectiveOperationException {
if (itemEnchantments == null) return Map.of();
Map<String, Integer> map = new HashMap<>();
Map<Object, Integer> enchantments = (Map<Object, Integer>) CoreReflections.field$ItemEnchantments$enchantments.get(itemEnchantments);