@block_factory/lib 0.0.3 → 0.0.5
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 +22 -0
- package/_module/Framework/EntityTasks.ts +203 -0
- package/_module/Framework/Threads.ts +72 -0
- package/_module/Framework/_INIT.ts +39 -0
- package/_module/Types.ts +10 -0
- package/_module/util/RawText.ts +75 -0
- package/{util → _module/util}/Signal.ts +4 -2
- package/{util → _module/util}/Wrapper/IEntity.ts +6 -5
- package/{util → _module/util}/Wrapper/IPlayer.ts +10 -4
- package/_types/_module/BlockFactory.d.ts +19 -0
- package/_types/_module/BlockFactory.d.ts.map +1 -0
- package/_types/_module/Framework/EntityTasks.d.ts +40 -0
- package/_types/_module/Framework/EntityTasks.d.ts.map +1 -0
- package/{sys → _types/_module/Framework}/Threads.d.ts +10 -4
- package/_types/_module/Framework/Threads.d.ts.map +1 -0
- package/_types/_module/Framework/_INIT.d.ts +19 -0
- package/_types/_module/Framework/_INIT.d.ts.map +1 -0
- package/_types/_module/Types.d.ts +10 -0
- package/_types/_module/Types.d.ts.map +1 -0
- package/_types/_module/util/Command.d.ts +92 -0
- package/_types/_module/util/Command.d.ts.map +1 -0
- package/{util → _types/_module/util}/Forms/Form.d.ts +12 -16
- package/_types/_module/util/Forms/Form.d.ts.map +1 -0
- package/_types/_module/util/Forms/FormAction.d.ts +73 -0
- package/_types/_module/util/Forms/FormAction.d.ts.map +1 -0
- package/{util → _types/_module/util}/Forms/FormMessage.d.ts +24 -30
- package/_types/_module/util/Forms/FormMessage.d.ts.map +1 -0
- package/{util → _types/_module/util}/Forms/FormModal.d.ts +66 -57
- package/_types/_module/util/Forms/FormModal.d.ts.map +1 -0
- package/_types/_module/util/Forms/FormRegistry.d.ts +12 -0
- package/_types/_module/util/Forms/FormRegistry.d.ts.map +1 -0
- package/{util → _types/_module/util}/Math.d.ts +8 -2
- package/_types/_module/util/Math.d.ts.map +1 -0
- package/_types/_module/util/RawText.d.ts +60 -0
- package/_types/_module/util/RawText.d.ts.map +1 -0
- package/{util → _types/_module/util}/Signal.d.ts +3 -5
- package/_types/_module/util/Signal.d.ts.map +1 -0
- package/_types/_module/util/System.d.ts.map +1 -0
- package/_types/_module/util/Vector.d.ts +212 -0
- package/_types/_module/util/Vector.d.ts.map +1 -0
- package/_types/_module/util/Wrapper/Container.d.ts.map +1 -0
- package/_types/_module/util/Wrapper/IEntity.d.ts +12 -0
- package/_types/_module/util/Wrapper/IEntity.d.ts.map +1 -0
- package/_types/_module/util/Wrapper/IPlayer.d.ts +13 -0
- package/_types/_module/util/Wrapper/IPlayer.d.ts.map +1 -0
- package/_types/index.d.ts +3 -0
- package/_types/index.d.ts.map +1 -0
- package/index.js +307 -366
- package/index.ts +2 -48
- package/package.json +34 -33
- package/tsconfig.types.json +2 -2
- package/index.d.ts +0 -47
- package/sys/Threads.ts +0 -43
- package/util/Command.d.ts +0 -23
- package/util/Forms/FormAction.d.ts +0 -41
- package/util/Forms/FormRegistry.d.ts +0 -26
- package/util/RawText.d.ts +0 -33
- package/util/RawText.ts +0 -76
- package/util/Vector.d.ts +0 -60
- package/util/Wrapper/IEntity.d.ts +0 -12
- package/util/Wrapper/IPlayer.d.ts +0 -12
- /package/{util → _module/util}/Command.ts +0 -0
- /package/{util → _module/util}/Forms/Form.ts +0 -0
- /package/{util → _module/util}/Forms/FormAction.ts +0 -0
- /package/{util → _module/util}/Forms/FormMessage.ts +0 -0
- /package/{util → _module/util}/Forms/FormModal.ts +0 -0
- /package/{util → _module/util}/Forms/FormRegistry.ts +0 -0
- /package/{util → _module/util}/Math.ts +0 -0
- /package/{util → _module/util}/System.ts +0 -0
- /package/{util → _module/util}/Vector.ts +0 -0
- /package/{util → _module/util}/Wrapper/Container.ts +0 -0
- /package/{util → _types/_module/util}/System.d.ts +0 -0
- /package/{util → _types/_module/util}/Wrapper/Container.d.ts +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { _INITIALIZE_BF_FRAMEWORK_ } from "@block_factory/lib/_module/Framework/_INIT";
|
|
2
|
+
|
|
3
|
+
export { MathUtils } from "./util/Math";
|
|
4
|
+
export { Signal } from "./util/Signal";
|
|
5
|
+
export { Vec2, Vec3 } from "./util/Vector";
|
|
6
|
+
export { RawText } from "./util/RawText";
|
|
7
|
+
export { Command } from "./util/Command";
|
|
8
|
+
export { System } from "./util/System";
|
|
9
|
+
|
|
10
|
+
export { IForm, IFormValue } from "./util/Forms/Form";
|
|
11
|
+
export { ActionFormCtor, type IButtonOptions, type IActionFormResponse, type IActionFormData } from "./util/Forms/FormAction";
|
|
12
|
+
export { type IModalFormResponse, type ITextFieldOptions, type IDropdownOptions, type ISliderOptions, type IToggleOptions, type IModalFormData } from "./util/Forms/FormModal";
|
|
13
|
+
export { type IMessageFormData, type IMessageFormResponse } from "./util/Forms/FormMessage";
|
|
14
|
+
export { type IFormRegistration, RegisterForm } from "./util/Forms/FormRegistry";
|
|
15
|
+
|
|
16
|
+
export { Inventory, ContainerWrapper } from "./util/Wrapper/Container";
|
|
17
|
+
export { type IEntity, IEntityWrapper } from "./util/Wrapper/IEntity";
|
|
18
|
+
export { type IPlayer, IPlayerWrapper } from "./util/Wrapper/IPlayer";
|
|
19
|
+
|
|
20
|
+
export { type Sound, type Animation } from "./Types";
|
|
21
|
+
export { _THREAD_ } from "@block_factory/lib/_module/Framework/Threads";
|
|
22
|
+
export { _EntityHandler_, type EntityEmissionEvent, onEntityEmission } from "@block_factory/lib/_module/Framework/EntityTasks";
|
|
@@ -0,0 +1,203 @@
|
|
|
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();
|
|
@@ -0,0 +1,72 @@
|
|
|
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();
|
|
@@ -0,0 +1,39 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { RawMessage } from '@minecraft/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Utility helpers for building rawtext messages.
|
|
5
|
+
*/
|
|
6
|
+
export class RawText {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a simple text component.
|
|
9
|
+
* @param value - The text value.
|
|
10
|
+
* @returns Text component object.
|
|
11
|
+
*/
|
|
12
|
+
public static text(value: string): RawMessage {
|
|
13
|
+
return { text: value };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a translation component with optional 'with' parameters.
|
|
18
|
+
* @param key - The translation key.
|
|
19
|
+
* @param params - The optional parameters for translation.
|
|
20
|
+
* @returns Translation component object.
|
|
21
|
+
*/
|
|
22
|
+
public static translate(key: string, ...params: string[]): RawMessage {
|
|
23
|
+
return {
|
|
24
|
+
translate: key,
|
|
25
|
+
with: params.length ? params : undefined
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a score component.
|
|
31
|
+
* @param name - The entity's name whose score is being displayed.
|
|
32
|
+
* @param objective - The name of the score objective.
|
|
33
|
+
* @returns Score component object.
|
|
34
|
+
*/
|
|
35
|
+
public static score(name: string, objective: string): RawMessage {
|
|
36
|
+
return { score: { name, objective } };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Wraps various text components into a rawtext structure.
|
|
41
|
+
* @param rawText - The raw text components.
|
|
42
|
+
* @returns Raw text object.
|
|
43
|
+
*/
|
|
44
|
+
public static message(...rawText: RawMessage[]): RawMessage {
|
|
45
|
+
return { rawtext: rawText };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Common formatting and color codes.
|
|
50
|
+
*/
|
|
51
|
+
public static FORMAT = {
|
|
52
|
+
DarkRed: "§4",
|
|
53
|
+
Red: "§c",
|
|
54
|
+
Gold: "§6",
|
|
55
|
+
Yellow: "§e",
|
|
56
|
+
Green: "§2",
|
|
57
|
+
Lime: "§a",
|
|
58
|
+
Aqua: "§b",
|
|
59
|
+
Cyan: "§3",
|
|
60
|
+
DarkBlue: "§1",
|
|
61
|
+
Blue: "§9",
|
|
62
|
+
Magenta: "§d",
|
|
63
|
+
Purple: "§5",
|
|
64
|
+
White: "§f",
|
|
65
|
+
Gray: "§7",
|
|
66
|
+
DarkGray: "§8",
|
|
67
|
+
Black: "§0",
|
|
68
|
+
Obfuscated: "§k",
|
|
69
|
+
Bold: "§l",
|
|
70
|
+
StrikeThrough: "§m",
|
|
71
|
+
Italic: "§o",
|
|
72
|
+
Reset: "§r",
|
|
73
|
+
NewLine: "\n"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -24,8 +24,10 @@ export class Signal<T = void> {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public emit(data: T): void {
|
|
27
|
-
for (const
|
|
28
|
-
|
|
27
|
+
for (const callback of Array.from(this.listeners)) {
|
|
28
|
+
try { callback(data) } catch (err) {
|
|
29
|
+
console.error("BFLIB: Signal listener error:", err);
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Entity, EntityInventoryComponent } from "@minecraft/server";
|
|
1
|
+
import { Entity, EntityInventoryComponent, PlayAnimationOptions, system, TicksPerSecond } from "@minecraft/server";
|
|
2
2
|
import { ContainerWrapper, Inventory } from "./Container";
|
|
3
3
|
import { System } from "../System";
|
|
4
|
+
import { Animation } from "../../Types";
|
|
4
5
|
|
|
5
6
|
export type IEntity = IEntityWrapper & Entity;
|
|
6
7
|
|
|
@@ -17,9 +18,8 @@ export class IEntityWrapper {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
//======================== Interal ========================
|
|
20
|
-
public isAlive: boolean = false;
|
|
21
21
|
|
|
22
|
-
public get inventory(): Inventory {
|
|
22
|
+
public get inventory(): Inventory | undefined {
|
|
23
23
|
const i = this.source.getComponent(
|
|
24
24
|
EntityInventoryComponent.componentId
|
|
25
25
|
) as EntityInventoryComponent;
|
|
@@ -27,8 +27,9 @@ export class IEntityWrapper {
|
|
|
27
27
|
return ContainerWrapper.wrap(i.container);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public
|
|
31
|
-
|
|
30
|
+
public async playAnimationAsync(animation: Animation, options: PlayAnimationOptions): Promise<void> {
|
|
31
|
+
this.source.playAnimation(animation.id, options);
|
|
32
|
+
await system.waitTicks(animation.length * TicksPerSecond);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { EntityInventoryComponent, Player } from "@minecraft/server";
|
|
1
|
+
import { EntityInventoryComponent, PlayAnimationOptions, Player, PlayerSoundOptions, system, TicksPerSecond } from "@minecraft/server";
|
|
2
2
|
import { ContainerWrapper, Inventory } from "./Container";
|
|
3
3
|
import { System } from "../System";
|
|
4
|
+
import { Animation, Sound } from "../../Types";
|
|
4
5
|
|
|
5
6
|
export type IPlayer = IPlayerWrapper & Player;
|
|
6
7
|
|
|
@@ -17,7 +18,6 @@ export class IPlayerWrapper {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
//======================== Interal ========================
|
|
20
|
-
public isAlive: boolean = false;
|
|
21
21
|
|
|
22
22
|
public get inventory(): Inventory {
|
|
23
23
|
const i = this.source.getComponent(
|
|
@@ -27,8 +27,14 @@ export class IPlayerWrapper {
|
|
|
27
27
|
return ContainerWrapper.wrap(i.container);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public
|
|
31
|
-
this.source.
|
|
30
|
+
public async playSoundAsync(sound:Sound, options: PlayerSoundOptions): Promise<void>{
|
|
31
|
+
this.source.playSound(sound.id, options);
|
|
32
|
+
await system.waitTicks(sound.length * TicksPerSecond);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async playAnimationAsync(animation: Animation, options: PlayAnimationOptions): Promise<void> {
|
|
36
|
+
this.source.playAnimation(animation.id, options);
|
|
37
|
+
await system.waitTicks(animation.length * TicksPerSecond);
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { _INITIALIZE_BF_FRAMEWORK_ } from "@block_factory/lib/_module/Framework/_INIT";
|
|
2
|
+
export { MathUtils } from "./util/Math";
|
|
3
|
+
export { Signal } from "./util/Signal";
|
|
4
|
+
export { Vec2, Vec3 } from "./util/Vector";
|
|
5
|
+
export { RawText } from "./util/RawText";
|
|
6
|
+
export { Command } from "./util/Command";
|
|
7
|
+
export { System } from "./util/System";
|
|
8
|
+
export { IForm, IFormValue } from "./util/Forms/Form";
|
|
9
|
+
export { ActionFormCtor, type IButtonOptions, type IActionFormResponse, type IActionFormData } from "./util/Forms/FormAction";
|
|
10
|
+
export { type IModalFormResponse, type ITextFieldOptions, type IDropdownOptions, type ISliderOptions, type IToggleOptions, type IModalFormData } from "./util/Forms/FormModal";
|
|
11
|
+
export { type IMessageFormData, type IMessageFormResponse } from "./util/Forms/FormMessage";
|
|
12
|
+
export { type IFormRegistration, RegisterForm } from "./util/Forms/FormRegistry";
|
|
13
|
+
export { Inventory, ContainerWrapper } from "./util/Wrapper/Container";
|
|
14
|
+
export { type IEntity, IEntityWrapper } from "./util/Wrapper/IEntity";
|
|
15
|
+
export { type IPlayer, IPlayerWrapper } from "./util/Wrapper/IPlayer";
|
|
16
|
+
export { type Sound, type Animation } from "./Types";
|
|
17
|
+
export { _THREAD_ } from "@block_factory/lib/_module/Framework/Threads";
|
|
18
|
+
export { _EntityHandler_, type EntityEmissionEvent, onEntityEmission } from "@block_factory/lib/_module/Framework/EntityTasks";
|
|
19
|
+
//# sourceMappingURL=BlockFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockFactory.d.ts","sourceRoot":"","sources":["../../_module/BlockFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC9H,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC/K,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,KAAK,iBAAiB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEjF,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,KAAK,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,KAAK,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,8CAA8C,CAAC;AACxE,OAAO,EAAE,eAAe,EAAG,KAAK,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Entity } from "@minecraft/server";
|
|
2
|
+
import { Signal } from "../util/Signal";
|
|
3
|
+
import { IEntity } from "../util/Wrapper/IEntity";
|
|
4
|
+
export type EntityEmissionEvent = {
|
|
5
|
+
iEntity: IEntity;
|
|
6
|
+
parms: any;
|
|
7
|
+
};
|
|
8
|
+
export declare const onEntityEmission: Signal<EntityEmissionEvent>;
|
|
9
|
+
declare class EntityHandler {
|
|
10
|
+
private PACK_ID;
|
|
11
|
+
private GLOBAL_MEMORY_ID;
|
|
12
|
+
private readonly scriptEventSignal;
|
|
13
|
+
private readonly loadEventSignal;
|
|
14
|
+
private readonly spawnEventSignal;
|
|
15
|
+
private readonly removeAfterEventSignal;
|
|
16
|
+
private readonly removeBeforeEventSignal;
|
|
17
|
+
private readonly EM_INDEX;
|
|
18
|
+
private readonly EM_KEYS;
|
|
19
|
+
private readonly SEARCH_TYPES;
|
|
20
|
+
private _started;
|
|
21
|
+
private _wired;
|
|
22
|
+
configure(): void;
|
|
23
|
+
registerEntity(typeId: string | string[]): void;
|
|
24
|
+
start(): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
private onWorldLoad;
|
|
27
|
+
private processScriptEvents;
|
|
28
|
+
private isValidType;
|
|
29
|
+
private onEntitySpawned;
|
|
30
|
+
private onEntityRemovedBefore;
|
|
31
|
+
private onEntityRemovedAfter;
|
|
32
|
+
private reloadEntityMemory;
|
|
33
|
+
private persistKeys;
|
|
34
|
+
saveEntityInMemory(entity: Entity): boolean;
|
|
35
|
+
deleteEntityInMemory(entity: Entity): boolean;
|
|
36
|
+
getEntitiesInMemory(): Entity[];
|
|
37
|
+
}
|
|
38
|
+
export declare const _EntityHandler_: EntityHandler;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=EntityTasks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityTasks.d.ts","sourceRoot":"","sources":["../../../_module/Framework/EntityTasks.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EAaT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAkB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAOlE,MAAM,MAAM,mBAAmB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,gBAAgB,6BAAoC,CAAC;AAQlE,cAAM,aAAa;IACf,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,gBAAgB,CAAoB;IAE5C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoF;IACtH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA0D;IAC1F,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8D;IAC/F,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAgE;IACvG,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAkE;IAE1G,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAElD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAS;IAEhB,SAAS,IAAI,IAAI;IAIjB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAK/C,KAAK,IAAI,IAAI;IAWb,IAAI,IAAI,IAAI;IAmBnB,OAAO,CAAC,WAAW,CAcjB;IAEF,OAAO,CAAC,mBAAmB,CAgBzB;IAMF,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,eAAe,CAIrB;IAEF,OAAO,CAAC,qBAAqB,CAI3B;IAEF,OAAO,CAAC,oBAAoB,CAE1B;IAMF,OAAO,CAAC,kBAAkB;IAsB1B,OAAO,CAAC,WAAW;IAIZ,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAU3C,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAY7C,mBAAmB,IAAI,MAAM,EAAE;CAGzC;AAED,eAAO,MAAM,eAAe,eAAsB,CAAC"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { Signal } from "../util/Signal";
|
|
2
|
+
export type ThreadConfig = {
|
|
3
|
+
mainRate?: number;
|
|
4
|
+
lateRate?: number;
|
|
5
|
+
};
|
|
2
6
|
declare class Threads {
|
|
3
|
-
static create(): Threads;
|
|
4
7
|
readonly MAIN: Signal<number>;
|
|
5
8
|
readonly LATE: Signal<void>;
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
private _mainRate;
|
|
10
|
+
private _lateRate;
|
|
8
11
|
private _MAIN_ID;
|
|
9
12
|
private _LATE_ID;
|
|
10
13
|
private _delta;
|
|
11
|
-
private
|
|
14
|
+
private _started;
|
|
15
|
+
configure(cfg: ThreadConfig): void;
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
12
18
|
private createDeltaTimer;
|
|
13
19
|
}
|
|
14
20
|
export declare const _THREAD_: Threads;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Threads.d.ts","sourceRoot":"","sources":["../../../_module/Framework/Threads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,MAAM,MAAM,YAAY,GAAG;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,cAAM,OAAO;IACT,SAAgB,IAAI,iBAAwB;IAC5C,SAAgB,IAAI,eAAsB;IAE1C,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,SAAS,CAAkB;IAEnC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,QAAQ,CAAqB;IAErC,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,QAAQ,CAAS;IAElB,SAAS,CAAC,GAAG,EAAE,YAAY;IAM3B,KAAK;IAwBL,IAAI;IASX,OAAO,CAAC,gBAAgB;CAS3B;AAED,eAAO,MAAM,QAAQ,SAAgB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initializes the Block Factory framework.
|
|
3
|
+
*
|
|
4
|
+
* This **must be called exactly once** before using any backend systems
|
|
5
|
+
* such as threads, entity tasks, or event routing.
|
|
6
|
+
*
|
|
7
|
+
* @param packId - Unique identifier for the active pack instance.
|
|
8
|
+
*
|
|
9
|
+
* @throws Error if the framework has already been initialized.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* _INITIALIZE_BF_FRAMEWORK_("bf:utility_tools");
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function _INITIALIZE_BF_FRAMEWORK_(packId: string): void;
|
|
17
|
+
export declare function getPackId(): string | undefined;
|
|
18
|
+
export declare function isInitalized(): boolean;
|
|
19
|
+
//# sourceMappingURL=_INIT.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_INIT.d.ts","sourceRoot":"","sources":["../../../_module/Framework/_INIT.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAI9D;AAMD,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C;AAED,wBAAgB,YAAY,IAAI,OAAO,CAEtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../_module/Types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB,CAAA"}
|