We've split up the commands, scripting and mods, and add ons category! Please be sure you get your thread in the right place.

2

Hasitem should exist on all versions and allow selection of data components

3 Comments

Please sign in to leave a comment.

Sorted by oldest
  • 2
    Registered User commented
    Comment actions Permalink

    I have some examples of what this would look like if it were added to help make discussing my point simpler.

    Someone could put these four commands behind a button to behave like a shop for an adventure map or minigame:

    /execute as @a[hasitem=[minecraft:diamond, 5..] run tag @s add enough_to_buy

    /give @a[tag=enough_to_buy] minecraft:diamond_sword[unbreakable={}]

    /clear @a[tag=enough_to_buy] minecraft:diamond 5

    /tag @a remove enough_to_buy

     

    When activated, it would give the tag “enough_to_buy” to any players with more than 5 diamonds. Then, it would give them an unbreakable diamond sword and take their 5 diamonds. The final command would remove their tag.

    In this case, the Hasitem selector would make things substantially easier. The addition of the component at the end of the item ID would make it more versatile in both versions.

     

    If this command was run every tick, it would give all players with more than 64 iron ingots named “Heavy Iron Ingot” slowness because of the weight.

    /effect @a[hasitem=[minecraft:iron_ingot[custom_name={“Heavy Iron Ingot”}], 64..] give slowness 1 1 true

    To make this command work in Bedrock edition, you could remove the “give” term in the command.

  • 2
    Registered User commented
    Comment actions Permalink

    Additional examples:

    @a[hasitem=[minecraft:diamond]]
    Selects all players with a diamond in their inventory, regardless of amount and data.

    @a[hasitem=![minecraft:diamond]]
    Selects all players without a single diamond in their inventory, regardless of data.

    @a[hasitem=[minecraft:diamond_sword[unbreakable={}]]]
    Selects all players with a diamond sword with the “unbreakable” data component. Other data components are ignored, including name, attack damage, and durability.

    @a[hasitem=![minecraft:diamond_sword[unbreakable={}]]]
    Selects all players without an unbreakable diamond sword. Players with breakable swords would be selected. Those who have unbreakable swords with different data would not be selected.

    @a[hasitem=[minecraft:diamond_sword, 2..]]
    Selects all players with multiple diamond swords.

    @a[hasitem=[minecraft:diamond_sword[unbreakable={}], 2..]]
    Selects all players with multiple unbreakable diamond swords. Players with one of each would not be counted, and players with multiple normal diamond swords would not be counted.

  • 2
    Registered User commented
    Comment actions Permalink

    Yes! This would be very useful for making chest UI shop systems, which lots of maps use.