@starktma/minecraft-utils 1.5.37 → 1.5.39

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 (33) 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/package.json +6 -6
  30. package/dist/player-event/index.d.ts +0 -52
  31. package/dist/player-event/index.d.ts.map +0 -1
  32. package/dist/player-event/index.js +0 -163
  33. 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.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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,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;YACtD,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC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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,SAAS,CAEzB;IAED,IAAI,QAAQ,wCAEX;IAKD,IAAI,eAAe,IAAI,qBAAqB,GAAG,SAAS,CAIvD;IAED,IAA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,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;IACb,+BAAe,CAAA;IACf,+BAAe,CAAA;IACf,qCAAqB,CAAA;IACrB,yCAAyB,CAAA;IACzB,2CAA2B,CAA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,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventGroup.js","sourceRoot":"","sources":["../../src/entity-system/EventGroup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,OAAO,UAAU;IACd,SAAS,GAAG,IAAI,GAAG,EAAiC,CAAC;IAE7D,YAAY,aAA2B;QACtC,IAAI,aAAa,EAAE,CAAC;YACnB,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,IAAe,EAAE,QAA0B;QAC7C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAA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M,EAAE,GAAG,IAAI,CAAC,CAAC;gBACrB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,OAAO,CAAC,IAAI,CACX,oDAAoD,IAAI,MAAM,KAAK,EAAE,CACrE,CAAC;gBACH,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAgB;QACrB,IAAI,IAAI,EAAE,CAAC;YACV,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @file PlayerManager.ts
