I am trying to build a custom Adventure Island. At this moment I am trying to limit the allowed items on this island. I'm trying to do this by filtering on a certain enchantment which is not item-specific.

For example.

When you want to filter an wooden sword with a custom name, you use this command:

/testfor @p[r=5] {Inventory:[{tag:{display:{Name:"Custom Sword"}}}]} <

When you want to filter a wooden sword with a custom name and specific enchantement, you can use:

/testfor @p[r=5] {Inventory:[{tag:{display:{Name:"Custom Sword"},ench:[{id:16,lvl:1}]}}]} <

But how can I filter on items with a specific enchantment on ANY item? I tried:

/testfor @p[r=5] {Inventory:[{tag:{ench:[{id:16,lvl:1}]}}]} <

But this ain't work. Does anyone know how to solve this issue?


Your issue here is that your values are not integers. Because enchantment level and id are both stored as shorts, you must add an 's' after them. Thus, the working command would be:
/testfor @p[r=5] {Inventory:[{tag:{ench:[{id:16s,lvl:1s}]}}]}

  • You are right about the 's'. I forgot to add them in the command. However, this is not the solution yet. In this case the /testfor doesn't respond either. It seems that it only works, combined with an item id.
    – VJA
    Sep 4 '15 at 21:14
  • Have to take back my words. It works! Now the only thing I try is to invert this command. I tried to put the '!' on multiple places, but that doesn't work out so far.
    – VJA
    Sep 4 '15 at 22:06
  • I do not believe that you can invert NBT data. Hopefully we'll get some more utilities in the snapshots for stuff like that. Sep 5 '15 at 3:25
  • Inverting NBT data is now possible as of 1.13
    – pppery
    Sep 6 '18 at 11:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.