@occultus/toolkit 0.22.2 → 0.22.4
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 +1 -1
- package/src/entity/EntitiesUtils.ts +16 -1
- package/src/entity/entityUtils.ts +29 -1
- package/src/identifier/namespace.ts +24 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -9,7 +9,13 @@ import {
|
|
|
9
9
|
ItemStack
|
|
10
10
|
} from "@minecraft/server";
|
|
11
11
|
import { EffectGroups, EffectData } from "@occultus/common";
|
|
12
|
-
import {
|
|
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
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "@minecraft/server";
|
|
12
12
|
import { EffectData, effectGroupMap, EffectGroups } from "@occultus/common";
|
|
13
13
|
import { OccultusSDKError } from "@occultus/core";
|
|
14
|
+
import { ensureNoNamespace } from "../identifier/namespace";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* 尝试对实体进行操作
|
|
@@ -172,19 +173,27 @@ export function clearEffect(
|
|
|
172
173
|
* 状态效果持续时间,以刻为单位 *(20刻 = 1秒)*
|
|
173
174
|
*
|
|
174
175
|
* 其值必须在范围`[0, 20000000]`内
|
|
176
|
+
*
|
|
177
|
+
* 如果值为`"infinite"`,则状态效果将无限期持续
|
|
175
178
|
* @param options 状态效果选项
|
|
176
179
|
* @since Starock 0.6.0 (0.1.0)
|
|
177
180
|
*/
|
|
178
181
|
export function addEffect(
|
|
179
182
|
entity: Entity,
|
|
180
183
|
effectType: EffectType | EffectType[] | string | string[] | EffectGroups,
|
|
181
|
-
duration: number,
|
|
184
|
+
duration: number | "infinite",
|
|
182
185
|
options?: EntityEffectOptions
|
|
183
186
|
): void {
|
|
184
187
|
const effects =
|
|
185
188
|
effectGroupMap[effectType as EffectGroups] ||
|
|
186
189
|
(Array.isArray(effectType) ? effectType : [effectType]);
|
|
187
190
|
for (const effect of effects) {
|
|
191
|
+
if (duration === "infinite") {
|
|
192
|
+
entity.runCommand(
|
|
193
|
+
`effect @s ${ensureNoNamespace(effect)} infinite ${options?.amplifier ?? 0} ${options?.showParticles ?? false}`
|
|
194
|
+
);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
188
197
|
entity.addEffect(effect, duration, options);
|
|
189
198
|
}
|
|
190
199
|
}
|
|
@@ -276,3 +285,22 @@ export function consumeEquipmentAmount(
|
|
|
276
285
|
if (!item) return false;
|
|
277
286
|
return setEquipmentItem(player, consumeAmount(item, amount));
|
|
278
287
|
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* 恢复实体的生命值
|
|
291
|
+
* @param entity 将要被治疗的实体
|
|
292
|
+
* @param amount 恢复的生命值,若治愈后生命值超过最大生命值,则重置为最大生命值
|
|
293
|
+
* @return 治愈后的生命值
|
|
294
|
+
* @throws 如果实体没有`minecraft:health`组件,则抛出`OccultusSDKError`
|
|
295
|
+
*/
|
|
296
|
+
export function heal(entity: Entity, amount: number): number {
|
|
297
|
+
const health = entity.getComponent("minecraft:health");
|
|
298
|
+
if (!health)
|
|
299
|
+
throw new OccultusSDKError("The entity does not have health component!");
|
|
300
|
+
const newHealth = health.currentValue + amount;
|
|
301
|
+
if (newHealth > health.effectiveMax) {
|
|
302
|
+
health.resetToMaxValue();
|
|
303
|
+
return health.effectiveMax;
|
|
304
|
+
} else health.setCurrentValue(newHealth);
|
|
305
|
+
return newHealth;
|
|
306
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* 确保命名空间存在,若不存在则自动加上`minecraft:`命名空间
|
|
4
|
+
* @param identifier 要检查的标识符
|
|
5
|
+
* @return 存在命名空间的标识符
|
|
6
|
+
*/
|
|
7
|
+
export function ensureNamespace(identifier: string): string {
|
|
8
|
+
if (identifier.includes(":")) {
|
|
9
|
+
return identifier;
|
|
10
|
+
}
|
|
11
|
+
return `minecraft:${identifier}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 确保命名空间**不**存在,若存在则自动去掉命名空间
|
|
16
|
+
* @param identifier 要检查的标识符
|
|
17
|
+
* @return 不存在命名空间的标识符
|
|
18
|
+
*/
|
|
19
|
+
export function ensureNoNamespace(identifier: string): string {
|
|
20
|
+
if (identifier.includes(":")) {
|
|
21
|
+
return identifier.split(":")[1];
|
|
22
|
+
}
|
|
23
|
+
return identifier;
|
|
24
|
+
}
|
package/src/index.ts
CHANGED