@occultus/toolkit 0.23.3 → 0.23.5
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/LICENSE +9 -9
- package/README.md +30 -30
- package/package.json +1 -1
- package/src/entity/EntitiesUtils.ts +121 -121
- package/src/entity/entityUtils.ts +327 -367
- package/src/entity/health.ts +71 -0
- package/src/identifier/namespace.ts +23 -23
- package/src/index.ts +10 -9
- package/src/item/container.ts +227 -227
- package/src/item/cooldown.ts +26 -26
- package/src/item/item.ts +98 -98
- package/tsconfig.json +21 -21
package/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright © 2025 CTN Studios
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 CTN Studios
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
# Star Tenon Toolkit
|
|
2
|
-
|
|
3
|
-
一个轻量的 API 工具包,包括一些常用的工具函数,可用于实体以及 ItemStack。
|
|
4
|
-
|
|
5
|
-
## 支持版本
|
|
6
|
-
|
|
7
|
-
本 API 支持任意可以运行 Script API v2.0.0+ 的游戏版本,包括:
|
|
8
|
-
|
|
9
|
-
- 1.21.90;
|
|
10
|
-
- 1.21.100;
|
|
11
|
-
- 1.21.110;
|
|
12
|
-
- 以及更多……
|
|
13
|
-
|
|
14
|
-
注意:本包理论上可以在部分更旧的版本上运作,但未经过严格的测试。
|
|
15
|
-
|
|
16
|
-
## 协议
|
|
17
|
-
|
|
18
|
-
本项目使用 MIT License 授权:
|
|
19
|
-
|
|
20
|
-
```text
|
|
21
|
-
The MIT License (MIT)
|
|
22
|
-
|
|
23
|
-
Copyright © 2025 CTN Studios
|
|
24
|
-
|
|
25
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
26
|
-
|
|
27
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
28
|
-
|
|
29
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
-
```
|
|
1
|
+
# Star Tenon Toolkit
|
|
2
|
+
|
|
3
|
+
一个轻量的 API 工具包,包括一些常用的工具函数,可用于实体以及 ItemStack。
|
|
4
|
+
|
|
5
|
+
## 支持版本
|
|
6
|
+
|
|
7
|
+
本 API 支持任意可以运行 Script API v2.0.0+ 的游戏版本,包括:
|
|
8
|
+
|
|
9
|
+
- 1.21.90;
|
|
10
|
+
- 1.21.100;
|
|
11
|
+
- 1.21.110;
|
|
12
|
+
- 以及更多……
|
|
13
|
+
|
|
14
|
+
注意:本包理论上可以在部分更旧的版本上运作,但未经过严格的测试。
|
|
15
|
+
|
|
16
|
+
## 协议
|
|
17
|
+
|
|
18
|
+
本项目使用 MIT License 授权:
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
The MIT License (MIT)
|
|
22
|
+
|
|
23
|
+
Copyright © 2025 CTN Studios
|
|
24
|
+
|
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
26
|
+
|
|
27
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
```
|
package/package.json
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Dimension,
|
|
3
|
-
EntityQueryOptions,
|
|
4
|
-
Entity,
|
|
5
|
-
EntityApplyDamageByProjectileOptions,
|
|
6
|
-
EntityApplyDamageOptions,
|
|
7
|
-
EffectType,
|
|
8
|
-
EntityEffectOptions,
|
|
9
|
-
ItemStack
|
|
10
|
-
} from "@minecraft/server";
|
|
11
|
-
import { EffectGroups, EffectData } from "@occultus/common";
|
|
12
|
-
import {
|
|
13
|
-
addEffect,
|
|
14
|
-
applyEffectData,
|
|
15
|
-
clearSlot,
|
|
16
|
-
giveItem,
|
|
17
|
-
heal
|
|
18
|
-
} from "./entityUtils";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 适用于批量实体的相关工具
|
|
22
|
-
* @since Starock 0.6.0 (0.1.0)
|
|
23
|
-
* @example
|
|
24
|
-
* new EntitiesUtils(world.getDimension("overworld"), {
|
|
25
|
-
* type: "minecraft:player",
|
|
26
|
-
* }).damage(10);
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
export class EntitiesUtils {
|
|
30
|
-
/**
|
|
31
|
-
* @param dimension 实体所在的维度
|
|
32
|
-
* @param queryOption 查询实体的选项
|
|
33
|
-
*/
|
|
34
|
-
constructor(
|
|
35
|
-
public dimension: Dimension,
|
|
36
|
-
public queryOption: EntityQueryOptions
|
|
37
|
-
) {}
|
|
38
|
-
/**
|
|
39
|
-
* 查询给定条件下的实体
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
query(): Entity[] {
|
|
43
|
-
return this.dimension.getEntities(this.queryOption);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 尝试对实体进行操作
|
|
47
|
-
* @param operate 操作函数,接受一个实体作为参数
|
|
48
|
-
*/
|
|
49
|
-
tryOperateEntity(operate: (entity: Entity) => void) {
|
|
50
|
-
this.query().forEach((entity) => {
|
|
51
|
-
if (entity.isValid) {
|
|
52
|
-
operate(entity);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 对批量实体进行伤害
|
|
58
|
-
* @param amount 施加的伤害量
|
|
59
|
-
* @param options 关于伤害来源的额外选项,可能会增加额外的效果或造成受伤实体的额外行为
|
|
60
|
-
* @since Starock 0.6.0 (0.1.0)
|
|
61
|
-
*/
|
|
62
|
-
applyDamage(
|
|
63
|
-
amount: number,
|
|
64
|
-
options?: EntityApplyDamageByProjectileOptions | EntityApplyDamageOptions
|
|
65
|
-
) {
|
|
66
|
-
this.query().forEach((entity) => entity.applyDamage(amount, options));
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 为批量实体添加效果
|
|
70
|
-
*
|
|
71
|
-
* @param effectType 效果的类型
|
|
72
|
-
* @param duration
|
|
73
|
-
* 效果持续时间,以刻为单位 *(20刻=1秒)*
|
|
74
|
-
*
|
|
75
|
-
* 其值必须在范围`[0, 20000000]`内
|
|
76
|
-
* @param effectOption 可选参数,状态效果的具体配置选项
|
|
77
|
-
* @since Starock 0.6.0 (0.1.0)
|
|
78
|
-
*/
|
|
79
|
-
addEffect(
|
|
80
|
-
effectType: EffectType | EffectType[] | string | string[] | EffectGroups,
|
|
81
|
-
duration: number,
|
|
82
|
-
effectOption?: EntityEffectOptions
|
|
83
|
-
) {
|
|
84
|
-
this.query().forEach((entity) =>
|
|
85
|
-
addEffect(entity, effectType, duration, effectOption)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 批量给予实体物品
|
|
90
|
-
* @param entity 要给予物品的实体
|
|
91
|
-
* @param item 要给予的物品
|
|
92
|
-
* @since Starock 0.6.0 (0.1.0)
|
|
93
|
-
*/
|
|
94
|
-
giveItem(item: ItemStack) {
|
|
95
|
-
this.query().forEach((entity) => giveItem(entity, item));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 批量清空实体的容器
|
|
99
|
-
* @since Starock 0.6.0 (0.1.0)
|
|
100
|
-
*/
|
|
101
|
-
clearSlot(): void {
|
|
102
|
-
this.query().forEach((entity) => clearSlot(entity));
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 批量为实体应用 {@link EffectData }
|
|
106
|
-
* @param data 要应用的 {@link EffectData }
|
|
107
|
-
* @returns
|
|
108
|
-
*/
|
|
109
|
-
applyEffectData(data: EffectData | EffectData[]): void {
|
|
110
|
-
return this.query().forEach((entity) => applyEffectData(entity, data));
|
|
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
|
-
}
|
|
121
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Dimension,
|
|
3
|
+
EntityQueryOptions,
|
|
4
|
+
Entity,
|
|
5
|
+
EntityApplyDamageByProjectileOptions,
|
|
6
|
+
EntityApplyDamageOptions,
|
|
7
|
+
EffectType,
|
|
8
|
+
EntityEffectOptions,
|
|
9
|
+
ItemStack
|
|
10
|
+
} from "@minecraft/server";
|
|
11
|
+
import { EffectGroups, EffectData } from "@occultus/common";
|
|
12
|
+
import {
|
|
13
|
+
addEffect,
|
|
14
|
+
applyEffectData,
|
|
15
|
+
clearSlot,
|
|
16
|
+
giveItem,
|
|
17
|
+
heal
|
|
18
|
+
} from "./entityUtils";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 适用于批量实体的相关工具
|
|
22
|
+
* @since Starock 0.6.0 (0.1.0)
|
|
23
|
+
* @example
|
|
24
|
+
* new EntitiesUtils(world.getDimension("overworld"), {
|
|
25
|
+
* type: "minecraft:player",
|
|
26
|
+
* }).damage(10);
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export class EntitiesUtils {
|
|
30
|
+
/**
|
|
31
|
+
* @param dimension 实体所在的维度
|
|
32
|
+
* @param queryOption 查询实体的选项
|
|
33
|
+
*/
|
|
34
|
+
constructor(
|
|
35
|
+
public dimension: Dimension,
|
|
36
|
+
public queryOption: EntityQueryOptions
|
|
37
|
+
) {}
|
|
38
|
+
/**
|
|
39
|
+
* 查询给定条件下的实体
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
query(): Entity[] {
|
|
43
|
+
return this.dimension.getEntities(this.queryOption);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 尝试对实体进行操作
|
|
47
|
+
* @param operate 操作函数,接受一个实体作为参数
|
|
48
|
+
*/
|
|
49
|
+
tryOperateEntity(operate: (entity: Entity) => void) {
|
|
50
|
+
this.query().forEach((entity) => {
|
|
51
|
+
if (entity.isValid) {
|
|
52
|
+
operate(entity);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 对批量实体进行伤害
|
|
58
|
+
* @param amount 施加的伤害量
|
|
59
|
+
* @param options 关于伤害来源的额外选项,可能会增加额外的效果或造成受伤实体的额外行为
|
|
60
|
+
* @since Starock 0.6.0 (0.1.0)
|
|
61
|
+
*/
|
|
62
|
+
applyDamage(
|
|
63
|
+
amount: number,
|
|
64
|
+
options?: EntityApplyDamageByProjectileOptions | EntityApplyDamageOptions
|
|
65
|
+
) {
|
|
66
|
+
this.query().forEach((entity) => entity.applyDamage(amount, options));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 为批量实体添加效果
|
|
70
|
+
*
|
|
71
|
+
* @param effectType 效果的类型
|
|
72
|
+
* @param duration
|
|
73
|
+
* 效果持续时间,以刻为单位 *(20刻=1秒)*
|
|
74
|
+
*
|
|
75
|
+
* 其值必须在范围`[0, 20000000]`内
|
|
76
|
+
* @param effectOption 可选参数,状态效果的具体配置选项
|
|
77
|
+
* @since Starock 0.6.0 (0.1.0)
|
|
78
|
+
*/
|
|
79
|
+
addEffect(
|
|
80
|
+
effectType: EffectType | EffectType[] | string | string[] | EffectGroups,
|
|
81
|
+
duration: number,
|
|
82
|
+
effectOption?: EntityEffectOptions
|
|
83
|
+
) {
|
|
84
|
+
this.query().forEach((entity) =>
|
|
85
|
+
addEffect(entity, effectType, duration, effectOption)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 批量给予实体物品
|
|
90
|
+
* @param entity 要给予物品的实体
|
|
91
|
+
* @param item 要给予的物品
|
|
92
|
+
* @since Starock 0.6.0 (0.1.0)
|
|
93
|
+
*/
|
|
94
|
+
giveItem(item: ItemStack) {
|
|
95
|
+
this.query().forEach((entity) => giveItem(entity, item));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 批量清空实体的容器
|
|
99
|
+
* @since Starock 0.6.0 (0.1.0)
|
|
100
|
+
*/
|
|
101
|
+
clearSlot(): void {
|
|
102
|
+
this.query().forEach((entity) => clearSlot(entity));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 批量为实体应用 {@link EffectData }
|
|
106
|
+
* @param data 要应用的 {@link EffectData }
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
applyEffectData(data: EffectData | EffectData[]): void {
|
|
110
|
+
return this.query().forEach((entity) => applyEffectData(entity, data));
|
|
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
|
+
}
|
|
121
|
+
}
|