When filtered and limit_slots are used together in a slot source definition, /item command applies the item filter before the slot limit. As a result, limit_slots limits the matching slots rather than limiting the slots to be checked by the filter.
Steps to reproduce the issue:
Hold the following items in your hotbar
hotbar.0: stonehotbar.1: red woolhotbar.2: blue wool
Run the following command:
item modify entity @s {type:filtered,item_filter:{items:"#wool"},slot_source:{type:limit_slots,limit:2,slot_source:{type:slot_range,slots:"container.*"}}} {type:set_count,count:1,add:true}
Expected result:
The slot_range source selects the slots matching container.*. The limit_slots source should then restrict this selection to the first two slots, which are hotbar .0 and hotbar.1. Finally, the filtered source should select only the slots containing items that match #wool from this limited selection.
Since hotbar.0 contains stone and hotbar.1 contains red wool, only the red wool in hotbar.1 should be modified. The blue wool in hotbar.2 should not be considered.
Actual result:
Modified 2 slot(s) on <username>
Both the red wool in hotbar.1 and the blue wool in hotbar.2 are modified. The item filter is applied before the slot limit, so the limit is applied to the filtered slots rather than to the original slot range.
Additional test case
To compare the behavior, run the following /execute if slots command:
execute if slots entity @s {type:filtered,item_filter:{items:"#wool"},slot_source:{type:limit_slots,limit:2,slot_source:{type:slot_range,slots:"container.*"}}}It outputs "Test passed. Count: 1", indicating that one slot was selected. This differs from the number of slots modified by /item modify, even though both commands use the same slot source. At least one of the two commands is wrong, and I suspect that /item is the one behaving incorrectly.
For
/item modifythe filter is gettingapplied before the limit is counted, so it limits matching items instead of the first two slots. Thats why both wool stacks change while/execute if slotsonly counts one.Still looks present in the Snapshot 5 code