diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-17 18:42:09 -0500 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-17 18:42:09 -0500 |
commit | e30e548f22c3c23f73498d7827f4ea87640f78b1 (patch) | |
tree | 9251a2ee26f939cf6a51208b082d258eef51242e /src/cleaners/skyblock | |
parent | 14ab63a82d750e897b4db2bd558ebbdb9fa0159c (diff) | |
download | skyblock-api-e30e548f22c3c23f73498d7827f4ea87640f78b1.tar.gz skyblock-api-e30e548f22c3c23f73498d7827f4ea87640f78b1.tar.bz2 skyblock-api-e30e548f22c3c23f73498d7827f4ea87640f78b1.zip |
add head_texture to items
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/inventory.ts | 22 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 117 |
2 files changed, 82 insertions, 57 deletions
diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts index 76acf60..5d72928 100644 --- a/src/cleaners/skyblock/inventory.ts +++ b/src/cleaners/skyblock/inventory.ts @@ -20,7 +20,7 @@ interface Item { timestamp?: string enchantments?: { [ name: string ]: number } - skull_owner?: string + head_texture?: string } export type Inventory = Item[] @@ -34,6 +34,21 @@ function cleanItem(rawItem): Item { const damageValue = rawItem.Damage const itemTag = rawItem.tag const extraAttributes = itemTag?.ExtraAttributes ?? {} + let headId: string + + if (vanillaId === 397) { + const headDataBase64 = itemTag?.SkullOwner?.Properties?.textures?.[0]?.Value + if (extraAttributes?.id === 'LARGE_MINING_SACK') console.log(headDataBase64) + if (headDataBase64) { + const headData = JSON.parse(base64decode(headDataBase64).toString()) + const headDataUrl = headData?.textures?.SKIN?.url + if (headDataUrl) { + const splitUrl = headDataUrl.split('/') + headId = splitUrl[splitUrl.length - 1] + } + } + } + return { id: extraAttributes?.id ?? null, count: itemCount ?? 1, @@ -51,8 +66,7 @@ function cleanItem(rawItem): Item { anvil_uses: extraAttributes?.anvil_uses, timestamp: extraAttributes?.timestamp, - skull_owner: itemTag?.SkullOwner?.Properties?.textures?.[0]?.value ?? undefined, - + head_texture: headId, } } @@ -83,7 +97,7 @@ export const INVENTORIES = { wardrobe: 'wardrobe_contents' } -export type Inventories = { [name in keyof typeof INVENTORIES ]: Inventories } +export type Inventories = { [name in keyof typeof INVENTORIES ]: Item[] } export async function cleanInventories(data: any): Promise<Inventories> { const cleanInventories: any = {} diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index fe86e2e..fb8132f 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -15,79 +15,90 @@ import { CleanRank } from '../rank' import { Bank } from './bank' export interface CleanBasicMember { - uuid: string - username: string - last_save: number - first_join: number - rank: CleanRank + uuid: string + username: string + last_save: number + first_join: number + rank: CleanRank } export interface CleanMember extends CleanBasicMember { - purse: number - stats: StatItem[] - rawHypixelStats?: { [ key: string ]: number } - minions: CleanMinion[] + purse: number + stats: StatItem[] + rawHypixelStats?: { [ key: string ]: number } + minions: CleanMinion[] fairy_souls: FairySouls - inventories: Inventories - objectives: Objective[] - skills: Skill[] - visited_zones: Zone[] - collections: Collection[] - slayers: SlayerData + inventories: Inventories + objectives: Objective[] + skills: Skill[] + visited_zones: Zone[] + collections: Collection[] + slayers: SlayerData } export async function cleanSkyBlockProfileMemberResponseBasic(member: any, included: Included[] = null): Promise<CleanBasicMember> { - const player = await cached.fetchPlayer(member.uuid) - return { - uuid: member.uuid, - username: player.username, - last_save: member.last_save / 1000, - first_join: member.first_join / 1000, - rank: player.rank - } + const player = await cached.fetchPlayer(member.uuid) + return { + uuid: member.uuid, + username: player.username, + last_save: member.last_save / 1000, + first_join: member.first_join / 1000, + rank: player.rank + } } /** Cleans up a member (from skyblock/profile) */ export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> { - // profiles.members[] - const inventoriesIncluded = included == null || included.includes('inventories') - const player = await cached.fetchPlayer(member.uuid) - if (!player) return - return { - uuid: member.uuid, - username: player.username, - last_save: member.last_save / 1000, - first_join: member.first_join / 1000, - rank: player.rank, + // profiles.members[] + const inventoriesIncluded = included == null || included.includes('inventories') + const player = await cached.fetchPlayer(member.uuid) + if (!player) return + return { + uuid: member.uuid, + username: player.username, + last_save: member.last_save / 1000, + first_join: member.first_join / 1000, + rank: player.rank, - purse: member.coin_purse, + purse: member.coin_purse, - stats: cleanProfileStats(member), + stats: cleanProfileStats(member), - // this is used for leaderboards - rawHypixelStats: member.stats ?? {}, + // this is used for leaderboards + rawHypixelStats: member.stats ?? {}, - minions: cleanMinions(member), - fairy_souls: cleanFairySouls(member), - inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, - objectives: cleanObjectives(member), - skills: cleanSkills(member), - visited_zones: cleanVisitedZones(member), - collections: cleanCollections(member), - slayers: cleanSlayers(member) - } + minions: cleanMinions(member), + fairy_souls: cleanFairySouls(member), + inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, + objectives: cleanObjectives(member), + skills: cleanSkills(member), + visited_zones: cleanVisitedZones(member), + collections: cleanCollections(member), + slayers: cleanSlayers(member) + } } export interface CleanMemberProfilePlayer extends CleanPlayer { - // The profile name may be different for each player, so we put it here - profileName: string - first_join: number - last_save: number - bank?: Bank + // The profile name may be different for each player, so we put it here + profileName: string + first_join: number + last_save: number + bank?: Bank + purse?: number + stats?: StatItem[] + rawHypixelStats?: { [ key: string ]: number } + minions?: CleanMinion[] + fairy_souls?: FairySouls + inventories?: Inventories + objectives?: Objective[] + skills?: Skill[] + visited_zones?: Zone[] + collections?: Collection[] + slayers?: SlayerData } export interface CleanMemberProfile { - member: CleanMemberProfilePlayer - profile: CleanFullProfileBasicMembers + member: CleanMemberProfilePlayer + profile: CleanFullProfileBasicMembers } |