Model items
How to make something happen when a player uses a custom model item such as a wand.
An item block
A model item is a custom item of the custom-models script, such as a wand, a sword or a hat. You name it by its model id; /models list shows the ids, for example wands.fire_wand.
# The fire wand: 20 charges, one a right click; the last one breaks it.
uses message, charges, particles, combat
text empty
en "&7The wand is empty."
es "&7La varita está vacía."
tr "&7Asa boş."
end
on use "wands.fire_wand"
charges 20 then break
if charges() = 1
message lang("empty")
end
take charge
cooldown 1 second
sound "entity.blaze.shoot"
particles "flame" 12 at target
damage target 4
endWhen blocks run
Block | Runs when a player | Values |
|
|---|---|---|---|
| right clicks with it, in the air or on a block |
| the use |
| hits an entity with it in the main hand |
| the hit |
| breaks a block with it in the main hand |
| the break |
| eats or drinks it, if the item can be eaten or drunk |
| the eating |
| puts it on (head, chest, legs or feet) |
| nothing |
| takes it off |
| nothing |
- In
on use,targetis the entity the player looks at within 5 blocks, or none. Inon attack, it is the entity hit. on breakwithout a model id is the block event.canceldoes not load inon equipandon unequip.- If a protection already refused the action, the item block does not run.
- A model id that the server does not have is not an error. Its blocks run once a player holds such an item.
What an item block can do
Ordinary statements such as if, set, loops and wait work. console, teleport, move, gamemode and broadcast do not.
Charges and cooldown
charges <n> [then stop|then break]gives the itemncharges (1 to 10,000). Write it directly in one of the model's blocks, once per model.- At zero,
stop(the default) keeps the item, and the nexttake chargestops its block.breakuses up the item with the last charge, and the rest of a stack starts again full. take chargeortake <n> chargestakes charges. If too few are left, the block stops there.give chargesorgive <n> chargesgives charges back, up to the item'scharges.charges()is the number of charges the item has.cooldown <n> ticks|seconds|minutesstarts the game's cooldown on the item, up to one hour.on useblocks do not run until it ends.- Charge lines and
cooldowndo not load inon unequip.
Charges show as a line under the item's name, in the holder's language. Use charges on items with a stack size of 1, because a stack shares one count.
Particles
particles "<name>" [<n>] [at <place>] [color "#rrggbb"] [size <n>] [spread <n>]
- The place is a location, a player or
target. Withoutat, the particles show around the player. <n>is 1 to 64 (default 10).spreadis 0 to 4 (default 0.3).colorandsize(0.1 to 4) work withdustonly.
The names are: angry_villager, ash, bubble, cloud, composter, crit, damage_indicator, dolphin, dust, electric_spark, enchant, enchanted_hit, end_rod, explosion, firework, flame, glow, gust, happy_villager, heart, large_smoke, lava, nautilus, note, poof, portal, reverse_portal, scrape, small_flame, smoke, snowflake, sonic_boom, soul, soul_fire_flame, splash, sweep_attack, totem_of_undying, wax_off, wax_on and witch.
Damage, heal and effects
damage <who> <n>hurtsplayerortarget: more than 0, at most 20. Damage to others counts as a hit by the player, so PvP rules and protections apply.heal <who> <n>gives health back: more than 0, at most 20.effect <who> <effect> [<level>] for <n> ticks|seconds|minutesgives a player an effect such asspeedorregeneration: level 1 to 5, at most 10 minutes.- A harmful effect such as
poisonorslownesscan only go to the player who uses the item. - There are no instant effects. Use
damageandheal. - On someone else, these three do nothing where the player may not use things, such as a protected area.
Messages and items
sound, message, title, actionbar, give, take and log work as in other blocks.
Permissions and limits
uses chargescovers charge lines andcooldown,particlescoversparticles, andcombatcoversdamage,healandeffect. Each needs your consent.- One run of an item block does at most 16 actions, and a mini-script has at most 64 item blocks.
- A number you write in a charge, cooldown, particle, damage, heal or effect line is checked when the file loads. A number worked out by the script is checked when the line runs.
- A hit caused by your own
damageruns no item block, so item blocks never start each other.