NyaaCat / NyaaCore

Code infrastructure for all NyaaCat plugins
MIT License
22 stars 12 forks source link

1.18 no getTag() #40

Open fafa-junhe opened 2 years ago

fafa-junhe commented 2 years ago

getTag() only exists on 1.17 version.

    public static Optional<Integer> getInt(ItemStack item, String key) {
        Optional<net.minecraft.world.item.ItemStack> item1;
        try {
            item1 = getItem(item);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            return Optional.empty();
        }
        if (item1.isEmpty()) return Optional.empty();
        NBTTagCompound tag = item1.get().getTag(); // exception
        if (tag == null) return Optional.empty();
        return !tag.contains(key) ? Optional.empty() : Optional.of(tag.getInt(key));
    }

from https://github.com/NyaaCat/NyaaCore/blob/1.18/src/main/java/cat/nyaa/nyaacore/utils/ItemTagUtils.java

Takaranoao commented 1 year ago

I don't have this problem here