0

I'm looking to add nbt to an item that's inside a dropper. For example: there's a wooden sword in the middle slot. First you add +10 Damage and +1 Attack speed to it. Then you add Fire Aspect II on it. And last you add a tag "Level3" and lore saying "Wildfire" to it.

I haven't done this before so I'm going to need a lot of explanation.

I had a question a lot like this one, but it's not for 1.17 and I can't get it to work.

2
  • What do you mean by "a level 3 tag"? Do you mean a custom NBT tag that can be detected later? – ExpertCoder14 Jun 8 at 19:18
  • Yeah, just a custom tag to check for later. I'm trying to make weapons that can be upgraded 3 times and I need to keep track of the level. Since each upgrade can be different I can't just make a complete version with every combination because that would soon reach over thousands in number. – Wicked Grinn Jun 8 at 19:29
2

This would require a lot of NBT modification. Let's look at what the completed NBT of your item should look like:

{
  AttributeModifiers: [
    {
      AttributeName: "generic.attack_damage",
      Slot: "mainhand",
      Operation: 0,
      Amount: 10.0d,
      UUID: [I;382757,9285892,28488284,19948385]
    },
    {
      AttributeName: "generic.attack_damage",
      Slot: "mainhand",
      Operation: 0,
      Amount: 10.0d,
      UUID: [I;382757,9285892,28488284,19948387]
    }
  ],
  Enchantments: [
    {id: "minecraft:fire_aspect", lvl: 2}
  ],
  display: {
    Lore: ['"Wildfire"']
  },
  Level3: 1b
}

You can modify the data of an item in the dropper using the following command:

data modify block ~ ~ ~ Items[{Slot:4b}].tag merge value …

From there, insert the NBT data I placed above.

5
  • Thank you! This helps, only one thing I hoped I could do is add lore rather than replace the already existing one. But other than that it works exactly as I hoped. – Wicked Grinn Jun 8 at 19:36
  • @WickedGrinn I'm not sure if that's even possible. You might be able to combine the lists by doing some other kind of more complicated thing and then set the new list as the lore, but I don't know too much about that. Just an idea – Penguin Jun 8 at 21:50
  • 1
    @WickedGrinn Oh, you can do that, just leave the Lore out of the first command, then use a separate command to add the lore text. – ExpertCoder14 Jun 8 at 22:40
  • 1
    @Penguin No, it's possible. Hint: data modify storage namespace:test MyList append value "second list item" – ExpertCoder14 Jun 8 at 22:41
  • just an addition, you can change the nbt selector from Items[{Slot:4b}] to anything more specific. If you want to select a wooden sword, then you can do Items[{id:"minecraft:wooden_sword"}] or any other tag that describes the item you want to target – Jam Jun 9 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.