2

I'm building a little shop for a map I'm doing and I'm trying to detect if the player has a certain number of gold nuggets on them. It works, but only for 1. I want it to check more than 1 item, I've tried numerous ways with the count command after it and none of them work. This is the command

execute if entity @p[nbt={Inventory:[id:"minecraft:gold_nugget"}]}]
4
  • 1
    As far as I'm aware, this isn't doable, unless you individually take them out of the users inventory and replace them. – CATboardBETA Jun 19 at 11:10
  • would there be a way to do that? – MilkAppreciate Jun 19 at 11:15
  • Well, I upvoted the question, maybe someone more experienced will be able to find your answer. – CATboardBETA Jun 19 at 11:16
  • Okay, thank you. – MilkAppreciate Jun 19 at 11:18
3

You could use something like:

  • /execute if entity @p[nbt={Inventory:[{id:"minecraft:gold_nugget",Count:1b}]}] run COMMAND

And change the value in Count:#b to the desired amount, but this only works if you are looking for the EXACT amount of an item.

If you want it to target a player with 1 or more gold nuggets, you will have to use a scoreboard:

  • /scoreboard objectives add gold_nuggets dummy (This is used to store the amount of gold nuggets players have.) [You only have to run this once]
  • execute as @a store result score @s gold_nuggets run clear @s minecraft:gold_nugget 0 (This stores the actually amount of gold nuggets each player has into the scoreboard (doesn't actually clear any items).) [You should put this in a repeating command block]
  • execute if entity @p[scores={gold_nuggets=1..}] run COMMAND (This is used to see if a player has 1 or more gold nuggets in their inventory.) [You should use one of these for each shop trade, just change the value of gold_nuggets=1..]
1
  • Thank you so much, now I just need to set up the reduction system when you buy something. I think I could figure it out but is there a certain command that would do that after you bought something? – MilkAppreciate Jun 19 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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