@occultus/toolkit 0.22.3 → 0.23.1
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 +2 -2
- package/src/entity/entityUtils.ts +2 -1
- package/src/identifier/namespace.ts +24 -0
- package/src/index.ts +2 -0
- package/src/item/cooldown.ts +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@occultus/common": "0.20.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"typedoc": "^0.28.
|
|
33
|
+
"typedoc": "^0.28.16"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "tsc"
|
|
@@ -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
|
* 尝试对实体进行操作
|
|
@@ -189,7 +190,7 @@ export function addEffect(
|
|
|
189
190
|
for (const effect of effects) {
|
|
190
191
|
if (duration === "infinite") {
|
|
191
192
|
entity.runCommand(
|
|
192
|
-
`effect @s ${effect} infinite ${options?.amplifier ?? 0} ${options?.showParticles ?? false}`
|
|
193
|
+
`effect @s ${ensureNoNamespace(effect)} infinite ${options?.amplifier ?? 0} ${options?.showParticles ?? false}`
|
|
193
194
|
);
|
|
194
195
|
return;
|
|
195
196
|
}
|
|
@@ -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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ItemStack, Player } from "@minecraft/server";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 返回物品是否处于冷却状态
|
|
5
|
+
* @param item 要检查的物品
|
|
6
|
+
* @param player 持有物品的玩家
|
|
7
|
+
* @return 是否处于冷却状态
|
|
8
|
+
*/
|
|
9
|
+
export function isInCooldown(item: ItemStack, player: Player): boolean {
|
|
10
|
+
const cooldown = item.getComponent("minecraft:cooldown");
|
|
11
|
+
if (!cooldown) return false;
|
|
12
|
+
return cooldown.getCooldownTicksRemaining(player) !== 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 让物品开始冷却
|
|
17
|
+
* @param item 要执行冷却操作的物品
|
|
18
|
+
* @param player 持有物品的玩家
|
|
19
|
+
* @return 是否成功执行冷却操作,若物品不支持冷却则返回`false`
|
|
20
|
+
*/
|
|
21
|
+
export function startCooldown(item: ItemStack, player: Player): boolean {
|
|
22
|
+
const cooldown = item.getComponent("minecraft:cooldown");
|
|
23
|
+
if (!cooldown) return false;
|
|
24
|
+
cooldown.startCooldown(player);
|
|
25
|
+
return true;
|
|
26
|
+
}
|