@block_factory/lib 0.0.6 → 0.0.9

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 (72) hide show
  1. package/_module/BlockFactory.ts +10 -19
  2. package/_module/util/Command.ts +1 -9
  3. package/_module/util/Forms/Form.ts +5 -31
  4. package/_module/util/Forms/FormAction.ts +2 -1
  5. package/_module/util/Forms/FormMessage.ts +2 -1
  6. package/_module/util/Forms/FormModal.ts +9 -10
  7. package/_module/util/Forms/FormRegistry.ts +20 -23
  8. package/_module/util/Forms/IForm.ts +31 -0
  9. package/_module/util/Globals.ts +26 -0
  10. package/_module/util/ISystem.ts +58 -0
  11. package/_module/util/IVector.ts +420 -0
  12. package/_module/util/Math.ts +2 -0
  13. package/_module/util/Navigation.ts +130 -0
  14. package/_module/util/TempLeaker.ts +137 -0
  15. package/_module/util/Wrapper/IEntity.ts +93 -25
  16. package/_module/util/Wrapper/IItemStack.ts +63 -0
  17. package/_module/util/Wrapper/IPlayer.ts +85 -29
  18. package/_module/util/Wrapper/_Common.ts +128 -0
  19. package/_module/util/Wrapper/{Container.ts → _Container.ts} +5 -5
  20. package/index.js +3941 -791
  21. package/package.json +9 -5
  22. package/_module/DataTypes.ts +0 -10
  23. package/_module/Framework/EntityTasks.ts +0 -164
  24. package/_module/Framework/ItemTasks.ts +0 -157
  25. package/_module/Framework/PlayerTasks.ts +0 -125
  26. package/_module/Framework/Threads.ts +0 -72
  27. package/_module/util/System.ts +0 -21
  28. package/_module/util/Vector.ts +0 -388
  29. package/_types/_module/BlockFactory.d.ts +0 -19
  30. package/_types/_module/BlockFactory.d.ts.map +0 -1
  31. package/_types/_module/DataTypes.d.ts +0 -10
  32. package/_types/_module/DataTypes.d.ts.map +0 -1
  33. package/_types/_module/Framework/EntityTasks.d.ts +0 -37
  34. package/_types/_module/Framework/EntityTasks.d.ts.map +0 -1
  35. package/_types/_module/Framework/ItemTasks.d.ts +0 -59
  36. package/_types/_module/Framework/ItemTasks.d.ts.map +0 -1
  37. package/_types/_module/Framework/PlayerTasks.d.ts +0 -28
  38. package/_types/_module/Framework/PlayerTasks.d.ts.map +0 -1
  39. package/_types/_module/Framework/Threads.d.ts +0 -22
  40. package/_types/_module/Framework/Threads.d.ts.map +0 -1
  41. package/_types/_module/Types.d.ts +0 -10
  42. package/_types/_module/Types.d.ts.map +0 -1
  43. package/_types/_module/util/Command.d.ts +0 -92
  44. package/_types/_module/util/Command.d.ts.map +0 -1
  45. package/_types/_module/util/Forms/Form.d.ts +0 -12
  46. package/_types/_module/util/Forms/Form.d.ts.map +0 -1
  47. package/_types/_module/util/Forms/FormAction.d.ts +0 -73
  48. package/_types/_module/util/Forms/FormAction.d.ts.map +0 -1
  49. package/_types/_module/util/Forms/FormMessage.d.ts +0 -24
  50. package/_types/_module/util/Forms/FormMessage.d.ts.map +0 -1
  51. package/_types/_module/util/Forms/FormModal.d.ts +0 -66
  52. package/_types/_module/util/Forms/FormModal.d.ts.map +0 -1
  53. package/_types/_module/util/Forms/FormRegistry.d.ts +0 -12
  54. package/_types/_module/util/Forms/FormRegistry.d.ts.map +0 -1
  55. package/_types/_module/util/Math.d.ts +0 -20
  56. package/_types/_module/util/Math.d.ts.map +0 -1
  57. package/_types/_module/util/RawText.d.ts +0 -60
  58. package/_types/_module/util/RawText.d.ts.map +0 -1
  59. package/_types/_module/util/Signal.d.ts +0 -70
  60. package/_types/_module/util/Signal.d.ts.map +0 -1
  61. package/_types/_module/util/System.d.ts +0 -4
  62. package/_types/_module/util/System.d.ts.map +0 -1
  63. package/_types/_module/util/Vector.d.ts +0 -212
  64. package/_types/_module/util/Vector.d.ts.map +0 -1
  65. package/_types/_module/util/Wrapper/Container.d.ts +0 -9
  66. package/_types/_module/util/Wrapper/Container.d.ts.map +0 -1
  67. package/_types/_module/util/Wrapper/IEntity.d.ts +0 -12
  68. package/_types/_module/util/Wrapper/IEntity.d.ts.map +0 -1
  69. package/_types/_module/util/Wrapper/IPlayer.d.ts +0 -13
  70. package/_types/_module/util/Wrapper/IPlayer.d.ts.map +0 -1
  71. package/_types/index.d.ts +0 -3
  72. package/_types/index.d.ts.map +0 -1
