1

I'm trying to create a command on my Minecraft realm that kills all items if there are more than 500 items. My only issue is, I can't figure out how to test for any specific number of items, much less more than. I'm wondering if there is any way to do this in a single execute command, without need for scoreboards, that just execute if there are 500 of a specific entity. I have tried this:

/execute if entity @e[type=item,limit=500] run kill @e[type=item]

I know why this wouldn't work, but it was the only thing I could think of. I couldn't find anything on the Minecraft wiki for it, nor could I find any questions about it. Is it possible to do this?

3

In the past, you would first reset a scoreboard, then make every item entity increase the scoreboard by 1. Nowadays, you can do it more lag-friendly and without a reset:

/execute store result score PlayerName scoreboardName if entity @e[type=item]

The execute command's purpose is usually to do something conditionally or under different circumstances, but here you don't want to do anything for these item entities, you just want to know their amount. So you can omit run and the chained command.

Now you have the amount of players in the scoreboard "scoreboardName" for the player "PlayerName" (doesn't even have to be a real player) and can do things with that number, for example killing all items if there are more than 500:

/execute if score PlayerName scoreboardName matches 500.. run kill @e[type=item]
  • 1
    This would be great, but I've noticed something that kinda ruins everything. It detects for items, but counts stacks of items on the ground as one item. that's mildly annoying, and I doubt there's a way to fix this, but if there is, could you let me know? Nonetheless, it'll serve for the time being. – Meowl Apr 24 at 21:51
  • There is actually a cool way to do it. Please post a new question for that, then I'll answer it. – Fabian Röling Apr 25 at 9:50
  • Done! I'm interested to see how this would work. – Meowl Apr 27 at 13:23

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.