Play Strawberry Docs

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.

text
# 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
end

When blocks run

Block

Runs when a player

Values

cancel stops

on use "<model>"

right clicks with it, in the air or on a block

player, item, target

the use

on attack "<model>"

hits an entity with it in the main hand

player, item, target

the hit

on break "<model>"

breaks a block with it in the main hand

player, item, block, block_location

the break

on consume "<model>"

eats or drinks it, if the item can be eaten or drunk

player, item

the eating

on equip "<model>"

puts it on (head, chest, legs or feet)

player, item, slot

nothing

on unequip "<model>"

takes it off

player, item, slot

nothing

  • In on use, target is the entity the player looks at within 5 blocks, or none. In on attack, it is the entity hit.
  • on break without a model id is the block event.
  • cancel does not load in on equip and on 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 item n charges (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 next take charge stops its block. break uses up the item with the last charge, and the rest of a stack starts again full.
  • take charge or take <n> charges takes charges. If too few are left, the block stops there.
  • give charges or give <n> charges gives charges back, up to the item's charges.
  • charges() is the number of charges the item has.
  • cooldown <n> ticks|seconds|minutes starts the game's cooldown on the item, up to one hour. on use blocks do not run until it ends.
  • Charge lines and cooldown do not load in on 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. Without at, the particles show around the player.
  • <n> is 1 to 64 (default 10). spread is 0 to 4 (default 0.3).
  • color and size (0.1 to 4) work with dust only.

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> hurts player or target: 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|minutes gives a player an effect such as speed or regeneration: level 1 to 5, at most 10 minutes.
  • A harmful effect such as poison or slowness can only go to the player who uses the item.
  • There are no instant effects. Use damage and heal.
  • 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 charges covers charge lines and cooldown, particles covers particles, and combat covers damage, heal and effect. 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 damage runs no item block, so item blocks never start each other.

On this page