
vred's DP Lib
A data-pack "library" makes the creation of custom weapons easier.
vred's Data-Pack Library (vred's DP Lib for short) is the first Data-Pack library I've ever made. The main scope of this project is to add useful tools for creating custom items faster and more easily. This tools is split into different sections:
- Data Components
- Behaviour Components
- Function Tags
- Misc
Data Components These define information about the item. Which will be quite important!
As general rule, every vred's DP lib component goes in the "..." part
custom_data={vred_lib:{...}}
Component: id
string
This one doesn't really do anything important, just defines the id of an item.
Example:
give @s stick[custom_data={vred_lib:{id:"example:cool_stick"}}]
Component: weapon_id
string
This one very important, as it's required for upcoming components. id contains 2 parts, one of these is the weapon_id, which is the part after the ":".
It requires a folder named from weapon_id in the current datapack. As for the namespace, it will be taken from the next component, namespace.
Example:
give @s stick[custom_data={vred_lib:{id:"example:cooler_stick",weapon_id:cooler_stick}}]
This item won't do anything yet.
Component: namespace
string
This one is also very important, as it's required for upcoming components too. id contains 2 parts, one of these is the namespace, which is the part before the ":".
It requires a folder named from namespace in the current datapack.
Example:
give @s stick[custom_data={vred_lib:{id:"example:very_cool_stick",weapon_id:very_cool_stick,namespace:example}}]
This item won't do anything yet.
Behaviour Components These will run functions in a specific condition. These require a certain slot to work with:
mainhand:{...} in mainhand.
offhand:{...} in offhand.
head:{...} head slot.
chest:{...} chest slot.
legs:{...} chest slot.
feet:{...} chest slot.
all:{...} all the previous slots.
hand:{...} either hand.
armor:{...} any armor slot.
Component: on_hit_effect
boolean
This will run a command on hit. The function that will be run is this:
data/<namespace>/function/<weapon_id>/on_hit.mcfunction
Example:
give @s bow[custom_data={vred_lib:{id:"example:fast_bow",weapon_id:fast_bow,namespace:example,hand:{on_hit_effect:true}}}]
# data/example/function/fast_bow/on_hit.mcfunction
give @s arrow
say I hit an entity!
When hitting an entity (either arrow or hand) it will give an arrow to the player.
Component: entity_hit_effect
boolean
This will run a command when recieving a hit. The function that will be run is this:
data/<namespace>/function/<weapon_id>/entity_hit.mcfunction
Example:
give @s stick[custom_data={vred_lib:{id:"example:strong_shield",weapon_id:strong_shield,namespace:example,offhand:{entity_hit_effect:true}}}]
# data/example/function/strong_shield/entity_hit.mcfunction
effect give @s resistance 4 1 true
execute rotated as @s on attacker run tp @s ^ ^ ^2
While holding the shield in offhand, recieving a hit from an entity will push it away by 2 blocks.
Component: on_kill
boolean
This will run a command when kiling an entity. The function that will be run is this:
data/<namespace>/function/<weapon_id>/on_kill.mcfunction
Example:
give @s iron_sword[custom_data={vred_lib:{id:"example:bloodlust",weapon_id:bloodlust,namespace:example,mainhand:{on_kill_effect:true}}}]
# data/example/function/bloodlust/on_kill.mcfunction
effect give @s strength 10 1 true
After killing an entity, the user will get strength 2 for a few seconds.
Component: double_sneak_effect
boolean
This will run a command when pressing the sneak button twice in a small amount of time. The command will be run as such:
data/<namespace>/function/<weapon_id>/double_sneak.mcfunction
Example:
give @s stick[custom_data={vred_lib:{id:"example:very_cool_stick",weapon_id:very_cool_stick,namespace:example,hand:{double_sneak:true}}}]
# data/example/function/very_cool_stick/double_sneak.mcfunction
effect give @s speed 2 2
This will make the stick give speed 3 when tapping the sneak button twice in quick succession(while holding the item in either hand).
Component: tap_sneak_effect
boolean
This will run a command when sneaking once (tapping). The command will be run as such:
data/<namespace>/function/<weapon_id>/tap_sneak.mcfunction
Example:
give @s diamond_boots[custom_data={vred_lib:{id:"example:jumping_boots",weapon_id:jumping_boots,namespace:example,feet:{tap_sneak:true}}}]
# data/example/function/jumping_boots/tap_sneak.mcfunction
effect give @s jump_boost 3 1
particle cloud ^ ^ ^ 0 0 0 0.2 30
This will make the boots give jump boost and emit particles when tapping sneak.
Component: interaction
string
This component will spawn an interaction entity in front of the player while the player is holding the item in the main hand. The interaction entity can be used for both right and left click and the functions will be ran like this:
data/<namespace>/function/<weapon_id>/left_click.mcfunction
data/<namespace>/function/<weapon_id>/right_click.mcfunction
If it's "interaction:no_shift", the interaction entity will always be there. If it's "interaction:shift", the interaction entity will only appear while the player is shifting.
Example:
give @s netherite_shovel[custom_data={vred_lib:{id:"example:offbrand_spear",weapon_id:offbrand_spear,interaction:no_shift}}]
# data/example/function/offbrand_spear/left_click.mcfunction
say left click
# data/example/function/offbrand_spear/right_click.mcfunction
say right click
Component: no_interaction_right_click
boolean
This will run a command while holding right click. It requires the food component: minecraft:food={nutrition:0,saturation:0,can_always_eat:1b,eat_seconds:1000000}
The function will be ran constantly while holding right click.
data/<namespace>/function/<weapon_id>/right_click.mcfunction
Example: (needs to be changed)
give @s blaze_rod[custom_data={vred_lib:{id:"example:hot_rod",weapon_id:hot_rod,namespace:example,no_interaction_right_click:1b}},food={nutrition:0,saturation:0,can_always_eat:1b,eat_seconds:1000000}]
# data/example/function/hot_rod/right_click.mcfunction
execute anchored eyes run particle flame ^ ^ ^1
execute anchored eyes run particle flame ^ ^ ^2
execute anchored eyes run particle flame ^ ^ ^3
Component: weapon_type:bow
string
This will create a custom item like a bow that doesn't require arrows. To make the effect look better, use matching custom model data between base item and bow.
The component requires the food component: minecraft:food={nutrition:0,saturation:0,can_always_eat:1b,eat_seconds:1000000}
And will require a base item: {vred_lib:{base_item:"<item_id"}}
It can run a function when shooting the "arrow":
data/<namespace>/function/<weapon_id>/shot.mcfunction
Example:
give @s breeze_rod[custom_data={vred_lib:{id:"example:tnt_wand",weapon_id:tnt_wand,namespace:example,weapon_type:bow,base_item:"minecraft:breeze_rod"}}]
# data/example/function/tnt_wand/shot.mcfunction
execute if score @s component.bow.timer matches 21.. run summon tnt ^ ^ ^5 {Fuse:0s}
If the bow-like item has been in use more than 21 ticks, it will summon a tnt 5 blocks foward. This will only work in the main hand.
Component: scrollable
boolean
When dropping the item from the main hand, it reference an item modifier based on the map_id component.
This is a brand new system I made for displaying item descriptions, as each item modifier can reference a different lore page and change the map_id to go on the next page.
data/<namespace>/item_modifier/page/<weapon_id>/<n>.json
Example:
give @s diamond_sword[custom_data={vred_lib:{id:"example:multitool",weapon_id:multitool,namespace:example,scrollable:1b}},map_id=1,unbreakable={}]
# data/example/item_modifier/page/multitool/1.json (you can't have comments in json)
[{function:"set_item",item:"minecraft:netherite_axe"},{function:"set_components",components:{map_id:2}}]
# data/example/item_modifier/page/multitool/2.json
[{function:"set_item",item:"minecraft:diamond_pickaxe"},{function:"set_components",components:{map_id:3}}]
# data/example/item_modifier/page/multitool/2.json
[{function:"set_item",item:"minecraft:diamond_pickaxe"},{function:"set_components",components:{map_id:3}}]
# data/example/item_modifier/page/multitool/3.json
[{function:"set_item",item:"minecraft:diamond_shovel"},{function:"set_components",components:{map_id:4}}]
# data/example/item_modifier/page/multitool/4.json
[{function:"set_item",item:"minecraft:diamond_hoe"},{function:"set_components",components:{map_id:1}}]
The example is a pretty simple multitool, where each "page" switches the multitool to a different item. An important thing to mention is that each item modifier changes the map_id for next item modifier to use.
Function Tags Various function tags I use. Why not use the vanilla ones? I don't know.
#vred_lib:load
Works identically to normal #minecraft:load function. No idea why I made it.
#vred_lib:entity
Tick function only for entity, excluding the player.
#vred_lib:entity
Tick function only for player.
Misc Contains various miscellaneous, but useful stuff.
Predicate: vred_lib:stuff
This predicate includes entities that shouldn't be targeted.
It includes:
- Display entities;
- Entities being ridden;
- Dropped items;
- Arrows.
Predicate: vred_lib:id_check
Simple id system. Each player gets a vred_lib.id score.
You can use a predicate to check if the player has the same ID as the specified ID (stored in a fake player on a scoreboard).
In this case, this predicate will only trigger if the player’s vred_lib.id score is equal to the vred_lib.id score of the fake player (#temp).
Score: vred_lib.config
This score will be used for different mod compats. The mod name is stored with acronym. The main and only example at the moment is Iron's Spells and Spellbooks.
To check if the mod is present, check the vred_lib.config score of the fake player #iss_compat.
If the score is 1, that means the mod is present. The detection works by using a command from the mod.
There's also the vred_lib.iss.mana score, which can be used to check the amount of mana of the player.
The compatibilies will be expanded in the future with more mods, be sure to send some suggestions!
tag: 1slot_tag
This tag checks if the player has at least 1 free inventory and hotbar slot. If it has one, the player will have the tag.
Custom Projectiles
You can add custom projectiles. These projectiles are very barebones and don't even have gravity (will changed in the future).
To add a custom projectile,
scoreboard players operation #test vred_lib.id = @s vred_lib.id
execute rotated as @s anchored eyes positioned ~ ~-1 ~ run function vred_lib:projectile/summon {id:"<projectile_id>"}
function vred_lib:projectile/throw {id:"<projectile_id>"}
This will spawn the projectile with the <projectile_id>.
To change the behaviour and data of said projectile, target it back in the tick function. It has a built-in timer, called rayAge.
The throw function will save a copy of the item and reduce the amount of the item in the main hand.
Later then use function vred_lib:projectile/return {id:"<projectile_id>"} as the projectile to make the item return to the owner.
Custom Particles
You can add custom particles. These particles are very barebones and are just fancy item displays that move. To spawn a custom projectile you first need to add the data function in this tag: #vred_lib:particle_load
{
"replace": false,
"values": [
"example:particle/load"
]
}
# data/example/function/particle/load.mcfunction
## beetroot particle, hell yeah
item replace entity @s[tag=<particle.id>] contents with beetroot
In order to summon it:
function vred_lib:particle_system/test/1 {id:<particle.id>,count:<count>,dx:<dx>,dy:<dy>,dz:<dz>,scale:<scale>,\
speed:<speed> lifetime:<lifetime>,\
owner_id:<owner_id, vred_lib.id score of the particle owner>}
<particle.id> is the particle id (string).
<dx>,<dy>,<dz> indicate the area in which the particle will be spawned (integer).
<speed> is used to calculate the speed of the particle (integer)
actual speed = (<lifetime> how long the particle will last (integer, arbitrary).
<owner_id> is the vred_lib.id score of the owner of the particle (either can be "none" or integer). If it's none, the particle has just no owner.
Back to our example:
function vred_lib:particle_system/test/1 {id:<particle.id>,count:15,dx:0,dy:0,dz:0,scale:1,speed:1,lifetime:20,owner_id:none}
