Reference

The guest SDK, rustmc-guest

rustmc-guest is the Rust crate a WebAssembly plugin builds against. It lives in the rustmc-plugins repository, at sdk/ (the crate is sdk/Cargo.toml, the calls are sdk/src/host.rs, sdk/src/net.rs and sdk/src/lib.rs). This page is generated from that repository at commit 972ad9c by python tools/gen_api_docs.py --sdk=<checkout>; do not edit it by hand.

Every host call can be made with host::call(name, fields) (or rustmc_guest::call in the JSON style), which sends {"call": name, ...fields} and answers Ok(value) or Err(message). The functions below are typed wrappers over that. A wrapper's fields and answer are the call's: see the linked call for both.

211 SDK functions make a host call. 47 calls have no typed wrapper and are made with host::call.

ModuleFunctionHost calls
hostplayers() -> Vec<PlayerId>players
hostplayer_name(player: PlayerId) -> Option<String>player_name
hostplayer_uuid(player: PlayerId) -> Option<String>player_uuid
hostvitals(player: PlayerId) -> Option<Vitals>vitals
hostgame_mode(player: PlayerId) -> Option<String>game_mode
hostworld_of(entity: i64) -> Option<String>world_of
hostrotation(entity: i64) -> Option<(f32, f32)>rotation
hostposition(entity: i64) -> Option<[f64; 3]>position
hostplayer_named(name: &str) -> Option<PlayerId>player_named
hostcan_see(viewer: PlayerId, subject: PlayerId) -> boolcan_see
hostallows(player: PlayerId, level: i32) -> boolallows
hostrefresh_commands(player: PlayerId) -> boolrefresh_commands
hostlatency(player: PlayerId) -> Option<u32>latency
hostis_bedrock(player: PlayerId) -> boolis_bedrock
hostmessage(player: PlayerId, text: &str)message
hostwatch_look(player: PlayerId, on: bool) -> boolwatch_look
hostwatch_input(player: PlayerId, on: bool) -> boolwatch_input
hostkick(player: PlayerId, reason: &str) -> boolkick
hostbroadcast(text: &str)broadcast
hostlog(text: &str)log
hostmessage_text(player: PlayerId, component: &Value, overlay: bool) -> Result<bool, String>message_text
hostshow_title(player: PlayerId, title: &Value, subtitle: Option<&Value>, times: TitleTimes) -> Result<bool, String>show_title
hostshow_sidebar(player: PlayerId, title: &Value, lines: &[Value]) -> Result<bool, String>show_sidebar
hosthide_sidebar(player: PlayerId) -> boolhide_sidebar
hostset_list_name(player: PlayerId, name: Option<&Value>) -> Result<bool, String>set_list_name
hostset_list_order(player: PlayerId, order: i32) -> boolset_list_order
hostset_tab_header(player: PlayerId, header: &Value, footer: &Value) -> Result<bool, String>set_tab_header
hostset_list_name_for(viewer: PlayerId, target: PlayerId, name: Option<&Value>) -> Result<bool, String>set_list_name_for
hostset_list_name_for_batch(entries: &[(PlayerId, PlayerId, Option<Value>)]) -> Result<u32, String>set_list_name_for_batch
hostset_listed_for(viewer: PlayerId, target: PlayerId, listed: bool) -> boolset_listed_for
hostset_listed_for_batch(entries: &[(PlayerId, PlayerId, bool)]) -> Result<u32, String>set_listed_for_batch
hostset_list_game_mode_shown_for(viewer: PlayerId, target: PlayerId, mode: Option<&str>) -> boolset_list_game_mode_shown_for
hostset_list_game_mode_shown_for_batch(entries: &[(PlayerId, PlayerId, Option<&str>)]) -> Result<u32, String>set_list_game_mode_shown_for_batch
hostset_list_latency(target: PlayerId, latency: Option<u32>) -> boolset_list_latency
hostset_nametag(player: PlayerId, nametag: Option<&Nametag>) -> Result<bool, String>set_nametag
hostset_nametag_batch(entries: &[(PlayerId, Option<Nametag>)]) -> Result<u32, String>set_nametag_batch
hostnametags_json(entries: &[(PlayerId, &str)]) -> Result<u32, String>set_nametag_batch
hostset_nametag_for(viewer: PlayerId, target: PlayerId, nametag: Option<&Nametag>) -> Result<bool, String>set_nametag_for
hostset_nametag_for_batch(entries: &[(PlayerId, PlayerId, Option<Nametag>)]) -> Result<u32, String>set_nametag_for_batch
hostlist_fake_entries(viewer: PlayerId, entries: &[crate::tab::FakeEntry]) -> Result<bool, String>list_fake_entries
hostlist_fake_entries_json(viewers: &[(PlayerId, &str)]) -> Result<u32, String>list_fake_entries_batch
hostset_below_name(viewer: PlayerId, target: PlayerId, score: Option<&Score>) -> Result<bool, String>set_below_name
hostset_below_name_batch(entries: &[(PlayerId, PlayerId, Option<Score>)]) -> Result<u32, String>set_below_name_batch
hostset_list_score(viewer: PlayerId, target: PlayerId, score: Option<&Score>) -> Result<bool, String>set_list_score
hostset_list_score_batch(entries: &[(PlayerId, PlayerId, Option<Score>)]) -> Result<u32, String>set_list_score_batch
hostobjective_title(slot: &str, title: &Value) -> Result<bool, String>objective_title
hostlist_score_render(render: crate::tab::ScoreRender) -> boollist_score_render
hostshow_sidebar_lines(player: PlayerId, title: &Value, lines: &[SidebarLine]) -> Result<bool, String>show_sidebar_lines
hostboss_bar_show(player: PlayerId, id: &str, bar: &BossBar) -> Result<bool, String>boss_bar_show
hostboss_bar_hide(player: PlayerId, id: &str) -> boolboss_bar_hide
hostsql_submit(setting: &str, statements: &[Value]) -> Result<u64, String>sql_submit
hostsql_result(batch: u64) -> Option<Result<Vec<u64>, String>>sql_result
hoststatistic(player: PlayerId, stat: &str, key: &str) -> Result<Option<i32>, String>statistic
hostchat_completions(player: PlayerId, action: &str, words: &[String]) -> Result<bool, String>chat_completions
hostbroadcast_text(component: &Value) -> Result<u32, String>broadcast_text
hostinventory_slot(player: PlayerId, slot: i32) -> Option<Value>inventory_slot
hostedit_slot(player: PlayerId, slot: i32, stamp: &str, set: &serde_json::Map<String, Value>, remove: &[&str]) -> Result<String, String>edit_slot
hostinventory_cursor(player: PlayerId) -> Option<Value>inventory_cursor
hostedit_cursor( player: PlayerId, stamp: &str, set: &serde_json::Map<String, Value>, remove: &[&str], count: Option<i32>, ) -> Result<String, String>edit_cursor
hostgive_item(player: PlayerId, item: &str, count: i32, components: &serde_json::Map<String, Value>) -> Result<i32, String>give_item
hostset_item_cooldown(player: PlayerId, group: &str, ticks: i32) -> boolset_item_cooldown
hostitem_cooldown(player: PlayerId, group: &str) -> i32item_cooldown
hostcapture_chat(player: PlayerId, wait_ms: u64, secret: bool) -> Result<Capture, String>capture_chat
hostrelease_chat(player: PlayerId) -> boolrelease_chat
hosttake_slot(player: PlayerId, slot: i32, stamp: Option<&str>) -> Result<Taken, String>take_slot
hostgive_stack(player: PlayerId, stack: &str, count: i32, spill: bool) -> Result<i32, String>give_stack
hostsave_player(player: PlayerId) -> boolsave_player
hosttake_item(player: PlayerId, item: &str, count: i32, components: &serde_json::Map<String, Value>) -> Result<i32, String>take_item
hostitem_count(player: PlayerId, item: &str) -> Result<Option<i32>, String>item_count
hostitem_count_tagged(player: PlayerId, item: Option<&str>, custom_data: &Value) -> Result<Option<i32>, String>item_count
hostitem_sum_tagged(player: PlayerId, item: Option<&str>, custom_data: &Value, sum_key: &str) -> Result<Option<i64>, String>item_sum_where
hosttake_item_tagged(player: PlayerId, item: Option<&str>, count: i32, custom_data: &Value) -> Result<i32, String>take_item
hostexperience_points(player: PlayerId) -> Option<i32>experience_points
hostgive_experience(player: PlayerId, points: i32) -> Result<bool, String>give_experience
hostplay_sound(player: PlayerId, sound: &str, volume: f32, pitch: f32) -> boolplay_sound
hostset_food(player: PlayerId, food: i32, saturation: f32) -> Result<bool, String>set_food
hostset_health(player: PlayerId, health: f32) -> Result<bool, String>set_health
hostheal(player: PlayerId, amount: f32) -> Result<Option<f32>, String>heal
hostselected_slot(player: PlayerId) -> Option<i32>selected_slot
hostset_respawn(player: PlayerId, world: &str, at: [i32; 3], yaw: f32) -> Result<bool, String>set_respawn
hostclear_respawn(player: PlayerId) -> boolclear_respawn
hostdrop_item( world: &str, to: [f64; 3], item: &str, count: i32, components: &serde_json::Map<String, Value>, velocity: Option<[f64; 3]>, ) -> Result<Option<i64>, String>drop_item
hostdamage_saying(entity: i64, amount: f32, cause: &str, died: &str)damage_saying
hostdamage_by(entity: i64, amount: f32, cause: &str, attacker: Option<i64>, skip_cooldown: bool) -> Result<bool, String>damage_by
hostadd_effect(entity: i64, effect: &str, ticks: i32, amplifier: i32) -> booladd_effect
hostadd_effect_shown(entity: i64, effect: &str, ticks: i32, amplifier: i32, shown: EffectShown) -> booladd_effect_shown
hostremove_effect(entity: i64, effect: &str) -> boolremove_effect
hostset_attribute_modifier(entity: i64, attribute: &str, id: &str, amount: f64, operation: Operation) -> Result<bool, String>set_attribute_modifier
hostremove_attribute_modifier(entity: i64, attribute: &str, id: &str) -> boolremove_attribute_modifier
hostplayer_motion(player: PlayerId) -> Option<Motion>player_motion
hostnudge_view(player: PlayerId, dyaw: f32, dpitch: f32) -> boolnudge_view
hostis_sneaking(entity: i64) -> boolis_sneaking
hostworld_spawn(world: &str) -> Option<[f64; 3]>world_spawn
hostteleport(player: PlayerId, to: [f64; 3]) -> boolteleport
hostparticle(world: &str, particle: &str, to: [f64; 3], count: i32, spread: [f64; 3], speed: f32) -> boolparticle
hostsound_at(world: &str, to: [f64; 3], sound: &str, category: &str, volume: f32, pitch: f32) -> boolsound_at
hosttick() -> u64tick
hostnow() -> u64now
hostsecure_random(length: usize) -> Result<Vec<u8>, String>secure_random
hostrsa_generate() -> Result<RsaKeyPair, String>rsa_generate
hostrsa_decrypt(private_key: &[u8], block: &[u8]) -> Result<Option<Vec<u8>>, String>rsa_decrypt
hostrequest_restart(reason: &str) -> Result<bool, String>request_restart
hostschedule_world_reset(seed: Option<i64>, reason: &str) -> Result<(), String>schedule_world_reset
hostcancel_world_reset() -> Result<bool, String>cancel_world_reset
hostserver_health() -> Valueserver_health
hostprofiler(op: &str, interval_ms: u32) -> Result<Value, String>profiler
hostblock_at(world: &str, at: [i32; 3]) -> Option<String>block_at
hostblock_state_at(world: &str, at: [i32; 3]) -> Option<String>block_state_at
hostset_block(world: &str, at: [i32; 3], block: &str) -> boolset_block
hostset_blocks(world: &str, blocks: &[([i32; 3], &str)]) -> Result<u32, String>set_blocks
hostread_blocks(world: &str, min: [i32; 3], max: [i32; 3]) -> Result<BlockBox, String>read_blocks
hostwrite_blocks(world: &str, min: [i32; 3], max: [i32; 3], palette: &[String], cells: &[u16]) -> Result<BlocksWritten, String>write_blocks
hostcheck_blocks(palette: &[String]) -> Result<(), String>check_blocks
hostset_block_data(world: &str, at: [i32; 3], snbt: &str) -> Result<bool, String>set_block_data
hostset_blocks_data(world: &str, entries: &[([i32; 3], &str)]) -> Result<u32, String>set_blocks_data
hostblock_data(world: &str, at: [i32; 3]) -> Option<String>block_data
hostblocks_are(world: &str, positions: &[[i32; 3]], fact: &str) -> Result<Vec<Option<bool>>, String>blocks_are
hostplayers_in(world: &str, min: [f64; 3], max: [f64; 3]) -> Vec<(PlayerId, [f64; 3])>players_in
hostentities_in(world: &str, centre: [f64; 3], radius: f64, kinds: &[&str]) -> Result<Vec<EntityNear>, String>entities_in
hostcontainer_add(world: &str, at: [i32; 3], item: &str, count: i32) -> i32container_add
hostcontainer_remove(world: &str, at: [i32; 3], item: &str, count: i32) -> i32container_remove
hostblock_is(world: &str, at: [i32; 3], fact: &str) -> Option<bool>block_is
hostbiome_at(world: &str, at: [i32; 3]) -> Option<String>biome_at
hostworld_ceiling(world: &str) -> Option<i32>world_ceiling
hostworld_floor(world: &str) -> Option<i32>world_floor
hostreserve_blocks(world: &str, states: &[&str], break_ticks: Option<u32>, drops: &[BlockDrop]) -> Result<u32, String>reserve_blocks
hostguard_zones(world: &str, put: &[GuardZone], remove: &[u64]) -> Result<u32, String>guard_zones
hostguard_hold(held: bool) -> Result<(), String>guard_hold
hostrelease_blocks(world: &str, states: &[&str]) -> Result<u32, String>release_blocks
hostraycast(from: RayFrom<'_>, max_distance: f64, filter: &RayFilter) -> Result<Option<RayHit>, String>raycast
hostspawn_entity(world: &str, kind: &str, to: [f64; 3], yaw: f32, pitch: f32, nbt: &str) -> Result<Option<i64>, String>spawn_entity
hostspawn_entity_for(world: &str, kind: &str, to: [f64; 3], yaw: f32, pitch: f32, nbt: &str, viewers: &[PlayerId]) -> Result<Option<i64>, String>spawn_entity_for
hostset_entity_viewers(entity: i64, viewers: &[PlayerId]) -> Result<bool, String>set_entity_viewers
hostentity_viewers(entity: i64) -> Option<Vec<PlayerId>>entity_viewers
hostset_display(entity: i64, nbt: &str) -> Result<bool, String>set_display
hostmove_entity(entity: i64, to: [f64; 3], yaw: f32, pitch: f32) -> boolmove_entity
hostmove_entities(moves: &[(i64, [f64; 3], f32)]) -> usizemove_entities
hostattach_entity(entity: i64, leader: Option<i64>, offset: [f64; 3]) -> boolattach_entity
hostremove_entity(entity: i64) -> boolremove_entity
hostmount(rider: i64, vehicle: i64) -> boolmount
hostdismount(rider: i64) -> booldismount
hostvehicle_of(entity: i64) -> Option<i64>vehicle_of
hostpassengers(entity: i64) -> Option<Vec<i64>>passengers
hostset_passengers(vehicle: i64, riders: &[i64]) -> Result<bool, String>set_passengers
hostentity_velocity(entity: i64) -> Option<[f64; 3]>entity_velocity
hostset_entity_velocity(entity: i64, velocity: [f64; 3]) -> boolset_entity_velocity
hostspawn_creature(world: &str, kind: &str, at: [f64; 3], options: &CreatureOptions) -> Result<Option<i64>, String>spawn_creature
hostset_creature_ai(entity: i64, ai: Ai) -> Result<bool, String>set_creature_ai
hostcreature_order(entity: i64, order: &Order) -> Result<bool, String>creature_order
hostcreature_state(entity: i64) -> Option<CreatureState>creature_state
hostset_creature_drops(entity: i64, drops: Option<(&[BlockDrop], Option<i32>)>) -> Result<bool, String>set_creature_drops
hostcan_spawn_at(world: &str, kind: &str, at: [i32; 3]) -> Result<bool, String>can_spawn_at
hostworlds() -> Vec<String>worlds
hostchunk_on_disk(world: &str, chunk_x: i32, chunk_z: i32) -> Option<bool>chunk_on_disk
hostworld_sidecar(world: &str, name: &str) -> Option<String>world_sidecar
hostrender_web_map(world: &str) -> Result<bool, String>render_web_map
hostweb_map_marker(world: &str, id: &str, label: &str, x: i32, z: i32, kind: MarkerKind) -> Result<bool, String>web_map_marker
hostweb_map_remove_marker(world: &str, id: &str) -> Result<bool, String>web_map_remove_marker
hostworld_border(world: &str) -> Option<(f64, f64, f64)>world_border
hostset_world_border(world: &str, centre_x: f64, centre_z: f64, size: f64) -> boolset_world_border
hostqueue_chunks(world: &str, chunks: &[(i32, i32)]) -> Option<u32>queue_chunks
hostchunks_generated(world: &str) -> Generatedchunks_generated
hostunqueue_chunks(world: &str) -> u32unqueue_chunks
hosttick_health() -> Option<TickHealth>tick_health
hoststore(key: &str, value: &str)store
hostload(key: &str) -> Option<String>load
hostdisabled_systems() -> Vec<String>disabled_systems
hostsettings() -> Valuesettings
hostsetting_set(key: &str, value: &Value) -> Result<Value, String>setting_set
hoststorage_get(table: &str, key: &str) -> Result<Option<Value>, String>storage_get
hoststorage_put(table: &str, key: &str, value: &Value) -> Result<(), String>storage_put
hoststorage_outcome(ticket: u64) -> StorageOutcomestorage_outcome
hoststorage_land() -> Result<(), String>storage_land
hoststorage_scan_raw(table: &str, prefix: &str, after: Option<&str>, limit: u32) -> Result<Vec<u8>, String>storage_scan
hoststorage_delete(table: &str, key: &str) -> Result<bool, String>storage_delete
hoststorage_scan(table: &str, prefix: &str, after: Option<&str>, limit: u32) -> Result<Vec<(String, Value)>, String>storage_scan
hoststorage_count(table: &str, prefix: &str) -> Result<u64, String>storage_count
hoststorage_migrate(from: &str, to: &str) -> Result<(), String>storage_migrate
hoststorage_migration() -> Result<Option<Migration>, String>storage_migration
hoststorage_drop(table: &str) -> Result<bool, String>storage_drop
hoststorage_backend() -> Result<String, String>storage_backend
hostmenu_open(player: PlayerId, rows: u8, title: &str, items: &[Value]) -> Result<i32, String>menu_open
hostmenu_set(player: PlayerId, menu: i32, items: &[Value]) -> Result<bool, String>menu_set
hostmenu_close(player: PlayerId, menu: i32) -> Result<bool, String>menu_close
hostpush_pack(player: PlayerId, id: u128, url: &str, hash: &str, required: bool) -> boolpush_pack
hostpop_pack(player: PlayerId, id: Option<u128>) -> boolpop_pack
hosthost_pack(name: &str, source: PackSource<'_>) -> Result<HostedPack, String>host_pack
hostplugin_call(target: &str, request: Value) -> Result<Value, String>plugin_call
hosthttp_send(grant: &str, method: &str, path: &str, headers: &[(&str, &str)], body: &str) -> Result<u64, String>http_send
hosthttp_result(fetch: u64, offset: usize, length: usize) -> Option<Result<HttpPiece, String>>http_result
hostplugin_state(name: &str) -> Option<String>plugin_state
hostschematic_list() -> Result<SchematicList, String>schematic_list
hostschematic_load(name: &str, keep_unsafe: bool) -> Result<u64, String>schematic_load
hostschematic_result(ticket: u64) -> Option<Result<SchematicInfo, String>>schematic_result
hostschematic_names(ticket: u64, start: usize, count: usize) -> Result<Vec<Option<String>>, String>schematic_names
hostschematic_cells(ticket: u64, start: usize, count: usize) -> Result<Vec<u16>, String>schematic_cells
hostschematic_entities(ticket: u64, start: usize, count: usize) -> Result<Vec<([i32; 3], String)>, String>schematic_entities
hostschematic_save(name: &str, size: [i32; 3], offset: [i32; 3], overwrite: bool) -> Result<u64, String>schematic_save
hostschematic_put(ticket: u64, names: &[&str], cells: &[u16], entities: &[([i32; 3], String)]) -> Result<(), String>schematic_put
hostschematic_finish(ticket: u64) -> Result<(), String>schematic_finish
hostschematic_close(ticket: u64)schematic_close
hostplugin_emit(topic: &str, data: Value) -> u32plugin_emit
(root)packet_fields(packet: &str, body: &str) -> Result<Value, String>packet_decode
(root)packet_body(packet: &str, fields: &Value) -> Result<String, String>packet_encode
(root)send_packet_hex(player: i64, packet: &str, body: &str) -> Result<bool, String>send_packet
netlisten(grant: &str) -> Result<Listening, String>net_listen
netunlisten(grant: &str) -> boolnet_unlisten
netpoll(max_bytes: usize) -> Vec<Event>net_poll
netsend(connection: u64, bytes: &[u8]) -> Result<bool, String>net_send
netrespond( connection: u64, status: u16, headers: &[(&str, &str)], body: &[u8], more: bool, ) -> Result<bool, String>net_respond
netclose(connection: u64) -> boolnet_close

Calls with no typed wrapper

air, attribute, ban, banned, block_property, client_brand, damage, destroy_block, enchantment_level, entity_unit, exhaust_for, fire_ticks, fluid_at, game_rule_flag, game_rule_number, give, has_effect, held_item, hidden, http_fetch, inspect_close, inspect_open, is_in_rain, is_on_ground, item_count_where, local_difficulty, may_interact, packet_schemas, pardon, send_payload, set_air, set_fire_ticks, set_game_mode, set_hidden, set_hidden_account, set_slot, set_ticks_frozen, set_time_of_day, storage_put_many, swing_arm, take_held, take_item_where, ticks_frozen, time_of_day, world_border_damage, world_id, worn

From docs/api/reference/guest-sdk.md in the RustMC repository at bbd81209ad.