simplified-mojang-api 0.0.25 → 0.0.26

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.
@@ -35,19 +35,23 @@ declare class CustomEventsSimplified {
35
35
  */
36
36
  manualDamageItem(ply: mc.Player, item: mc.ItemStack): void;
37
37
  /**
38
- * Metodo auxiliar que simplifica la logica de detectar en el inventario del jugador, si tiene uno o varios items en concreto.
38
+ * Metodo auxiliar que simplifica la logica de detectar en el inventario del jugador, si tiene uno o varios items en concreto de forma explicita o no.
39
39
  * @param {mc.Player} plySource Jugador en cuestion.
40
40
  * @param {(string | string[] | vanilla.MinecraftItemTypes | vanilla.MinecraftItemTypes[] )} itemsToDetect Item o items a buscar.
41
+ * @param {boolean?} exactItems (Opcional) Busca explicitamente el nombre del item palabra por palabra. Por defecto esta apagado, entonces buscara items sin importar si tienen diferencias. Por ej: Si se busca 'diamond'; minecraft:diamond y minecraft:diamond_sword serian true.
41
42
  * @returns {boolean} Devuelve true en caso de tener ese item, sino, sera false.
42
43
  * @author HaJuegos - 18-03-2026
43
44
  * @public
44
45
  * @example
45
46
  * ```ts
46
- * // Esto es true si el jugador tiene un item en su inventario.
47
- * customEventsManager.plyHasItems(player, vanilla.MinecraftItemTypes.TotemOfUndying);
47
+ * // Esto es true si el jugador tiene un item llamado totem o mas de forma no explicita.
48
+ * customEventsManager.plyHasItems(player, 'totem');
49
+ *
50
+ * // Esto es true si el jugador tiene un totem de la inmortalidad de forma explicita.
51
+ * customEventsManager.plyHasItems(player, vanilla.MinecraftItemTypes.TotemOfUndying, true);
48
52
  * ```
49
53
  */
50
- plyHasItems(plySource: mc.Player, itemsToDetect: string | string[] | vanilla.MinecraftItemTypes | vanilla.MinecraftItemTypes[]): boolean;
54
+ plyHasItems(plySource: mc.Player, itemsToDetect: string | string[] | vanilla.MinecraftItemTypes | vanilla.MinecraftItemTypes[], exactItems?: boolean): boolean;
51
55
  /**
52
56
  * Metodo auxiliar que simplifica loa logica al detectar el uso de un totem en un jugaodor, ejecutando los eventos relacionados.
53
57
  * @param {(ply: mc.Player) => void} callback Los eventos relacionados a ejecutar.
@@ -69,6 +69,8 @@ class CustomEventsSimplified {
69
69
  * ```
70
70
  */
71
71
  manualDamageItem(ply, item) {
72
+ if (ply.getGameMode() != (mc.GameMode.Adventure || mc.GameMode.Survival))
73
+ return;
72
74
  const invPly = ply.getComponent(mc.EntityComponentTypes.Inventory)?.container;
73
75
  const slot = ply.selectedSlotIndex;
74
76
  const newItem = item.clone();
@@ -94,27 +96,34 @@ class CustomEventsSimplified {
94
96
  }
95
97
  ;
96
98
  /**
97
- * Metodo auxiliar que simplifica la logica de detectar en el inventario del jugador, si tiene uno o varios items en concreto.
99
+ * Metodo auxiliar que simplifica la logica de detectar en el inventario del jugador, si tiene uno o varios items en concreto de forma explicita o no.
98
100
  * @param {mc.Player} plySource Jugador en cuestion.
99
101
  * @param {(string | string[] | vanilla.MinecraftItemTypes | vanilla.MinecraftItemTypes[] )} itemsToDetect Item o items a buscar.
102
+ * @param {boolean?} exactItems (Opcional) Busca explicitamente el nombre del item palabra por palabra. Por defecto esta apagado, entonces buscara items sin importar si tienen diferencias. Por ej: Si se busca 'diamond'; minecraft:diamond y minecraft:diamond_sword serian true.
100
103
  * @returns {boolean} Devuelve true en caso de tener ese item, sino, sera false.
101
104
  * @author HaJuegos - 18-03-2026
102
105
  * @public
103
106
  * @example
104
107
  * ```ts
105
- * // Esto es true si el jugador tiene un item en su inventario.
106
- * customEventsManager.plyHasItems(player, vanilla.MinecraftItemTypes.TotemOfUndying);
108
+ * // Esto es true si el jugador tiene un item llamado totem o mas de forma no explicita.
109
+ * customEventsManager.plyHasItems(player, 'totem');
110
+ *
111
+ * // Esto es true si el jugador tiene un totem de la inmortalidad de forma explicita.
112
+ * customEventsManager.plyHasItems(player, vanilla.MinecraftItemTypes.TotemOfUndying, true);
107
113
  * ```
108
114
  */
109
- plyHasItems(plySource, itemsToDetect) {
115
+ plyHasItems(plySource, itemsToDetect, exactItems = false) {
110
116
  const invPly = plySource.getComponent(mc.EntityComponentTypes.Inventory)?.container;
111
117
  const armorPly = plySource.getComponent(mc.EntityComponentTypes.Equippable);
112
118
  const targetItems = Array.isArray(itemsToDetect) ? itemsToDetect : [itemsToDetect];
113
119
  if (invPly) {
114
120
  for (let i = 0; i < invPly.size; i++) {
115
121
  const item = invPly.getItem(i);
116
- if (item && targetItems.some((target) => item.typeId.includes(target))) {
117
- return true;
122
+ if (item) {
123
+ const itemFound = !exactItems ? targetItems.some((target) => item.typeId.includes(target)) : targetItems.some((target) => item.typeId == target);
124
+ if (itemFound) {
125
+ return true;
126
+ }
118
127
  }
119
128
  }
120
129
  }
@@ -128,8 +137,11 @@ class CustomEventsSimplified {
128
137
  ];
129
138
  for (const slot of equipmentSlots) {
130
139
  const item = armorPly.getEquipment(slot);
131
- if (item && targetItems.some((target) => item.typeId.includes(target))) {
132
- return true;
140
+ if (item) {
141
+ const itemFound = !exactItems ? targetItems.some((target) => item.typeId.includes(target)) : targetItems.some((target) => item.typeId == target);
142
+ if (itemFound) {
143
+ return true;
144
+ }
133
145
  }
134
146
  }
135
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplified-mojang-api",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "About Public repository to simplify the event logic of Mojang's Script API, for informal or professional use",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",