@@ -1,21 +1,12 @@
1
+ export { Command } from "./util/Command";
2
+ export { Inventory } from "./util/Wrapper/_Container";
3
+ export { IPlayer, ICustomPlayer } from "./util/Wrapper/IPlayer";
4
+ export { iSystem, ISystem } from "./util/ISystem";
5
+ export { IVector2, IVector3 } from "./util/IVector";
1
6
  export { MathUtils } from "./util/Math";
2
- export { Signal } from "./util/Signal";
3
- export { Vec2, Vec3 } from "./util/Vector";
7
+ export { Navigation, OnNavPointReachedEvent, OnNavigatingEntityStuckEvent } from "./util/Navigation";
4
8
  export { RawText } from "./util/RawText";
5
- export { Command } from "./util/Command";
6
- export { System } from "./util/System";
7
-
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
-
14
- export { Inventory, ContainerWrapper } from "./util/Wrapper/Container";
15
- export { type IEntity, IEntityWrapper } from "./util/Wrapper/IEntity";
16
- export { type IPlayer, IPlayerWrapper } from "./util/Wrapper/IPlayer";
17
-
18
- export { Thread } from "./Framework/Threads";
19
- export { PlayerHandler } from "./Framework/PlayerTasks";
20
- export { EntityHandler, type EntityEmissionEvent } from "./Framework/EntityTasks";
21
- export { ItemHandler, type ItemRegistration, type OnItemHeldEvent, type OnItemUnheldEvent, type WhileHoldingItemEvent } from "./Framework/ItemTasks";
9
+ export { Signal } from "./util/Signal";
10
+ export { type Ctor, type PropertyRecord, type PropertyValue } from "./util/Globals";
11
+ export { type IEntity, ICustomEntity } from "./util/Wrapper/IEntity";
12
+ export * as Form from "./util/Forms/Form";
@@ -1,12 +1,4 @@
1
- import {
2
- CustomCommand,
3
- CommandPermissionLevel,
4
- CustomCommandParameter,
5
- CustomCommandOrigin,
6
- CustomCommandResult,
7
- system,
8
- StartupEvent
9
- } from "@minecraft/server";
1
+ import { CustomCommand, CommandPermissionLevel, CustomCommandParameter, CustomCommandOrigin, CustomCommandResult, system, StartupEvent } from "@minecraft/server";
10
2
 
