simplified-mojang-jsons 0.0.4 → 0.0.6

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.
@@ -7,6 +7,20 @@ import { BehaviorEntityBuilder } from "./EntityBuilder";
7
7
  * @author HaJuegos - 30-09-2026
8
8
  */
9
9
  export declare class FinalEntityBuilderTemplate extends BehaviorEntityBuilder {
10
+ /**
11
+ * Variable general para identificar un valor unico y completo para separar los valores a eliminar de la plantilla base.
12
+ * @type {symbol}
13
+ * @readonly
14
+ * @private
15
+ */
16
+ private readonly removedList;
17
+ /**
18
+ * Variable general para identificar los keys dentro de los eventos generales.
19
+ * @type {string[]}
20
+ * @readonly
21
+ * @private
22
+ */
23
+ private readonly metaKeys;
10
24
  /**
11
25
  * Argumentos principales para la creacion de una entidad a base de una plantilla en concreto.
12
26
  * @param {LoseDefinition} def Los valores definidos de la entidad en la plantilla.
@@ -77,6 +91,24 @@ export declare class FinalEntityBuilderTemplate extends BehaviorEntityBuilder {
77
91
  * @private
78
92
  */
79
93
  private validateEvents;
94
+ /**
95
+ * Metodo auxiliar que comprueba de forma recursiva si un nodo contiene, como subconjunto, todo lo indicado de la mascara. Comparando cada clave.
96
+ * @param {unknown} node Nodo real de la plantilla base a evaluar.
97
+ * @param {unknown} mask Mascara de los valroes que deben estar presentes en el nodo.
98
+ * @returns {boolean} Devuelve true si el nodo contiene una mascara, de lo contrario, sera false.
99
+ * @author HaJuegos - 26-10-2026
100
+ * @private
101
+ */
102
+ private matches;
103
+ /**
104
+ * Metodo auxiliar que elimina de forma no mutante, de un nodo, lo indicado en la mascara. Si la mascara es true se elimina el nodo por completo.
105
+ * @param {unknown} node Nodo real de la plantilla base a cual aplicar los cambios.
106
+ * @param {unknown} mask Mascara que describe lo que se debe eliminar.
107
+ * @returns {unknown} Devuelve el nodo resultante o el simbolo interno removedList si el nodo debe eliminarse por completo.
108
+ * @author HaJuegos - 26-10-2026
109
+ * @private
110
+ */
111
+ private prune;
80
112
  }
81
113
  /**
82
114
  * Funcion principal de fabrica para la creacion de una entidad custom o vanilla a partir de una definicion fija.
@@ -1 +1 @@
1
- {"version":3,"file":"EntityTemplateBuilder.d.ts","sourceRoot":"","sources":["../../../../src/builders/behaviors/entities/EntityTemplateBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,iBAAiB,EAAqD,iBAAiB,EAAE,sBAAsB,EAAE,UAAU,EAAe,cAAc,EAAE,QAAQ,EAAE,MAAM,oDAAoD,CAAC;AAC3R,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,qBAAqB;IACjE;;;;;;OAMG;IACH,YAAa,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EA+E/C;IAED;;;;;OAKG;IACI,UAAU,IAAI,MAAM,CAE1B;IAED;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,QAAQ;IAwBhB;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI;IAcZ;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,SAAS;IAUjB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,cAAc;CAmCzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC1B,KAAK,CAAC,KAAK,SAAS,SAAS,iBAAiB,EAAE,EAChD,KAAK,CAAC,EAAE,SAAS,sBAAsB,EACvC,EAAE,SAAS,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAC9C,GAAG,EAAE,qBAAqB,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,IAEnC,KAAK,CAAC,EAAE,SAAS,SAAS,iBAAiB,EAAE,GAAG,EAAE,EAClD,KAAK,CAAC,EAAE,SAAS,sBAAsB,GAAG,EAAE,SACxC,0BAA0B,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,C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iBAAiB,EAAE,GAAG,EAAE,EAClD,KAAK,CAAC,EAAE,SAAS,sBAAsB,GAAG,EAAE,SACxC,0BAA0B,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,KAAQ,0BAA0B,CAG9F"}
package/dist/index.js CHANGED
@@ -13415,6 +13415,20 @@ var FinalEntityBuilderTemplate = class extends BehaviorEntityBuilder {
13415
13415
  */
