Skip to content

Script API reference ​

The methods and objects every binding offers (KubeJS, CraftTweaker, MineTweaker 3) and the Java API other mods can call. Where a binding differs, its page says so (for example the Api / Player objects of MineTweaker 3).

Registration ​

MethodEffect
condition(name, [description,] fn)rule condition script:<name>; fn(player) returns true / false
variable(name, [description,] fn)template variable {script:<name>}; fn(player, damage) returns text (& colors, lang: keys)
addRule(rule)a rule with match, conditions, then / else (an object in KubeJS, JSON text in ZenScript)
addTemplate(output, lines)a template of hover, line, summary, alert or copy
setSetting(key, value, locked)a pack value and lock of a setting (Settings & locks); an empty value only locks
setSettingRule(key, json)a setting with unlock conditions: a display switch or command.<name> and its object
addLock(group, name)turn a command off for everyone (commands, same as command.<name>: none; for operators only use setSetting("command.<name>", "op", false)), lock a personal feature (personal: renames, hints, ignore, templates) or a template output (templates)
disableVariable(name)switch a template variable off (renders empty everywhere)

Names use letters, digits, _, . and - and are not case-sensitive. Registering a name again replaces it. Runtime entries are an extra pack source after the pack files: their rules come after the files' rules, their settings and templates replace the files' entries of the same key, locks and switched-off variables add up. The pack files themselves are never changed. In /whm reload and the pack editor they appear as script:<mod> (read-only).

Events ​

EventPropertiesMethods
damageRecordedplayer, damagesetName(text), setHint(text) ("" = no tip), addBadge(text), hide(field), cancel()
deathplayer, death, killingBlowsetName, setHint, addBadge, hide (all on the killing blow), addSummaryLine(text)
respawnplayer, death-
alertplayer, kind (totem, heavy, prevented), damage, snapshot-

hide takes the field names of the rules hide list. A rule that sets a name or tip still wins; hidden fields of rules and scripts add up. Summary lines and badges accept & colors, lang: keys and template variables such as {player}.

Damage ​

All script mods: damageId, damageType, name (English, as a rename / rule shows it), attackerName, attackerId, modId, weaponName, weaponId, amount (health points), hearts, healthAfter, maxHealth, distance (-1 = unknown), hits, dimension, killingBlow, projectile, fire, explosion, magic, variable(name). KubeJS also: directName, modName, ownerName, rawAmount, absorbed, time, totem, heavy, reflected, bypassArmor, properties, hidden, badges.

Death ​

kind, time, records (oldest first), killingBlow, deathMessage (plain English), totalAmount.

Reading ​

MethodResult
lastDeath(player)the last death recap, or nothing
history(player, n)the newest n records, oldest first
stats(player)deaths, damageTaken, causes (KubeJS)
test(player, damageId[, entityId])what /whm test shows for that player: name, hint, rule (the first matching rule), fieldRules (field -> "match (file #n)"), hidden, ignored, deathMessage, commands
check(player, condition)any rule condition, e.g. check(player, 'advancement:minecraft:story/mine_diamond')
registrations() (KubeJS)what scripts have registered: kind, owner, name, value, fromHook, failed
apiVersion (KubeJS)version of the What Hit Me? API, 2 in What Hit Me? 2.0

Java API for mod developers ​

Other mods can use the same API from Java without any script mod: io.github.junjun1z.whathitme.api.WhatHitMeApi (Java 8, no Minecraft classes). Pass your mod id as the owner; players can be given as the Minecraft player object, a UUID or a name.

java
WhatHitMeApi.registerCondition("mymod", "boss_ready", "Boss altar activated", p -> MyData.ready(p.getUuid()));
WhatHitMeApi.listen("mymod", DeathEvent.class, e -> e.addSummaryLine("&7Tip from My Mod"));
MethodDoes
API_VERSION2 (What Hit Me? 2.0)
registerCondition(owner, name, description, condition) / registerVariable(owner, name, description, variable)script:<name> condition (WhmPlayer -> boolean) / {script:<name>} variable ((WhmPlayer, WhmDamage) -> text)
listen(owner, eventClass, listener) / listen(owner, "death", listener)DamageRecordedEvent, DeathEvent, RespawnEvent, AlertEvent (names damageRecorded, death, respawn, alert)
onRegister(owner, hook)Runs the hook on every rebuild (server start, /whm reload, the script mod's reload; at once when the server is already running). What it registers is removed before each rebuild. One hook per owner: a new one replaces the old one
addRule(owner, map or json), addTemplate(owner, output, lines)Runtime rules and templates (source script:<owner>), after the pack files
setSetting(owner, key, value, locked), setSettingRule(owner, key, map or json)Pack values, locks and unlock conditions of settings
lock(owner, group, name) with LOCK_COMMANDS / LOCK_PERSONAL / LOCK_TEMPLATES, disableVariable(owner, name)Locks and switched-off variables
lastDeath(player), history(player, n), stats(player), test(player, damageId, entityId[, assume]), player(player)Read access; player(...) gives a WhmPlayer with getUuid(), getName(), getNativePlayer() and check(condition)
registrations()Everything registered, with owner and failures
clear(owner) / removeHooks(owner)Remove everything of an owner / only its register hooks
rebuild() / rebuildLater()Rebuild now / on the next server tick (for script mods without an "after the scripts" hook)

Load your integration class only when What Hit Me? is installed (for example behind a mod-loaded check), so What Hit Me? stays optional for your mod too.

Made by junjun1z. The mods are MIT licensed.