mojira.dev
MC-278804

Some slot indexes not working as intended

The index for the cursor slot used to be 499, according to the wiki, but attempting to detect items in that slot no longer works. The wiki also states that the slot used to be exclusive to survival mode, but it doesn't work for any game mode I tested.

Steps to Reproduce:

  1. Set up a command block with the command:Β 

    execute if data entity <username> Inventory[{Slot:499b}] run say item detected
  1. Add redstone with sufficient delay so that you can open your inventory and pick up an item

  2. Set game mode to survival

  3. Activate redstone, open inventory, and pick up an item using the cursor

Observed Results:

no chat message

Expected Results:

chat message "item detected" appears

Linked issues

Comments 10

The reason this issue concerns me is that I am trying to create a datapack that modifies the components of items purchased by villagers (giving bows the repairable component, for example), and while I can detect and modify the items purchased if they are transferred directly to the other inventory slots (i.e. shift click) I cannot detect the item in the cursor, which causes the test to fail, and prevents the function from modifying the item purchased. Without the test, blindly changing the components could result in errors if the player is holding a different item and shift clicks the bow(s) into their inventory.

Through additional testing I identified the following:

Indexes that properly detect items

1. 0-35 (the 36 inventory spaces)
2. 100-103 (armor slots)
3. -106 (offhand slot)

Other indexes that no longer work as described on the wiki:
1. 98-99, marked main hand and off hand

2. 500-503, marked as the crafting grid slots

Can confirm. I suspect this change was made intentionally, since there is no reason for the game to store items in the cursor or crafting slots in NBT because those slots are expected to be empty when the player joins the world. If you want to simply see what's in the slot you can copy it elsewhere with eg.

/item replace entity @n[type=chest_minecart,tag=temp_storage] container.0 from entity @s player.cursor

and then replace it later. Of course this requires an additional entity or block entity, possibly a forceloaded one in an auxiliary dimension, so it's not a particularly elegant solution, but it should work fine. (There may also be a way to do it in a single line using a predicate– I don't work with predicates often so idk off the top of my head if that's possible now.)

According to others in public forums, a new condition "items" i.e.Β 

Execute if items <pos> <slot> <item_predicate>

is available and could be used instead.

As someone very unfamiliar with coding, especially NBT, I didn't realize this was checking NBT entity data, or that there was another command that checked player inventory slots.

Oh I totally overlooked /execute if items when it was added in 24w10a, thanks for bringing it to my attention.

Please tell us the most recent version where the command worked as intended

Do you want the most recent full release version, or just the most recent version of any kind?

The wiki was changed to add the slot information around June 24, which means I will check between 1.20.5 and 1.21

Thank you for your report!
After consideration, the issue is being closed as Invalid.

This report does not describe a bug.

Quick Links:
πŸ““ Bug Tracker Guidelines – πŸ’¬ Community Support – πŸ“§ Mojang Support (Technical Issues) – πŸ“§ Microsoft Support (Account Issues)
πŸ““ Project Summary – ✍️ Feedback and Suggestions – πŸ“– Game Wiki

Well I would prefer WAI but regardless it seems like this change is here to stay. Glad a workaround was identified.

Invalid seems appropriate, considering that the "expected behavior" comes from the wiki and not my personal, previous experience. Next time I think I have an issue, I will make sure to have information on hand to prove that it works in a previous version, instead of relying on second-hand information.

cakeyeater99

(Unassigned)

Confirmed

Commands

1.21.4

Retrieved