Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sisilicon
GitHub Repository: sisilicon/worldedit-be
Path: blob/master/src/editor/util.ts
1782 views
1
import { BlockVolume, BlockVolumeBase, ListBlockVolume, system } from "@minecraft/server";
2
import { Vector } from "@notbeer-api";
3
import { Shape } from "server/shapes/base_shape";
4
import { CuboidShape } from "server/shapes/cuboid";
5
6
export const newLineMarkup = "[~*newLine~]";
7
8
export function shapeToBlockVolume() {
9
let job: number;
10
11
return {
12
update: (shape: Shape | undefined, callback: (volume: BlockVolumeBase | undefined) => void) => {
13
if (job) system.clearJob(job);
14
15
if (!shape) {
16
callback(undefined);
17
} else if (shape instanceof CuboidShape) {
18
callback(new BlockVolume(...shape.getRegion(Vector.ZERO)));
19
} else {
20
const activeJob = (job = system.runJob(
21
(function* () {
22
const volume = new ListBlockVolume([]);
23
for (const block of shape.getBlocks(Vector.ZERO)) {
24
volume.add([block]);
25
yield;
26
}
27
if (activeJob === job) callback(volume);
28
})()
29
));
30
}
31
},
32
};
33
}
34
35