Placing schematics
This commit is contained in:
@@ -12,8 +12,10 @@ import {
|
||||
is_waterlogged,
|
||||
set_state_value,
|
||||
shared_items_api,
|
||||
value_with_states,
|
||||
} from "@/common/utils.ts";
|
||||
import { LootTables } from "./loot.ts";
|
||||
import { prepare_schematic } from "./schematics.ts";
|
||||
import { collision_shape_at, covers_face, raycast_blocks, type Shape } from "@/common/block_shapes.ts";
|
||||
import { AIR, CHUNK_SIZE, faces, ID_MASK } from "@/common/constants.ts";
|
||||
import { physics } from "@/common/physics.ts";
|
||||
@@ -769,15 +771,13 @@ export class ModRuntime {
|
||||
set_block: (x, y, z, id, states) => {
|
||||
const info = id === AIR_ID ? undefined : EverythingRegistry.get<BlockRegistry>("blocks", id);
|
||||
if (id !== AIR_ID && !info) throw new Error(`unknown block ${id}`);
|
||||
let value = info && game().world.default_values[game().world.block_ids[id]];
|
||||
for (const [name, state] of Object.entries(states ?? {})) {
|
||||
const bits = info?.states?.find((s) => s.name === name)?.bits;
|
||||
if (bits === undefined || !Number.isInteger(state) || state < 0 || state >= 2 ** bits) {
|
||||
throw new Error(`${id} has no state ${name} that fits ${state}`);
|
||||
}
|
||||
value = set_state_value(value!, info!, name, state)!;
|
||||
const state = info && states
|
||||
? value_with_states(game().world.block_ids[id], info, states) >>> 16
|
||||
: undefined;
|
||||
if (id === AIR_ID && states && Object.keys(states).length > 0) {
|
||||
throw new Error(`${id} has no state ${Object.keys(states)[0]}`);
|
||||
}
|
||||
game().set_block(x, y, z, id, undefined, states && value !== undefined ? value >>> 16 : undefined);
|
||||
game().set_block(x, y, z, id, undefined, state);
|
||||
return true;
|
||||
},
|
||||
break_block: (x, y, z, options = {}) => {
|
||||
@@ -1061,6 +1061,15 @@ export class ModRuntime {
|
||||
},
|
||||
schematics: {
|
||||
export: (from, to) => game().export_schematic(from, to),
|
||||
register: (id, schematic) => {
|
||||
register.new_id("schematic", id, game().schematics.has(id));
|
||||
try {
|
||||
game().schematics.set(id, prepare_schematic(game(), schematic));
|
||||
} catch (e) {
|
||||
register.fail(`schematic ${id}: ${(e as Error).message}`);
|
||||
}
|
||||
},
|
||||
place: (id, placement) => game().place_schematic(id, placement),
|
||||
},
|
||||
menus: {
|
||||
extend_player_menu: (build) => {
|
||||
|
||||
Reference in New Issue
Block a user