The /clear Command in Minecraft: Clear an Inventory, Take an Item From Everyone and Count It
/clear empties inventories. Used well, it takes away from everyone the item that slipped into the server, charges diamonds in a shop made with commands or leaves everyone equal before an event. Used badly, it wipes hours of someone's game in a second, and there's no undo. Here's how it's written in today's version of Java, which isn't the one in old videos.
How it's written
The shape is /clear <players> <item> <amount>, and all three parts are optional. Typed on its own, /clear empties your own whole inventory.
You need to be an operator (level 2) or have cheats turned on in a single-player world. On a server, you make yourself op from the console with op YourName (explained in the guide to giving op).
It only works on players: with @e or with a mob it gives an error. It clears the inventory, the armor being worn and the offhand, but not the ender chest.
Many tutorials teach /clear Ana minecraft:wool 14 -1, with a “data” number and -1 for “all”. That was up to 1.12: today the color goes in the name (red_wool), there's no “data” and the amount starts at 0. If you copy a command from a video and it fails, it's almost always that.
Rather not set it up yourself? Minecraft servers from €6 a month, no contract and a full refund within 72 hours. Or create a free Minecraft server, no card needed.
The ones used most
Empty a player's inventory
/clear Anatakes everything from Ana. To do it to everyone connected,/clear @a: think twice before pressing Enter.Take one item from everyone
/clear @a minecraft:tnttakes all the TNT from every connected player and leaves the rest. The name is the item ID; if you don't know it, look it up in the list of Minecraft item IDs.Take only a few
/clear Ana minecraft:diamond 10takes at most 10 diamonds from her. If she has fewer, it takes all of them without an error.A group of items
With a game tag after
#:/clear @a #minecraft:logstakes all logs, of any wood, and/clear @a #minecraft:woolall wool of any color.Everyone but you
/clear @a[name=!YourName]empties everyone else. The options in square brackets are the usual selector ones: you have them in the selectors guide.
Count what someone carries without taking it
With amount 0, /clear removes nothing and only counts: /clear Ana minecraft:diamond 0 answers “Found 23 matching item(s) on player Ana”. It's for checking whether someone has brought in something odd without touching their inventory.
With @a it counts the total for everyone: /clear @a minecraft:elytra 0 tells you how many elytra there are on the server among everyone connected.
If they don't have any, the game answers “No items were found on player Ana”. It's not the command failing: they just don't have any.
Charging in a shop or a quest made with commands
The trick in maps and servers with shops and no plugins is to store the count in a scoreboard and only charge if it's enough. First create the scoreboard once: /scoreboard objectives add diamonds dummy.
Count
In a command block or a function:
execute as @p store result score @s diamonds run clear @s minecraft:diamond 0. It stores in the scoreboard how many diamonds the nearest player has.Charge and give
execute as @p[scores={diamonds=10..}] run clear @s minecraft:diamond 10takes 10 only if they have 10 or more, and after it, with the same condition, thegiveof what they're buying (chained command blocks (in Spanish) do it in order).If they don't have enough
With
scores={diamonds=..9}you send them a warning withtellrawinstead of charging them. That way nobody loses the 7 diamonds they had for not having 10.
From the server console
In the console it goes without the slash and always with the player: clear Ana minecraft:tnt. Without a name it doesn't know whose inventory to empty, because the console isn't a player.
It works even if you're not in, but only on connected players: you can't empty the inventory of someone who isn't on the server with /clear.
If you have EssentialsX
EssentialsX has its own /clearinventory and takes the name “/clear” (it's one of its shortcuts, along with /ci and /clean). So with EssentialsX, /clear @a #minecraft:logs or amount 0 to count may not do what this guide says.
To use the game's, type its prefix: /minecraft:clear @a minecraft:tnt (in the console, minecraft:clear Ana). It always goes to the game's command, whatever plugins you have.
The other EssentialsX commands that come in handy as an admin, in the EssentialsX commands guide.
What /clear doesn't do
It doesn't remove items dropped on the ground: that's /kill @e[type=item] (the /kill guide).
It doesn't save anything: what's cleared doesn't come back. If you want nobody to lose their things when they die, that's not /clear, it's gamerule keep_inventory true (its name since 1.21.11, the gamerules guide).
And to give back something you took by mistake, all you can do is give it again with /give: the /give guide explains how, enchantments and all.
On NapNodes
Minecraft servers run Paper on the latest version, so everything in this guide works. From the panel's “Console” you run any /clear without being connected.
Before a big /clear on a paid server, make a backup in “Backups”: each player's inventory is saved with the world, so if you get it wrong, you go back to how it was. The free server has no backups, so there count first with amount 0.
Frequently asked questions
How do I clear a player's inventory in Minecraft?
With /clear and their name, for example /clear Ana. From the server console, without the slash: clear Ana.
How do I take one item from every player?
With /clear @a and the item ID, for example /clear @a minecraft:tnt. It takes that item and leaves everything else.
How do I know how many items someone has without taking them?
Use amount 0: /clear Ana minecraft:diamond 0 says how many diamonds she has and takes none.
Why does /clear give an error with -1?
Because -1 for “all” was from old versions. Today you leave the amount out and it takes them all; the lowest number it accepts is 0, which only counts.
Does /clear wipe the ender chest?
No. It clears the inventory, the armor being worn and the offhand, but the ender chest stays as it was.
Why doesn't /clear do what the guide says on my server?
You probably have EssentialsX, which uses /clear for its own command. Type /minecraft:clear to use the game's.
Shall we set it up for you?
Minecraft servers from €6 a month, never oversold: your RAM is yours alone. And if you'd rather start without paying, there's a free Minecraft server, no card needed.
Your server doesn't show up in the game? Check it in a second with “Is my Minecraft server online?”: players, version and MOTD, free. Need a player's UUID for the whitelist or permissions? Look it up here. Handing out enchanted items? Build the command with the /give generator.
Free tool: Minecraft item IDs. Search any block or item by its in-game name and copy its ID or the /give. Every one from the latest version.
Keep reading
- The /kill Command in Minecraft: Clear Dropped Items, Mobs and Entities Without Breaking Anything
How to use /kill in Minecraft to clear dropped items, mobs or arrows without killing pets or villagers, with a radius, from the console, and the errors.
- The /give Command in Minecraft: Items With a Custom Name, Enchantments and Lore
How to use /give in today's Minecraft: the component syntax, items with a coloured name, enchantments and lore, the usual errors and the server console.
- The /particle Command in Minecraft: Colored Particles, Above Players and on Repeat
How to use /particle in today's Minecraft: what each number does, colored dust, block and item particles, particles above every player, force and common errors.