@occultus/toolkit 0.22.2 → 0.22.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@occultus/toolkit",
3
- "version": "0.22.2",
3
+ "version": "0.22.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
@@ -9,7 +9,13 @@ import {
9
9
  ItemStack
10
10
  } from "@minecraft/server";
11
11
  import { EffectGroups, EffectData } from "@occultus/common";
12
- import { addEffect, applyEffectData, clearSlot, giveItem } from "./entityUtils";
12
+ import {
13
+ addEffect,
14
+ applyEffectData,
15
+ clearSlot,
16
+ giveItem,
17
+ heal
18
+ } from "./entityUtils";
13
19
 
14
20
  /**
15
21
  * 适用于批量实体的相关工具
@@ -103,4 +109,13 @@ export class EntitiesUtils {
103
109
  applyEffectData(data: EffectData | EffectData[]): void {
104
110
  return this.query().forEach((entity) => applyEffectData(entity, data));
105
111
  }
112
+ /**
113
+ * 恢复实体的生命值
114
+ * @param amount 恢复的生命值,若治愈后生命值超过最大生命值,则重置为最大生命值
115
+ * @return 治愈后的生命值
116
+ * @throws 如果实体没有`minecraft:health`组件,则抛出`OccultusSDKError`
117
+ */
118
+ heal(amount: number) {
119
+ this.query().forEach((entity) => heal(entity, amount));
120
+ }
106
121
  }
@@ -172,19 +172,27 @@ export function clearEffect(
172
172
  * 状态效果持续时间,以刻为单位 *(20刻 = 1秒)*
173
173
  *
174
174
  * 其值必须在范围`[0, 20000000]`内
175
+ *
176
+ * 如果值为`"infinite"`,则状态效果将无限期持续
175
177
  * @param options 状态效果选项
176
178
  * @since Starock 0.6.0 (0.1.0)
177
179
  */
178
180
  export function addEffect(
179
181
  entity: Entity,
180
182
  effectType: EffectType | EffectType[] | string | string[] | EffectGroups,
181
- duration: number,
183
+ duration: number | "infinite",
182
184
  options?: EntityEffectOptions
183
185
  ): void {
184
186
  const effects =
185
187
  effectGroupMap[effectType as EffectGroups] ||
186
188
  (Array.isArray(effectType) ? effectType : [effectType]);
187
189
  for (const effect of effects) {
190
+ if (duration === "infinite") {
191
+ entity.runCommand(
192
+ `effect @s ${effect} infinite ${options?.amplifier ?? 0} ${options?.showParticles ?? false}`
193
+ );
194
+ return;
195
+ }
188
196
  entity.addEffect(effect, duration, options);
189
197
  }
190
198
  }
@@ -276,3 +284,22 @@ export function consumeEquipmentAmount(
276
284
  if (!item) return false;
277
285
  return setEquipmentItem(player, consumeAmount(item, amount));
278
286
  }
287
+
288
+ /**
289
+ * 恢复实体的生命值
290
+ * @param entity 将要被治疗的实体
291
+ * @param amount 恢复的生命值,若治愈后生命值超过最大生命值,则重置为最大生命值
292
+ * @return 治愈后的生命值
293
+ * @throws 如果实体没有`minecraft:health`组件,则抛出`OccultusSDKError`
294
+ */
295
+ export function heal(entity: Entity, amount: number): number {
296
+ const health = entity.getComponent("minecraft:health");
297
+ if (!health)
298
+ throw new OccultusSDKError("The entity does not have health component!");
299
+ const newHealth = health.currentValue + amount;
300
+ if (newHealth > health.effectiveMax) {
301
+ health.resetToMaxValue();
302
+ return health.effectiveMax;
303
+ } else health.setCurrentValue(newHealth);
304
+ return newHealth;
305
+ }