3
+ * @description Specialized manager extending `EntityManager<PlayerWrapper>` for managing player instances.
4
+ */
5
+ import { Player } from "@minecraft/server";
6
+ import { PlayerWrapper } from "./PlayerWrapper";
7
+ import { EntityManager } from "./EntityManager";
8
+ export declare abstract class PlayerManager<T extends PlayerWrapper = PlayerWrapper> extends EntityManager<T> {
9
+ protected constructor(tickInterval?: number);
10
+ protected shouldManageEntity(entity: any): boolean;
11
+ protected onWorldLoad(): void;
12
+ getAllPlayers(): T[];
13
+ getPlayer(id: string): T | undefined;
14
+ addPlayer(player: Player): void;
15
+ removePlayer(id: string): void;
16
+ }
17
+ //# sourceMappingURL=PlayerManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlayerManager.d.ts","sourceRoot":"","sources":["../../src/entity-system/PlayerManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAS,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,8BAAsB,aAAa,CAClC,CAAC,SAAS,aAAa,GAAG,aAAa,CACtC,SAAQ,aAAa,CAAC,CAAC,CAAC;IACzB,SAAS,aAAa,YAAY,CAAC,EAAE,MAAM;cAiBxB,kBAAkB,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO;cAIxC,WAAW,IAAI,IAAI;IAItC,aAAa,IAAI,CAAC,EAAE;IAIpB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIpC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAG9B"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @file PlayerManager.ts
3
+ * @description Specialized manager extending `EntityManager<PlayerWrapper>` for managing player instances.
4
+ */
5
+ import { world, Player } from "@minecraft/server";
6
+ import { EntityManager } from "./EntityManager";
7
+ export class PlayerManager extends EntityManager {
8
+ constructor(tickInterval) {
9
+ super(tickInterval ?? 1);
10
+ world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
11
+ const existing = this.getEntity(player.id);
12
+ if (initialSpawn || !existing) {
13
+ this.addEntity(player);
14
+ }
15
+ else {
16
+ existing.reset();
17
+ }
18
+ });
19
+ world.afterEvents.playerLeave.subscribe(({ playerId }) => {
20
+ this.removeEntity(playerId);
21
+ });
22
+ }
23
+ shouldManageEntity(entity) {
24
+ return entity instanceof Player;
25
+ }
26
+ onWorldLoad() {
27
+ world.getAllPlayers().forEach((player) => this.addEntity(player));
28
+ }
29
+ getAllPlayers() {
30
+ return this.getAllEntities();
31
+ }
32
+ getPlayer(id) {
33
+ return this.getEntity(id);
34
+ }
35
+ addPlayer(player) {
36
+ this.addEntity(player);
37
+ }
38
+ removePlayer(id) {
39
+ this.removeEntity(id);
40
+ }
41
+ }
42
+ //# sourceMappingURL=PlayerManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlayerManager.js","sourceRoot":"","sources":["../../src/entity-system/PlayerManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EA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AAY,CAAC,EAAU;QACtB,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC;CACD"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @file PlayerWrapper.ts
3
+ * @description Specialized Player wrapper extending `EntityWrapper<Player>`.
4
+ * Manages player inputs (jump & sneak state machines), movement/ground state tracking, camera clears, and event triggers.
5
+ */
6
+ import { Player, ItemStack, Vector3 } from "@minecraft/server";
7
+ import { EntityWrapper } from "./EntityWrapper";
8
+ import type { EntityManager } from "./EntityManager";
9
+ export declare enum PlayerEvents {
10
+ WorldLoad = "worldLoad",
11
+ PreTick = "preTick",
12
+ PostTick = "postTick",
13
+ EntityAdded = "entityAdded",
14
+ EntityRemoved = "entityRemoved",
15
+ Tick = "tick",
16
+ Hurt = "hurt",
17
+ Heal = "heal",
18
+ Dying = "dying",
19
+ Death = "death",
20
+ TagAdded = "tagAdded",
21
+ TagRemoved = "tagRemoved",
22
+ ScriptEvent = "scriptEvent",
23
+ JumpStart = "jumpStart",
24
+ JumpHold = "jumpHold",
25
+ JumpEnd = "jumpEnd",
26
+ SneakStart = "sneakStart",
27
+ SneakHold = "sneakHold",
28
+ SneakEnd = "sneakEnd",
29
+ Land = "land"
30
+ }
31
+ export declare class PlayerWrapper extends EntityWrapper<Player> {
32
+ jumpTick: number;
33
+ sneakTick: number;
34
+ wasOnGround: boolean;
35
+ constructor(player: Player, manager?: EntityManager<any>);
36
+ get player(): Player;
37
+ get isJumping(): boolean;
38
+ get isSneaking(): boolean;
39
+ get isOnGround(): boolean;
40
+ get isFalling(): boolean;
41
+ get velocity(): Vector3;
42
+ getEquippedItem(): ItemStack | undefined;
43
+ reset(): void;
44
+ tick(): void;
45
+ }
46
+ //# sourceMappingURL=PlayerWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlayerWrapper.d.ts","sourceRoot":"","sources":["../../src/entity-system/PlayerWrapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,MAAM,EAIN,SAAS,EACT,OAAO,EACP,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAgB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,oBAAY,YAAY;IAEvB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,aAAa,kBAAkB;IAC/B,IAAI,SAAS;IACb,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAG3B,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,IAAI,SAAS;CACb;AAED,qBAAa,aAAc,SAAQ,aAAa,CAAC,MAAM,CAAC;IACvD,QAAQ,SAAK;IACb,SAAS,SAAK;IACd,WAAW,UAAQ;gBAEP,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC;IAKxD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,IAAI,SAAS,IAAI,OAAO,CAGvB;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,eAAe,IAAI,SAAS,GAAG,SAAS;IAIxC,KAAK,IAAI,IAAI;IAUJ,IAAI,IAAI,IAAI;CA0ErB"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @file PlayerWrapper.ts
3
+ * @description Specialized Player wrapper extending `EntityWrapper<Player>`.
4
+ * Manages player inputs (jump & sneak state machines), movement/ground state tracking, camera clears, and event triggers.
5
+ */
6
+ import { ButtonState, EquipmentSlot, InputButton, } from "@minecraft/server";
7
+ import { EntityWrapper } from "./EntityWrapper";
8
+ export var PlayerEvents;
9
+ (function (PlayerEvents) {
10
+ // Unified Entity Events
11
+ PlayerEvents["WorldLoad"] = "worldLoad";
12
+ PlayerEvents["PreTick"] = "preTick";
13
+ PlayerEvents["PostTick"] = "postTick";
14
+ PlayerEvents["EntityAdded"] = "entityAdded";
15
+ PlayerEvents["EntityRemoved"] = "entityRemoved";
16
+ PlayerEvents["Tick"] = "tick";
17
+ PlayerEvents["Hurt"] = "hurt";
18
+ PlayerEvents["Heal"] = "heal";
19
+ PlayerEvents["Dying"] = "dying";
20
+ PlayerEvents["Death"] = "death";
21
+ PlayerEvents["TagAdded"] = "tagAdded";
22
+ PlayerEvents["TagRemoved"] = "tagRemoved";
23
+ PlayerEvents["ScriptEvent"] = "scriptEvent";
24
+ // Player Specific Input & Movement Events
25
+ PlayerEvents["JumpStart"] = "jumpStart";
26
+ PlayerEvents["JumpHold"] = "jumpHold";
27
+ PlayerEvents["JumpEnd"] = "jumpEnd";
28
+ PlayerEvents["SneakStart"] = "sneakStart";
29
+ PlayerEvents["SneakHold"] = "sneakHold";
30
+ PlayerEvents["SneakEnd"] = "sneakEnd";
31
+ PlayerEvents["Land"] = "land";
32
+ })(PlayerEvents || (PlayerEvents = {}));
33
+ export class PlayerWrapper extends EntityWrapper {
34
+ jumpTick = 0;
35
+ sneakTick = 0;
36
+ wasOnGround = true;
37
+ constructor(player, manager) {
38
+ super(player, manager);
39
+ this.reset();
40
+ }
41
+ get player() {
42
+ return this.entity;
43
+ }
44
+ get isJumping() {
45
+ return this.jumpTick > 0;
46
+ }
47
+ get isSneaking() {
48
+ return this.sneakTick > 0;
49
+ }
50
+ get isOnGround() {
51
+ return this.isValid ? this.player.isOnGround : true;
52
+ }
53
+ get isFalling() {
54
+ if (!this.isValid)
55
+ return false;
56
+ return !this.player.isOnGround && this.velocity.y < 0;
57
+ }
58
+ get velocity() {
59
+ return this.isValid ? this.player.getVelocity() : { x: 0, y: 0, z: 0 };
60
+ }
61
+ getEquippedItem() {
62
+ return this.equippableComponent?.getEquipment(EquipmentSlot.Mainhand);
63
+ }
64
+ reset() {
65
+ this.stateTick = 0;
66
+ this.jumpTick = 0;
67
+ this.sneakTick = 0;
68
+ this.wasOnGround = true;
69
+ try {
70
+ this.player.camera.clear();
71
+ }
72
+ catch (e) { }
73
+ }
74
+ tick() {
75
+ super.tick();
76
+ if (!this.isValid)
77
+ return;
78
+ let isJumpPressed = false;
79
+ let isSneakPressed = false;
80
+ try {
81
+ const inputInfo = this.player.inputInfo;
82
+ if (inputInfo) {
83
+ isJumpPressed =
84
+ inputInfo.getButtonState(InputButton.Jump) === ButtonState.Pressed;
85
+ isSneakPressed =
86
+ inputInfo.getButtonState(InputButton.Sneak) === ButtonState.Pressed;
87
+ }
88
+ }
89
+ catch (e) {
90
+ // InputInfo might throw if permissions or camera modes lock input state
91
+ }
92
+ // --- Jump State Machine ---
93
+ if (isJumpPressed) {
94
+ if (this.jumpTick <= 0) {
95
+ this.jumpTick = 1;
96
+ this.manager?.triggerEntityEvent(PlayerEvents.JumpStart, this);
97
+ }
98
+ else {
99
+ this.jumpTick++;
100
+ }
101
+ this.manager?.triggerEntityEvent(PlayerEvents.JumpHold, this, this.jumpTick);
102
+ }
103
+ else {
104
+ if (this.jumpTick > 0) {
105
+ this.manager?.triggerEntityEvent(PlayerEvents.JumpEnd, this, this.jumpTick);
106
+ }
107
+ this.jumpTick = 0;
108
+ }
109
+ // --- Sneak State Machine ---
110
+ if (isSneakPressed) {
111
+ if (this.sneakTick <= 0) {
112
+ this.sneakTick = 1;
113
+ this.manager?.triggerEntityEvent(PlayerEvents.SneakStart, this);
114
+ }
115
+ else {
116
+ this.sneakTick++;
117
+ }
118
+ this.manager?.triggerEntityEvent(PlayerEvents.SneakHold, this, this.sneakTick);
119
+ }
120
+ else {
121
+ if (this.sneakTick > 0) {
122
+ this.manager?.triggerEntityEvent(PlayerEvents.SneakEnd, this, this.sneakTick);
123
+ }
124
+ this.sneakTick = 0;
125
+ }
126
+ // --- Ground & Landing State Machine ---
127
+ const currentlyOnGround = this.isOnGround;
128
+ if (currentlyOnGround && !this.wasOnGround) {
129
+ this.manager?.triggerEntityEvent(PlayerEvents.Land, this);
130
+ }
131
+ this.wasOnGround = currentlyOnGround;
132
+ }
133
+ }
134
+ //# sourceMappingURL=PlayerWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlayerWrapper.js","sourceRoot":"","sources":["../../src/entity-system/PlayerWrapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEN,WAAW,EACX,aAAa,EACb,WAAW,GAGX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAgB,MAAM,iBAAiB,CAAC;AAG9D,MAAM,CAAN,IAAY,YAwBX;AAxBD,WAAY,YAAY;IACvB,wBAAwB;IACxB,uCAAuB,CAAA;IACvB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;IACrB,2CAA2B,CAAA;IAC3B,+CAA+B,CAAA;IAC/B,6BAAa,CAAA;IACb,6BAAa,CAAA;IACb,6BAAa,CAAA;IACb,+BAAe,CAAA;IACf,+BAAe,CAAA;IACf,qCAAqB,CAAA;IACrB,yCAAyB,CAAA;IACzB,2CAA2B,CAAA;IAE3B,0CAA0C;IAC1C,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,mCAAmB,CAAA;IACnB,yCAAyB,CAAA;IACzB,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,6BAAa,CAAA;AACd,CAAC,EAxBW,YAAY,KAAZ,YAAY,QAwBvB;AAED,MAAM,OAAO,aAAc,SAAQ,aAAqB;IACvD,QAAQ,GAAG,CAAC,CAAC;IACb,SAAS,GAAG,CAAC,CAAC;IACd,WAAW,GAAG,IAAI,CAAC;IAEnB,YAAY,MAAc,EAAE,OAA4B;QACvD,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvB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AED,8BAA8B;QAC9B,IAAI,cAAc,EAAE,CAAC;YACpB,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC;gBACzB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;gBACnB,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YACjE,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,SAAS,EAAE,CAAC;YAClB,CAAC;YACD,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAC/B,YAAY,CAAC,SAAS,EACtB,IAAI,EACJ,IAAI,CAAC,SAAS,CACd,CAAC;QACH,CAAC;aAAM,CAAC;YACP,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;gBACxB,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAC/B,YAAY,CAAC,QAAQ,EACrB,IAAI,EACJ,IAAI,CAAC,SAAS,CACd,CAAC;YACH,CAAC;YACD,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACpB,CAAC;QAED,yCAAyC;QACzC,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC;QAC1C,IAAI,iBAAiB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5C,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,iBAAiB,CAAC;IACtC,CAAC;CACD"}
@@ -0,0 +1,7 @@
1
+ export * from "./EventGroup";
2
+ export * from "./EntityWrapper";
3
+ export * from "./PlayerWrapper";
4
+ export * from "./EntityManager";
5
+ export * from "./PlayerManager";
6
+ export * from "./EntityAttributeDatabase";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entity-system/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./EventGroup";
2
+ export * from "./EntityWrapper";
3
+ export * from "./PlayerWrapper";
4
+ export * from "./EntityManager";
5
+ export * from "./PlayerManager";
6
+ export * from "./EntityAttributeDatabase";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity-system/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starktma/minecraft-utils",
3
- "version": "1.5.37",
3
+ "version": "1.5.39",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,9 +33,9 @@
33
33
  "import": "./dist/database/index.js",
