Items on the ground clump together in stacks, so getting the number of entities doesn't give me the number of items there are. Is there a way to count the number of items instead of the number of item entities?

  • So you mean if there was one stack of 64 items on the ground, it would only see it as 1 item? – Jack L. Apr 27 '19 at 14:20
  • I rewrote the question to make it clearer what you wanted, I hope that's ok with you. Context for everyone else. This question started from this comment. – Fabian Röling Apr 27 '19 at 15:03
  • Thanks, I wasn't really sure how to word it xD – Meowl Apr 28 '19 at 12:38

First you need a scoreboard to store the amount of items per entity into:

/scoreboard objectives add count dummy

Then you can easily transfer the stack size of every item entity into their "count" scoreboard like this:

/execute as @e[type=item] store result score @s count run data get entity @s Item.Count

If you want to do this only for a certain type of item, you can filter that as well:

/execute as @e[type=item,nbt={Item:{id:"minecraft:stone"}}] store result score @s count run data get entity @s Item.Count

Then you just need to add all those scores up to a shared score, for example yours:

/scoreboard players operation @s count += @e[type=item] count

Of course if you want to do this multiple times, you have to reset your score before the next repetition:

/scoreboard players reset @s count

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.