I would like to test for more than 1 item in one's inventory. However, I'm having some difficulties.

I have tried the /testfor @p[r=2] {Inventory [{id:"minecraft:gold_nugget"}]} command, but it doesn't work. It says "UUID incorrect". I would rather not use scoreboards, because I don't really get along too well with it.

Can someone please put the command to set the amount? (I.E. Of the gold nuggets). If it matters, I would like it in command block form.

Thanks in advance.

  • 3
    The problem with not using scoreboards is you can test that there is a player that meets conditions with /testfor fine, but you can't do anything with that player. All you know is that player exists, but a different command block doesn't know who he is. In any case, I'll look into this in a bit. – Unionhawk Aug 19 '15 at 20:41
  • 5
    There is no good reason not to use the scoreboard. scoreboard is your friend. testfor is not your friend, he's the guy that's really popular in your school, and pretends to be your friend, but that's just so he can get close to you in order to shove you in a locker, because that's all that he's good for. Everyone thinks they should like testfor and that they should be around him, but he's just a shallow twerp that can barely do anything useful. – MBraedley Aug 20 '15 at 1:45

You've got a couple syntax errors in the NBT portion of your /testfor command. The command, as you have it, should be /testfor @p[r=2] {Inventory:[{id:minecraft:gold_nugget}]}

However, unless you literally only want to do something to the world whenever there is a player within 2 blocks with a gold nugget in their inventory, you are not going to be able to do anything with this testfor command. testfor does not allow you to pass player information to any other commands. You can see if that player exists, great, but you can't do anything to that player. If you want to do anything to that particular player, you will absolutely need to use a scoreboard. I don't care if you don't want to learn it, that's your only choice (if you just want to do something simple like summon a TNT at a particular location, then you can continue on your merry way with your testfor I guess).

| improve this answer | |
  • You are missing part of the question. OP asked how he can test for a player with at least X gold nuggets, rather than any amount. – MrLemon Aug 20 '15 at 7:46
  • No, what i mean, like im making a bit of a start of a map, and the currencye is gold nuggets. For example, i have an enchanting room with some enchantments, with prices. Protection level 1 is 10 gold nuggets. I would like to make it, so that it takes the 10 gold nuggets from you and adds the enchantment. if you dont have 10 gold nuggets, it dosent enchant. – TOMDIEGO Aug 20 '15 at 9:45
  • @MrLemon Right. At least is complicated. Exactly is less so. Hmm....... – Unionhawk Aug 20 '15 at 12:12
  • @TOMDIEGO Hmm. I'll revisit this when I have access to Minecraft to come up with a more comprehensive solution. You can do exactly 10 nuggets, which will count if the player has a separate stack of 10 with {Inventory:[{id:minecraft:gold_nugget,Count:10b}]}, but I'll get a more comprehensive solution running later today – Unionhawk Aug 20 '15 at 12:20
  • @TOMDIEGO if you want to build adventure maps, there are two sets of commands you absolutely need to know and be comfortable using, and they are execute and scoreboard commands. Everything else is just specialized filler that either reacts to a scoreboard and/or is part of an execute. – MBraedley Aug 20 '15 at 16:56

If you do these setup commands:

/scoreboard objectives add items dummy

/stats entity @a set AffectedItems @p items

/scoreboard players set @a items 0

Then run this command: (N.B. The execute is ESSENTIAL)

/execute @a ~ ~ ~ /clear @p minecraft:gold_ingot 0

This will then mean that each player has the number of gold ingots in their inventory as their items score.

| improve this answer | |

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