Minecraft – Clearing a named sword

minecraft-java-edition

I am attempting to use a command block to removed a named diamond sword from players inventory. The sword is PVP_Sword.

clear @p diamond_sword 1 276 {display:{Name:"PVP_Sword"}}

This is the command I thought would work, but it's returning the error that I do not have a diamond sword.

How can I make it remove the named sword instead of the basic one? Keep in mind I don't want to clear the whole inventory.

Best Answer

The syntax of the clear command is

clear [player] [item] [data] [maxCount] [dataTag]

There are 5 optional, positional arguments here. Your problem is not the data tag (dataTag) but the data value, which for historical reasons corresponds to the Damage tag of the item. So what your command is doing is trying to remove up to 276 diamond swords called PVP_sword with a damage value of 1, i.e. which were used for one hit.

In order to remove the sword regardless of damage/data, use a value of -1:

clear @p diamond_sword -1 -1 {display:{Name:"PVP_Sword"}}

Using -1 for the count as well removes all of them.