@occultus/toolkit 0.22.0 → 0.22.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 +5 -5
- package/src/entity/EntitiesUtils.ts +2 -4
- package/src/entity/entityUtils.ts +18 -16
- package/src/index.ts +4 -4
- package/src/item/container.ts +48 -0
- package/src/item/item.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/toolkit",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"author": "CTN Studios",
|
|
25
25
|
"dependencies": {},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@minecraft/server": "
|
|
28
|
-
"@minecraft/server-ui": "
|
|
29
|
-
"@occultus/core": "
|
|
27
|
+
"@minecraft/server": "^2.4.0",
|
|
28
|
+
"@minecraft/server-ui": "^2.0.0",
|
|
29
|
+
"@occultus/core": "~0.18.4",
|
|
30
30
|
"@occultus/common": "0.20.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"typedoc": "^0.28.
|
|
33
|
+
"typedoc": "^0.28.15"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "tsc"
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
EntityApplyDamageOptions,
|
|
7
7
|
EffectType,
|
|
8
8
|
EntityEffectOptions,
|
|
9
|
-
ItemStack
|
|
9
|
+
ItemStack
|
|
10
10
|
} from "@minecraft/server";
|
|
11
11
|
import { EffectGroups, EffectData } from "@occultus/common";
|
|
12
12
|
import { addEffect, applyEffectData, clearSlot, giveItem } from "./entityUtils";
|
|
@@ -101,8 +101,6 @@ export class EntitiesUtils {
|
|
|
101
101
|
* @returns
|
|
102
102
|
*/
|
|
103
103
|
applyEffectData(data: EffectData | EffectData[]): void {
|
|
104
|
-
return this.query().forEach((entity) =>
|
|
105
|
-
applyEffectData(entity, data)
|
|
106
|
-
);
|
|
104
|
+
return this.query().forEach((entity) => applyEffectData(entity, data));
|
|
107
105
|
}
|
|
108
106
|
}
|
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
Effect,
|
|
4
4
|
EffectType,
|
|
5
5
|
Entity,
|
|
6
|
+
EntityComponentTypes,
|
|
6
7
|
EntityEffectOptions,
|
|
7
8
|
EntityEquippableComponent,
|
|
8
9
|
EquipmentSlot,
|
|
9
10
|
ItemStack,
|
|
10
|
-
Player
|
|
11
|
+
Player
|
|
11
12
|
} from "@minecraft/server";
|
|
12
13
|
import { EffectData, effectGroupMap, EffectGroups } from "@occultus/common";
|
|
13
14
|
import { OccultusSDKError } from "@occultus/core";
|
|
@@ -32,9 +33,10 @@ export function tryOperateEntity(
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
+
* 获取给定**玩家**的指定装备槽物品 {@see EquipmentSlot}
|
|
37
|
+
*
|
|
38
|
+
* 注意:该方法仅适用于玩家实体
|
|
36
39
|
*
|
|
37
|
-
* **IMPORTANT: 受原版接口限制, 当前只能获取玩家的装备**
|
|
38
40
|
* @param entity 要获取槽位的实体
|
|
39
41
|
* @param slot 要获取的槽位,默认为 {@link EquipmentSlot.Mainhand}
|
|
40
42
|
* @return 槽位中的物品
|
|
@@ -44,16 +46,16 @@ export function getEquipmentItem(
|
|
|
44
46
|
entity: Entity,
|
|
45
47
|
slot = EquipmentSlot.Mainhand
|
|
46
48
|
): ItemStack | undefined {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return equipment?.getEquipment(slot);
|
|
49
|
+
return entity
|
|
50
|
+
?.getComponent(EntityComponentTypes.Equippable)
|
|
51
|
+
?.getEquipment(slot);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
+
* 设置给定**玩家**的指定装备槽物品 {@see EquipmentSlot}
|
|
56
|
+
*
|
|
57
|
+
* 注意:该方法仅适用于玩家实体
|
|
55
58
|
*
|
|
56
|
-
* **IMPORTANT: 受原版接口限制, 当前只能获取玩家的装备**
|
|
57
59
|
* @param entity 要设置槽位的实体
|
|
58
60
|
* @param item 要设置的物品,如果为undefined则清空该槽位
|
|
59
61
|
* @param slot 要设置的槽位,默认为 {@link EquipmentSlot.Mainhand}
|
|
@@ -64,11 +66,11 @@ export function setEquipmentItem(
|
|
|
64
66
|
item?: ItemStack,
|
|
65
67
|
slot: EquipmentSlot = EquipmentSlot.Mainhand
|
|
66
68
|
): boolean {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
return (
|
|
70
|
+
entity
|
|
71
|
+
?.getComponent(EntityComponentTypes.Equippable)
|
|
72
|
+
?.setEquipment(slot, item) ?? false
|
|
73
|
+
);
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
/**
|
|
@@ -79,7 +81,7 @@ export function setEquipmentItem(
|
|
|
79
81
|
* @since Starock 0.6.0 (0.1.0)
|
|
80
82
|
*/
|
|
81
83
|
export function getContainer(entity: Entity): Container | undefined {
|
|
82
|
-
return entity.getComponent(
|
|
84
|
+
return entity.getComponent(EntityComponentTypes.Inventory)?.container;
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
/**
|
|
@@ -140,7 +142,7 @@ export function applyEffectData(
|
|
|
140
142
|
return data.flatMap((effectData) => {
|
|
141
143
|
return entity.addEffect(effectData.effectType, effectData.duration, {
|
|
142
144
|
amplifier: effectData.amplifier,
|
|
143
|
-
showParticles: effectData.showParticles
|
|
145
|
+
showParticles: effectData.showParticles
|
|
144
146
|
});
|
|
145
147
|
});
|
|
146
148
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module toolkit
|
|
3
3
|
*/
|
|
4
|
-
export * from "./entity/EntitiesUtils"
|
|
5
|
-
export * from "./entity/entityUtils"
|
|
6
|
-
export * from "./item/item"
|
|
7
|
-
export * from "./item/container"
|
|
4
|
+
export * from "./entity/EntitiesUtils";
|
|
5
|
+
export * from "./entity/entityUtils";
|
|
6
|
+
export * from "./item/item";
|
|
7
|
+
export * from "./item/container";
|
package/src/item/container.ts
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
import { Container, ItemStack } from "@minecraft/server";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 获取容器中指定含指定物品标签的物品的数量
|
|
5
|
+
* @param container 容器对象
|
|
6
|
+
* @param tag 要获取的物品标签
|
|
7
|
+
* @returns 容器中指定物品的数量
|
|
8
|
+
* @author RawDiamondMC, FangLiulii
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export function getTagItemAmountInContainer(
|
|
12
|
+
container: Container,
|
|
13
|
+
tag: string
|
|
14
|
+
): number {
|
|
15
|
+
let amount = 0;
|
|
16
|
+
for (let slot = 0; slot < container.size; slot++) {
|
|
17
|
+
const itemStack: undefined | ItemStack = container.getItem(slot);
|
|
18
|
+
if (itemStack?.hasTag(tag)) {
|
|
19
|
+
amount += itemStack.amount;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return amount;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 从容器中移除指定数量的含有特定标签的物品
|
|
27
|
+
* @param container 容器对象
|
|
28
|
+
* @param tag 物品标签
|
|
29
|
+
* @param amount 要移除物品的数量
|
|
30
|
+
* @author RawDiamondMC, FangLiulii
|
|
31
|
+
*/
|
|
32
|
+
export function removeTagItemInContainer(
|
|
33
|
+
container: Container,
|
|
34
|
+
tag: string,
|
|
35
|
+
amount: number
|
|
36
|
+
): void {
|
|
37
|
+
for (let slot = 0; slot < container.size; slot++) {
|
|
38
|
+
const itemStack: undefined | ItemStack = container.getItem(slot);
|
|
39
|
+
if (itemStack?.hasTag(tag)) {
|
|
40
|
+
if (itemStack.amount > amount) {
|
|
41
|
+
itemStack.amount -= amount;
|
|
42
|
+
container.setItem(slot, itemStack);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
container.setItem(slot);
|
|
46
|
+
amount -= itemStack.amount;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
3
51
|
/**
|
|
4
52
|
* 获取容器中指定物品的数量
|
|
5
53
|
* @param container 容器对象
|
package/src/item/item.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ItemComponentTypes,
|
|
6
6
|
ItemDurabilityComponent,
|
|
7
7
|
Player,
|
|
8
|
-
GameMode
|
|
8
|
+
GameMode
|
|
9
9
|
} from "@minecraft/server";
|
|
10
10
|
import { OccultusSDKError } from "@occultus/core";
|
|
11
11
|
|
|
@@ -48,6 +48,10 @@ export function consumeDurability(
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* 消耗物品的数量
|
|
51
|
+
*
|
|
52
|
+
* 注意!这个函数不会直接修改传入的物品堆,而是返回一个新的物品堆。在原版,直接修改物品堆的数量不会正确同步,需要重新设定。
|
|
53
|
+
* F**K U Mojang
|
|
54
|
+
*
|
|
51
55
|
* @param item 要消耗物品的数量
|
|
52
56
|
* @param value 要消耗的数量
|
|
53
57
|
* @returns 消耗后的物品堆
|