# Verified server facts
Everything checked on the live server (English summary of https://jmvcc.dev/src/semantics.md): variables and threads, control flow, numbers and text, units, items and menus, blocks, events, loops and placeholders, displays, selection and mobs, open questions. Open when unsure how the server behaves.

## Module size (2026-12-04)
- One code row (event / function / process) ≤ 67 blocks in the `jmvcc trace` count (each action, condition, else,
  loop and closing bracket = 1); 68+ → "Не хватает места для загрузки импортируемого модуля". The compiler cuts rows
  at 67 by default (tail → `jmcc.fN`). A module ≤ about 526 rows on rank Star, 548 on Nova.
## Variables and threads
- Scopes: `save var` whole world, survives restart; `game var` whole world until restart; `var` local to the
  thread, passed into called functions (they see AND change it); `line var` only its code line, survives
  `code::wait` inside that line, not passed to functions.
- A thread tied to a player/entity (its events, `proc()` started from them) stops mid-execution when the target
  leaves/dies. `repeat::forever` in `player_join` dies when the player quits. World loops: top-level code or
  `code::start_process("p", target_mode = "NO_TARGET")`.
- A variable never assigned is the NUMBER 0 (text `0`). So: defaults with `x ??= value`; before teleporting
  to a stored location keep a flag (`%player%_has_cp = 1` when you store `%player%_cp`, `if (%player%_has_cp == 1)`
  before `player::teleport(%player%_cp)`); `m.set_map_value(...)` on a never-set `m` is a server error that
  STOPS the code line — first `m ??= variable::create_map_from_values([], [])` (= empty map, size 0, text `{}`).
- `var b = a` for a list COPIES it: `b[0] = "z"` does not change `a`.
- `variable::is_type(x, variable_type = "ARRAY")`: list (also empty) ARRAY, map MAP, text (also "5") TEXT, number
  NUMBER, never set NUMBER; a list in `value` is not spread (server-check-32). The kind check for mixed calls uses it.
- `code::catch_error(e) { }` (controller_exception; e and t of `code::measure_time(t) { }` need no `var`): without an error e is not touched; an error stops the body, e = the
  error id (text) or the throw message, the code after the block runs; nested blocks catch only their own error.
  `code::end_thread()` inside the body (also from a called function) exits ONLY the block — `try` re-ends the thread
  after it when end_thread is in the try body itself (not from a called function: warning). return / stop_repeat / skip_iteration pass through. `>` / number_in_range on a non-number text is a server
  error (server-check-28, -34, -35; the try/match sugar verified live: server-check-36).
- On `/play` world code (top level) runs FIRST, then `player_join`; join sees the game vars world code set.
- Background blocks (sc-lang57): `std::every` in `player_join` + a second `/play` — the old loop stops, only the new
  one runs; the counter is per player (top-level code: one per world); `break` works also when a long body is cut
  into `jmcc.fN`; a server error inside `std::async` does not stop the caller; the caller's `var`s arrive as copies.
- The `entity_death` thread keeps running after `code::wait` (the entity is already dead, the code goes on) —
  the exception to "threads die with their target".
## Control flow
- `return` in a function leaves only the function; the code after the call goes on; return values arrive.
- `&&`, `||`, `!`, `else`, text `==`, `repeat::while(i < 3)` work as written.
- `break` outside a loop inside a function = `control_end_thread`: ends the WHOLE calling event line (the
  caller's loop and the code after it too; the compiler warns). Leave a function with `return`; stop the
  caller's `repeat::forever` with `code::stop_repeat()` (works from a called function).
- `repeat::on_range(0, 3)` includes the end: 0 1 2 3.
## Numbers and text
- List indexes start at 0. `floor(75 / 60)` = 1 (no `.0`), `75 % 60` = 15, `-7 % 60` = -7 (sign kept, like Java).
- Text that looks like a number works in math: `var s = "5"` then `s * 2` = 10 (a text LITERAL in math, `"5" * 2`,
  is a compile error — write the number).
- `cos`/`sin` take degrees: `cos(120)` = `-0.5000000000` in text (10 decimals), `sin(90)` = `1`.
- `\n` in text and `player::message([...], merging = "SEPARATE_LINES")` give line breaks.
- Colors: `&a`, `&c`... work (until the end of the text); MiniMessage `<red>` and `§b` do NOT (shown as text).
- Text components with `set_component_hover` / `set_component_click` work (show_text, copy_to_clipboard).
- A text value keeps at most 25000 characters: the rest is cut SILENTLY, no error (a literal, `repeat_text`, joining).
  Longer → split into a list of texts. The compiler warns `text-too-long` on such texts in the module.
- `sort_any_map` keeps the sorted order: `get_map_key_by_index` and `for_each` follow it.
## Units
- Number arguments show their unit in signatures (`fade_in: number(ticks)`); `*_ticks`/`ticks` are ticks
  (20 = 1 s). `code::wait` takes `time_unit` (default TICKS). `potion(..., duration = 200)` = 200 ticks (10 s).
- `value::timestamp` = UNIX time in milliseconds; `value::world_time` = world time in ticks.
## Items, sound, menus
- `give_item` without `amount` gives the item's count: `item("x")` → 1, `item("golden_apple", count = 3)` → 3.
  With `amount` it replaces count: `give_item(item("arrow", count = 16), amount = 2)` gives 2.
- `play_sound` without `location` plays to the player, not from a point.
- A missing key / index out of range in an explicit `get_map_value` / `get_map_value_single` / `get_list_value`
  call without `default_value` gives null: it prints "0" and math reads 0, but `== 0` and `in 0..0` are FALSE
  (verified). `m[k]` / `l[i]` pass `default_value = 0` for you; in explicit calls pass `default_value = 0`.
- `player_click_inventory` on a `show_menu`: `value::event_slot` from 0, `value::event_item` = the clicked
  menu item, `value::open_inventory_custom_id` = the `custom_id` of `show_menu`, `value::event_slot_type` =
  `"container"` for a menu slot. Only the menu half reaches `player_click_inventory`: clicks in the player's
  own inventory while a menu is open go to `player_click_own_inventory` (`event_slot` hotbar 0..8, main
  9..35, `event_slot_type` also `"container"`). There `value::open_inventory_custom_id` is also set (the open
  menu's id) and a shift-click has `value::event_inventory_click_type` = `"shift_left"`; `world::cancel_event()`
  on it keeps the item out of the menu.
- `show_menu` puts the 1st list item in slot 0, then slots follow list order. For a gap `item("air")` in the
  list probably gives an empty slot (compiles; not checked on the server).
- `player::set_boss_bar(..., progress)` is 0..100 (50 = half; 0.5 is almost empty); `&` colors in its title
  work (`&4&l` = dark red bold).
- `player::set_slot_item(item, 8)`: slot 8 is the LAST hotbar slot (slots start at 0). It overwrites that slot.
- `world::remove_scoreboard` of a board that does not exist does nothing; the code line goes on.
- Sidebar: `world::create_scoreboard(id, "&cTitle")` + `world::set_scoreboard_score(id, "Line text", n)` +
  `player::show_scoreboard(id)` shows it on the right; `text` is the line label, `&` colors work.
- `player_right_click` with a book in hand fires; `value::main_hand_item` is that book.
## Blocks
- `value::event_block_type` is the FULL block state, e.g. `"minecraft:light_weighted_pressure_plate[power=0]"`:
  `==` with an id (with or without `minecraft:`) is always false. Check the block type with
  `world::event_block_equals([item("id")])` or `world::block_equals(value::event_block, [item("id")])` (both work).
- `value::event_block` is the block's location (`{"x":0.5,"y":4.5,"z":0.5}`), not an id.
- `==` on two locations works (equal `value::location`s, equal literals `location(1, 2, 3)`). A stored
  `value::event_block` == the next one of the same plate is true too (verified) — de-dup plates this way. Comparing `value::event_block` with a
  literal is NOT checked either (it is the block centre x.5 y.5 z.5, and `location()` defaults yaw to 90): to mark one
  special plate use a different plate type (the parkour recipe's stone start plate).
## Events and players
- `value::players` (number in the world) and `value::all_players_names` (list of names) work in world code
  with no target (top-level code / world loop).
- `event<player_join>` also fires for players already in the world when the game starts (`/play`,
  `jmvcc client deploy`), so per-player init and HUD loops in `player_join` cover them.
- `event<player_move>` fires every tick while the player moves (20/s, also while falling), 0 times standing still.
  Camera rotation alone: not checked. Keep it cheap.
- Standing on a pressure plate: `player_interact` with `event_interaction == "physical"` fires about 2 times a
  second while you stand (6 in 3 s) — add a cooldown, or act only on a NEW plate (compare `value::event_block`
  with the stored one, as the parkour recipe does; both ways are verified).
- `player_right_click` fires ONCE per click (`event_equipment_slot` = `"hand"`, interaction `"right_click_air"`;
  checked with an empty off-hand). A right click with an EMPTY hand into the air fires nothing (the client
  sends nothing). The filter `if (value::event_equipment_slot != "hand") { return }` is a cheap safety net.
- `player_death`: the event player (`%player%`, actions without `<selector>`) is the one who died. On a death
  not caused by a player (e.g. `player::damage`) `%killer%` and `%victim%` are NOT substituted: they stay as
  the literal text `%killer%`.
- A runtime error reaches chat as "Action <name> stopped the code line because of an error: <reason>" with the
  code block's x y z (the bridge prints it as an `error` line). The rest of that line does not run (topic async «Error isolation»).
## Loops, conditions, placeholders (verified, server-check-8)
- `repeat::on_range(1, n)` reads `n` once; modifying the list you `for_each_in_list` over STOPS the loop after the
  current step (no error) — collect changes in another list (the compiler warns: `loop-list-modified`). `stop_repeat` / `skip_iteration` act immediately.
  A function with `code::wait` inside: the caller waits for it to finish.
- `==` / `!=` are the expensive conditions (≈8 actions: they compile to equals / not_equals with a list); `>` `<` cost ≈1
  (measured, dev/research/ops-bench.md; `>=` `<=` compile the same way). `x == 1 || x == 2 || x == 3` costs 3 equals — write
  `variable::equals(x, [1, 2, 3], compare_type = "ANY")` (one) on hot paths.
- `variable::equals(x, [5, 6], compare_type = "ANY")` = x is one of; `variable::not_equals(x, [a, b])` = x equals none;
  `number_in_range` NOT_INCLUDE (min,max) / INCLUDE_FIRST [min,max) / INCLUDE_LAST (min,max] / INCLUDE_ALL [min,max]; `multiple_equals` compares
  pairwise; `list_value_equals(l, i, [v])` — index from 0, out of range = false; `list_is_empty([l])` works.
- Placeholders in text: `%val(timestamp)`, `%val(x_coordinate)`, `%val(current_health)` (NOT `health` — unknown ids give 0);
  `%length(name)` / `%length_local(name)` (missing variable → -1); `%index(name, 0)` (from 0); `%entry(map, key)`
  (missing → 0); `%math(%length(gl)-1)` works; `%math(10/4)` = 2.5. `%%` is NOT an escape — never write it.
- `variable::format_timestamp(ms, "mm:ss", "UTC")` → `01:15` (zero-padded; hours are dropped past 60 min — use
  `"H:mm:ss"` → `1:02:05`); `"mm:ss.SSS"` → `01:15.123`; a single `S` does not shorten (`1:15.123`).
- `var y = x` where `x` was never set: `y` becomes 0 and `variable::exists([y])` is true.
- An event caused by an action runs synchronously: right after `player::damage(1)` the `player_take_damage`
  handler has already run (its writes are visible).
- `code::controller_async_run() { }` does NOT work (server error, line stops; compile error `async-run-broken`) — use a `process` with `code::wait`.
- Two functions with the same name: a call runs BOTH, in order (the compiler warns `duplicate-function`).
- `%val(id)` without a selector reads the event's default target like `value::x` (the damaged mob in
  `entity_take_damage`; the selected player in a process after `select::all_players()`).
- `l[9]` past the end gives 0 (no error); `variable::list_is_empty([x])` is true for an unset variable and an empty
  map, false for a text.
- An unset variable is 0 in conditions too: `if (x == 0)` is true, `multiple_equals([x], [0])` is true.
- `!cond` is always the exact opposite of `cond`, also with several or zero targets. A condition with several
  targets (`entity::name_equals` on 2 selected) is true when ANY of them matches; with zero targets it is false.
- `number_in_range`: INCLUDE_LAST is (min,max]; min > max is always false (bounds are not swapped). A text value in
  `number_in_range` or `>=` is a server error (line stops) — but a numeric text ("5") is read as a number, and a
  never-set variable is 0 (server-check-22).
- `%val(id)` uses the server id (`x_coordinate`, `y_coordinate`, `current_health`, `timestamp`, `event_final_damage`) and
  gives the same as `value::x`; an unknown id silently gives 0. `%length(x)`: list size, -1 for an unset variable,
  the text LENGTH for a text, the size of a map. `get_list_length` / `l[i]` on a non-list is a server error.
- `l[-1]` and `l[9]` past the end give 0; `list_value_equals(l, -1, [v])` is false.
- `list.append(x)` on a never-set variable does NOTHING (no error, still unset) — create the list first
  (`l ??= []` or `var l = []`); `l.remove(x)` on it is a server error.
- `%index_local(l, 1)`, `%entry_line(m, k)`, `%length_line(l)` etc. work like the game-scope forms.
## Displays and blocks
- `player::display_hologram(loc, "A\n&cB")`: two lines, & colors work; a second hologram at the SAME location replaces
  the first (update a board by re-displaying at the same spot), another location makes a separate one.
- `value::block_beneath` is the block under the feet in block coordinates (`{x:0, y:3, z:0}`);
  `player::is_standing_on_block([item("gold_block")])` and `is_standing_on_block(locations = [loc])` both work.
- Fireworks: `var fw = variable::set_item_component(item("firework_rocket"), "fireworks",
  "{flight_duration:1b,explosions:[{shape:\"large_ball\",colors:[I;16766720]}]}")` then
  `world::launch_firework(fw, loc, "UPWARDS", instant = false)` (verified, server-check-6).
- An empty list literal `[]` fits any list parameter (= argument left empty).
- Block STATES go as TEXT straight into the block argument: `world::set_block("oak_stairs[facing=north,half=top]", loc)`,
  `"grass_block[snowy=true]"` (verified: snowy grass and an upside-down stair; the compiler checks property names/values
  against the MC registry and suggests fixes). NOT inside item(): `item("oak_stairs[facing=north]")` is an error. Values read back from the server look the
  same (`value::event_block_type` = `"minecraft:light_weighted_pressure_plate[power=0]"`).
## Selection (`select::...`) and mobs
- In a NO_TARGET process (and in top-level world code) after `select::player_by_name([name])` /
  `select::entity_by_name([uuid])` / `select::all_mobs()`, actions WITHOUT `<selector>` (`player::message`,
  `entity::damage`, `entity::remove`) act on the selection. `value::x<current>` READS the selection (verified:
  `value::health<current>` = the mob's 200, `value::uuid<current>` = its uuid); `value::x` WITHOUT a selector does not (0). Checked with one player: that nobody else is
  affected is not checked.
- Another way to READ a selected entity's values is a process for it: `select::entity_by_name([u])` +
  `code::start_process("p", target_mode = "FOR_EACH_IN_SELECTION")` — inside `p`, `value::health`, `value::uuid`
  are that entity's (verified with the process started from a PLAYER event; started from a NO_TARGET process it
  is not checked). `CURRENT_SELECTION`, and a player event after `select`, still read the PLAYER's `value::`.
- After `select::reset()` in a NO_TARGET process an action without `<selector>` reaches nobody; the line goes on.
- `select::entity_by_name(["no such"])` + `entity::remove()` removes nothing and raises no error.
- `world::spawn_mob(item("zombie_spawn_egg"), loc, 200, "&4&lKing")`: health 200 works (no set_max_health needed);
  right after it `value::uuid<last_entity>` is that mob's uuid (checked in a player event). Its name comes back
  with § codes (`§4§lKing`) — do not compare names.
- `world::has_entity([uuid])` is true for a live mob, false for `""`.
- EVERYTHING code builds or spawns PERSISTS through `/play` and `/build`: blocks (`set_block`, `set_region`...),
  mobs, armor stands, displays, NPCs. Top-level (world_start) code runs on EVERY world start, so an unguarded
  `world::spawn_mob(...)` / `spawn_armor_stand` / `spawn_text_display` there adds ANOTHER copy each start (the compiler
  warns). Spawn a static NPC once: keep its uuid in a `save var` and spawn only if it is gone —
  `save var npc = ""` is WRONG (a save var with a value is reset every start, core «Variables»); use
  `save var npc` + `npc ??= ""`, then `if (!world::has_entity([npc])) { world::spawn_mob(...); npc = value::uuid<last_entity> }`
  (verified: uuid<last_entity> works in world code too, and after a second /play there is still ONE NPC).
  A message sent by world code right at start can miss a player re-entering after /play: `code::wait(2, time_unit = "seconds")` first.
  Blocks: setting the same block again is harmless; just do not build something whose old copy would be in the way.
- Mobs SURVIVE `/play` (world restart) while `game var`s holding their uuids are reset. Remove every mob with
  `select::all_mobs()` + `entity::remove()` in world code (removes ALL mobs in the world) or keep the uuids in a
  `save var` (docs/recipes-boss.jc).
- `entity::damage(5, "PlayerName")` on a selected mob counts as that player's attack: `player_damage_entity` fires
  with `%player%` = that player, `value::event_damage_cause` = `entity_attack`, `value::event_final_damage` filled
  (4.92 with armour). Without a source the cause is `custom`.
- In `entity_take_damage` `value::health` is the health BEFORE the hit; `value::event_final_damage` is what it takes.
- A zombie burns by day: `entity_combust` with `value::event_combust_reason` = `unknown`, then `fire_tick` damage
  1 per second. Whether `world::cancel_event()` stops it is not checked.
## Not verified, but standard Minecraft / JustMC behaviour
- The action bar fades after a few seconds. For a permanent HUD refresh it every 20 ticks from a per-player
  loop: `event<player_join> { std::every(20) { player::action_bar("...") } }`.
- Acting on all players from a world loop with the selector `<all_players>` (`player::message<all_players>(...)`).
## OPEN questions (do not rely on either answer)
- #9: whose name `%player%` (`%killer%`, ...) becomes inside a text sent with `<all_players>` — maybe each
  recipient's own. Capture first: `line var who = "%player%"`, then `player::message<all_players>("$who ...")`.
- #10: who the default player is in `player_kill_player` (killer or victim). Use `%killer%`/`%victim%`,
  `<killer_player>`/`<victim_player>`, `value::x<killer_entity>`.
