API

CraftScript リファレンス

使えるすべてのキーワード、演算子、関数、メンバー。

キーワード

キーワード 用途
let / var / const 変数の宣言(const は再代入できません)。
fun 名前付き関数とラムダ fun(x) { }。
class、extends、this、super クラスと継承。
enum 列挙型。
import、from、as モジュール。
if、else、while、for … in、break、continue、return 制御フロー。
and、or、not(または &&、||、!) 論理演算。
true、false、null リテラル。
mod、item、block、recipe コンテンツの宣言。
ore、tree、patch、structure、biome、dimension、terrain、biome_map、carver ワールド生成の宣言。ワールド生成とコードによる生成を参照。
on … priority イベントハンドラー。
command … requires … alias … describe コマンド。
every、after + ticks/seconds/minutes タイマー。

コメント:// line、# line、/* block */。文は改行(または ;)で区切ります。

演算子

演算子 意味
+ - * / % 算術演算。どちらかが文字列なら + は連結します。リストの結合にも使えます。
== != < <= > >= 比較。id と文字列は、同じ id を表していれば等しくなります。
= += -= *= /= 代入。
?? 左辺が null のときのデフォルト値。
?. 安全なアクセス:失敗する代わりに null を返します。
a..b 両端を含む数値の範囲。
x[i] リストのインデックス(負の値は末尾から数える)、マップのキー、文字列の文字。

偽とみなされる値:null、false、0、""、空のリストやマップ。

組み込み関数

関数 説明
print(...) サーバーのログに書き込みます。
log(...) print と同じですが、Mod の名前付き。
str(x) 文字列に変換します。
num(x) 数値に変換します(または null)。
int(x) 整数部分。
round, floor, ceil, abs, sqrt 数学関数。
min(...), max(...) 数値の最小値・最大値。
sin, cos, atan2, pi() 三角関数(ラジアン)。
len(x) 文字列、リスト、マップの長さ。
type(x) 型の名前。
is(x, Class) クラスや列挙型を確認します。
random(), random(n), random(a, b) 0–1 の小数、0–n の整数、a–b の整数。
chance(p) 確率 p(0–1)で true。
pick(list) ランダムな要素。
now() 現在のミリ秒。
id("ns:path") 識別子を作成します。
item(id, count?, name?) ItemStack を作成します。
color(text) & を色コードに変換します。
broadcast(msg) 全プレイヤーへのメッセージ。
run(command) ゲームのコマンドをコンソールとして実行します。抜け道:コマンドの形式はゲームのものなので、変わる可能性があります。
player(name) オンラインのプレイヤー、または null。
players() プレイヤーの一覧。
world(id?) ワールド(デフォルトはオーバーワールド)。
mod_loaded(id) 別の Mod が読み込まれているか。
config(name, values?, synced?) Mod の設定ファイルを宣言または読み込みます。
listen(channel, fun(data, player)) Mod のチャンネルでデータを受信します。
send(player, channel, data) サーバーからプレイヤーへデータを送ります。
send_to_server(channel, data) クライアントからサーバーへデータを送ります。
server サーバー。
tick 現在のティック。
game_version, namespace Minecraft のバージョンと Mod の名前空間。

文字列のメンバー

length、upper()、lower()、trim()、contains(s)、starts_with(s)、ends_with(s)、split(sep)、replace(a, b)、repeat(n)、substring(from, to?)、is_empty。

リストのメンバー

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()。

マップのメンバー

keys()、values()、has(k)、get(k, default?)、remove(k)、size。さらに map.key や map["key"] で直接アクセスできます。

ゲームのオブジェクト

名前は snake_case(max_health)で、Kotlin のメンバー(maxHealth)と同じものです。列挙型は文字列として使います(player.game_mode = "creative")。それぞれの詳細は ワールドとプレイヤー にあります。

型 プロパティ メソッド
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(状態は省略可能), 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 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(ストア) keys; data["key"] で読み書き 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

ワールド生成のオブジェクト

ワールド生成の宣言の関数が、チャンクの生成中に受け取るものです。コードによる生成のページで説明しています。

オブジェクト プロパティ メソッド
world(構造物の build) x, y, z, seed, min_y, max_y block, state, is_air, is_in, can_stay, set(状態は省略可能), inside, surface, top, flow, structures, place_file
plan(構造物の plan) chunk_x, chunk_z, seed, min_y height, biome, column, file_size
site(構造物の build) x, y, z, radius, min_y, max_y, data, seed
world(terrain) seed, min_y, height biome
world(biome_map) seed tagged
ctx(carver) seed, start_x, start_z, chunk_x, chunk_z, min_y, max_y carve
at(バイオームの surface) x, y, z, depth_above, depth_below, surface_depth, steep noise

コマンド引数の型

player、int、number、bool、string(1 語)、text(行の残り全部)、id。? を付けると省略可能になります。

制限

  • 1 回の呼び出し(イベント、コマンド、タイマー)につき 2,000,000 ステップ。
  • ネストした呼び出し(再帰)は 200 まで。
  • 範囲は最大 1,000,000 要素。