What I'm trying to do: Make sure players always have a particular guidebook/spellbook (a special command-generated one with clickable links and a special tag).

If they lose their book, it should appear back in their inventory. If they drop their book, it should do that and the book on the ground should disappear.

I have this working on a basic level, except... Any time a player tries to move their book to a different slot, it gives them a new one, which just feels wrong. There is apparently no inventory slot you can detect for the mouse. Even if there were... This can lead to fast infinite generation if, for instance, they open a chest and repeatedly put that book in that chest.

So the thought process here is maybe make it so that if the player has the inventory GUI open, they are excluded from the selection. So they don't get the book until the inventory is closed. It still leaves some gaps, and they could fill chests with these books. But they would have to try to make it glitch out, and I think it would feel right at that point. And in order to do infinite generation, they'd have to repeatedly open and close the chest.

Here are my commands as it stands. (2 command blocks per spellbook)

/give @a[nbt=!{Inventory:[{id:"minecraft:written_book", tag:{spellbook:basic}}]}] written_book{pages:[...yada...],title:"Spellbook",author:"Dartania @ http://minecraft.tools/",display:{Lore:["You need this for lots of stuff!  Don't lose it!"]},spellbook:basic}
/kill @e[nbt={Item:{id:"minecraft:written_book", tag:{spellbook:basic}}}]

What I'm looking to do is add to this part... @a[nbt=!{Inventory:[{...}] and make it more like @a[nbt=!{Inventory:[{...}]},nbt=!{Client:{InventoryOpen:true}}]

I know Client:{InventoryOpen} is not the correct thing, but I don't know what is the correct thing.

For reference, I'm building a Singleplayer/Multiplayer puzzle map on Vanilla Minecraft 1.14, with a bedrock/command_block bunker below spawn. I'm using http://minecraft.tools/ to generate stuff (like the spellbook)

  • You can indeed clear items on the cursor, except that there's a bug which makes it not work for items that were clicked after being picked up after being taken from the Creative inventory or something complicated like that. Try your system in Survival instead. Also, why not just use a menu in chest instead of this book? You seem to have chosen one method without considering all the complications it brings with it and then tried to patch it up more and more instead of simply choosing a different method. There will always be more special cases when you want to something like this with items. Aug 18, 2019 at 5:36
  • Menu In Chest? Like... have the player open a chest menu with /help? My players tend to forget about those commands, plus I wanted it to feel like a book. More importantly, I haven't figured out how to open a fake GUI, or detect when players type in a particular command. I might use a tellraw menu screen if I could figure out how to determine when the help button has left the screen. I have considered lots of methods. This one is the easiest with the least amount of help needed. I have it mostly working already. Any other method would require like 50 more QA's like this. Aug 18, 2019 at 17:56
  • As for the creative bug, "after being taken from the creative inventory" would not apply, as you cannot obtain this book from the creative inventory. It has to be given via commands. As for clicking on a chest to open a menu, that wouldn't work because they use the book to tp places, especially when lost. As for clearing items on the cursor, I don't want to remove the item from the mouse. I want to allow the player to move the item around in their inventory. Aug 18, 2019 at 18:10
  • Oh, sorry, I wanted to type "chat", not "chest". I meant /tellraw with clickEvent. About the Creative inventory: I meant your regular player inventory, but while you are in Creative mode. /clear has a surprisingly specific bug with that, so you should just test your /clear command in Survival and in the best case drop the item and pick it up a few times before that. The bug is really weird. Aug 19, 2019 at 0:33
  • You could give the books to those who don't have them in any space of the inventory nor the cursor, thus being either on ground or on others containers. I'm actually interested in it, since it can aply to many other contraptions. Also, clearing it from cursor isn't that bad, you can move it with the numbers, even tough it's pretty anti-intuitive.
    – BunnyMerz
    Nov 11, 2019 at 15:11

1 Answer 1


easy fix:

clear @a[nbt=!{Inventory: [{Slot: 0b, id: "minecraft:written_book"}]}] minecraft:written_book

replaceitem entity @a hotbar.0 minecraft:written_book.......

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .