plugin-host: Implement block_get and block_set host calls · feather-rs/feather@144f306 · GitHub
Skip to content

Commit 144f306

Browse files
committed
plugin-host: Implement block_get and block_set host calls
Connections: feather-rs/quill#2
1 parent 4c34e17 commit 144f306

6 files changed

Lines changed: 34 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/Cargo.toml

Lines changed: 1 addition & 1 deletion

crates/plugin-host/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ feather-common = { path = "../common" }
1010
feather-ecs = { path = "../ecs" }
1111
feather-plugin-host-macros = { path = "macros" }
1212

13-
quill-common = { git = "https://github.com/feather-rs/quill", rev = "b6def83" }
14-
quill-plugin-format = { git = "https://github.com/feather-rs/quill", rev = "b6def83" }
13+
quill-common = { git = "https://github.com/feather-rs/quill", rev = "d4da5b6" }
14+
quill-plugin-format = { git = "https://github.com/feather-rs/quill", rev = "d4da5b6" }
1515
wasmer = { version = "1", default-features = false, features = ["jit"] }
1616
wasmer-wasi = { version = "1", default-features = false }
1717
libloading = "0.7"

crates/plugin-host/src/host_calls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use paste::paste;
88
use crate::env::PluginEnv;
99
use crate::host_function::{NativeHostFunction, WasmHostFunction};
1010

11+
mod block;
1112
mod component;
1213
mod entity;
1314
mod entity_builder;
@@ -43,6 +44,7 @@ macro_rules! host_calls {
4344
}
4445
}
4546

47+
use block::*;
4648
use component::*;
4749
use entity::*;
4850
use entity_builder::*;
@@ -59,4 +61,6 @@ host_calls! {
5961
"entity_query" => entity_query,
6062
"entity_exists" => entity_exists,
6163
"entity_send_message" => entity_send_message,
64+
"block_get" => block_get,
65+
"block_set" => block_set,
6266
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use feather_base::{BlockId, BlockPosition};
2+
use feather_plugin_host_macros::host_function;
3+
use quill_common::block::BlockGetResult;
4+
5+
use crate::context::PluginContext;
6+
7+
/// NB: `u32` has the same layout as `BlockGetResult`.
8+
#[host_function]
9+
pub fn block_get(cx: &PluginContext, x: i32, y: i32, z: i32) -> anyhow::Result<u32> {
10+
let pos = BlockPosition::new(x, y, z);
11+
12+
let block = cx.game_mut().world.block_at(pos);
13+
let result = BlockGetResult::new(block.map(BlockId::vanilla_id));
14+
Ok(result.to_u32())
15+
}
16+
17+
#[host_function]
18+
pub fn block_set(cx: &PluginContext, x: i32, y: i32, z: i32, block_id: u16) -> anyhow::Result<u32> {
19+
let pos = BlockPosition::new(x, y, z);
20+
let block = BlockId::from_vanilla_id(block_id);
21+
22+
let was_successful = cx.game_mut().world.set_block_at(pos, block);
23+
Ok(was_successful as u32)
24+
}

crates/server/Cargo.toml

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)