@block_factory/lib 0.0.5 → 0.0.8
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/_module/BlockFactory.ts +10 -20
- package/_module/util/Command.ts +1 -9
- package/_module/util/Forms/Form.ts +5 -31
- package/_module/util/Forms/FormAction.ts +2 -1
- package/_module/util/Forms/FormMessage.ts +2 -1
- package/_module/util/Forms/FormModal.ts +9 -10
- package/_module/util/Forms/FormRegistry.ts +20 -23
- package/_module/util/Forms/IForm.ts +31 -0
- package/_module/util/Globals.ts +26 -0
- package/_module/util/ISystem.ts +58 -0
- package/_module/util/IVector.ts +420 -0
- package/_module/util/Math.ts +2 -0
- package/_module/util/Navigation.ts +130 -0
- package/_module/util/Signal.ts +71 -7
- package/_module/util/TempLeaker.ts +137 -0
- package/_module/util/Wrapper/IEntity.ts +93 -25
- package/_module/util/Wrapper/IItemStack.ts +63 -0
- package/_module/util/Wrapper/IPlayer.ts +73 -29
- package/_module/util/Wrapper/_Common.ts +130 -0
- package/_module/util/Wrapper/{Container.ts → _Container.ts} +5 -5
- package/index.js +3911 -521
- package/package.json +10 -4
- package/typedoc.json +6 -0
- package/_module/Framework/EntityTasks.ts +0 -203
- package/_module/Framework/Threads.ts +0 -72
- package/_module/Framework/_INIT.ts +0 -39
- package/_module/Types.ts +0 -10
- package/_module/util/System.ts +0 -21
- package/_module/util/Vector.ts +0 -388
- package/_types/_module/BlockFactory.d.ts +0 -19
- package/_types/_module/BlockFactory.d.ts.map +0 -1
- package/_types/_module/Framework/EntityTasks.d.ts +0 -40
- package/_types/_module/Framework/EntityTasks.d.ts.map +0 -1
- package/_types/_module/Framework/Threads.d.ts +0 -22
- package/_types/_module/Framework/Threads.d.ts.map +0 -1
- package/_types/_module/Framework/_INIT.d.ts +0 -19
- package/_types/_module/Framework/_INIT.d.ts.map +0 -1
- package/_types/_module/Types.d.ts +0 -10
- package/_types/_module/Types.d.ts.map +0 -1
- package/_types/_module/util/Command.d.ts +0 -92
- package/_types/_module/util/Command.d.ts.map +0 -1
- package/_types/_module/util/Forms/Form.d.ts +0 -12
- package/_types/_module/util/Forms/Form.d.ts.map +0 -1
- package/_types/_module/util/Forms/FormAction.d.ts +0 -73
- package/_types/_module/util/Forms/FormAction.d.ts.map +0 -1
- package/_types/_module/util/Forms/FormMessage.d.ts +0 -24
- package/_types/_module/util/Forms/FormMessage.d.ts.map +0 -1
- package/_types/_module/util/Forms/FormModal.d.ts +0 -66
- package/_types/_module/util/Forms/FormModal.d.ts.map +0 -1
- package/_types/_module/util/Forms/FormRegistry.d.ts +0 -12
- package/_types/_module/util/Forms/FormRegistry.d.ts.map +0 -1
- package/_types/_module/util/Math.d.ts +0 -20
- package/_types/_module/util/Math.d.ts.map +0 -1
- package/_types/_module/util/RawText.d.ts +0 -60
- package/_types/_module/util/RawText.d.ts.map +0 -1
- package/_types/_module/util/Signal.d.ts +0 -11
- package/_types/_module/util/Signal.d.ts.map +0 -1
- package/_types/_module/util/System.d.ts +0 -4
- package/_types/_module/util/System.d.ts.map +0 -1
- package/_types/_module/util/Vector.d.ts +0 -212
- package/_types/_module/util/Vector.d.ts.map +0 -1
- package/_types/_module/util/Wrapper/Container.d.ts +0 -9
- package/_types/_module/util/Wrapper/Container.d.ts.map +0 -1
- package/_types/_module/util/Wrapper/IEntity.d.ts +0 -12
- package/_types/_module/util/Wrapper/IEntity.d.ts.map +0 -1
- package/_types/_module/util/Wrapper/IPlayer.d.ts +0 -13
- package/_types/_module/util/Wrapper/IPlayer.d.ts.map +0 -1
- package/_types/index.d.ts +0 -3
- package/_types/index.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@block_factory/lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"description": "Typescript Library for Minecraft Bedrock Edition",
|
|
@@ -21,14 +21,20 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/Block-Factory-Studio/bf-mcbr-library#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@minecraft/server": "^2.
|
|
24
|
+
"@minecraft/server": "^2.5.0",
|
|
25
25
|
"@minecraft/server-ui": "^2.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"esbuild": "^0.25.9"
|
|
28
|
+
"esbuild": "^0.25.9",
|
|
29
|
+
"typedoc": "^0.28.17",
|
|
30
|
+
"typedoc-plugin-markdown": "^4.10.0"
|
|
31
|
+
},
|
|
32
|
+
"overrides": {
|
|
33
|
+
"minimatch": "^10.2.1"
|
|
29
34
|
},
|
|
30
35
|
"scripts": {
|
|
31
36
|
"build": "node esbuild.config.mjs",
|
|
32
|
-
"build:types": "tsc -p tsconfig.types.json"
|
|
37
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
38
|
+
"build:docs": "typedoc --options typedoc.json"
|
|
33
39
|
}
|
|
34
40
|
}
|
package/typedoc.json
ADDED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Entity,
|
|
3
|
-
system,
|
|
4
|
-
ScriptEventCommandMessageAfterEvent,
|
|
5
|
-
ScriptEventCommandMessageAfterEventSignal,
|
|
6
|
-
world,
|
|
7
|
-
WorldLoadAfterEventSignal,
|
|
8
|
-
WorldLoadAfterEvent,
|
|
9
|
-
EntitySpawnAfterEventSignal,
|
|
10
|
-
EntityRemoveAfterEventSignal,
|
|
11
|
-
EntitySpawnAfterEvent,
|
|
12
|
-
EntityRemoveAfterEvent,
|
|
13
|
-
EntityRemoveBeforeEvent,
|
|
14
|
-
EntityRemoveBeforeEventSignal,
|
|
15
|
-
} from "@minecraft/server";
|
|
16
|
-
|
|
17
|
-
import { Signal } from "../util/Signal";
|
|
18
|
-
import { IEntityWrapper, IEntity } from "../util/Wrapper/IEntity";
|
|
19
|
-
|
|
20
|
-
/* -------------------------------------------------------------------------- */
|
|
21
|
-
/* Public API */
|
|
22
|
-
/* -------------------------------------------------------------------------- */
|
|
23
|
-
|
|
24
|
-
export type EntityEmissionEvent = {
|
|
25
|
-
iEntity: IEntity;
|
|
26
|
-
parms: any;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const onEntityEmission = new Signal<EntityEmissionEvent>();
|
|
30
|
-
|
|
31
|
-
/* -------------------------------------------------------------------------- */
|
|
32
|
-
/* Singleton */
|
|
33
|
-
/* -------------------------------------------------------------------------- */
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class EntityHandler {
|
|
38
|
-
private PACK_ID: string | undefined;
|
|
39
|
-
private GLOBAL_MEMORY_ID = "GLB_MEM.ENTITY";
|
|
40
|
-
|
|
41
|
-
private readonly scriptEventSignal: ScriptEventCommandMessageAfterEventSignal = system.afterEvents.scriptEventReceive;
|
|
42
|
-
private readonly loadEventSignal: WorldLoadAfterEventSignal = world.afterEvents.worldLoad;
|
|
43
|
-
private readonly spawnEventSignal: EntitySpawnAfterEventSignal = world.afterEvents.entitySpawn;
|
|
44
|
-
private readonly removeAfterEventSignal: EntityRemoveAfterEventSignal = world.afterEvents.entityRemove;
|
|
45
|
-
private readonly removeBeforeEventSignal: EntityRemoveBeforeEventSignal = world.beforeEvents.entityRemove;
|
|
46
|
-
|
|
47
|
-
private readonly EM_INDEX = new Map<string, Entity>();
|
|
48
|
-
private readonly EM_KEYS: string[] = [];
|
|
49
|
-
private readonly SEARCH_TYPES = new Set<string>();
|
|
50
|
-
|
|
51
|
-
private _started = false;
|
|
52
|
-
private _wired = false;
|
|
53
|
-
|
|
54
|
-
public configure(): void {
|
|
55
|
-
if (this._started) throw new Error("BFLIB: EntityHandler already started;");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public registerEntity(typeId: string | string[]): void {
|
|
59
|
-
if (Array.isArray(typeId)) typeId.forEach((t) => this.SEARCH_TYPES.add(t));
|
|
60
|
-
else this.SEARCH_TYPES.add(typeId);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public start(packId: string): void {
|
|
64
|
-
if (this._started) return;
|
|
65
|
-
this._started = true;
|
|
66
|
-
this.PACK_ID = packId;
|
|
67
|
-
|
|
68
|
-
this.loadEventSignal.subscribe(this.onWorldLoad);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public stop(): void {
|
|
72
|
-
if (!this._started) return;
|
|
73
|
-
|
|
74
|
-
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
75
|
-
if (this._wired) {
|
|
76
|
-
this.scriptEventSignal.unsubscribe(this.processScriptEvents);
|
|
77
|
-
this.spawnEventSignal.unsubscribe(this.onEntitySpawned);
|
|
78
|
-
this.removeBeforeEventSignal.unsubscribe(this.onEntityRemovedBefore);
|
|
79
|
-
this.removeAfterEventSignal.unsubscribe(this.onEntityRemovedAfter);
|
|
80
|
-
this._wired = false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
this._started = false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/* ------------------------------------------------------------------------ */
|
|
87
|
-
/* Event Wiring */
|
|
88
|
-
/* ------------------------------------------------------------------------ */
|
|
89
|
-
|
|
90
|
-
private onWorldLoad = (_event: WorldLoadAfterEvent): void => {
|
|
91
|
-
|
|
92
|
-
this.scriptEventSignal.subscribe(this.processScriptEvents);
|
|
93
|
-
|
|
94
|
-
if (this.SEARCH_TYPES.size > 0) {
|
|
95
|
-
this.spawnEventSignal.subscribe(this.onEntitySpawned);
|
|
96
|
-
this.removeBeforeEventSignal.subscribe(this.onEntityRemovedBefore);
|
|
97
|
-
this.removeAfterEventSignal.subscribe(this.onEntityRemovedAfter);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
this._wired = true;
|
|
101
|
-
this.reloadEntityMemory();
|
|
102
|
-
this.loadEventSignal.unsubscribe(this.onWorldLoad);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
private processScriptEvents = (event: ScriptEventCommandMessageAfterEvent): void => {
|
|
106
|
-
if (!event.sourceEntity) return;
|
|
107
|
-
if (event.id !== `${this.PACK_ID}:entity_emitter`) return;
|
|
108
|
-
|
|
109
|
-
let parms: any;
|
|
110
|
-
try {
|
|
111
|
-
parms = JSON.parse(event.message);
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error(`BFLIB: entity_emitter JSON parse failed:`, e);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
onEntityEmission.emit({
|
|
118
|
-
iEntity: IEntityWrapper.wrap(event.sourceEntity),
|
|
119
|
-
parms,
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/* ------------------------------------------------------------------------ */
|
|
124
|
-
/* Filters */
|
|
125
|
-
/* ------------------------------------------------------------------------ */
|
|
126
|
-
|
|
127
|
-
private isValidType(typeId: string): boolean {
|
|
128
|
-
return this.SEARCH_TYPES.has(typeId);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private onEntitySpawned = (event: EntitySpawnAfterEvent): void => {
|
|
132
|
-
const entity = event.entity;
|
|
133
|
-
if (!this.isValidType(entity.typeId)) return;
|
|
134
|
-
this.saveEntityInMemory(entity);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
private onEntityRemovedBefore = (event: EntityRemoveBeforeEvent): void => {
|
|
138
|
-
const entity = event.removedEntity;
|
|
139
|
-
if (!this.isValidType(entity.typeId)) return;
|
|
140
|
-
this.deleteEntityInMemory(entity);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
private onEntityRemovedAfter = (_event: EntityRemoveAfterEvent): void => {
|
|
144
|
-
//
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
/* ------------------------------------------------------------------------ */
|
|
148
|
-
/* Persistence */
|
|
149
|
-
/* ------------------------------------------------------------------------ */
|
|
150
|
-
|
|
151
|
-
private reloadEntityMemory(): void {
|
|
152
|
-
this.EM_INDEX.clear();
|
|
153
|
-
this.EM_KEYS.length = 0;
|
|
154
|
-
|
|
155
|
-
const raw = world.getDynamicProperty(this.GLOBAL_MEMORY_ID) as string | undefined;
|
|
156
|
-
if (!raw) return;
|
|
157
|
-
|
|
158
|
-
let parsed: string[];
|
|
159
|
-
try {
|
|
160
|
-
parsed = JSON.parse(raw) as string[];
|
|
161
|
-
} catch (e) {
|
|
162
|
-
console.error(`BFLIB: Failed to parse ${this.GLOBAL_MEMORY_ID}:`, e);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
for (const id of parsed) {
|
|
167
|
-
this.EM_KEYS.push(id);
|
|
168
|
-
const entity = world.getEntity(id);
|
|
169
|
-
if (entity) this.EM_INDEX.set(entity.id, entity);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private persistKeys(): void {
|
|
174
|
-
world.setDynamicProperty(this.GLOBAL_MEMORY_ID, JSON.stringify(this.EM_KEYS));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public saveEntityInMemory(entity: Entity): boolean {
|
|
178
|
-
if (this.EM_INDEX.has(entity.id)) return false;
|
|
179
|
-
this.EM_KEYS.push(entity.id);
|
|
180
|
-
this.EM_INDEX.set(entity.id, entity);
|
|
181
|
-
this.persistKeys();
|
|
182
|
-
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public deleteEntityInMemory(entity: Entity): boolean {
|
|
187
|
-
const existed = this.EM_INDEX.delete(entity.id);
|
|
188
|
-
if (!existed) return false;
|
|
189
|
-
|
|
190
|
-
const idx = this.EM_KEYS.indexOf(entity.id);
|
|
191
|
-
if (idx !== -1) this.EM_KEYS.splice(idx, 1);
|
|
192
|
-
|
|
193
|
-
this.persistKeys();
|
|
194
|
-
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
public getEntitiesInMemory(): Entity[] {
|
|
199
|
-
return Array.from(this.EM_INDEX.values());
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export const _EntityHandler_ = new EntityHandler();
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { system, TicksPerSecond } from "@minecraft/server";
|
|
2
|
-
import { Signal } from "../util/Signal";
|
|
3
|
-
|
|
4
|
-
export type ThreadConfig = {
|
|
5
|
-
mainRate?: number; // interval ticks
|
|
6
|
-
lateRate?: number; // interval ticks
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
class Threads {
|
|
10
|
-
public readonly MAIN = new Signal<number>();
|
|
11
|
-
public readonly LATE = new Signal<void>();
|
|
12
|
-
|
|
13
|
-
private _mainRate = 0;
|
|
14
|
-
private _lateRate = TicksPerSecond;
|
|
15
|
-
|
|
16
|
-
private _MAIN_ID: number | undefined;
|
|
17
|
-
private _LATE_ID: number | undefined;
|
|
18
|
-
|
|
19
|
-
private _delta = this.createDeltaTimer();
|
|
20
|
-
private _started = false;
|
|
21
|
-
|
|
22
|
-
public configure(cfg: ThreadConfig) {
|
|
23
|
-
if (this._started) throw new Error("BFLIB: _THREAD_ already started; configure before start().");
|
|
24
|
-
if (cfg.mainRate !== undefined) this._mainRate = cfg.mainRate;
|
|
25
|
-
if (cfg.lateRate !== undefined) this._lateRate = cfg.lateRate;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public start() {
|
|
29
|
-
if (this._started) return; // idempotent
|
|
30
|
-
this._started = true;
|
|
31
|
-
|
|
32
|
-
this._MAIN_ID = system.runInterval(() => {
|
|
33
|
-
if (this.MAIN.count <= 0) return;
|
|
34
|
-
try {
|
|
35
|
-
const delta = this._delta();
|
|
36
|
-
this.MAIN.emit(delta);
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.error(`ERROR: _THREAD_.MAIN:${this._MAIN_ID} |`, e);
|
|
39
|
-
}
|
|
40
|
-
}, this._mainRate);
|
|
41
|
-
|
|
42
|
-
this._LATE_ID = system.runInterval(() => {
|
|
43
|
-
if (this.LATE.count <= 0) return;
|
|
44
|
-
try {
|
|
45
|
-
this.LATE.emit();
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.error(`ERROR: _THREAD_.LATE:${this._LATE_ID} |`, e);
|
|
48
|
-
}
|
|
49
|
-
}, this._lateRate);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public stop() {
|
|
53
|
-
if (this._MAIN_ID !== undefined) system.clearRun(this._MAIN_ID);
|
|
54
|
-
if (this._LATE_ID !== undefined) system.clearRun(this._LATE_ID);
|
|
55
|
-
this._MAIN_ID = undefined;
|
|
56
|
-
this._LATE_ID = undefined;
|
|
57
|
-
this._started = false;
|
|
58
|
-
this._delta = this.createDeltaTimer(); // reset delta timing
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private createDeltaTimer() {
|
|
62
|
-
let last = Date.now();
|
|
63
|
-
return () => {
|
|
64
|
-
const now = Date.now();
|
|
65
|
-
const delta = (now - last) / 1000;
|
|
66
|
-
last = now;
|
|
67
|
-
return delta;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const _THREAD_ = new Threads();
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
let IS_INITIALIZED: boolean = false
|
|
2
|
-
let PACK_ID: string | undefined = undefined
|
|
3
|
-
|
|
4
|
-
/* -------------------------------------------------------------------------- */
|
|
5
|
-
/* Public API */
|
|
6
|
-
/* -------------------------------------------------------------------------- */
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the Block Factory framework.
|
|
10
|
-
*
|
|
11
|
-
* This **must be called exactly once** before using any backend systems
|
|
12
|
-
* such as threads, entity tasks, or event routing.
|
|
13
|
-
*
|
|
14
|
-
* @param packId - Unique identifier for the active pack instance.
|
|
15
|
-
*
|
|
16
|
-
* @throws Error if the framework has already been initialized.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* _INITIALIZE_BF_FRAMEWORK_("bf:utility_tools");
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function _INITIALIZE_BF_FRAMEWORK_(packId: string): void {
|
|
24
|
-
if (IS_INITIALIZED) throw Error(`CONFLICT WARNING: ${PACK_ID} already initialized.`);
|
|
25
|
-
PACK_ID = packId; IS_INITIALIZED = true;
|
|
26
|
-
console.log("Block Factory Framework Loaded");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/* -------------------------------------------------------------------------- */
|
|
30
|
-
/* Internal API */
|
|
31
|
-
/* -------------------------------------------------------------------------- */
|
|
32
|
-
|
|
33
|
-
export function getPackId(): string | undefined {
|
|
34
|
-
return PACK_ID;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function isInitalized(): boolean {
|
|
38
|
-
return IS_INITIALIZED;
|
|
39
|
-
}
|
package/_module/Types.ts
DELETED
package/_module/util/System.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export namespace System {
|
|
2
|
-
export const ProxyConstructor = ((_instance: any, source: any) => {
|
|
3
|
-
return new Proxy(_instance, {
|
|
4
|
-
get: (target, prop) => {
|
|
5
|
-
if (prop in target) return (target as any)[prop];
|
|
6
|
-
const v = (source as any)[prop];
|
|
7
|
-
return typeof v === "function" ? v.bind(source) : v;
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
set: (target, prop, value) => {
|
|
11
|
-
if (prop in target) { (target as any)[prop] = value; return true; }
|
|
12
|
-
(source as any)[prop] = value;
|
|
13
|
-
return true;
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
has: (target, prop) => prop in target || prop in source,
|
|
17
|
-
ownKeys: () => [...Reflect.ownKeys(source), ...Reflect.ownKeys(_instance)],
|
|
18
|
-
getOwnPropertyDescriptor: (_t, prop) => Object.getOwnPropertyDescriptor((prop in _instance ? _instance : source) as any, prop)
|
|
19
|
-
}) as any;
|
|
20
|
-
})
|
|
21
|
-
}
|