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

Incorrect behavior for ItemMeta#serialize() method #938

Open
2 tasks done
Thorinwasher opened this issue Dec 27, 2023 · 0 comments
Open
2 tasks done

Incorrect behavior for ItemMeta#serialize() method #938

Thorinwasher opened this issue Dec 27, 2023 · 0 comments

Comments

@Thorinwasher
Copy link
Contributor

Thorinwasher commented Dec 27, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest version of MockBukkit?

  • I am using the latest version of MockBukkit.

Minecraft Version

1.20

Describe the bug

The method ItemMetaMock does not follow the same behavior as that on a real paper server instance (1.20.4). There was also an serialization change in 1.20.4, but I doubt the difference is because of that. I will look at these following tests which all pass at the moment i.e. this gives a good view of the real behavior of ItemMetaMock#serialize()

meta.setDisplayName("Test name");
eta.setLore(List.of("Test lore"));
meta.setUnbreakable(true);
meta.setDamage(5);
meta.setRepairCost(3);
Set<Namespaced> expectedPlaceableKeys = Set.of(
		Material.STONE.getKey(),
		Material.ACACIA_BOAT.getKey()
);
meta.setPlaceableKeys(expectedPlaceableKeys);
Set<Namespaced> expectedDestroyableKeys = Set.of(
		Material.BEEHIVE.getKey()
);
meta.setDestroyableKeys(expectedDestroyableKeys);
Map<String, Object> actual = meta.serialize();
assertEquals("{\"text\":\"Test name\"}", actual.get("display-name"));
assertEquals(List.of("{\"text\":\"Test lore\"}"), actual.get("lore"));
assertEquals(true, actual.get("Unbreakable"));
assertEquals(5, actual.get("Damage"));
assertEquals(3, actual.get("repair-cost"));
assertEquals(expectedPlaceableKeys, actual.get("placeable-keys"));
assertEquals(expectedDestroyableKeys, actual.get("destroyable-keys"));

Now compare that behavior to the real output as described in the reproducible test

Reproducible Test

Make a testplugin with the following script that runs on startup:

ItemStack itemStack = new ItemStack(Material.DIAMOND_PICKAXE);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName("Test string");
meta.setLore(List.of("Test lore"));
meta.setUnbreakable(true);
((Damageable) meta).setDamage(5);
((Repairable) meta).setRepairCost(3);

Set<Namespaced> expectedPlaceableKeys = Set.of(
       Material.STONE.getKey(),
        Material.ACACIA_BOAT.getKey()
 );
 meta.setPlaceableKeys(expectedPlaceableKeys);

Set<Namespaced> expectedDestroyableKeys = Set.of(
        Material.BEEHIVE.getKey()
);
meta.setDestroyableKeys(expectedDestroyableKeys);
Map<String, Object> actual = meta.serialize();

this.getLogger().log(Level.INFO, actual.toString());

The resulting output is:

{meta-type=UNSPECIFIC, display-name={"text":"","extra":["Test string"]}, lore=[{"text":"","extra":["Test lore"]}], repair-cost=3, Unbreakable=true, Damage=5, CanPlaceOn=[minecraft:stone, minecraft:acacia_boat], CanDestroy=[minecraft:beehive]}

Anything else?

If anyone want to implement this, please wait after we update to 1.20.4 to avoid merge conflicts, and also because there was a serialization change in that version

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

No branches or pull requests

1 participant