Send block data to clients

This commit is contained in:
2026-10-13 23:26:10 -03:00
parent a10b15a3fd
commit 55ad08266e
18 changed files with 283 additions and 90 deletions
+9 -11
View File
@@ -549,6 +549,11 @@ export class ModRuntime {
set data(value) {
game.set_tile_data(x, y, z, value);
},
get_client_data: (field) => structuredClone(game.world.get_tile(x, y, z)?.client_data?.[field]) as never,
set_client_data(field, value) {
if (typeof field !== "string" || field === "") throw new Error("a client data field needs a name");
game.set_tile_client_data(x, y, z, field, structuredClone(value));
},
set_ticking(ticking) {
game.set_tile_ticking(x, y, z, ticking);
},
@@ -691,18 +696,11 @@ export class ModRuntime {
get_block_data: (x, y, z) => game().world.get_tile(x, y, z)?.mod_data as never,
set_block_ticking: (x, y, z, ticking) => game().set_tile_ticking(x, y, z, ticking),
set_block_item: (x, y, z, item) => {
if (game().world.get_block_id(x, y, z) === AIR_ID) return;
if (!item || item.count <= 0) {
const tile = game().world.get_tile(x, y, z);
if (tile?.item) game().world.set_tile_item(tile, undefined);
return;
}
game().world.set_tile_item(game().get_or_create_tile(x, y, z), new_stack(item).to_data());
},
get_block_item: (x, y, z) => {
const item = game().world.get_tile(x, y, z)?.item;
return item && structuredClone(item);
const shown = item && item.count > 0 ? new_stack(item).to_data() : undefined;
game().set_tile_client_data(x, y, z, "item", shown);
},
get_block_item: (x, y, z) =>
structuredClone(game().world.get_tile(x, y, z)?.client_data?.item as ItemStack),
drop_item: (x, y, z, item) => void game().pop_item(x, y, z, new_stack(item)),
spawn_entity: (id, x, y, z) => {
const entity = EverythingRegistry.get("entities", id)