@occultus/toolkit 0.24.0 → 0.25.0
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/item/item.ts +41 -1
package/package.json
CHANGED
package/src/item/item.ts
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
ItemComponentTypes,
|
|
6
6
|
ItemDurabilityComponent,
|
|
7
7
|
Player,
|
|
8
|
-
GameMode
|
|
8
|
+
GameMode,
|
|
9
|
+
EnchantmentTypeNotCompatibleError
|
|
9
10
|
} from "@minecraft/server";
|
|
10
11
|
import { OccultusSDKError } from "@occultus/core";
|
|
11
12
|
|
|
@@ -96,3 +97,42 @@ export function pushLore(loreText: string, item: ItemStack): ItemStack {
|
|
|
96
97
|
item.setLore(lore);
|
|
97
98
|
return item;
|
|
98
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 迁移物品的附魔数据
|
|
103
|
+
* @param from 附魔数据的源
|
|
104
|
+
* @param to 将会被迁移到的目标
|
|
105
|
+
* @author FangLimao
|
|
106
|
+
* @return void
|
|
107
|
+
*/
|
|
108
|
+
export function migrateEnchantments(from: ItemStack, to: ItemStack): void {
|
|
109
|
+
const [fromCom, toCom] = [
|
|
110
|
+
from.getComponent("minecraft:enchantable"),
|
|
111
|
+
to.getComponent("minecraft:enchantable")
|
|
112
|
+
];
|
|
113
|
+
if (fromCom === undefined || toCom === undefined) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const enchantments = fromCom.getEnchantments().filter((enchantment) =>{
|
|
117
|
+
return toCom.canAddEnchantment(enchantment);
|
|
118
|
+
});
|
|
119
|
+
toCom.addEnchantments(enchantments);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 迁移物品的损坏值
|
|
124
|
+
* @param from 损坏值数据的源
|
|
125
|
+
* @param to 将会被迁移到的目标
|
|
126
|
+
* @author FangLimao
|
|
127
|
+
* @return void
|
|
128
|
+
*/
|
|
129
|
+
export function migrateDamage(from: ItemStack, to: ItemStack): void {
|
|
130
|
+
const [fromCom, toCom] =[
|
|
131
|
+
from.getComponent("minecraft:durability"),
|
|
132
|
+
to.getComponent("minecraft:durability")
|
|
133
|
+
]
|
|
134
|
+
if (fromCom === undefined || toCom === undefined) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
toCom.damage = fromCom.damage;
|
|
138
|
+
}
|