How do I make item frames unbreakable in Adventure Mode without locking the item inside?

I'm trying to make a map and the players in adventure mode can break item frames, so I'm trying to change that.

I've searched it up and both the Invulnerable tag and the Fixed tag don't work for me, because the item frame becomes unbreakable, but it also prevents the item from being removed.

I want to make the item frame unbreakable, but I want to be able to take the item in Adventure mode. How can I do this?


You can fix this problem by adding Invulnerability to the item frame when there is not an item in it.

This requires you to specify which item:

execute as @e[type=minecraft:item_frame] unless entity @s[nbt={Item:{id:"minecraft:stone"}}] run data merge entity @s {Invulnerable:1b}

This will make the item frame Invulnerable when it doesn't hold stone.

Then you can remove the Invulnerability whit this:

execute as @e[type=minecraft:item_frame] if entity @s[nbt={Item:{id:"minecraft:stone"}}] run data merge entity @s {Invulnerable:0b}

This will remove the Invulnerability when it holds stone.

Doing this makes sure that if the players put the item back they will be able to grab it again.


Make sure you specify what item you use and if you're going to have multiple item frames you should also add coordinates to the selector, might work without but I'm not sure:

@e[type=minecraft:item_frame,x=5,y=5,z=5,dx=0,dy=0,dz=0]

This will select any item frame at block 5 5 5.

The dx dy dz is really important, if they aren't used the command doesn't work.


So you can place the commands in separate repeating command blocks and then add two for every item frame you'd like the players to grab items from.

It might be a bit of command block setup, but this is the only solution I know and it works quite well.


The minecraft: part in @s[nbt={Item:{id:"minecraft:stone"}}] is also needed for the command to work, but no need for the Count:1b part wich is needed for the summon command.