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 타이머.

주석: // 줄, # 줄, /* 블록 */. 문장은 줄바꿈(또는 ;)으로 구분합니다.

연산자

연산자 의미
+ - * / % 산술. 한쪽이 문자열이면 +는 이어 붙이며, 리스트도 합칩니다.
== != < <= > >= 비교. id와 문자열은 같은 id를 나타내면 같습니다.
= += -= *= /= 대입.
?? 왼쪽이 null이면 기본값.
?. 안전한 접근: 실패하는 대신 null을 반환합니다.
a..b 끝을 포함하는 숫자 범위.
x[i] 리스트 인덱스(음수는 끝에서부터), 맵 키, 문자열의 문자.

거짓으로 취급되는 값: null, false, 0, "", 빈 리스트나 맵.

내장 함수

함수 설명
print(...) 서버 로그에 씁니다.
log(...) print와 같지만 모드 이름이 붙습니다.
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) 다른 모드가 불러와졌는지 여부.
config(name, values?, synced?) 모드 설정 파일을 선언하거나 읽습니다.
listen(channel, fun(data, player)) 모드 채널에서 데이터를 받습니다.
send(player, channel, data) 서버에서 플레이어에게 데이터를 보냅니다.
send_to_server(channel, data) 클라이언트에서 서버로 데이터를 보냅니다.
server 서버.
tick 현재 틱.
game_version, namespace Minecraft 버전과 모드 네임스페이스.

문자열 멤버

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(단어 하나), text(줄의 나머지), id. 선택 사항으로 만들려면 ?를 붙입니다.

제한

  • 호출(이벤트, 명령어, 타이머)당 2,000,000단계.
  • 중첩 호출(재귀) 200단계.
  • 범위는 최대 1,000,000개 요소.