1

I am creating a set of command blocks which allow my survival players to trade a normal item frame for an invisible item frame. Here is what I have so far:

The first command block removes an item frame from the players inventory. The command block is set to impulse, unconditional, needs redstone. Players push a button to activate this command block.

clear @p item_frame 1

The second command block gives an invisible item frame to the player. This command block is set to chain, conditional, always active.

/give @p minecraft:item_frame{EntityTag:{Invisible:1}, display:{Name:'{"text":"Invisible Item Frame"}'}}

These two command blocks actually work fairly well. However, the first command block does not distinguish between an invisible item frame and a normal item frame. If a player has an invisible item frame in their inventory, it may be cleared and then immediately replaced, which makes it appear as though the command block is doing nothing.

I want the first command to accept only normal item frames. I have tried two codes:

clear @p item_frame{EntityTag:{Invisible:0}} 1

and

clear @p item_frame{display:{Name:'{"text":""}'}} 1

Neither of these codes work.

How do I write the code so that it only accepts items frames that are visible or item frames without a custom name?

1 Answer 1

1

Unfortunately it is not possible to /clear an item based on the absence of NBT.

There are workarounds, like checking every single slot whether it has the NBT before changing the count of the item in said slot, or using some tag that the item has by default, like a Damage value for items that support said value (as that one does have a default value of 0s).

I'm not entirely sure about whether item frames store their default values, if they do you were close - using Invisible:0b should work then (when testing for NBT you need to include the correct data type).


Otherwise in this case it's probably easiest to instead modify a dropped item entity instead, to make it the responsibility of the player to choose a non-invisible item frame in the first place.

/data merge entity @e[type=item,limit=1,sort=nearest,nbt={Item:{id:"minecraft:item_frame"}}] {Item:{tag:{EntityTag:{Invisible:1b}, display:{Name:'{"text":"Invisible Item Frame"}'}}}}

Add a Count:1b tag check (inside the Item nbt in the selector) if you want to prevent players from converting entire stacks at once.

2
  • 1
    Thank you so much for your help! Unfortunately, changing the code to Invisible:0b does not work. However, having the command block convert a dropped item entity is very clever. That may be the solution that I use. I appreciate the good suggestion!
    – Megan
    Apr 13 at 2:25
  • @Megan Maybe you can add an enchantment glint (by adding an empty enchantment NBT tag) or CustomModelData (if you're using a resource pack) to more visually distinctly change the item frame, both in the inventory and in item form. This way it's very obvious when the commandblock did something and also easier to distinguish the different frames.
    – Plagiatus
    Apr 13 at 5:39

You must log in to answer this question.

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