mojira.dev
MC-73887

NBT list comparison tests if item in list, but ignores position

The NBT list comparison (like it is used for the /testfor or /scoreboard command only tests if an item is in the list, but ignores the position.

Example:

Test command

/summon item ~2 ~ ~ {Item:{id:stone,Count:1,tag:{display:{Lore:[A,B,C]}}}}

Comparison commands

/execute if entity @e[type=item,limit=1,nbt={Item:{tag:{display:{Lore:[A]}}}}] run say test (works as "A" is in "Lore")
/execute if entity @e[type=item,limit=1,nbt={Item:{tag:{display:{Lore:[A,C,B]}}}}] run say test (works as "A", "C" and "B" are in "Lore")
/execute if entity @e[type=item,limit=1,nbt={Item:{tag:{display:{Lore:[A,C,B,D]}}}}] run say test (doesn't work as "D" is not in "Lore")

This is mostly problematic when testing for numbers like for example:

/execute if entity @s[nbt={Motion:[0d,0d,0d]}] run say test

as this would return true if 0d is in "Motion", that means however that the other two numbers in "Motion" can be anything.

Note: Maybe this is the intended feature, if so it would be appreciated if the developers find a way to make direct comparison possible (maybe by saying if a list contains the same amount of items as the to-compare list, then try comparing it directly).


Original description:

There is a bug where using the /testfor ArmorStand command with a specified NBT Rotation value of {0.0f, 0.0f} returns all Armor Stands, regardless of rotation. Using a Rotation value other than {0.0f, 0.0f} works as expected. This happens when your command is run in a command block or from the chat. I haven't tested this with anything other than armor stands.

This command returns only armor stands with the specified rotation:

/testfor @e[type=ArmorStand] {Rotation:[45.0f,0.0f]}

This command returns all armor stands, regardless of rotation.

/testfor @e[type=ArmorStand] {Rotation:[0.0f,0.0f]}

To reproduce, place stand with 45 degree rotation, and place a stand with 0 degree rotation. Run the two commands above. The first will give one result, the second will return two results.

Linked issues

Comments 5

confirmed in 1.8-pre4.
It seems like testing for a rotation of [0.0f,0.0f] on armor stands defaults to testing for the base plate rotation, which I'm assuming is always [0.0f,0.0f].
That might explain why it outputs a signal for any armor stand, regardless of rotation.

If you use the entitydata command, it shows that the Motion and Rotation tag lists have numerical position indicators, for example

Rotation:[0:2.0f,1:3.0f]

However, using them in a testfor command doesn't make any difference in whether or not it detects the entity. Zero values also seem to match any entity.

Confirmed for 17w50a with

/execute if entity @s[nbt={Motion:[0d,0d,0d]}] run say test

Confirmed in 18w06a, using updated commands.

Relates to/ duplicated by MC-124532.

Ben Reddersen

(Unassigned)

Confirmed

Platform

Low

Commands

Minecraft 1.8, Minecraft 15w49b, Minecraft 16w04a, Minecraft 1.10.2, Minecraft 16w32b, ..., 1.16.2 Release Candidate 1, 1.16.2, 1.17.1, 1.20.4, 1.21 Pre-Release 1

Retrieved