Minecraft Java Edition – How to Detect a Minecraft Banner of a Specific Color

minecraft-commandsminecraft-java-edition

I'd like to detect a banner of a specific color in various situations: Standing, hanging, dropped, and inside player/entity inventory (as well as in the head slot).

These work:

/testfor @e[type=Item] {Item:{id:"minecraft:banner"}}
/testfor @a {Inventory:[{id:"minecraft:banner"}]}

These don't work:

/testfor @e[type=Item] {Item:{id:"minecraft:banner",Damage:0}}
/testfor @e[type=Item] {Item:{id:"minecraft:banner",Base:0}}
/testfor @e[type=Item] {Item:{id:"minecraft:banner"},Damage:0}
/testfor @e[type=Item] {Item:{id:"minecraft:banner"},Base:0}
/testfor @e[type=Item] {Item:{id:"minecraft:banner",tag:{Damage:0}}}
/testfor @e[type=Item] {Item:{id:"minecraft:banner",tag:{Base:0}}}

Any ideas?

Best Answer

I have read the entire internet and discovered the ways to detect banners with specific base colors. It turns out that I was really close. Here are some examples that are working in 1.8.1:

Test for a placed banner (on the ground) that is Blue colored ({Base:4}), and facing north (8):

/testforblock 60 14 116 minecraft:standing_banner 8 {Base:4}

Test for a placed banner (hanging) that is Blue colored ({Base:4}), and facing north (2):

/testforblock 48 2 38 minecraft:wall_banner 2 {Base:4}

Test for a banner in a player's inventory (note the 4s means Blue. The s is important):

/testfor @p {Inventory:[{Slot:103b,id:"minecraft:banner",Damage:4s}]}

Test for a banner that has been dropped on the ground that is Blue colored (Damage:4s):

/testfor @e[type=Item,x=40,y=1,z=40,dx=40,dy=27,dz=80] {Item:{id:"minecraft:banner",Damage:4s}}

Notes:

  • The values for facing didn't appear to be optional in my tests. Without them, the match would simply fail. See all the values for facing here. Please correct me if I'm wrong.
  • It's possible to match every detail about the flag, including the patterns, as demonstrated here.
  • The banner base color "Damage" or "Base" values are 0-15. 0 being black, 1 being red, etc. etc.