API
Dokumentacja CraftScript
Wszystkie dostępne słowa kluczowe, operatory, funkcje i składowe.
Słowa kluczowe
| Słowo kluczowe | Zastosowanie |
|---|---|
let / var / const |
Deklaracja zmiennych (const nie można przypisać ponownie). |
fun |
Funkcje nazwane i lambdy fun(x) { }. |
class, extends, this, super |
Klasy i dziedziczenie. |
enum |
Typy wyliczeniowe. |
import, from, as |
Moduły. |
if, else, while, for … in, break, continue, return |
Sterowanie przepływem. |
and, or, not (lub &&, ||, !) |
Logika. |
true, false, null |
Literały. |
mod, item, block, recipe |
Deklaracje zawartości. |
ore, tree, patch, structure, biome, dimension, terrain, biome_map, carver |
Deklaracje generowania świata. Zobacz Generowanie świata i Generowanie kodem. |
on … priority |
Obsługa zdarzenia. |
command … requires … alias … describe |
Polecenia. |
every, after + ticks/seconds/minutes |
Timery. |
Komentarze: // line, # line, /* block */. Instrukcje oddziela się znakami nowego wiersza (lub ;).
Operatory
| Operator | Znaczenie |
|---|---|
+ - * / % |
Arytmetyka. + łączy napisy, jeśli jedna strona jest napisem; łączy też listy. |
== != < <= > >= |
Porównanie. Id i napis są równe, jeśli reprezentują to samo id. |
= += -= *= /= |
Przypisanie. |
?? |
Wartość domyślna, jeśli lewa strona to null. |
?. |
Bezpieczny dostęp: zwraca null zamiast zawieść. |
a..b |
Domknięty zakres liczb. |
x[i] |
Indeks listy (ujemny liczy od końca), klucz mapy, znak napisu. |
Wartości fałszywe: null, false, 0, "", pusta lista lub mapa.
Funkcje wbudowane
| Funkcja | Opis |
|---|---|
print(...) |
Pisze do dziennika serwera. |
log(...) |
Jak print, z nazwą moda. |
str(x) |
Zamienia na napis. |
num(x) |
Zamienia na liczbę (lub null). |
int(x) |
Część całkowita. |
round, floor, ceil, abs, sqrt |
Matematyka. |
min(...), max(...) |
Minimum/maksimum liczb. |
sin, cos, atan2, pi() |
Trigonometria, w radianach. |
len(x) |
Długość napisu, listy lub mapy. |
type(x) |
Nazwa typu. |
is(x, Class) |
Sprawdza klasę lub typ wyliczeniowy. |
random(), random(n), random(a, b) |
Ułamek 0–1, liczba całkowita 0–n, liczba całkowita a–b. |
chance(p) |
true z prawdopodobieństwem p (0–1). |
pick(list) |
Losowy element. |
now() |
Bieżące milisekundy. |
id("ns:path") |
Tworzy identyfikator. |
item(id, count?, name?) |
Tworzy ItemStack. |
color(text) |
Zamienia & na kody kolorów. |
broadcast(msg) |
Wiadomość do wszystkich graczy. |
run(command) |
Wykonuje polecenie gry jako konsola. Furtka awaryjna: format polecenia należy do gry i może się zmienić. |
player(name) |
Gracz online lub null. |
players() |
Lista graczy. |
world(id?) |
Świat (domyślnie Overworld). |
mod_loaded(id) |
Czy inny mod jest wczytany? |
config(name, values?, synced?) |
Deklaruje lub czyta plik ustawień moda. |
listen(channel, fun(data, player)) |
Odbiera dane na kanale moda. |
send(player, channel, data) |
Wysyła dane z serwera do gracza. |
send_to_server(channel, data) |
Wysyła dane z klienta do serwera. |
server |
Serwer. |
tick |
Bieżący tick. |
game_version, namespace |
Wersja Minecrafta i przestrzeń nazw moda. |
Składowe napisów
length, upper(), lower(), trim(), contains(s), starts_with(s), ends_with(s), split(sep), replace(a, b), repeat(n), substring(from, to?), is_empty.
Składowe list
size, is_empty, first, last, add(x)/push(x), remove(x), remove_at(i), contains(x), index_of(x), join(sep), reverse(), sort(), clear(), map(f), filter(f), each(f), any(f), all(f), sum().
Składowe map
keys(), values(), has(k), get(k, default?), remove(k), size; plus bezpośredni dostęp przez map.key lub map["key"].
Obiekty gry
Nazwy używają snake_case (max_health) i są tymi samymi składowymi co w Kotlinie (maxHealth). Typów wyliczeniowych używa się jako napisów (player.game_mode = "creative"). Szczegóły każdego z nich znajdziesz na stronie Świat i gracze.
| Typ | Właściwości | Metody |
|---|---|---|
| Player | name, uuid, health, max_health, food_level, game_mode, inventory, held_item, is_op, is_sleeping, has_crafting_client, location, world, custom_name, is_alive, data | send, action_bar, title, give, set_held_item, play_sound, teleport, heal, damage, has_permission, kick, set_rotation, add_tag, has_tag, set_cooldown, has_cooldown |
| World | id, players, time, is_raining, data | block_at, set_block (z opcjonalnymi stanami), spawn, drop_item, explode, strike_lightning, spawn_particle, play_sound, light_at, container_at, set_sign_text, set_chunk_loaded, entities, living_near, shoot, summon |
| Block | type, x, y, z, world, location, is_solid, data | set_type, relative |
| Entity | uuid, type, world, location, custom_name, is_alive, data, direction, vehicle | teleport, remove, set_rotation, add_tag, has_tag |
| LivingEntity | wszystko z Entity, health, max_health | damage, heal, set_ai, add_effect, remove_effect, has_effect, effects, add_modifier, remove_modifier, attribute, set_attribute, equipment, set_equipment |
| Inventory | size | get, set, add, count, clear |
| Location | world, x, y, z, yaw, pitch, block_x, block_y, block_z | add, distance_to |
| data (magazyn) | keys; data["key"] odczytuje i zapisuje | get, set, get_int, get_number, get_string, get_boolean, remove, clear |
| ItemStack | item, count, name, lore, data, enchantments | with_count |
| Server | players, worlds, motd, tps, is_dedicated | player, world, broadcast, stop, run_command |
Obiekty generowania świata
To, co dostają funkcje deklaracji generowania świata podczas tworzenia chunków. Wyjaśnione na stronie Generowanie kodem.
| Obiekt | Właściwości | Metody |
|---|---|---|
| world (budowa struktury) | x, y, z, seed, min_y, max_y | block, state, is_air, is_in, can_stay, set (z opcjonalnymi stanami), inside, surface, top, flow, structures, place_file |
| plan (plan struktury) | chunk_x, chunk_z, seed, min_y | height, biome, column, file_size |
| site (budowa struktury) | x, y, z, radius, min_y, max_y, data, seed | |
| world (teren) | seed, min_y, height | biome |
| world (biome_map) | seed | tagged |
| ctx (wyrzynacz) | seed, start_x, start_z, chunk_x, chunk_z, min_y, max_y | carve |
| at (grunt biomu) | x, y, z, depth_above, depth_below, surface_depth, steep | noise |
Typy argumentów poleceń
player, int, number, bool, string (jedno słowo), text (reszta wiersza), id. Dodaj ?, żeby argument był opcjonalny.
Limity
- 2 000 000 kroków na wywołanie (zdarzenie, polecenie lub timer).
- 200 zagnieżdżonych wywołań (rekurencja).
- Zakresy do 1 000 000 elementów.