11
3
  /**
12
4
  * Command utilities and base classes for defining and registering
@@ -1,31 +1,5 @@
1
- import { Player, RawMessage, world } from "@minecraft/server";
2
- import { uiManager } from "@minecraft/server-ui";
3
-
4
- export declare type IFormValue = string | boolean | number | undefined;
5
-
6
- export abstract class IForm {
7
- private static readonly occupiedPlayers: Set<string> = new Set();
8
- public static returnText: RawMessage | string = "Back";
9
-
10
- public static isOccupied(player: Player): boolean {
11
- return IForm.occupiedPlayers.has(player.id);
12
- }
13
-
14
- public static closeForms(player: Player): void {
15
- uiManager.closeAllForms(player);
16
- }
17
-
18
- public static closeOccupiedForms(): void {
19
- for (const playerId of IForm.occupiedPlayers) {
20
- const player = world.getEntity(playerId) as Player | undefined;
21
- if (player) uiManager.closeAllForms(player);
22
- }
23
- }
24
-
25
- protected setOccupied(player: Player, occupied: boolean): void {
26
- if (occupied) IForm.occupiedPlayers.add(player.id);
27
- else IForm.occupiedPlayers.delete(player.id);
28
- }
29
-
30
- protected abstract build(player: Player): void;
31
- }
1
+ export { IForm, IFormValue } from "./IForm";
2
+ export { type IFormRegistration, RegisterForm } from "./FormRegistry";
3
+ export { type IMessageFormData, type IMessageFormResponse } from "./FormMessage";
4
+ export { ActionFormCtor, type IButtonOptions, type IActionFormResponse, type IActionFormData } from "./FormAction";
5
+ export { type IModalFormResponse, type ITextFieldOptions, type IDropdownOptions, type ISliderOptions, type IToggleOptions, type IModalFormData } from "./FormModal";
@@ -1,6 +1,7 @@
1
- import { IForm } from "./Form";
1
+
2
2
  import { Player, RawMessage } from "@minecraft/server";
3
3
  import { ActionFormData, ActionFormResponse, FormCancelationReason } from "@minecraft/server-ui";
4
+ import { IForm } from "./IForm";
4
5
 
5
6
  const RETURN_ID = "d7213196-4cb6-4199-a40b-22fbf2d944ef";
6
7
 
@@ -1,9 +1,10 @@
1
- import { IForm } from "./Form";
1
+
2
2
  import { Player, RawMessage } from "@minecraft/server";
3
3
  import {
4
4
  MessageFormData,
5
5
  MessageFormResponse,
6
6
  } from "@minecraft/server-ui";
7
+ import { IForm } from "./IForm";
7
8
 
8
9
  /**
9
10
  * Abstract base class for MessageFormData.
@@ -1,4 +1,4 @@
1
- import { IForm } from "./Form";
1
+
2
2
  import { Player, RawMessage } from "@minecraft/server";
3
3
  import {
4
4
  ModalFormData,
@@ -9,8 +9,7 @@ import {
9
9
  ModalFormDataTextFieldOptions,
10
10
  ModalFormDataToggleOptions,
11
11
  } from "@minecraft/server-ui";
12
-
13
- export type FormValue = string | boolean | number | undefined;
12
+ import { IForm, IFormValue } from "./IForm";
14
13
 
15
14
  /** Normalized response for Modal forms */
16
15
  export interface IModalFormResponse {
@@ -19,9 +18,9 @@ export interface IModalFormResponse {
19
18
  /** Whether the form was canceled by the player.*/
20
19
  readonly canceled: boolean;
21
20
  /** Raw values array from the form */
22
- readonly formValues?: FormValue[];
21
+ readonly formValues?: IFormValue[];
23
22
  /** Mapped values by widget id */
24
- readonly widget?: Map<string, FormValue>;
23
+ readonly widget?: Map<string, IFormValue>;
25
24
  }
26
25
 
27
26
  /** Options for each widget type */
@@ -139,19 +138,19 @@ export abstract class IModalFormData extends IForm {
139
138
  }
140
139
  }
141
140
 
