Need help in command to remove item from inventory
I have a small server with my friends, and we want to remove mending from play. I was thinking it will be easy now to just place a command block which looks on players inventory and removes enchantment books with mending on it.
But I can't create that command, I was trying this various:
/clear Excidium minecraft:enchanted_book{Enchantments:[{id:"minecraft:Mending"}]}
/clear Excidium minecraft:enchanted_book{Enchantments:[{id:"minecraft:Mending",lvl:1}]}
/clear Excidium minecraft:enchanted_book{Enchantments:[{id:"minecraft:Mending",;lvl:1s}]}
clear Excidium minecraft:enchanted_book{StoredEnchantments:[{id:mending,lvl:1}]} 1
And nothing happened.
When I use the command /give Excidium minecraft:enchanted_book{StoredEnchantments:[{id:mending,lvl:1}]} 1
to give myself a book with mending, then I can remove it from the bag. But when the mending book is from another source like villager, chest, fishing, ect, the command doesn't work. The mending book is still in the inventory.
Please help.
Solution 1:
Basically, make sure you're not putting all of the commands in a single command block.
If that's good to go, then you should also know that you don't need the first 3 lines of commands, since enchantment books' enchantments are always stored in the StoredEnchantments:[]
NBT tag.
Another problem is that you're checking for a single player. Use @a to clear all players' inventories of said item.
That said, you should also take note that items that have the Mending enchantment will not be cleared. You'll have to clear them seperately one by one using seperate command blocks. (e.g. /clear @a golden_pickaxe{Enchantments:[{id:mending,lvl:1}]}
)
Solution 2:
Always use this command to check what data an item has (while holding it):
/data get entity @s SelectedItem
That basically tells you the solution already:
{id:"minecraft:enchanted_book",Count:1b,tag:{StoredEnchantments:[{lvl:1s,id:"minecraft:mending"}]}}
Since you can only naturally get level 1, lvl
don't matter for you, so it's this:
/clear @a enchanted_book{StoredEnchantments:[{id:"minecraft:mending"}]}