Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Shields lore is immutable after setting

Open deadbeef-enc0de opened this issue 1 year ago • 2 comments

Expected behavior

Adding lines of lore to a minecraft:shield in different ticks should work

Observed/Actual behavior

After setting the lore of a minecraft:shield in one tick you can no longer modify or clear the lore in following ticks

Steps/models to reproduce

// excerpt from test plugin using a command system

        public boolean runCommand(Player player) {
            ItemStack stack = player.getInventory().getItemInMainHand();
            ItemMeta meta = stack.getItemMeta();
            List<Component> lore = meta.lore();
            if(lore == null || lore.isEmpty()) {
                System.out.println("lore empty, adding line");
                lore = new LinkedList<>();
                lore.add(Component.text("This is lore line "+(lore.size() + 1)));
            } else {
                System.out.println("lore not empty, clearing");
                lore = null;
            }
            meta.lore(lore);
            stack.setItemMeta(meta);
            player.getInventory().setItemInMainHand(stack);

            return true;
        }

Running the command more than once does not remove the lore as expected. Removing the lore can be replaced with adding a new line and that also does not work,

Plugin and Datapack List

EasyCommands is what makes the runCommand parameter list short

[19:21:55 INFO]: Bukkit Plugins: [19:21:55 INFO]: - EasyCommands, PaperTest

Paper version

[19:22:21 INFO]: Checking version, please wait... [19:22:22 INFO]: This server is running Paper version git-Paper-34 (MC: 1.20.6) (Implementing API version 1.20.6-R0.1-SNAPSHOT) (Git: 544ce20)

Other

No response

deadbeef-enc0de avatar May 01 '24 23:05 deadbeef-enc0de

Looks like after further testing it might be more than just lore and include a lot of other item metadata (including custom plugin data added to the item)

deadbeef-enc0de avatar May 01 '24 23:05 deadbeef-enc0de

I am able to reproduce this with the code provided with a shield item, not just any random item however. In CraftMetaBlockState#applyToItem, the lore component is being re-added because it's stored on the BlockEntity object (for anyone looking into this before I can).

Machine-Maker avatar May 01 '24 23:05 Machine-Maker

@deadbeef-enc0de I'd appreciate if you could test out what you are doing by running the server linked in this PR with your plugin. I tested with the code you provided to reproduce, but this is an icky area, and it's also possible I created additional unforseen issues.

Machine-Maker avatar May 02 '24 18:05 Machine-Maker

@Machine-Maker this looks like it did it. I can change lore, custom data, and other data on the item stack.

This was tested with both the Test plugin with the code above as well as the more complex plugin that found it in the first place.

Thanks.

deadbeef-enc0de avatar May 02 '24 19:05 deadbeef-enc0de

There is something weird going on with shields, .setItemMeta() for specifically shields doesn't seem to work?

ghost avatar May 04 '24 21:05 ghost

@ThrowerWay Test with the PR linked above

Owen1212055 avatar May 04 '24 21:05 Owen1212055