Fill on serverworld and clear out tiles on new day
This commit is contained in:
@@ -969,16 +969,12 @@ export class GameServer {
|
||||
}
|
||||
}
|
||||
|
||||
// /fill: every block between two corners, both included, replaced with id. like a schematic, they all change before
|
||||
// any of them hears of it. throws for a box that's too big, and says how many blocks it changed
|
||||
// /fill and ctx.world.fill: every block between two corners, both included, replaced with id. like a schematic, they
|
||||
// all change before any of them hears of it. says how many blocks it changed
|
||||
fill(from: Position, to: Position, id: string): number {
|
||||
const [x0, x1] = [Math.min(from.x, to.x), Math.max(from.x, to.x)];
|
||||
const [y0, y1] = [Math.min(from.y, to.y), Math.max(from.y, to.y)];
|
||||
const [z0, z1] = [Math.min(from.z, to.z), Math.max(from.z, to.z)];
|
||||
const volume = (x1 - x0 + 1) * (y1 - y0 + 1) * (z1 - z0 + 1);
|
||||
if (volume > MAX_FILL_VOLUME) {
|
||||
throw new Error(`fill changes up to ${MAX_FILL_VOLUME} blocks, and that box has ${volume}`);
|
||||
}
|
||||
const placed: Position[] = [];
|
||||
for (let y = y0; y <= y1; y++) {
|
||||
if (!this.world.shape.contains(y)) continue;
|
||||
@@ -1969,12 +1965,14 @@ export class GameServer {
|
||||
argument<string, ServerCommandSource>("block", block_or_air()).executes((context) => {
|
||||
const [from, to] = corners(context);
|
||||
const id = context.get<string>("block");
|
||||
let count: number;
|
||||
try {
|
||||
count = this.fill(from, to, id);
|
||||
} catch (e) {
|
||||
throw new CommandError(`Couldn't fill it: ${(e as Error).message}`);
|
||||
const volume = (Math.abs(to.x - from.x) + 1) * (Math.abs(to.y - from.y) + 1) *
|
||||
(Math.abs(to.z - from.z) + 1);
|
||||
if (volume > MAX_FILL_VOLUME) {
|
||||
throw new CommandError(
|
||||
`Couldn't fill it: fill changes up to ${MAX_FILL_VOLUME} blocks, and that box has ${volume}`,
|
||||
);
|
||||
}
|
||||
const count = this.fill(from, to, id);
|
||||
context.source.send_message(`Filled ${count} blocks with ${display_name(id)}`);
|
||||
}),
|
||||
)),
|
||||
|
||||
@@ -911,6 +911,10 @@ export class ModRuntime {
|
||||
game().set_block(x, y, z, id, undefined, state);
|
||||
return true;
|
||||
},
|
||||
fill: (from, to, id) => {
|
||||
if (id !== AIR_ID && !EverythingRegistry.get("blocks", id)) throw new Error(`unknown block ${id}`);
|
||||
return game().fill(from, to, id);
|
||||
},
|
||||
break_block: (x, y, z, options = {}) => {
|
||||
if (game().world.get_block_id(x, y, z) === AIR_ID) return undefined;
|
||||
const how = { harvest: options.harvest === true, collect: options.collect === true };
|
||||
|
||||
Reference in New Issue
Block a user