19 lines
884 B
TypeScript
19 lines
884 B
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import type { BlockRef, ServerContext } from "cubi/server";
|
|
|
|
// export_data for a block that keeps its items in a container whose id is its data's "container", like a chest: its
|
|
// data with the items in place of the id, one for each slot and null for an empty one, so a schematic has them. its
|
|
// data as it is when it has no container yet
|
|
export function export_container_data(ctx: ServerContext, block: BlockRef): unknown {
|
|
const container = block.data?.container && ctx.containers.get(block.data.container);
|
|
if (!container) return block.data;
|
|
const items = [];
|
|
for (let slot = 0; slot < container.size; slot++) {
|
|
const item = container.get(slot);
|
|
items.push(item ? { id: item.id, count: item.count, data: item.data } : null);
|
|
}
|
|
return { ...block.data, container: items };
|
|
}
|