@occultus/entity-api
Version:
Star Tenon entity api and utils
30 lines (29 loc) • 785 B
text/typescript
/**
* 存储在方块实体的动态属性中的物品堆栈数据
*
* **IMPORTANT: 由于动态属性的大小限制,将 ItemStack 转换为 ItemStackData 后,物品的部分数据将丢失**
*/
export class ItemStackData {
/**
* @param typeId 物品的 ID
* @param amount 物品数量
* @param damage 物品的损坏值(若有)
*/
constructor(
readonly typeId: string,
readonly amount: number,
readonly damage?: number
) { }
/**
* 将数据转换为字符串类型以方便存储
* @returns 字符串类型的物品堆栈数据
*/
toString(): string {
const data = {
typeId: this.typeId,
amount: this.amount,
damage: this.damage,
};
return JSON.stringify(data);
}
}