34
34
  "types": "./dist/database/index.d.ts"
35
35
  },
36
- "./player-events": {
37
- "import": "./dist/player-event/index.js",
38
- "types": "./dist/player-event/index.d.ts"
36
+ "./entity-system": {
37
+ "import": "./dist/entity-system/index.js",
38
+ "types": "./dist/entity-system/index.d.ts"
39
39
  },
40
40
  "./game-state-machine": {
41
41
  "import": "./dist/game-state-machine/index.js",
@@ -51,8 +51,8 @@
51
51
  "LICENSE"
52
52
  ],
53
53
  "devDependencies": {
54
- "@minecraft/server": "^2.7.0",
55
- "@minecraft/server-ui": "^2.0.0",
54
+ "@minecraft/server": "^2.9.0",
55
+ "@minecraft/server-ui": "^2.1.0",
56
56
  "typescript": "^5.9.2"
57
57
  }
58
58
  }
@@ -1,52 +0,0 @@
1
- import { Player, EntityEquippableComponent, EntityInventoryComponent, ItemStack } from "@minecraft/server";
2
- type EventCallback<T = CustomPlayer> = (player: T, args: any[]) => void;
3
- type PlayerEventType = CustomPlayerEvents | string;
4
- declare enum CustomPlayerEvents {
5
- Tick = "tick",
6
- JumpStart = "jumpStart",
7
- JumpHold = "jumpHold",
8
- JumpEnd = "jumpEnd",
9
- SneakStart = "sneakStart",
10
- SneakHold = "sneakHold",
11
- SneakEnd = "sneakEnd"
12
- }
13
- declare class EventGroup<T = CustomPlayer> {
14
- private callbacks;
15
- constructor();
16
- private run;
17
- trigger(type: PlayerEventType, player: T, args?: any[]): void;
18
- on(type: PlayerEventType, callback: EventCallback<T>): void;
19
- off(type: PlayerEventType, callback: EventCallback<T>): void;
20
- }
21
- declare class CustomPlayer {
22
- player: Player;
23
- stateTick: number;
24
- jumpTick: number;
25
- sneakTick: number;
26
- constructor(player: Player);
27
- get equippableComponent(): EntityEquippableComponent;
28
- get inventoryComponent(): EntityInventoryComponent;
29
- get isValid(): boolean;
30
- get location(): import("@minecraft/server").Vector3;
31
- get rotation(): import("@minecraft/server").Vector2;
32
- getEquippedItem(): ItemStack | undefined;
33
- reset(): void;
34
- tick(): void;
35
- }
36
- declare abstract class PlayerManager<T extends CustomPlayer = CustomPlayer> {
37
- private players;
38
- private events;
39
- protected constructor(tick?: number);
40
- protected abstract createPlayerManager(player: Player): T;
41
- getAllPlayers(): T[];
42
- getPlayer(id: string): T | undefined;
43
- removePlayer(id: string): void;
44
- addPlayer(player: Player): void;
45
- registerEvents(eventID: string): {
46
- event: EventGroup<T>;
47
- };
48
- getEvents(eventID: string): EventGroup<T> | undefined;
49
- tick(): void;
50
- }
51
- export { CustomPlayerEvents, CustomPlayer, PlayerManager, EventGroup };
52
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/player-event/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,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Aa,IAAI,CAAC,EAAE,MAAM;IAwBnC,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC;IAEzD,aAAa,IAAI,CAAC,EAAE;IAIpB,SAAS,CAAC,EAAE,EAAE,MAAM;IAIpB,YAAY,CAAC,EAAE,EAAE,MAAM;IAIvB,SAAS,CAAC,MAAM,EAAE,MAAM;IAKxB,cAAc,CAAC,OAAO,EAAE,MAAM;;;IAM9B,SAAS,CAAC,OAAO,EAAE,MAAM;IAIzB,IAAI;CAaJ;AAED,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC"}
@@ -1,163 +0,0 @@
1
- import { system, world, ButtonState, EntityEquippableComponent, EntityInventoryComponent, EquipmentSlot, InputButton, } from "@minecraft/server";
2
- var CustomPlayerEvents;
3
- (function (CustomPlayerEvents) {
4
- CustomPlayerEvents["Tick"] = "tick";
5
- CustomPlayerEvents["JumpStart"] = "jumpStart";
6
- CustomPlayerEvents["JumpHold"] = "jumpHold";
7
- CustomPlayerEvents["JumpEnd"] = "jumpEnd";
8
- CustomPlayerEvents["SneakStart"] = "sneakStart";
9
- CustomPlayerEvents["SneakHold"] = "sneakHold";
10
- CustomPlayerEvents["SneakEnd"] = "sneakEnd";
11
- })(CustomPlayerEvents || (CustomPlayerEvents = {}));
12
- class EventGroup {
13
- callbacks = new Map();
14
- constructor() {
15
- // Initialize with core events
16
- Object.values(CustomPlayerEvents).forEach((event) => {
17
- this.callbacks.set(event, []);
18
- });
19
- }
20
- run(callbacks, player, args = []) {
21
- for (const cb of callbacks)
22
- cb(player, args);
23
- }
24
- trigger(type, player, args = []) {
25
- const callbacks = this.callbacks.get(type);
26
- if (callbacks) {
27
- this.run(callbacks, player, args);
28
- }
29
- }
30
- on(type, callback) {
31
- if (!this.callbacks.has(type)) {
32
- this.callbacks.set(type, []);
33
- }
34
- this.callbacks.get(type).push(callback);
35
- }
36
- // Simple way to remove listeners
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
- }
46
- }
47
- class CustomPlayer {
48
- player;
49
- stateTick = 0;
50
- jumpTick = 0;
51
- sneakTick = 0;
52
- constructor(player) {
53
- this.player = player;
54
- this.reset();
55
- }
56
- get equippableComponent() {
57
- return this.player.getComponent(EntityEquippableComponent.componentId);
58
- }
59
- get inventoryComponent() {
60
- return this.player.getComponent(EntityInventoryComponent.componentId);
61
- }
62
- get isValid() {
63
- return this.player.isValid;
64
- }
65
- get location() {
66
- return this.player.location;
67
- }
68
- get rotation() {
69
- return this.player.getRotation();
70
- }
71
- getEquippedItem() {
72
- return this.equippableComponent.getEquipment(EquipmentSlot.Mainhand);
73
- }
74
- reset() {
75
- this.stateTick = 0;
76
- this.jumpTick = 0;
77
- this.player.camera.clear();
78
- }
79
- tick() {
80
- this.stateTick++;
81
- if (this.player.inputInfo.getButtonState(InputButton.Jump) ===
82
- ButtonState.Pressed) {
83
- this.jumpTick++;
84
- }
85
- else if (this.jumpTick > 0) {
86
- this.jumpTick = -1;
87
- }
88
- else {
89
- this.jumpTick = 0;
90
- }
91
- if (this.player.inputInfo.getButtonState(InputButton.Sneak) ===
92
- ButtonState.Pressed) {
93
- this.sneakTick++;
94
- }
95
- else if (this.sneakTick > 0) {
96
- this.sneakTick = -1;
97
- }
98
- else {
99
- this.sneakTick = 0;
100
- }
101
- }
102
- }
103
- class PlayerManager {
104
- players = new Map();
105
- events = new Map();
106
- constructor(tick) {
107
- world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
108
- const id = player.id;
109
- const existing = this.getPlayer(id);
110
- if (initialSpawn || !existing) {
111
- this.addPlayer(player);
112
- }
113
- else {
114
- existing.reset();
115
- }
116
- });
117
- world.afterEvents.playerLeave.subscribe(({ playerId }) => {
118
- this.removePlayer(playerId);
119
- });
120
- world.afterEvents.worldLoad.subscribe(() => {
121
- world.getAllPlayers().forEach((player) => this.addPlayer(player));
122
- system.runInterval(() => {
123
- this.tick();
124
- }, tick ?? 1);
125
- });
126
- }
127
- getAllPlayers() {
128
- return Array.from(this.players.values());
129
- }
130
- getPlayer(id) {
131
- return this.players.get(id);
132
- }
133
- removePlayer(id) {
134
- this.players.delete(id);
135
- }
136
- addPlayer(player) {
137
- if (this.players.has(player.id))
138
- return;
139
- this.players.set(player.id, this.createPlayerManager(player));
140
- }
141
- registerEvents(eventID) {
142
- const eventGroup = new EventGroup();
143
- this.events.set(eventID, eventGroup);
144
- return { event: eventGroup };
145
- }
146
- getEvents(eventID) {
147
- return this.events.get(eventID);
148
- }
149
- tick() {
150
- const allPlayers = this.getAllPlayers();
151
- for (const manager of allPlayers) {
152
- const { player } = manager;
153
- if (!player.isValid)
154
- continue;
155
- manager.tick();
156
- this.events.forEach((eventGroup) => {
157
- eventGroup.trigger(CustomPlayerEvents.Tick, manager);
158
- });
159
- }
160
- }
161
- }
162
- export { CustomPlayerEvents, CustomPlayer, PlayerManager, EventGroup };
163
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/player-event/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,MAAM,EACN,KAAK,EAEL,WAAW,EACX,yBAAyB,EACzB,wBAAwB,EACxB,aAAa,EACb,WAAW,GAEX,MAAM,mBAAmB,CAAC;AAK3B,IAAK,kBAQJ;AARD,WAAK,kBAAkB;IACtB,mCAAa,CAAA;IACb,6CAAuB,CAAA;IACvB,2CAAqB,CAAA;IACrB,yCAAmB,CAAA;IACnB,+CAAyB,CAAA;IACzB,6CAAuB,CAAA;IACvB,2CAAqB,CAAA;AACtB,CAAC,EARI,kBAAkB,KAAlB,kBAAkB,QAQtB;AAED,MAAM,UAAU;IACP,SAAS,GAAG,IAAI,GAAG,EAAuC,CAAC;IAEnE;QACC,8BAA8B;QAC9B,MAAM,CAAC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