1

Item Effects?

Larry the Hamster's Avatar Larry the Hamster3/18/23 2:11 pm
1 emeralds 166 3
4/27/2023 7:40 am
EndEmperor's Avatar EndEmperor
Is it possible to make holding an item give you an effect? If so, how do you do it?
Posted by Larry the Hamster's Avatar
Larry the Hamster
Level 25 : Expert Engineer
41

Create an account or sign in to comment.

3

EndEmperor
04/27/2023 7:40 am
Level 8 : Apprentice Miner
history
EndEmperor's Avatar
it isn't working in 1.19.2

(with cycled command blocks)
1
AmericanBagel
03/20/2023 6:43 pm
Level 43 : Master Engineer
AmericanBagel's Avatar
Sure. Let's say the item is a nametag called "Talisman of Speed". Here's the /give command:

/give @p name_tag{display:{Name:'{"text":"Lesser Talisman of Speed","color":"aqua"}',Lore:['{"text":"This talisman bears the Sigil","color":"gray","italic":true}','{"text":"of the Wind, a mark which calls","color":"gray","italic":true}','{"text":"upon the wind spirits of old.","color":"gray","italic":true}']},talisman:1b,talismanEffects:[{effect:"speed",lvl:1b}],Enchantments:[{}]} 1
What this command does is gives a name tag with NBT tags which set the item's name and lore (description) to something fancy. I also added custom nbt tags -- tags which don't mean anything to the game, but which we can read and use to store data in the item. In this case, that data represents that this item is a talisman (talisman:1b), and it gives an array (a list with unnamed items) of objects (a list with named objects) showing the effect and level of effect that we want this talisman to give the holder. Again, this data means nothing to the game. Putting this data in there won't make the game magically give the holder Speed I. It just gives us data so we can, for example, easily add multiple talismans into the game.

Now we need to set up a data pack. There's many tutorials on that . Look it up yourself or download a template. In the main function, which should be called something like "1t.mcfunction" or "main.mcfunction" or "tick.mcfunction" or "loop.mcfunction" or something along those lines if you're using a template (if you're making your own, just name it whatever, preferably something conventional like I listed above, and make sure the minecraft:tick function tag lists it), add the following command:

execute as @a[nbt={SelectedItem:{tag:{talisman:1b}}}] run function your_datapack_namespace_here:hold_talisman... if you want to run a function which can run multiple commands, or:

execute as @a[nbt={SelectedItem:{tag:{talisman:1b}}}] run effect give @s speed 1 0 true... if you don't want to bother with another function or you want to just use a repeating, always-active (or redstone powered) command block.

What these execute commands do is they try to run a command from every player (@a) who has a the NBT (nbt=) an item in their main hand (SelectedItem) with the NBT tag of talisman:1b. The effect command in the second option gives the speed effect to the player who is holding the talisman (@s) speed for 1 second at level 0 (you'll know it as Level I. Computers usually start counting from 0 instead of 1 like normal people, so level I is, in the code, level 0, and level II is, in the code, level 1, and so on.).



Feel free to use something like MCStacker to generate your own item with a fancy name and description, give it a custom NBT tag in the CustomNBT slot, and change the "talisman:1b" NBT tag to your custom NBT tag. Also feel free to change the effect it gives.



This is obviously a simplified example. If you want several items, for example, several talismans or even talismans with random effects and levels, that's where it would get more complicated. LMK if you need help. Good luck!
2
Larry the Hamster
03/21/2023 12:13 am
Level 25 : Expert Engineer
Larry the Hamster's Avatar
Thank you, this was very helpful. It was enough detail to get me started but not so much that is overwhelmed me.
I'll let you know if I run into issues or questions.
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome