nucleation 0.2.18 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Autostack.d.ts +43 -0
- package/Autostack.mjs +134 -0
- package/BlockPos.d.ts +28 -0
- package/BlockPos.mjs +129 -0
- package/BlockState.d.ts +39 -0
- package/BlockState.mjs +134 -0
- package/Brush.d.ts +68 -0
- package/Brush.mjs +220 -0
- package/BuildingTool.d.ts +29 -0
- package/BuildingTool.mjs +74 -0
- package/ChunkMeshResult.d.ts +75 -0
- package/ChunkMeshResult.mjs +253 -0
- package/CircuitBuilder.d.ts +118 -0
- package/CircuitBuilder.mjs +516 -0
- package/DefinitionRegion.d.ts +274 -0
- package/DefinitionRegion.mjs +973 -0
- package/Diff.d.ts +88 -0
- package/Diff.mjs +316 -0
- package/Dimensions.d.ts +28 -0
- package/Dimensions.mjs +129 -0
- package/ExecutionMode.d.ts +42 -0
- package/ExecutionMode.mjs +127 -0
- package/Fingerprint.d.ts +44 -0
- package/Fingerprint.mjs +197 -0
- package/InterpolationSpace.d.ts +25 -0
- package/InterpolationSpace.mjs +73 -0
- package/IoLayout.d.ts +26 -0
- package/IoLayout.mjs +81 -0
- package/IoLayoutBuilder.d.ts +73 -0
- package/IoLayoutBuilder.mjs +315 -0
- package/IoType.d.ts +41 -0
- package/IoType.mjs +125 -0
- package/ItemModelConfig.d.ts +65 -0
- package/ItemModelConfig.mjs +223 -0
- package/ItemModelPackBuilder.d.ts +32 -0
- package/ItemModelPackBuilder.mjs +104 -0
- package/ItemModelResult.d.ts +72 -0
- package/ItemModelResult.mjs +268 -0
- package/ItemScale.d.ts +31 -0
- package/ItemScale.mjs +132 -0
- package/LayoutFunction.d.ts +52 -0
- package/LayoutFunction.mjs +159 -0
- package/MchprsWorld.d.ts +131 -0
- package/MchprsWorld.mjs +423 -0
- package/MeshBounds.d.ts +40 -0
- package/MeshBounds.mjs +180 -0
- package/MeshConfig.d.ts +101 -0
- package/MeshConfig.mjs +306 -0
- package/MeshJob.d.ts +44 -0
- package/MeshJob.mjs +116 -0
- package/MeshPhase.d.ts +38 -0
- package/MeshPhase.mjs +90 -0
- package/MeshProgress.d.ts +32 -0
- package/MeshProgress.mjs +133 -0
- package/MeshResult.d.ts +60 -0
- package/MeshResult.mjs +206 -0
- package/MultiMeshResult.d.ts +50 -0
- package/MultiMeshResult.mjs +166 -0
- package/Nbt.d.ts +50 -0
- package/Nbt.mjs +161 -0
- package/NucleationError.d.ts +36 -0
- package/NucleationError.mjs +104 -0
- package/OutputCondition.d.ts +45 -0
- package/OutputCondition.mjs +129 -0
- package/Palette.d.ts +84 -0
- package/Palette.mjs +269 -0
- package/PaletteBuilder.d.ts +76 -0
- package/PaletteBuilder.mjs +297 -0
- package/README.md +28 -197
- package/RawMeshExport.d.ts +74 -0
- package/RawMeshExport.mjs +243 -0
- package/RedstoneGraph.d.ts +58 -0
- package/RedstoneGraph.mjs +242 -0
- package/RegionBounds.d.ts +41 -0
- package/RegionBounds.mjs +181 -0
- package/RenderConfig.d.ts +66 -0
- package/RenderConfig.mjs +170 -0
- package/Renderer.d.ts +35 -0
- package/Renderer.mjs +139 -0
- package/ResourcePack.d.ts +105 -0
- package/ResourcePack.mjs +447 -0
- package/ResourcePackList.d.ts +32 -0
- package/ResourcePackList.mjs +96 -0
- package/Schematic.d.ts +655 -0
- package/Schematic.mjs +2647 -0
- package/SchematicBuilder.d.ts +103 -0
- package/SchematicBuilder.mjs +401 -0
- package/SchematicRegions.d.ts +93 -0
- package/SchematicRegions.mjs +411 -0
- package/Scripting.d.ts +40 -0
- package/Scripting.mjs +138 -0
- package/Sdf.d.ts +31 -0
- package/Sdf.mjs +107 -0
- package/Shape.d.ts +108 -0
- package/Shape.mjs +336 -0
- package/SortStrategy.d.ts +86 -0
- package/SortStrategy.mjs +272 -0
- package/Store.d.ts +83 -0
- package/Store.mjs +369 -0
- package/StoreIo.d.ts +71 -0
- package/StoreIo.mjs +292 -0
- package/TextureAtlas.d.ts +40 -0
- package/TextureAtlas.mjs +122 -0
- package/TextureInfo.d.ts +34 -0
- package/TextureInfo.mjs +148 -0
- package/TypedCircuitExecutor.d.ts +101 -0
- package/TypedCircuitExecutor.mjs +378 -0
- package/Value.d.ts +73 -0
- package/Value.mjs +275 -0
- package/WorldChunkView.d.ts +63 -0
- package/WorldChunkView.mjs +201 -0
- package/WorldSink.d.ts +50 -0
- package/WorldSink.mjs +177 -0
- package/WorldStream.d.ts +45 -0
- package/WorldStream.mjs +184 -0
- package/diplomat-runtime.d.ts +15 -0
- package/diplomat-runtime.mjs +774 -0
- package/diplomat-wasm.mjs +52 -0
- package/diplomat.config.mjs +6 -0
- package/index.d.ts +117 -0
- package/index.mjs +120 -0
- package/{nucleation_bg.wasm → nucleation.wasm} +0 -0
- package/package.json +19 -41
- package/LICENSE +0 -21
- package/api.js +0 -608
- package/nucleation-cdn-loader.js +0 -15
- package/nucleation-original.js +0 -8383
- package/nucleation.d.ts +0 -2947
- package/nucleation.js +0 -36
package/Autostack.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import type { NucleationError } from "./NucleationError"
|
|
3
|
+
import type { Schematic } from "./Schematic"
|
|
4
|
+
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Free functions in the old ABI hung directly off `schematic_*`; here they get a
|
|
10
|
+
* namespacing opaque-less home via static methods on a zero-size type is not
|
|
11
|
+
* supported, so they live as static methods taking `&Schematic` explicitly.
|
|
12
|
+
*/
|
|
13
|
+
export class Autostack {
|
|
14
|
+
/** @internal */
|
|
15
|
+
get ffiValue(): pointer;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor();
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Detect repeating structures (region coverage). Writes a JSON array string;
|
|
22
|
+
* each element has `mode`, `vectors`, `coverage`, `region_min`/`region_max`,
|
|
23
|
+
* `cell_min`/`cell_max`, `label`.
|
|
24
|
+
*/
|
|
25
|
+
static detectStructures(schematic: Schematic): string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Graph-based detection: recovers diagonal lattice periods via the redstone
|
|
29
|
+
* logic graph. Writes `"[]"` for non-redstone builds. Requires the
|
|
30
|
+
* `simulation` feature; writes `"[]"` when compiled without it.
|
|
31
|
+
*/
|
|
32
|
+
static detectStructuresGraph(schematic: Schematic): string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resize a 1D / diagonal structure along its period vector.
|
|
36
|
+
*/
|
|
37
|
+
static resize1d(schematic: Schematic, vx: number, vy: number, vz: number, units: number): Schematic;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resize a 2D structure to `n1`×`n2` cells along the two period vectors.
|
|
41
|
+
*/
|
|
42
|
+
static resize2d(schematic: Schematic, v1x: number, v1y: number, v1z: number, v2x: number, v2y: number, v2z: number, n1: number, n2: number): Schematic;
|
|
43
|
+
}
|
package/Autostack.mjs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import { NucleationError } from "./NucleationError.mjs"
|
|
3
|
+
import { Schematic } from "./Schematic.mjs"
|
|
4
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
5
|
+
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
6
|
+
|
|
7
|
+
const Autostack_box_destroy_registry = new FinalizationRegistry((ptr) => {
|
|
8
|
+
wasm.Autostack_destroy(ptr);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Free functions in the old ABI hung directly off `schematic_*`; here they get a
|
|
13
|
+
* namespacing opaque-less home via static methods on a zero-size type is not
|
|
14
|
+
* supported, so they live as static methods taking `&Schematic` explicitly.
|
|
15
|
+
*/
|
|
16
|
+
export class Autostack {
|
|
17
|
+
// Internal ptr reference:
|
|
18
|
+
#ptr = null;
|
|
19
|
+
|
|
20
|
+
// Lifetimes are only to keep dependencies alive.
|
|
21
|
+
// Since JS won't garbage collect until there are no incoming edges.
|
|
22
|
+
#selfEdge = [];
|
|
23
|
+
|
|
24
|
+
#internalConstructor(symbol, ptr, selfEdge) {
|
|
25
|
+
if (symbol !== diplomatRuntime.internalConstructor) {
|
|
26
|
+
console.error("Autostack is an Opaque type. You cannot call its constructor.");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.#ptr = ptr;
|
|
30
|
+
this.#selfEdge = selfEdge;
|
|
31
|
+
|
|
32
|
+
// Are we being borrowed? If not, we can register.
|
|
33
|
+
if (this.#selfEdge.length === 0) {
|
|
34
|
+
Autostack_box_destroy_registry.register(this, this.#ptr);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/** @internal */
|
|
40
|
+
get ffiValue() {
|
|
41
|
+
return this.#ptr;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Detect repeating structures (region coverage). Writes a JSON array string;
|
|
47
|
+
* each element has `mode`, `vectors`, `coverage`, `region_min`/`region_max`,
|
|
48
|
+
* `cell_min`/`cell_max`, `label`.
|
|
49
|
+
*/
|
|
50
|
+
static detectStructures(schematic) {
|
|
51
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
52
|
+
|
|
53
|
+
wasm.Autostack_detect_structures(schematic.ffiValue, write.buffer);
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
return write.readString8();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
finally {
|
|
60
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
61
|
+
write.free();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Graph-based detection: recovers diagonal lattice periods via the redstone
|
|
67
|
+
* logic graph. Writes `"[]"` for non-redstone builds. Requires the
|
|
68
|
+
* `simulation` feature; writes `"[]"` when compiled without it.
|
|
69
|
+
*/
|
|
70
|
+
static detectStructuresGraph(schematic) {
|
|
71
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
72
|
+
|
|
73
|
+
wasm.Autostack_detect_structures_graph(schematic.ffiValue, write.buffer);
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
return write.readString8();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
finally {
|
|
80
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
81
|
+
write.free();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Resize a 1D / diagonal structure along its period vector.
|
|
87
|
+
*/
|
|
88
|
+
static resize1d(schematic, vx, vy, vz, units) {
|
|
89
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const result = wasm.Autostack_resize_1d(diplomatReceive.buffer, schematic.ffiValue, vx, vy, vz, units);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
if (!diplomatReceive.resultFlag) {
|
|
96
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
97
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
98
|
+
}
|
|
99
|
+
return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
finally {
|
|
103
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
104
|
+
diplomatReceive.free();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Resize a 2D structure to `n1`×`n2` cells along the two period vectors.
|
|
110
|
+
*/
|
|
111
|
+
static resize2d(schematic, v1x, v1y, v1z, v2x, v2y, v2z, n1, n2) {
|
|
112
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
const result = wasm.Autostack_resize_2d(diplomatReceive.buffer, schematic.ffiValue, v1x, v1y, v1z, v2x, v2y, v2z, n1, n2);
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
if (!diplomatReceive.resultFlag) {
|
|
119
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
120
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
121
|
+
}
|
|
122
|
+
return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
finally {
|
|
126
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
127
|
+
diplomatReceive.free();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
constructor(symbol, ptr, selfEdge) {
|
|
132
|
+
return this.#internalConstructor(...arguments)
|
|
133
|
+
}
|
|
134
|
+
}
|
package/BlockPos.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
3
|
+
|
|
4
|
+
export type BlockPos_obj = {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
z: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export class BlockPos {
|
|
13
|
+
get x(): number;
|
|
14
|
+
set x(value: number);
|
|
15
|
+
get y(): number;
|
|
16
|
+
set y(value: number);
|
|
17
|
+
get z(): number;
|
|
18
|
+
set z(value: number);
|
|
19
|
+
/** @internal */
|
|
20
|
+
static fromFields(structObj : BlockPos_obj) : BlockPos;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create `BlockPos` from an object that contains all of `BlockPos`s fields.
|
|
24
|
+
* Optional fields do not need to be included in the provided object.
|
|
25
|
+
*/
|
|
26
|
+
constructor(structObj: BlockPos_obj);
|
|
27
|
+
|
|
28
|
+
}
|
package/BlockPos.mjs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
3
|
+
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class BlockPos {
|
|
8
|
+
#x;
|
|
9
|
+
get x() {
|
|
10
|
+
return this.#x;
|
|
11
|
+
}
|
|
12
|
+
set x(value){
|
|
13
|
+
this.#x = value;
|
|
14
|
+
}
|
|
15
|
+
#y;
|
|
16
|
+
get y() {
|
|
17
|
+
return this.#y;
|
|
18
|
+
}
|
|
19
|
+
set y(value){
|
|
20
|
+
this.#y = value;
|
|
21
|
+
}
|
|
22
|
+
#z;
|
|
23
|
+
get z() {
|
|
24
|
+
return this.#z;
|
|
25
|
+
}
|
|
26
|
+
set z(value){
|
|
27
|
+
this.#z = value;
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
static fromFields(structObj) {
|
|
31
|
+
return new BlockPos(structObj);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#internalConstructor(structObj) {
|
|
35
|
+
if (typeof structObj !== "object") {
|
|
36
|
+
throw new Error("BlockPos's constructor takes an object of BlockPos's fields.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if ("x" in structObj) {
|
|
40
|
+
this.#x = structObj.x;
|
|
41
|
+
} else {
|
|
42
|
+
throw new Error("Missing required field x.");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ("y" in structObj) {
|
|
46
|
+
this.#y = structObj.y;
|
|
47
|
+
} else {
|
|
48
|
+
throw new Error("Missing required field y.");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ("z" in structObj) {
|
|
52
|
+
this.#z = structObj.z;
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error("Missing required field z.");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Return this struct in FFI function friendly format.
|
|
61
|
+
// Returns an array that can be expanded with spread syntax (...)
|
|
62
|
+
_intoFFI(
|
|
63
|
+
dst,
|
|
64
|
+
functionCleanupArena,
|
|
65
|
+
appendArrayMap
|
|
66
|
+
) {
|
|
67
|
+
|
|
68
|
+
this._writeToArrayBuffer(wasm.memory.buffer, dst, functionCleanupArena, appendArrayMap);
|
|
69
|
+
|
|
70
|
+
return dst;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static get _sizeBytes() {
|
|
74
|
+
return 12;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// Currently unused, we may want to use later on though:
|
|
78
|
+
static get _sizeAlign() {
|
|
79
|
+
return 4;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static _fromSuppliedValue(internalConstructor, obj) {
|
|
83
|
+
if (internalConstructor !== diplomatRuntime.internalConstructor) {
|
|
84
|
+
throw new Error("_fromSuppliedValue cannot be called externally.");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (obj instanceof BlockPos) {
|
|
88
|
+
return obj;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return BlockPos.fromFields(obj);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_writeToArrayBuffer(
|
|
95
|
+
arrayBuffer,
|
|
96
|
+
offset,
|
|
97
|
+
functionCleanupArena,
|
|
98
|
+
appendArrayMap
|
|
99
|
+
) {
|
|
100
|
+
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#x, Int32Array);
|
|
101
|
+
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#y, Int32Array);
|
|
102
|
+
diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 8, this.#z, Int32Array);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// This struct contains borrowed fields, so this takes in a list of
|
|
106
|
+
// "edges" corresponding to where each lifetime's data may have been borrowed from
|
|
107
|
+
// and passes it down to individual fields containing the borrow.
|
|
108
|
+
// This method does not attempt to handle any dependencies between lifetimes, the caller
|
|
109
|
+
// should handle this when constructing edge arrays.
|
|
110
|
+
static _fromFFI(internalConstructor, ptr) {
|
|
111
|
+
if (internalConstructor !== diplomatRuntime.internalConstructor) {
|
|
112
|
+
throw new Error("BlockPos._fromFFI is not meant to be called externally. Please use the default constructor.");
|
|
113
|
+
}
|
|
114
|
+
let structObj = {};
|
|
115
|
+
const xDeref = (new Int32Array(wasm.memory.buffer, ptr, 1))[0];
|
|
116
|
+
structObj.x = xDeref;
|
|
117
|
+
const yDeref = (new Int32Array(wasm.memory.buffer, ptr + 4, 1))[0];
|
|
118
|
+
structObj.y = yDeref;
|
|
119
|
+
const zDeref = (new Int32Array(wasm.memory.buffer, ptr + 8, 1))[0];
|
|
120
|
+
structObj.z = zDeref;
|
|
121
|
+
|
|
122
|
+
return new BlockPos(structObj);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
constructor(structObj) {
|
|
127
|
+
return this.#internalConstructor(...arguments)
|
|
128
|
+
}
|
|
129
|
+
}
|
package/BlockState.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import type { NucleationError } from "./NucleationError"
|
|
3
|
+
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A block state: a block name plus its properties. Port of the old
|
|
9
|
+
* `BlockStateWrapper` / `blockstate_*` fns.
|
|
10
|
+
*/
|
|
11
|
+
export class BlockState {
|
|
12
|
+
/** @internal */
|
|
13
|
+
get ffiValue(): pointer;
|
|
14
|
+
/** @internal */
|
|
15
|
+
constructor();
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a block state with the given name and no properties.
|
|
20
|
+
*/
|
|
21
|
+
static create(name: string): BlockState;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A copy of this block state with `key=value` set; the original is
|
|
25
|
+
* unchanged.
|
|
26
|
+
*/
|
|
27
|
+
withProperty(key: string, value: string): BlockState;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The block name (e.g. `minecraft:stone`).
|
|
31
|
+
*/
|
|
32
|
+
name(): string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The properties as a JSON object of string→string (the old
|
|
36
|
+
* `CPropertyArray`).
|
|
37
|
+
*/
|
|
38
|
+
propertiesJson(): string;
|
|
39
|
+
}
|
package/BlockState.mjs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import { NucleationError } from "./NucleationError.mjs"
|
|
3
|
+
import wasm from "./diplomat-wasm.mjs";
|
|
4
|
+
import * as diplomatRuntime from "./diplomat-runtime.mjs";
|
|
5
|
+
|
|
6
|
+
const BlockState_box_destroy_registry = new FinalizationRegistry((ptr) => {
|
|
7
|
+
wasm.BlockState_destroy(ptr);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A block state: a block name plus its properties. Port of the old
|
|
12
|
+
* `BlockStateWrapper` / `blockstate_*` fns.
|
|
13
|
+
*/
|
|
14
|
+
export class BlockState {
|
|
15
|
+
// Internal ptr reference:
|
|
16
|
+
#ptr = null;
|
|
17
|
+
|
|
18
|
+
// Lifetimes are only to keep dependencies alive.
|
|
19
|
+
// Since JS won't garbage collect until there are no incoming edges.
|
|
20
|
+
#selfEdge = [];
|
|
21
|
+
|
|
22
|
+
#internalConstructor(symbol, ptr, selfEdge) {
|
|
23
|
+
if (symbol !== diplomatRuntime.internalConstructor) {
|
|
24
|
+
console.error("BlockState is an Opaque type. You cannot call its constructor.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.#ptr = ptr;
|
|
28
|
+
this.#selfEdge = selfEdge;
|
|
29
|
+
|
|
30
|
+
// Are we being borrowed? If not, we can register.
|
|
31
|
+
if (this.#selfEdge.length === 0) {
|
|
32
|
+
BlockState_box_destroy_registry.register(this, this.#ptr);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
get ffiValue() {
|
|
39
|
+
return this.#ptr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create a block state with the given name and no properties.
|
|
45
|
+
*/
|
|
46
|
+
static create(name) {
|
|
47
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
48
|
+
|
|
49
|
+
const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
|
|
50
|
+
|
|
51
|
+
const result = wasm.BlockState_create(nameSlice.ptr);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
return new BlockState(diplomatRuntime.internalConstructor, result, []);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
finally {
|
|
58
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
59
|
+
functionCleanupArena.free();
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A copy of this block state with `key=value` set; the original is
|
|
66
|
+
* unchanged.
|
|
67
|
+
*/
|
|
68
|
+
withProperty(key, value) {
|
|
69
|
+
let functionCleanupArena = new diplomatRuntime.CleanupArena();
|
|
70
|
+
|
|
71
|
+
const keySlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, key)));
|
|
72
|
+
const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, value)));
|
|
73
|
+
const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
const result = wasm.BlockState_with_property(diplomatReceive.buffer, this.ffiValue, keySlice.ptr, valueSlice.ptr);
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
if (!diplomatReceive.resultFlag) {
|
|
80
|
+
const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
|
|
81
|
+
throw new globalThis.Error('NucleationError.' + cause.value, { cause });
|
|
82
|
+
}
|
|
83
|
+
return new BlockState(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
finally {
|
|
87
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
88
|
+
functionCleanupArena.free();
|
|
89
|
+
|
|
90
|
+
diplomatReceive.free();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The block name (e.g. `minecraft:stone`).
|
|
96
|
+
*/
|
|
97
|
+
name() {
|
|
98
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
99
|
+
|
|
100
|
+
wasm.BlockState_name(this.ffiValue, write.buffer);
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
return write.readString8();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
finally {
|
|
107
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
108
|
+
write.free();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The properties as a JSON object of string→string (the old
|
|
114
|
+
* `CPropertyArray`).
|
|
115
|
+
*/
|
|
116
|
+
propertiesJson() {
|
|
117
|
+
const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
|
|
118
|
+
|
|
119
|
+
wasm.BlockState_properties_json(this.ffiValue, write.buffer);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
return write.readString8();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
finally {
|
|
126
|
+
diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
|
|
127
|
+
write.free();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
constructor(symbol, ptr, selfEdge) {
|
|
132
|
+
return this.#internalConstructor(...arguments)
|
|
133
|
+
}
|
|
134
|
+
}
|
package/Brush.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// generated by diplomat-tool
|
|
2
|
+
import type { InterpolationSpace } from "./InterpolationSpace"
|
|
3
|
+
import type { NucleationError } from "./NucleationError"
|
|
4
|
+
import type { Palette } from "./Palette"
|
|
5
|
+
import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Decides which block goes at each point of a filled shape. Wraps `BrushEnum`.
|
|
11
|
+
*/
|
|
12
|
+
export class Brush {
|
|
13
|
+
/** @internal */
|
|
14
|
+
get ffiValue(): pointer;
|
|
15
|
+
/** @internal */
|
|
16
|
+
constructor();
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Every point becomes `block_name` (a block-state string).
|
|
21
|
+
*/
|
|
22
|
+
static solid(blockName: string): Brush;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Nearest-block-to-RGB-color brush.
|
|
26
|
+
*/
|
|
27
|
+
static color(r: number, g: number, b: number): Brush;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Linear color gradient between two anchored points.
|
|
31
|
+
*/
|
|
32
|
+
static linearGradient(x1: number, y1: number, z1: number, r1: number, g1: number, b1: number, x2: number, y2: number, z2: number, r2: number, g2: number, b2: number, space: InterpolationSpace): Brush;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Base color shaded by surface normal against light direction
|
|
36
|
+
* (`lx`, `ly`, `lz`).
|
|
37
|
+
*/
|
|
38
|
+
static shaded(r: number, g: number, b: number, lx: number, ly: number, lz: number): Brush;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Bilinear gradient over the patch `origin + s*u + t*v` with corner colors
|
|
42
|
+
* c00/c10/c01/c11.
|
|
43
|
+
*/
|
|
44
|
+
static bilinearGradient(ox: number, oy: number, oz: number, ux: number, uy: number, uz: number, vx: number, vy: number, vz: number, r00: number, g00: number, b00: number, r10: number, g10: number, b10: number, r01: number, g01: number, b01: number, r11: number, g11: number, b11: number, space: InterpolationSpace): Brush;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Inverse-distance-weighted gradient between colored anchor points.
|
|
48
|
+
* `positions` is flat `[x0, y0, z0, x1, …]` and `colors` is flat
|
|
49
|
+
* `[r0, g0, b0, r1, …]`; both must describe the same non-zero number of
|
|
50
|
+
* points (`positions.len() == colors.len()`, a multiple of 3).
|
|
51
|
+
*/
|
|
52
|
+
static pointGradient(positions: Array<number>, colors: Array<number>, falloff: number, space: InterpolationSpace): Brush;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Use `palette` for this brush's color→block snapping instead of the
|
|
56
|
+
* default all-blocks palette. No-op for `solid` brushes, which place
|
|
57
|
+
* a fixed block state. Set it before filling; the palette is shared,
|
|
58
|
+
* not copied.
|
|
59
|
+
*/
|
|
60
|
+
setPalette(palette: Palette): void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Gradient along a parametric curve: `stops` holds the curve parameters in
|
|
64
|
+
* `[0, 1]` and `colors` the matching flat RGB triples
|
|
65
|
+
* (`colors.len() == stops.len() * 3`, `stops` non-empty).
|
|
66
|
+
*/
|
|
67
|
+
static curveGradient(stops: Array<number>, colors: Array<number>, space: InterpolationSpace): Brush;
|
|
68
|
+
}
|