@starktma/minecraft-utils 1.5.36 → 1.5.38

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.
Files changed (36) hide show
  1. package/dist/entity-system/EntityAttributeDatabase.d.ts +19 -0
  2. package/dist/entity-system/EntityAttributeDatabase.d.ts.map +1 -0
  3. package/dist/entity-system/EntityAttributeDatabase.js +31 -0
  4. package/dist/entity-system/EntityAttributeDatabase.js.map +1 -0
  5. package/dist/entity-system/EntityManager.d.ts +35 -0
  6. package/dist/entity-system/EntityManager.d.ts.map +1 -0
  7. package/dist/entity-system/EntityManager.js +96 -0
  8. package/dist/entity-system/EntityManager.js.map +1 -0
  9. package/dist/entity-system/EntityWrapper.d.ts +69 -0
  10. package/dist/entity-system/EntityWrapper.d.ts.map +1 -0
  11. package/dist/entity-system/EntityWrapper.js +252 -0
  12. package/dist/entity-system/EntityWrapper.js.map +1 -0
  13. package/dist/entity-system/EventGroup.d.ts +31 -0
  14. package/dist/entity-system/EventGroup.d.ts.map +1 -0
  15. package/dist/entity-system/EventGroup.js +75 -0
  16. package/dist/entity-system/EventGroup.js.map +1 -0
  17. package/dist/entity-system/PlayerManager.d.ts +17 -0
  18. package/dist/entity-system/PlayerManager.d.ts.map +1 -0
  19. package/dist/entity-system/PlayerManager.js +42 -0
  20. package/dist/entity-system/PlayerManager.js.map +1 -0
  21. package/dist/entity-system/PlayerWrapper.d.ts +46 -0
  22. package/dist/entity-system/PlayerWrapper.d.ts.map +1 -0
  23. package/dist/entity-system/PlayerWrapper.js +134 -0
  24. package/dist/entity-system/PlayerWrapper.js.map +1 -0
  25. package/dist/entity-system/index.d.ts +7 -0
  26. package/dist/entity-system/index.d.ts.map +1 -0
  27. package/dist/entity-system/index.js +7 -0
  28. package/dist/entity-system/index.js.map +1 -0
  29. package/dist/math/BFSScanner.d.ts.map +1 -1
  30. package/dist/math/BFSScanner.js +43 -4
  31. package/dist/math/BFSScanner.js.map +1 -1
  32. package/package.json +4 -4
  33. package/dist/player-event/index.d.ts +0 -52
  34. package/dist/player-event/index.d.ts.map +0 -1
  35. package/dist/player-event/index.js +0 -163
  36. package/dist/player-event/index.js.map +0 -1
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file EntityAttributeDatabase.ts
3
+ * @description Persistent entity attribute database child class extending SimpleDatabase.
4
+ */
5
+ import { Entity } from "@minecraft/server";
6
+ import { SimpleDatabase, SimpleObject } from "../database";
7
+ export interface AttributeEntry extends SimpleObject {
8
+ id: string;
9
+ value: any;
10
+ }
11
+ export declare class EntityAttributeDatabase extends SimpleDatabase<AttributeEntry> {
12
+ constructor(targetEntity: Entity);
13
+ setAttribute(key: string, value: any): void;
14
+ getAttribute<T = any>(key: string): T | undefined;
15
+ hasAttribute(key: string): boolean;
16
+ removeAttribute(key: string): void;
17
+ getAllAttributes(): Record<string, any>;
18
+ }
19
+ //# sourceMappingURL=EntityAttributeDatabase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityAttributeDatabase.d.ts","sourceRoot":"","sources":["../../src/entity-system/EntityAttributeDatabase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3D,MAAM,WAAW,cAAe,SAAQ,YAAY;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,GAAG,CAAC;CACX;AAED,qBAAa,uBAAwB,SAAQ,cAAc,CAAC,cAAc,CAAC;gBAC9D,YAAY,EAAE,MAAM;IAIhC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAI3C,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAKjD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIlC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIlC,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAOvC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file EntityAttributeDatabase.ts
3
+ * @description Persistent entity attribute database child class extending SimpleDatabase.
4
+ */
5
+ import { SimpleDatabase } from "../database";
6
+ export class EntityAttributeDatabase extends SimpleDatabase {
7
+ constructor(targetEntity) {
8
+ super("entity_attributes", targetEntity, 1, 20 * 5);
9
+ }
10
+ setAttribute(key, value) {
11
+ this.updateObject({ id: key, value });
12
+ }
13
+ getAttribute(key) {
14
+ const entry = this.getObject(key);
15
+ return entry ? entry.value : undefined;
16
+ }
17
+ hasAttribute(key) {
18
+ return this.hasObject(key);
19
+ }
20
+ removeAttribute(key) {
21
+ this.removeObject(key);
22
+ }
23
+ getAllAttributes() {
24
+ const result = {};
25
+ for (const entry of this.getAllObjects()) {
26
+ result[entry.id] = entry.value;
27
+ }
28
+ return result;
29
+ }
30
+ }
31
+ //# sourceMappingURL=EntityAttributeDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityAttributeDatabase.js","sourceRoot":"","sources":["../../src/entity-system/EntityAttributeDatabase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AAO3D,MAAM,OAAO,uBAAwB,SAAQ,cAA8B;IAC1E,YAAY,YAAoB;QAC/B,KAAK,CAAC,mBAAmB,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,YAAY,CAAC,GAAW,EAAE,KAAU;QACnC,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,YAAY,CAAU,GAAW;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAClC,OAAO,KAAK,CAAC,CAAC,CAAE,KAAK,CAAC,KAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;IAED,YAAY,CAAC,GAAW;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,eAAe,CAAC,GAAW;QAC1B,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,gBAAgB;QACf,MAAM,MAAM,GAAwB,EAAE,CAAC;QACvC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;YAC1C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QAChC,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @file EntityManager.ts
3
+ * @description Abstract manager class managing collections of `EntityWrapper` instances.
4
+ * Dispatches entity and manager lifecycle events across all registered `EventGroup` instances.
5
+ */
6
+ import { Entity } from "@minecraft/server";
7
+ import { EntityWrapper } from "./EntityWrapper";
8
+ import { EventGroup } from "./EventGroup";
9
+ export declare abstract class EntityManager<T extends EntityWrapper = EntityWrapper> {
10
+ private entities;
11
+ private events;
12
+ protected constructor(tickInterval?: number);
13
+ /** Factory method creating specialized wrapper subclass instance */
14
+ protected abstract createEntityWrapper(entity: Entity): T;
15
+ /** Predicate determining whether an entity should be managed by this manager */
16
+ protected shouldManageEntity(entity: Entity): boolean;
17
+ getAllEntities(): T[];
18
+ getEntity(id: string): T | undefined;
19
+ addEntity(entity: Entity): T | undefined;
20
+ removeEntity(id: string): void;
21
+ /**
22
+ * Dispatches an event across all registered EventGroup instances.
23
+ */
24
+ triggerEntityEvent(eventType: string, target: any, ...args: any[]): void;
25
+ /**
26
+ * Registers or retrieves a named EventGroup for event dispatches.
27
+ */
28
+ registerEvents(eventID: string): {
29
+ event: EventGroup<T>;
30
+ };
31
+ getEvents(eventID: string): EventGroup<T> | undefined;
32
+ tick(): void;
33
+ protected onWorldLoad(): void;
34
+ }
35
+ //# sourceMappingURL=EntityManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../src/entity-system/EntityManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAgB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,8BAAsB,aAAa,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa;IAC1E,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,MAAM,CAAoC;IAElD,SAAS,aAAa,YAAY,GAAE,MAAU;IAoB9C,oEAAoE;IACpE,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC;IAEzD,gFAAgF;IAChF,SAAS,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIrD,cAAc,IAAI,CAAC,EAAE;IAIrB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIpC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAcxC,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAS9B;;OAEG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAMxE;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;KAAE;IASzD,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS;IAIrD,IAAI,IAAI,IAAI;IAkBZ,SAAS,CAAC,WAAW,IAAI,IAAI;CAC7B"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @file EntityManager.ts
3
+ * @description Abstract manager class managing collections of `EntityWrapper` instances.
4
+ * Dispatches entity and manager lifecycle events across all registered `EventGroup` instances.
5
+ */
6
+ import { system, world } from "@minecraft/server";
7
+ import { EntityEvents } from "./EntityWrapper";
8
+ import { EventGroup } from "./EventGroup";
9
+ export class EntityManager {
10
+ entities = new Map();
11
+ events = new Map();
12
+ constructor(tickInterval = 1) {
13
+ world.afterEvents.entitySpawn.subscribe(({ entity }) => {
14
+ if (this.shouldManageEntity(entity)) {
15
+ this.addEntity(entity);
16
+ }
17
+ });
18
+ world.afterEvents.entityRemove.subscribe(({ removedEntityId }) => {
19
+ this.removeEntity(removedEntityId);
20
+ });
21
+ world.afterEvents.worldLoad.subscribe(() => {
22
+ this.onWorldLoad();
23
+ this.triggerEntityEvent(EntityEvents.WorldLoad, this);
24
+ system.runInterval(() => {
25
+ this.tick();
26
+ }, tickInterval);
27
+ });
28
+ }
29
+ /** Predicate determining whether an entity should be managed by this manager */
30
+ shouldManageEntity(entity) {
31
+ return !!(entity && entity.isValid);
32
+ }
33
+ getAllEntities() {
34
+ return Array.from(this.entities.values());
35
+ }
36
+ getEntity(id) {
37
+ return this.entities.get(id);
38
+ }
39
+ addEntity(entity) {
40
+ if (this.entities.has(entity.id)) {
41
+ return this.entities.get(entity.id);
42
+ }
43
+ const wrapper = this.createEntityWrapper(entity);
44
+ wrapper.manager = this;
45
+ this.entities.set(entity.id, wrapper);
46
+ this.triggerEntityEvent(EntityEvents.EntityAdded, wrapper);
47
+ this.triggerEntityEvent(EntityEvents.Spawn, wrapper);
48
+ return wrapper;
49
+ }
50
+ removeEntity(id) {
51
+ const wrapper = this.entities.get(id);
52
+ if (wrapper) {
53
+ this.triggerEntityEvent(EntityEvents.EntityRemoved, wrapper);
54
+ this.triggerEntityEvent(EntityEvents.Despawn, wrapper);
55
+ this.entities.delete(id);
56
+ }
57
+ }
58
+ /**
59
+ * Dispatches an event across all registered EventGroup instances.
60
+ */
61
+ triggerEntityEvent(eventType, target, ...args) {
62
+ this.events.forEach((eventGroup) => {
63
+ eventGroup.trigger(eventType, target, ...args);
64
+ });
65
+ }
66
+ /**
67
+ * Registers or retrieves a named EventGroup for event dispatches.
68
+ */
69
+ registerEvents(eventID) {
70
+ let eventGroup = this.events.get(eventID);
71
+ if (!eventGroup) {
72
+ eventGroup = new EventGroup(Object.values(EntityEvents));
73
+ this.events.set(eventID, eventGroup);
74
+ }
75
+ return { event: eventGroup };
76
+ }
77
+ getEvents(eventID) {
78
+ return this.events.get(eventID);
79
+ }
80
+ tick() {
81
+ this.triggerEntityEvent(EntityEvents.PreTick, this);
82
+ const all = this.getAllEntities();
83
+ for (const wrapper of all) {
84
+ if (!wrapper.isValid) {
85
+ this.removeEntity(wrapper.id);
86
+ continue;
87
+ }
88
+ wrapper.tick();
89
+ this.triggerEntityEvent(EntityEvents.Tick, wrapper);
90
+ }
91
+ this.triggerEntityEvent(EntityEvents.PostTick, this);
92
+ }
93
+ // Optional Hook Method for Subclasses
94
+ onWorldLoad() { }
95
+ }
96
+ //# sourceMappingURL=EntityManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityManager.js","sourceRoot":"","sources":["../../src/entity-system/EntityManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAiB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,OAAgB,aAAa;IAC1B,QAAQ,GAAG,IAAI,GAAG,EAAa,CAAC;IAChC,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAElD,YAAsB,eAAuB,CAAC;QAC7C,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,CA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MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;IAC9B,CAAC;IAED,SAAS,CAAC,OAAe;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,IAAI;QACH,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,OAAO,EAAE,IAAW,CAAC,CAAC;QAE3D,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAClC,KAAK,MAAM,OAAO,IAAI,GAAG,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACtB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBAC9B,SAAS;YACV,CAAC;YAED,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAW,CAAC,CAAC;IAC7D,CAAC;IAED,sCAAsC;IAC5B,WAAW,KAAU,CAAC;CAChC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @file EntityWrapper.ts
3
+ * @description Generic base wrapper class encapsulating native Bedrock `@minecraft/server` Entity instances.
4
+ * Provides property helpers, component accessors, tag events, effect delegations, damage routing,
5
+ * and attributes backed by EntityAttributeDatabase.
6
+ */
7
+ import { Entity, EntityHealthComponent, EntityInventoryComponent, EntityEquippableComponent, Vector3, Dimension, EntityDamageCause, Effect, EffectType } from "@minecraft/server";
8
+ import type { EntityManager } from "./EntityManager";
9
+ export declare enum EntityEvents {
10
+ WorldLoad = "worldLoad",
11
+ PreTick = "preTick",
12
+ PostTick = "postTick",
13
+ EntityAdded = "entityAdded",
14
+ EntityRemoved = "entityRemoved",
15
+ Spawn = "spawn",
16
+ Despawn = "despawn",
17
+ Tick = "tick",
18
+ Hurt = "hurt",
19
+ Heal = "heal",
20
+ Dying = "dying",
21
+ Death = "death",
22
+ TagAdded = "tagAdded",
23
+ TagRemoved = "tagRemoved",
24
+ ScriptEvent = "scriptEvent"
25
+ }
26
+ export declare class EntityWrapper<E extends Entity = Entity> {
27
+ readonly entity: E;
28
+ stateTick: number;
29
+ manager?: EntityManager<any>;
30
+ private attributeDB?;
31
+ constructor(entity: E, manager?: EntityManager<any>);
32
+ private get db();
33
+ get id(): string;
34
+ get typeId(): string;
35
+ get isValid(): boolean;
36
+ get location(): Vector3;
37
+ get dimension(): Dimension;
38
+ get rotation(): import("@minecraft/server").Vector2;
39
+ get healthComponent(): EntityHealthComponent | undefined;
40
+ get inventoryComponent(): EntityInventoryComponent | undefined;
41
+ get equippableComponent(): EntityEquippableComponent | undefined;
42
+ getComponent<T>(componentId: string): T | undefined;
43
+ hasComponent(componentId: string): boolean;
44
+ getProperty<T = any>(propertyName: string): T | undefined;
45
+ setProperty<T = any>(propertyName: string, value: T): void;
46
+ getDynamicProperty<T = any>(propertyName: string): T | undefined;
47
+ setDynamicProperty<T = any>(propertyName: string, value: T): void;
48
+ getCustomProperty<T = any>(propertyName: string): T | undefined;
49
+ setCustomProperty<T = any>(propertyName: string, value: T): void;
50
+ hasTag(tag: string): boolean;
51
+ addTag(tag: string): boolean;
52
+ removeTag(tag: string): boolean;
53
+ getTags(): string[];
54
+ get health(): number;
55
+ set health(value: number);
56
+ get maxHealth(): number;
57
+ applyDamage(damageAmount: number, source?: Entity, cause?: EntityDamageCause | string): void;
58
+ heal(healAmount: number, source?: Entity): void;
59
+ addEffect(effectType: EffectType | string, duration: number, options?: any): Effect | undefined;
60
+ removeEffect(effectType: EffectType | string): boolean;
61
+ getEffect(effectType: EffectType | string): Effect | undefined;
62
+ setAttribute<T = any>(key: string, value: T): void;
63
+ getAttribute<T = any>(key: string): T | undefined;
64
+ hasAttribute(key: string): boolean;
65
+ removeAttribute(key: string): boolean;
66
+ getAllAttributes(): Record<string, any>;
67
+ tick(): void;
68
+ }
69
+ //# sourceMappingURL=EntityWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityWrapper.d.ts","sourceRoot":"","sources":["../../src/entity-system/EntityWrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,MAAM,EACN,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,OAAO,EACP,SAAS,EACT,iBAAiB,EACjB,MAAM,EACN,UAAU,EACV,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,oBAAY,YAAY;IACvB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,aAAa,kBAAkB;IAC/B,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,WAAW,gBAAgB;CAC3B;AAED,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACnD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnB,SAAS,SAAK;IACd,OAAO,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAE7B,OAAO,CAAC,WAAW,CAAC,CAA0B;gBAElC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC;IAKnD,OAAO,KAAK,EAAE,GAKb;IAKD,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,SAAS,IAAI,SAA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AM,EACf,KAAK,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAChC,IAAI;IAwBP,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAa/C,SAAS,CACR,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,GAAG,GACX,MAAM,GAAG,SAAS;IAKrB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO;IAKtD,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAQ9D,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAKlD,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAKjD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKlC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IASrC,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAQvC,IAAI,IAAI,IAAI;CAIZ"}
@@ -0,0 +1,252 @@
1
+ /**
2
+ * @file EntityWrapper.ts
3
+ * @description Generic base wrapper class encapsulating native Bedrock `@minecraft/server` Entity instances.
4
+ * Provides property helpers, component accessors, tag events, effect delegations, damage routing,
5
+ * and attributes backed by EntityAttributeDatabase.
6
+ */
7
+ import { EntityHealthComponent, EntityInventoryComponent, EntityEquippableComponent, } from "@minecraft/server";
8
+ import { getNamespace } from "../constants";
9
+ import { EntityAttributeDatabase } from "./EntityAttributeDatabase";
10
+ export var EntityEvents;
11
+ (function (EntityEvents) {
12
+ EntityEvents["WorldLoad"] = "worldLoad";
13
+ EntityEvents["PreTick"] = "preTick";
14
+ EntityEvents["PostTick"] = "postTick";
15
+ EntityEvents["EntityAdded"] = "entityAdded";
16
+ EntityEvents["EntityRemoved"] = "entityRemoved";
17
+ EntityEvents["Spawn"] = "spawn";
18
+ EntityEvents["Despawn"] = "despawn";
19
+ EntityEvents["Tick"] = "tick";
20
+ EntityEvents["Hurt"] = "hurt";
21
+ EntityEvents["Heal"] = "heal";
22
+ EntityEvents["Dying"] = "dying";
23
+ EntityEvents["Death"] = "death";
24
+ EntityEvents["TagAdded"] = "tagAdded";
25
+ EntityEvents["TagRemoved"] = "tagRemoved";
26
+ EntityEvents["ScriptEvent"] = "scriptEvent";
27
+ })(EntityEvents || (EntityEvents = {}));
28
+ export class EntityWrapper {
29
+ entity;
30
+ stateTick = 0;
31
+ manager;
32
+ attributeDB;
33
+ constructor(entity, manager) {
34
+ this.entity = entity;
35
+ this.manager = manager;
36
+ }
37
+ get db() {
38
+ if (!this.attributeDB) {
39
+ this.attributeDB = new EntityAttributeDatabase(this.entity);
40
+ }
41
+ return this.attributeDB;
42
+ }
43
+ // -------------------------------------------------------------------------
44
+ // Core Delegated Properties
45
+ // -------------------------------------------------------------------------
46
+ get id() {
47
+ return this.entity.id;
48
+ }
49
+ get typeId() {
50
+ return this.entity.typeId;
51
+ }
52
+ get isValid() {
53
+ return !!(this.entity && this.entity.isValid);
54
+ }
55
+ get location() {
56
+ return this.entity.location;
57
+ }
58
+ get dimension() {
59
+ return this.entity.dimension;
60
+ }
61
+ get rotation() {
62
+ return this.entity.getRotation();
63
+ }
64
+ // -------------------------------------------------------------------------
65
+ // Component Accessors
66
+ // -------------------------------------------------------------------------
67
+ get healthComponent() {
68
+ return this.entity.getComponent(EntityHealthComponent.componentId);
69
+ }
70
+ get inventoryComponent() {
71
+ return this.entity.getComponent(EntityInventoryComponent.componentId);
72
+ }
73
+ get equippableComponent() {
74
+ return this.entity.getComponent(EntityEquippableComponent.componentId);
75
+ }
76
+ getComponent(componentId) {
77
+ return this.entity.getComponent(componentId);
78
+ }
79
+ hasComponent(componentId) {
80
+ return this.entity.hasComponent(componentId);
81
+ }
82
+ // -------------------------------------------------------------------------
83
+ // Dynamic & Namespaced Property Helpers
84
+ // -------------------------------------------------------------------------
85
+ getProperty(propertyName) {
86
+ if (!this.isValid)
87
+ return undefined;
88
+ return this.entity.getProperty(propertyName);
89
+ }
90
+ setProperty(propertyName, value) {
91
+ if (!this.isValid)
92
+ return;
93
+ this.entity.setProperty(propertyName, value);
94
+ }
95
+ getDynamicProperty(propertyName) {
96
+ if (!this.isValid)
97
+ return undefined;
98
+ return this.entity.getDynamicProperty(propertyName);
99
+ }
100
+ setDynamicProperty(propertyName, value) {
101
+ if (!this.isValid)
102
+ return;
103
+ this.entity.setDynamicProperty(propertyName, value);
104
+ }
105
+ getCustomProperty(propertyName) {
106
+ if (!this.isValid)
107
+ return undefined;
108
+ const ns = getNamespace();
109
+ const fullName = ns ? `${ns}:${propertyName}` : propertyName;
110
+ return (this.entity.getProperty(fullName) ??
111
+ this.entity.getDynamicProperty(fullName));
112
+ }
113
+ setCustomProperty(propertyName, value) {
114
+ if (!this.isValid)
115
+ return;
116
+ const ns = getNamespace();
117
+ const fullName = ns ? `${ns}:${propertyName}` : propertyName;
118
+ try {
119
+ this.entity.setProperty(fullName, value);
120
+ }
121
+ catch (e) {
122
+ this.entity.setDynamicProperty(fullName, value);
123
+ }
124
+ }
125
+ // -------------------------------------------------------------------------
126
+ // Tag Helpers
127
+ // -------------------------------------------------------------------------
128
+ hasTag(tag) {
129
+ return this.isValid ? this.entity.hasTag(tag) : false;
130
+ }
131
+ addTag(tag) {
132
+ if (!this.isValid)
133
+ return false;
134
+ const added = this.entity.addTag(tag);
135
+ if (added) {
136
+ this.manager?.triggerEntityEvent(EntityEvents.TagAdded, this, tag);
137
+ }
138
+ return added;
139
+ }
140
+ removeTag(tag) {
141
+ if (!this.isValid)
142
+ return false;
143
+ const removed = this.entity.removeTag(tag);
144
+ if (removed) {
145
+ this.manager?.triggerEntityEvent(EntityEvents.TagRemoved, this, tag);
146
+ }
147
+ return removed;
148
+ }
149
+ getTags() {
150
+ return this.isValid ? this.entity.getTags() : [];
151
+ }
152
+ // -------------------------------------------------------------------------
153
+ // Native Health & Damage
154
+ // -------------------------------------------------------------------------
155
+ get health() {
156
+ return this.healthComponent?.currentValue ?? 0;
157
+ }
158
+ set health(value) {
159
+ if (this.healthComponent) {
160
+ const maxHp = this.maxHealth;
161
+ const clampedHp = Math.max(0, Math.min(value, maxHp > 0 ? maxHp : value));
162
+ this.healthComponent.setCurrentValue(clampedHp);
163
+ }
164
+ }
165
+ get maxHealth() {
166
+ return this.healthComponent?.defaultValue ?? 20;
167
+ }
168
+ applyDamage(damageAmount, source, cause) {
169
+ if (!this.isValid || damageAmount <= 0)
170
+ return;
171
+ const currentHp = this.health;
172
+ const newHp = Math.max(0, currentHp - damageAmount);
173
+ this.health = newHp;
174
+ this.manager?.triggerEntityEvent(EntityEvents.Hurt, this, damageAmount, source, cause);
175
+ if (newHp <= 0 && !this.hasTag("is_dead_handled")) {
176
+ this.addTag("is_dead_handled");
177
+ try {
178
+ this.entity.triggerEvent("is_dying");
179
+ }
180
+ catch (e) { }
181
+ this.manager?.triggerEntityEvent(EntityEvents.Dying, this);
182
+ }
183
+ }
184
+ heal(healAmount, source) {
185
+ if (!this.isValid || healAmount <= 0)
186
+ return;
187
+ const currentHp = this.health;
188
+ const maxHp = this.maxHealth;
189
+ const newHp = Math.min(maxHp, currentHp + healAmount);
190
+ this.health = newHp;
191
+ this.manager?.triggerEntityEvent(EntityEvents.Heal, this, healAmount, source);
192
+ }
193
+ // -------------------------------------------------------------------------
194
+ // Native Bedrock Effect Delegations
195
+ // -------------------------------------------------------------------------
196
+ addEffect(effectType, duration, options) {
197
+ if (!this.isValid)
198
+ return undefined;
199
+ return this.entity.addEffect(effectType, duration, options);
200
+ }
201
+ removeEffect(effectType) {
202
+ if (!this.isValid)
203
+ return false;
204
+ return this.entity.removeEffect(effectType);
205
+ }
206
+ getEffect(effectType) {
207
+ if (!this.isValid)
208
+ return undefined;
209
+ return this.entity.getEffect(effectType);
210
+ }
211
+ // -------------------------------------------------------------------------
212
+ // Attribute Store (backed by EntityAttributeDatabase child of SimpleDatabase)
213
+ // -------------------------------------------------------------------------
214
+ setAttribute(key, value) {
215
+ if (!this.isValid)
216
+ return;
217
+ this.db.setAttribute(key, value);
218
+ }
219
+ getAttribute(key) {
220
+ if (!this.isValid)
221
+ return undefined;
222
+ return this.db.getAttribute(key);
223
+ }
224
+ hasAttribute(key) {
225
+ if (!this.isValid)
226
+ return false;
227
+ return this.db.hasAttribute(key);
228
+ }
229
+ removeAttribute(key) {
230
+ if (!this.isValid)
231
+ return false;
232
+ if (this.db.hasAttribute(key)) {
233
+ this.db.removeAttribute(key);
234
+ return true;
235
+ }
236
+ return false;
237
+ }
238
+ getAllAttributes() {
239
+ if (!this.isValid)
240
+ return {};
241
+ return this.db.getAllAttributes();
242
+ }
243
+ // -------------------------------------------------------------------------
244
+ // Tick Loop
245
+ // -------------------------------------------------------------------------
246
+ tick() {
247
+ if (!this.isValid)
248
+ return;
249
+ this.stateTick++;
250
+ }
251
+ }
252
+ //# sourceMappingURL=EntityWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityWrapper.js","sourceRoot":"","sources":["../../src/entity-system/EntityWrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEN,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,GAMzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAGpE,MAAM,CAAN,IAAY,YAgBX;AAhBD,WAAY,YAAY;IACvB,uCAAuB,CAAA;IACvB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;IACrB,2CAA2B,CAAA;IAC3B,+CAA+B,CAAA;IAC/B,+BAAe,CAAA;IACf,mCAAmB,CAAA;IACnB,6BAAa,CAAA;IACb,6BAAa,CAAA;IACb,6BAAa,CAAA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IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QAChC,IAAI,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,gBAAgB;QACf,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACnC,CAAC;IAED,4EAA4E;IAC5E,YAAY;IACZ,4EAA4E;IAC5E,IAAI;QACH,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAC1B,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file EventGroup.ts
3
+ * @description Event pub/sub mechanism supporting typed event callbacks for wrapped entities and players.
4
+ */
5
+ export type EventCallback<T = any> = (target: T, ...args: any[]) => void;
6
+ export type EventType = string;
7
+ export declare class EventGroup<T = any> {
8
+ private callbacks;
9
+ constructor(initialEvents?: EventType[]);
10
+ /**
11
+ * Registers an event listener callback for the specified event type.
12
+ */
13
+ on(type: EventType, callback: EventCallback<T>): this;
14
+ /**
15
+ * Registers a one-time event listener callback that automatically unregisters after first trigger.
16
+ */
17
+ once(type: EventType, callback: EventCallback<T>): this;
18
+ /**
19
+ * Removes an event listener callback.
20
+ */
21
+ off(type: EventType, callback: EventCallback<T>): this;
22
+ /**
23
+ * Triggers all registered callbacks for the specified event type.
24
+ */
25
+ trigger(type: EventType, target: T, ...args: any[]): void;
26
+ /**
27
+ * Clears all callbacks for a specific event type, or all event types if omitted.
28
+ */
29
+ clear(type?: EventType): void;
30
+ }
31
+ //# sourceMappingURL=EventGroup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventGroup.d.ts","sourceRoot":"","sources":["../../src/entity-system/EventGroup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AACzE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG;IAC9B,OAAO,CAAC,SAAS,CAA4C;gBAEjD,aAAa,CAAC,EAAE,SAAS,EAAE;IAQvC;;OAEG;IACH,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI;IAQrD;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI;IAQvD;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI;IAWtD;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAezD;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI;CAO7B"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @file EventGroup.ts
3
+ * @description Event pub/sub mechanism supporting typed event callbacks for wrapped entities and players.
4
+ */
5
+ export class EventGroup {
6
+ callbacks = new Map();
7
+ constructor(initialEvents) {
8
+ if (initialEvents) {
9
+ initialEvents.forEach((event) => {
10
+ this.callbacks.set(event, []);
11
+ });
12
+ }
13
+ }
14
+ /**
15
+ * Registers an event listener callback for the specified event type.
16
+ */
17
+ on(type, callback) {
18
+ if (!this.callbacks.has(type)) {
19
+ this.callbacks.set(type, []);
20
+ }
21
+ this.callbacks.get(type).push(callback);
22
+ return this;
23
+ }
24
+ /**
25
+ * Registers a one-time event listener callback that automatically unregisters after first trigger.
26
+ */
27
+ once(type, callback) {
28
+ const onceWrapper = (target, ...args) => {
29
+ this.off(type, onceWrapper);
30
+ callback(target, ...args);
31
+ };
32
+ return this.on(type, onceWrapper);
33
+ }
34
+ /**
35
+ * Removes an event listener callback.
36
+ */
37
+ off(type, callback) {
38
+ const callbacks = this.callbacks.get(type);
39
+ if (callbacks) {
40
+ const index = callbacks.indexOf(callback);
41
+ if (index > -1) {
42
+ callbacks.splice(index, 1);
43
+ }
44
+ }
45
+ return this;
46
+ }
47
+ /**
48
+ * Triggers all registered callbacks for the specified event type.
49
+ */
50
+ trigger(type, target, ...args) {
51
+ const callbacks = this.callbacks.get(type);
52
+ if (callbacks) {
53
+ for (const cb of callbacks) {
54
+ try {
55
+ cb(target, ...args);
56
+ }
57
+ catch (error) {
58
+ console.warn(`[EventGroup] Error executing event callback for '${type}': ${error}`);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ /**
64
+ * Clears all callbacks for a specific event type, or all event types if omitted.
65
+ */
66
+ clear(type) {
67
+ if (type) {
68
+ this.callbacks.delete(type);
69
+ }
70
+ else {
71
+ this.callbacks.clear();
72
+ }
73
+ }
74
+ }
75
+ //# sourceMappingURL=EventGroup.js.map