13416
13416
  constructor(def, over) {
13417
13417
  super(def.id);
13418
+ /**
13419
+ * Variable general para identificar un valor unico y completo para separar los valores a eliminar de la plantilla base.
13420
+ * @type {symbol}
13421
+ * @readonly
13422
+ * @private
13423
+ */
13424
+ this.removedList = /* @__PURE__ */ Symbol("removed");
13425
+ /**
13426
+ * Variable general para identificar los keys dentro de los eventos generales.
13427
+ * @type {string[]}
13428
+ * @readonly
13429
+ * @private
13430
+ */
13431
+ this.metaKeys = ["weight", "filters", "target", "trigger"];
13418
13432
  const where = `[${def.id}]`;
13419
13433
  if (def.formatVersion) {
13420
13434
  this.setDefaultVersion(def.formatVersion);
@@ -13439,22 +13453,49 @@ var FinalEntityBuilderTemplate = class extends BehaviorEntityBuilder {
13439
13453
  }
13440
13454
  const baseComps = over.clearAllData ? {} : this.byID(def.components, `${where} components`);
13441
13455
  const comps = over.clearAllData ? {} : this.patchMap(baseComps, over.components, `${where} components`);
13456
+ if (!over.clearAllData) {
13457
+ for (const id of over.remove?.components ?? []) {
13458
+ if (!(id in comps)) {
13459
+ throw new Error(`${where} remove.components: "${id}" no existe en la plantilla base.`);
13460
+ }
13461
+ delete comps[id];
13462
+ }
13463
+ }
13442
13464
  this.addUnique(comps, over.add?.components, `${where} add.components`, "components");
13443
13465
  const compsGroups = {};
13444
- if (!over.clearAllData && def.componentsGroups) {
13466
+ if (!over.clearAllData) {
13445
13467
  for (const id of Object.keys(over.componentsGroups ?? {})) {
13446
- if (!(id in def.componentsGroups)) {
13468
+ if (!(id in (def.componentsGroups ?? {}))) {
13447
13469
  throw new Error(`${where} componentsGroups: el grupo "${id}" no existe en la plantilla base. Usa add.componentsGroups para crearlo y a\xF1adirlo a la plantilla base.`);
13448
13470
  }
13449
13471
  }
13450
- for (const [id, list] of Object.entries(def.componentsGroups)) {
13472
+ for (const [id, list] of Object.entries(def.componentsGroups ?? {})) {
13451
13473
  const groupOverride = over.componentsGroups?.[id];
13452
- if (groupOverride == null) {
13474
+ if (groupOverride === null) {
13453
13475
  continue;
13454
13476
  }
13455
- ;
13456
13477
  const path = `${where} componentsGroups."${id}"`;
13457
- compsGroups[id] = this.patchMap(this.byID(list, path), groupOverride, path);
13478
+ const baseGroup = this.byID(list, path);
13479
+ compsGroups[id] = groupOverride ? this.patchMap(baseGroup, groupOverride, path) : baseGroup;
13480
+ }
13481
+ for (const [id, ids] of Object.entries(over.remove?.componentsGroups ?? {})) {
13482
+ const path = `${where} remove.componentsGroups."${id}"`;
13483
+ if (!(id in compsGroups)) {
13484
+ throw new Error(`${path}: el grupo no existe en la plantilla base.`);
13485
+ }
13486
+ if (!Array.isArray(ids) || ids.length == 0) {
13487
+ delete compsGroups[id];
13488
+ continue;
13489
+ }
13490
+ for (const compId of ids) {
13491
+ if (!(compId in compsGroups[id])) {
13492
+ throw new Error(`${path}: el componente "${compId}" no existe en el grupo.`);
13493
+ }
13494
+ delete compsGroups[id][compId];
13495
+ }
13496
+ if (Object.keys(compsGroups[id]).length == 0) {
13497
+ delete compsGroups[id];
13498
+ }
13458
13499
  }
13459
13500
  }
13460
13501
  for (const [id, list] of Object.entries(over.add?.componentsGroups ?? {})) {
@@ -13463,13 +13504,26 @@ var FinalEntityBuilderTemplate = class extends BehaviorEntityBuilder {
13463
13504
  }
13464
13505
  const baseEvents = over.clearAllData ? {} : this.patchMap(def.events, over.events, `${where} events`, BPEntityDefaultEventsNames);
13465
13506
  const events = { ...baseEvents };
13507
+ if (!over.clearAllData) {
13508
+ for (const [name, mask] of Object.entries(over.remove?.events ?? {})) {
13509
+ if (!(name in events)) {
13510
+ throw new Error(`${where} remove.events: el evento "${name}" no existe en la plantilla base.`);
13511
+ }
13512
+ const res = mask === true || Object.keys(mask).length == 0 ? this.removedList : this.prune(events[name], mask);
13513
+ if (res === this.removedList) {
13514
+ delete events[name];
13515
+ } else {
13516
+ events[name] = res;
13517
+ }
13518
+ }
13519
+ }
13466
13520
  for (const [name, event] of Object.entries(over.add?.events ?? {})) {
13467
13521
  if (!over.clearAllData && name in events) {
13468
13522
  throw new Error(`${where} add.events: el evento "${name}" ya existe en la plantilla base. Usa events para reemplazarlo de la plantilla base.`);
13469
13523
  }
13470
13524
  events[name] = event;
13471
13525
  }
13472
- this.validateEvents(events, Object.keys(compsGroups), where);
13526
+ this.validateEvents(events, Object.keys(compsGroups), where, !def.id.startsWith("minecraft:"));
13473
13527
  this.setDefaultComponents(Object.values(comps));
13474
13528
  this.setDefaultComponentGroups(Object.fromEntries(Object.entries(compsGroups).map(([id, g]) => [id, Object.values(g)])));
13475
13529
  this.setDefaultEvents(events);
@@ -13570,7 +13624,7 @@ var FinalEntityBuilderTemplate = class extends BehaviorEntityBuilder {
13570
13624
  * @author HaJuegos - 01-10-2026
13571
13625
  * @private
13572
13626
  */
13573
- validateEvents(events, groups, where) {
13627
+ validateEvents(events, groups, where, strict) {
13574
13628
  const walk = (node, event) => {
13575
13629
  if (Array.isArray(node)) {
13576
13630
  node.forEach((item) => walk(item, event));
@@ -13583,7 +13637,7 @@ var FinalEntityBuilderTemplate = class extends BehaviorEntityBuilder {
13583
13637
  const names = value?.componentGroups;
13584
13638
  if ((key == "add" || key == "remove") && Array.isArray(names)) {
13585
13639
  names.forEach((name, i) => {
13586
- if (!groups.includes(name)) {
13640
+ if (strict && !groups.includes(name)) {
13587
13641
  throw new Error(`${where} events."${event}".${key}: el grupo "${name}" no existe. Disponibles: ${groups.join(", ") || "(ninguno)"}.`);
13588
13642
  }
13589
13643
  if (names.indexOf(name) != i) {
@@ -13599,6 +13653,70 @@ var FinalEntityBuilderTemplate = class extends BehaviorEntityBuilder {
13599
13653
  walk(event, name);
13600
13654
  }
13601
13655
  }
13656
+ /**
13657
+ * Metodo auxiliar que comprueba de forma recursiva si un nodo contiene, como subconjunto, todo lo indicado de la mascara. Comparando cada clave.
13658
+ * @param {unknown} node Nodo real de la plantilla base a evaluar.
13659
+ * @param {unknown} mask Mascara de los valroes que deben estar presentes en el nodo.
13660
+ * @returns {boolean} Devuelve true si el nodo contiene una mascara, de lo contrario, sera false.
13661
+ * @author HaJuegos - 26-10-2026
13662
+ * @private
13663
+ */
13664
+ matches(node, mask) {
13665
+ if (Array.isArray(mask)) {
13666
+ return Array.isArray(node) && mask.every((m) => node.some((n) => this.matches(n, m)));
13667
+ }
13668
+ if (mask && typeof mask == "object") {
13669
+ return !!node && typeof node == "object" && !Array.isArray(node) && Object.entries(mask).every(([k, v]) => k in node && this.matches(node[k], v));
13670
+ }
13671
+ return node === mask;
13672
+ }
13673
+ /**
13674
+ * Metodo auxiliar que elimina de forma no mutante, de un nodo, lo indicado en la mascara. Si la mascara es true se elimina el nodo por completo.
13675
+ * @param {unknown} node Nodo real de la plantilla base a cual aplicar los cambios.
13676
+ * @param {unknown} mask Mascara que describe lo que se debe eliminar.
13677
+ * @returns {unknown} Devuelve el nodo resultante o el simbolo interno removedList si el nodo debe eliminarse por completo.
13678
+ * @author HaJuegos - 26-10-2026
13679
+ * @private
13680
+ */
13681
+ prune(node, mask) {
13682
+ if (mask === true) {
13683
+ return this.removedList;
13684
+ }
13685
+ if (Array.isArray(node) && Array.isArray(mask)) {
13686
+ const out = [];
13687
+ for (const item of node) {
13688
+ let current = item;
13689
+ for (const m of mask) {
13690
+ if (current === this.removedList) {
13691
+ break;
13692
+ }
13693
+ if (current && typeof current == "object" ? this.matches(current, m) : current === m) {
13694
+ current = typeof m == "object" && m != null ? this.prune(current, m) : this.removedList;
13695
+ }
13696
+ }
13697
+ if (current !== this.removedList) {
13698
+ out.push(current);
13699
+ }
13700
+ }
13701
+ return out.length ? out : this.removedList;
13702
+ }
13703
+ if (node && mask && typeof node == "object" && typeof mask == "object" && !Array.isArray(node) && !Array.isArray(mask)) {
13704
+ const out = { ...node };
13705
+ for (const [key, sub] of Object.entries(mask)) {
13706
+ if (!(key in out) || this.metaKeys.includes(key)) {
13707
+ continue;
13708
+ }
13709
+ const res = this.prune(out[key], sub);
13710
+ if (res === this.removedList) {
13711
+ delete out[key];
13712
+ } else {
13713
+ out[key] = res;
13714
+ }
13715
+ }
13716
+ return Object.keys(out).every((k) => this.metaKeys.includes(k)) ? this.removedList : out;
13717
+ }
13718
+ return node;
13719
+ }
13602
13720
  };
13603
13721
  function createBPEntity(def) {
13604
13722
  return (over = {}) => {