#target dropped item with specific nbt

1 messages · Page 1 of 1 (latest)

green rune
#

In an adventure map i'd like to make it so when the player drops a certain item in their inventory, the datapack will instantly execute a function as that item (in order to give it back to the player and then kill itself).

the give command i used to give it was this:
/give @a iron_pickaxe[item_model="minecraft:shears",can_break=[{blocks:"waxed_oxidized_copper_grate"}],item_name="Wire cutters"]

i am unsure how to translate this to nbt so i can target item type entities with that specific data.

i'm on 26.1.1 and my goal is to basically prevent the player from losing that item since its their main tool throughout the map.

if there is a way to just tag that specific item so i only have to target a specific nbt feild that would be great too. i just need a way to target that specific item when it gets dropped.

sleek dew
#

You do not want to target nbt directly. That's expensive.

First, you can set up a scoreboard with the criteria of dropping that specific item.

In your tick function check for any player with a score of 1 or higher on that scoreboard. If there is one, kill every item entity that matches the item and give it to the player with that score. Then reset it back to 0.

You can easily make your item unique by adding a custom data component like so:

give @a iron_pickaxe[item_model="minecraft:shears",can_break=[{blocks:"waxed_oxidized_copper_grate"}],item_name="Wire cutters",custom_data={id:"wire_cutter"}]`

To target the item entity, use this:

execute as @e[type=item] if items entity @s contents iron_pickaxe[custom_data~{id:wire_cutter}] run kill
#

if item is much more performance friendly than nbt checks.

green rune
#

oh interesting, didnt realize that could work. thanks.

#

how/when would i increment that score though (or does it automatically?) and what if i add more "no not drop" items later with different values and stuff?

#

just add more scoreboard objectives for dropping the other items?

#

nvm i think those are dumb questions- easy to figure out myself.

#

closing for now.

short brookBOT
green rune
#

re-opening because apparently the coreboard part isnt as straightforward as i thought.

green rune
#

my question:

First, you can set up a scoreboard with the criteria of dropping that specific item.

yeah uh...scoreboards dont have a "drop specific item" critieria. or a drop item critieria in general

#

so what did you mean by this?

#

i'd ping but...your a moderator. i dont wanna break "dont ping staff" rules

willow ferry
#

They do

#

minecraft.dropped:<item id>

green rune
#

not according to the minecraft wiki. so im a bit confused

willow ferry
#
Minecraft Wiki

Statistics is a game feature that allows players to track certain tasks in the form of numerical data.
Statistics are present only in Java Edition. Bedrock Edition has no equivalent of statistics in-game, but a part of statistics can be viewed on the player's profile screen.

green rune
willow ferry
#

Any statistic can be used as a criteria for a scoreboard

green rune
#

oh

#

didnt know that

willow ferry
#

And the Compound Criteria section

green rune
#

ah

#

didnt see that

#

it wasnt in the table so i kinda glossed over it

willow ferry
#

No problem, learning where to find information like this is part of the learning process, which is why I pointed out where you could have looked

#

Info gets very wide and applied in many ways, very quickly