How to use RepairCost tag within testing commands [duplicate]

I had answered this question and ran into a problem tagging a dropped item.

The command I gave will tag a leather chestplate with a protection level 1 enchantment. Here is the command:

/scoreboard players tag @e[type=Item] add example {Item:{id:"minecraft:leather_chestplate",tag:{ench:[{id:0,lvl:1}]}},OnGround:1b}

This works properly if the item is obtained using the command:

/give @p minecraft:leather_chestplate 1 0 {ench:[{id:0,lvl:1}]}

The problem is that if the chest plate is enchanted with a book at the anvil, it gives the item another tag of RepairCost so the item has increased repair costs. I attempted to add RepairCost:1 to the command inside the tag brackets:

/scoreboard players tag @e[type=Item] add example {Item:{id:"minecraft:leather_chestplate",tag:{RepairCost:1,ench:[{id:0,lvl:1}]}},OnGround:1b}

Over at this page, I found:

when you are testing for/giving a score depending on its tag you often need to specify that data type

I have never seen integers specified so I tried RepairCost:1i. This did not work either.

Then over at this page I found:

"auto:1b" is read as a Byte tag, while "auto:1" is read as an Integer tag.

byte:1b OR byte:true OR byte:false
short:1s
integer:1
long:1l
float:1f OR float:1.0f
double:1.0 OR double:1.0d
compound:{}
list:["data","data"]
intArray:[1,1,1]
string:"text"

It seems, integer is the default if unspecified.

I even took a look at the item in my inventory using NBTExplorer:
NBTExporer

I ended up building a testfor command where I just guessed at different variations and different positions within the command:

testfor @p {SelectedItem:{id:"minecraft:leather_chestplate",tag:{ench:[{id:0,lvl:1}],RepairCost:1}}}

Nothing I have tried has worked. Is there some way to include RepairCost in detection commands like this?


Solution 1:

RepairCost is an integer. id and lvl, on the other hand, are shorts. You don't even need to include RepairCost to properly detect naturally enchanted items, just make sure you use the correct types (and if you use the correct types when /giveing the items too, you can detect both of them).

tag:{ench:[{id:0s,lvl:1s}]}