Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ItemFrameMeta API #11271

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

TehBrian
Copy link
Contributor

@TehBrian TehBrian commented Aug 15, 2024

Draft PR; CraftMetaItemFrame is (probably) currently non-functional, but I wanted to share progress so far.

The second commit is a rewrite based on #11107, and I'm waiting on that PR to finalize changes here.

Concerns:

  • Do we have to care about entity ID being different for glow item frames? Does that warrant a separate GlowItemFrameMeta? Entity IDs only even seem to matter on spawn eggs.
  • Should CraftMetaItemFrame be wrapped in // Paper? It's in org.bukkit (because there were a nightmarish amount of access transformers until I moved it from io.papermc), but it's also a new file.

Please let me know your thoughts :D

@TehBrian

This comment was marked as outdated.

patches/server/1046-add-ItemFrameMeta-API.patch Outdated Show resolved Hide resolved
patches/server/1046-add-ItemFrameMeta-API.patch Outdated Show resolved Hide resolved
+ Material.GLOW_ITEM_FRAME
+ );
+
+ static final ItemMetaKeyType<CustomData> ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.ENTITY_DATA, "EntityTag", "entity-tag");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is NBT supposed to be entity-tag instead of EntityTag?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity-tag for both, so you can remove that param

@TehBrian TehBrian marked this pull request as ready for review August 17, 2024 11:16
@TehBrian TehBrian requested a review from a team as a code owner August 17, 2024 11:16
+@DelegateDeserialization(SerializableMeta.class)
+public class CraftMetaItemFrame extends CraftMetaItem implements ItemFrameMeta {
+
+ private static final Set<Material> ENTITY_TAGGABLE_MATERIALS = Sets.newHashSet(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set.of

Comment on lines +169 to +172
+ @Override
+ void serializeInternal(Map<String, Tag> internalTags) {
+ // correctly serialised as entity tag.
+ }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just don't override this at all.

Comment on lines +145 to +152
+ SerializableMeta.getObjectOptionally(Boolean.class, map, FIXED.BUKKIT, true).ifPresent((value) -> {
+ populateTagIfNull();
+ this.entityTag.putBoolean(FIXED.NBT, value);
+ });
+ SerializableMeta.getObjectOptionally(Boolean.class, map, INVISIBLE.BUKKIT, true).ifPresent((value) -> {
+ populateTagIfNull();
+ this.entityTag.putBoolean(INVISIBLE.NBT, value);
+ });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this is needed. We are always serializing it as a full nbt tag instead of splitting it up. The only reason ArmorStand has similar logic is were weren't always doing that. But since this is brand new, we can do this.

+ try {
+ this.entityTag = NbtIo.readCompressed(buf, NbtAccounter.unlimitedHeap());
+ } catch (IOException ex) {
+ Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make this an slf4j logger in a private static field like LogUtils.getClassLogger()

+
+import org.bukkit.inventory.meta.ItemMeta;
+
+public interface ItemFrameMeta extends ItemMeta {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we making the same mistake here lots of other ItemMetas have done? technically there are 3 states for every boolean. It could be true, false, or not present in the custom data.

Comment on lines +178 to +180
+ if (this.entityTag != null) {
+ tag.put(CraftMetaItemFrame.ENTITY_TAG, CustomData.of(this.entityTag));
+ }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to do a sanity check here to make sure the custom data compound, if its not empty, that it has the "id" key/value in it. If it doesn't and its not empty, it'll throw errors all over the place as the codec requires it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Changes required
Development

Successfully merging this pull request may close these issues.

5 participants