1

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?

3
  • 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, 2019 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. Apr 27, 2019 at 15:03
  • Thanks, I wasn't really sure how to word it xD
    – Meowl
    Apr 28, 2019 at 12:38

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .