Minecraft – How to clear 2 items from the inventory, with one being a specific name

minecraft-commandsminecraft-java-editionminecraft-java-edition-server

I am working on my VANILLA Minecraft server right now and I'm in a bit of a struggle. A player can purchase an iron sword called SLAYER Sword, and can also purchase a regular iron sword. A player can also sell an iron sword at a price of 3 Scoreboard Units. I want ONLY the regular iron sword to be sold, not the SLAYER Sword. The text I am currently using to sell a single sword is /clear @p minecraft:iron_sword -1 1. This is currently clearing BOTH swords, not just the regular iron sword.

Best Answer

I figured it out: make the regular iron sword-giver have a custom name of Iron Sword, which can be done by adding {display:{Name:"Iron Sword"}}. In the seller, make it clear the sword by adding the same display name.