Now it's time to make your item do stuff!
The limits of your custom item are the limits of Minecraft commands and your imagination!
If you know how, you could develop some sort of plugin/mod implementation, but if not that's fine!
In my opinion, using Visual Studio Code is optimal, but other text editors should work too. I HIGHLY recommend using the following extensions for VS Code:
"Data-pack Helper Plus" & "language-mcfunction" (Both should have 100,000+ downloads)
Setting up the functionality is pretty straightforward:
We want to have all of the code that the item runs all in one place.
To start, navigate through the following folders of the data-pack and open the file: data/custom_items/functions/technical/item_use.mcfunction
Look at the section labeled "ITEMS":
#------------------------------------------ITEMS------------------------------------------#
execute if score @s CustomItemStorage matches 1 run function custom_item:technical/use/1
execute if score @s CustomItemStorage matches 2 run function custom_item:technical/use/2
execute if score @s CustomItemStorage matches 3 run function custom_item:technical/use/3
...
execute if score @s CustomItemStorage matches # run function custom_item:technical/use/#
#-----------------------------------------------------------------------------------------#
Copy/paste one of those lines below the others and change the numbers to the MDV (Established on the Custom Model Data (Texture) page) (Change both the number after "matches" and at the end of the line)
If you're using VS Code and my recommended extensions, do 'Ctrl + . (period)' and select the option to create the function or press the enter/return key.
Otherwise, right click the "use" folder under "technical" and select new file. Name it "#.mcfunction" # being the MDV.
You should also create a function for giving the item.
Navigate to data/custom_items/functions/give/
Right click the give folder, select new file, and give it the name "name.mcfunction". "name" being the name you want for the item. (Must be lower case w/ underscores)
In that function put something like this (one line):
give @s minecraft:snowball{Custom:1, CustomModelData:<MDV>, display:{Name:'[{"text":"<NAME>","italic":false,"color":"<NAME_COLOR>"}]',Lore:['{"text": "DESCRIPTION","color": "gray"}']}}
Replace phrases like '<ALL_CAPS>' with their respective values.
You can now get your item by running the command:
" /function custom_item:give/<NAME> "
Time for the fun part...
* DON'T FORGET TO SAVE THE FILES! (Ctrl + S) *
Now we can actually set up the code for the custom item!
This is also when you can start to depart from the tutorial and customize!
However, this tutorial will walk you through one of the pre-made items in this pack; the "Dirt Blaster"!
First Line:
execute if entity @s[gamemode=!creative] run function custom_item:give/dirt_blaster
You'll probably have this as the first line for many of your custom items. This command makes the item multi-use instead of single-use. It does this by giving a copy of the item to the user, assuming they aren't in creative.
Also, by default, commands ran by an item are ran as and at the player.
Next 4 Lines:
scoreboard players set @s CustomItemRaycastType 2
scoreboard players set @s CustomItemRaycastSubtype 2
scoreboard players set @s CustomItemRaycastRange 35
scoreboard players set @s CustomItemRaycastParticleID 2
These lines are for raycast setup. If you didn't know, this datapack has a built-in raycast utility and you need to implement these 4 parameters whenever it's used:
"CustomItemRaycastType": Value determines what the ray collides with. (1:player,2:blocks,3:entities)
"CustomItemRaycastSubtype": Value determines what function is ran on collision. (Functions are under the "use_ext" (Use Extended) folder)
"CustomItemRaycastRange": Value determines how far the ray will go before terminating. (Units of 0.25 meters) (1 Block-length = 1 meter) (Collision function will not be ran)
"CustomItemRaycastParticleID": Value determines what particle effects are created as the ray travels.
Final Line:
function custom_item:utility/ray/cast
Casts the ray.
Ray Collision Function ("raysub2.mcfunction"):
setblock ~ ~ ~ dirt
playsound minecraft:block.rooted_dirt.place block @a ~ ~ ~
Any commands ran inside a ray collision function are ran as and at the ray when it collides. In this case, we will set the block that the ray collides with to dirt and play a sound effect at that location.
I trust that you can figure out how to add onto the ray utility by going into the code and copying/pasting some lines to create more particles, functions, etc.
Well, that should cover everything that you would need to know. I started working on this project a while back so I'm honestly am not sure how out-dated this is or will be. Good luck creating your custom items!