Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Itemstack Glint API

Open Machine-Maker opened this issue 3 years ago • 13 comments

Closes #5274

First time touching item meta stuff

Unsure of a few things, mainly the behavior of this elsewhere in the codebase, like anvils/grindstones. Currently you can remove the glint with the grindstone (and get no xp), and you can put enchanted books on the item, BUT that removes the empty NBTTagCompound, so removing that enchant will make the item lose it's glint.

Issue relating to this: #5723

Machine-Maker avatar May 25 '21 19:05 Machine-Maker

Not sure how I feel about this because all this seems like is a helper method for adding enchantments while making it seem like an inherent property an ItemStack can have.

Also, has this been tested with items that already have enchantments on them?

JRoy avatar May 25 '21 19:05 JRoy

I didn’t specifically test that JRoy, but the result would be an Enchantments nbt list with a normal tagcompound and an empty one. I don’t see how that would behave differently from a list with just an empty one

Machine-Maker avatar May 25 '21 19:05 Machine-Maker

Won't that still show up on the item? I dont know how the client determines what shows up or not if its missing an equivalent on the client side.

Machine-Maker avatar May 25 '21 19:05 Machine-Maker

You can easily create "invisible" enchantments, even with API (with no hide tag required).

kennytv avatar May 25 '21 19:05 kennytv

Aside from Bukkit, the most basic format a client accepts perfectly fine is something along the lines of this (just some Via code stuffed somewhere to get the gist of it):

            // Add dummy enchant for the glow effect if there are no actual enchantments left
            if (!storedEnchant && enchantments.size() == 0) {
                CompoundTag dummyEnchantment = new CompoundTag();
                dummyEnchantment.put("id", new StringTag()); // String value empty = ""
                dummyEnchantment.put("lvl", new ShortTag((short) 0));
                enchantments.add(dummyEnchantment);
            }

kennytv avatar May 25 '21 20:05 kennytv

Curious, how does normal items have the enchantment glint without any enchantments such as the golden apple?

HexedHero avatar May 25 '21 21:05 HexedHero

Pretty sure those are hardcoded by on the client.

Machine-Maker avatar May 25 '21 21:05 Machine-Maker

image (yarn mappings)

Owen1212055 avatar May 25 '21 21:05 Owen1212055

image (yarn mappings)

Yes, exactly, I don’t think that is ever passed between the client and server, hence, hardcoded.

Machine-Maker avatar May 25 '21 21:05 Machine-Maker

Can we just ask Mojang for an NBT flag it seems super easy.

HexedHero avatar May 25 '21 22:05 HexedHero

I've dropped that suggestion in a place where we often speak to mojang devs, will see if they have any comments on this as the general handling of this always feels a bit icky, so I'd love to avoid having to do something like this as supported API

electronicboy avatar May 25 '21 23:05 electronicboy

@electronicboy Do you have any news on it ?

nicolasvac avatar Oct 18 '21 14:10 nicolasvac

In general, this can prolly be closed? Hopefully waiting on mojang for this, but with my item property API these types of items will work just fine in the future due to no item meta processing being done.

Owen1212055 avatar Dec 23 '22 18:12 Owen1212055

Closing in favor of the item property api.

Owen1212055 avatar Apr 02 '23 18:04 Owen1212055

in 1.20.5, we will be getting components, and one is override_enchantment_glint

lowercasebtw avatar Apr 13 '24 23:04 lowercasebtw