mojira.dev
MC-277597

"/item" has odd replacement behavior on players in Creative if triggered from an "inventory_changed" advancement

Description:
In the following situation:

  • A "/item" command (that modifies slot X) is contained within a reward function of an "inventory_changed" criteria advancement.

  • Slot X is changed on a player that has their inventory open and is in creative mode, triggering said advancement.

The original item change on slot X that triggered the advancement overrides the modification made by the "/item" command (even though, logically, the "/item" command happens after, and should affect the final item).

Furthermore, if the reward function of said advancement contains a command to revoke the same advancement and the same situation occurs:
For as long as the player stays in creative and keeps their inventory open: The item generated by the "/item" command and the item from the inventory original change will "fight" repeatedly in slot X. Once the player exits creative mode or their inventory, the item generated by the "/item" command will finally occupy slot X.

To Reproduce:

  1. Create a world with the attached datapack.

  2. Attempt to put any item from the creative inventory in the first hotbar slot.

  3. Observe that the slot rapidly switches between a slimeball and the item placed in the slot until you exit your inventory.

The attached datapack contains the advancement 'example:inv_change' which triggers on inventory change, and has the following reward function:

execute unless items entity @s hotbar.0 slime_ball run item replace entity @s hotbar.0 with slime_ball[item_name='{"text":"example"}']
advancement revoke @s only example:inv_change

A video is attached demonstrating the bug behavior.

Note:
If the "/item" command is replaced with "/clear", the item in the first hotbar slot is simply cleared as what is logically expected.

Linked issues

Attachments

Comments 7

Please provide a functional datapack to reproduce this issue, and a video showcasing the described bug with F3 open.

I realize my original description was convoluted and inaccurate, apologies. I have updated the bug report description and attached the requested files.

 

It seems you forgot to attach the data pack.

I did forget. It has been attached.

Would MC-239935 describe your issue by any chance?

@ManosSef I believe it may, or is at least related. In my opinion, MC-239935 does not fully encompass this report, specifically the interaction with creative, and how the "inventory_changed" criteria can be triggered multiple times when logically it shouldn't. I do believe that my bug report is part of a larger issue. With all being said, I don't have the technical knowledge to say any of this with confidence.

Thanks. From my testing, I cannot reproduce this in 1.21.1, so it seems that this issue was introduced in 1.21.2. That update made some small tweaks to the creative inventory, so it is entirely possible that this is a new bug exclusive to the creative inventory. Since I can reproduce this issue in 1.21.3, I'm confirming it so that Mojang can see it and decide if it's the same issue or not.

Ryan Taylor

(Unassigned)

Confirmed

Platform

Low

Advancements, Commands

1.21.2 Pre-Release 3, 1.21.3

Retrieved