142
- private _wrapResponse(res: ModalFormResponse, values?: Map<string, FormValue>): IModalFormResponse {
141
+ private _wrapResponse(res: ModalFormResponse, values?: Map<string, IFormValue>): IModalFormResponse {
143
142
  return {
144
143
  canceled: res.canceled,
145
144
  cancelationReason: res.cancelationReason,
146
- formValues: res.formValues as FormValue[] | undefined,
145
+ formValues: res.formValues as IFormValue[] | undefined,
147
146
  widget: values,
148
147
  };
149
148
  }
150
149
 
151
- private _mapValues(formValues: FormValue[] | undefined): Map<string, FormValue> | undefined {
150
+ private _mapValues(formValues: IFormValue[] | undefined): Map<string, IFormValue> | undefined {
152
151
  if (!formValues) return undefined;
153
152
 
154
- const out = new Map<string, FormValue>();
153
+ const out = new Map<string, IFormValue>();
155
154
  for (let i = 0; i < formValues.length; i++) {
156
155
  const meta = this._widgetMeta[i];
157
156
  if (!meta) continue;
@@ -174,7 +173,7 @@ export abstract class IModalFormData extends IForm {
174
173
  return wrapped;
175
174
  }
176
175
 
177
- const values = this._mapValues(res.formValues as FormValue[] | undefined);
176
+ const values = this._mapValues(res.formValues as IFormValue[] | undefined);
178
177
  const wrapped = this._wrapResponse(res, values);
179
178
 
180
179
  this.onSubmit(player, wrapped);
@@ -3,41 +3,38 @@ import { IActionFormData } from "./FormAction";
3
3
  import { IModalFormData } from "./FormModal";
4
4
  import { IMessageFormData } from "./FormMessage";
5
5
 
6
- type AnyShowableForm = IActionFormData | IModalFormData | IMessageFormData;
7
- type AnyShowableCtor = new () => AnyShowableForm;
6
+ export type AnyShowableForm = IActionFormData | IModalFormData | IMessageFormData;
7
+ export type AnyShowableCtor = new () => AnyShowableForm;
8
8
 
9
9
  export interface IFormRegistration {
10
- itemId: string;
10
+ formId: string;
11
11
  formCtor: AnyShowableCtor;
12
12
  }
13
13
 
14
- const registeredForms: IFormRegistration[] = [];
14
+ const registeredForms = new Map<string, AnyShowableCtor>();
15
15
 
16
- export function RegisterForm(itemId: string) {
17
- return function <T extends AnyShowableCtor>(formCtor: T): void {
18
- const i = registeredForms.findIndex(r => r.itemId === itemId);
19
- if (i !== -1) registeredForms[i] = { itemId, formCtor };
20
- else registeredForms.push({ itemId, formCtor });
21
- };
16
+ export function RegisterForm(formId: string) {
17
+ return function <T extends AnyShowableCtor>(formCtor: T): void {
18
+ registeredForms.set(formId, formCtor); // replaces or inserts
19
+ };
22
20
  }
23
21
 
24
- function getFormForItem(itemId: string): AnyShowableCtor | undefined {
25
- return registeredForms.find(r => r.itemId === itemId)?.formCtor;
22
+ function getForm(formId: string): AnyShowableCtor | undefined {
23
+ return registeredForms.get(formId);
26
24
  }
27
25
 
28
26
  world.afterEvents.itemUse.subscribe((event: ItemUseAfterEvent) => {
29
- const player = event.source;
30
- if (!(player instanceof Player)) return;
27
+ const player = event.source;
28
+ if (!(player instanceof Player)) return;
31
29
 
32
- const item = event.itemStack;
33
- if (!item) return;
30
+ const item = event.itemStack;
31
+ if (!item) return;
34
32
 
35
- const formCtor = getFormForItem(item.typeId);
36
- if (!formCtor) return;
33
+ const formCtor = getForm(item.typeId);
34
+ if (!formCtor) return;
37
35
 
38
- const form = new formCtor();
39
-
40
- form.show(player).catch((e) => {
41
- player.sendMessage(`§cForm error: ${String(e)}`);
42
- });
36
+ const form = new formCtor();
37
+ form.show(player).catch((e) => {
38
+ player.sendMessage(`§cForm error: ${String(e)}`);
39
+ });
43
40
  });
@@ -0,0 +1,31 @@
1
+ import { Player, RawMessage, world } from "@minecraft/server";
2
+ import { uiManager } from "@minecraft/server-ui";
3
+
4
+ export declare type IFormValue = string | boolean | number | undefined;
5
+
6
+ export abstract class IForm {
7
+ private static readonly occupiedPlayers: Set<string> = new Set();
8
+ public static returnText: RawMessage | string = "Back";
9
+
10
+ public static isOccupied(player: Player): boolean {
11
+ return IForm.occupiedPlayers.has(player.id);
12
+ }
13
+
14
+ public static closeForms(player: Player): void {
15
+ uiManager.closeAllForms(player);
16
+ }
17
+
18
+ public static closeOccupiedForms(): void {
19
+ for (const playerId of IForm.occupiedPlayers) {
20
+ const player = world.getEntity(playerId) as Player | undefined;
21
+ if (player) uiManager.closeAllForms(player);
22
+ }
23
+ }
24
+
25
+ protected setOccupied(player: Player, occupied: boolean): void {
26
+ if (occupied) IForm.occupiedPlayers.add(player.id);
27
+ else IForm.occupiedPlayers.delete(player.id);
28
+ }
29
+
30
+ protected abstract build(player: Player): void;
31
+ }
@@ -0,0 +1,26 @@
1
+ import { Vector3 } from "@minecraft/server";
2
+
3
+ /**
4
+ * Constructor type for wrapper-style classes.
5
+ *
6
+ * Used when you want to pass a class into a factory like `wrap(source, Ctor)`.
7
+ *
8
+ * @template T Instance type created by the constructor
9
+ */
10
+ export type Ctor<T extends any> = new (source: any) => T;
11
+
12
+ /**
13
+ * Allowed value types for Minecraft dynamic properties.
14
+ *
15
+ * Dynamic properties support a limited set of primitives plus `Vector3`,
16
+ * and may be `undefined` when a property is absent or cleared.
17
+ */
18
+ export type PropertyValue = string | number | boolean | Vector3 | undefined;
19
+
20
+ /**
21
+ * Key/value record representing a bundle of dynamic properties.
22
+ *
23
+ * Typically returned from a `save()` method and then written back via
24
+ * `setDynamicProperty(key, value)`.
25
+ */
26
+ export type PropertyRecord = Record<string, PropertyValue>;
@@ -0,0 +1,58 @@
1
+ import { Ctor } from "./Globals";
2
+ import { system, System } from "@minecraft/server";
3
+
4
+ export type ISystem = _ISystem & System;
5
+
6
+ class _ISystem {
7
+ public static wrap(): ISystem { return new _ISystem() as ISystem; }
8
+ private constructor() { return this.ProxyConstructor(this, system); }
9
+
10
+ private _packId: string = "undefined";
11
+ public get packId(): string { return this._packId; }
12
+ public set packId(value: string) { this._packId = value; }
13
+
14
+ private _iClassRegistry = new Map<string, Ctor<any>>();
15
+ public get iClassRegistry(): Map<string, Ctor<any>> { return this._iClassRegistry; }
16
+
17
+ /**
18
+ * Registers a wrapper class so it can be reconstructed after reload.
19
+ *
20
+ * The constructor name is used as the runtime key when restoring
21
+ * entities from their saved dynamic property (e.g. "CLASS_ID").
22
+ *
23
+ * @template T Wrapper type
24
+ * @param Ctor The class constructor to register.
25
+ */
26
+ public registerIClass<T extends any>(Ctor: Ctor<T>): void {
27
+ this._iClassRegistry.set(Ctor.name, Ctor);
28
+ }
29
+
30
+ /**
31
+ * Proxy helper: reads/writes prefer the wrapper instance, otherwise fall back to `source`.
32
+ * @param _instance Wrapper object to proxy (your class instance).
33
+ * @param source Backing object to forward unknown properties/methods to.
34
+ */
35
+ public ProxyConstructor = ((_instance: any, source: any) => {
36
+ return new Proxy(_instance, {
37
+ get: (target, prop) => {
38
+ if (prop in target) return (target as any)[prop];
39
+ const v = (source as any)[prop];
40
+ return typeof v === "function" ? v.bind(source) : v;
41
+ },
42
+
43
+ set: (target, prop, value) => {
44
+ if (prop in target) { (target as any)[prop] = value; return true; }
45
+ (source as any)[prop] = value;
46
+ return true;
47
+ },
48
+
49
+ has: (target, prop) => prop in target || prop in source,
50
+ ownKeys: () => [...Reflect.ownKeys(source), ...Reflect.ownKeys(_instance)],
51
+ getOwnPropertyDescriptor: (_t, prop) => Object.getOwnPropertyDescriptor((prop in _instance ? _instance : source) as any, prop)
52
+ }) as any;
53
+ })
54
+ }
55
+
56
+
57
+
58
+ export const iSystem: ISystem = _ISystem.wrap();