aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-23 14:50:27 -0500
committermat <github@matdoes.dev>2022-04-23 14:50:27 -0500
commit3a8393deb2f057e9b9601f23dc53b23913160e13 (patch)
tree27ebec4b7747c747c7b31a1652495fc9f5ab01e8 /src/cleaners/skyblock
parentae55726abe66ef29fe410dc02e04db1bf6e99735 (diff)
downloadskyblock-api-3a8393deb2f057e9b9601f23dc53b23913160e13.tar.gz
skyblock-api-3a8393deb2f057e9b9601f23dc53b23913160e13.tar.bz2
skyblock-api-3a8393deb2f057e9b9601f23dc53b23913160e13.zip
return better skin id in item list
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r--src/cleaners/skyblock/inventory.ts20
-rw-r--r--src/cleaners/skyblock/itemList.ts3
2 files changed, 14 insertions, 9 deletions
diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts
index 9e5ee29..6be87c8 100644
--- a/src/cleaners/skyblock/inventory.ts
+++ b/src/cleaners/skyblock/inventory.ts
@@ -27,6 +27,16 @@ interface Item {
export type Inventory = Item[]
+export function headIdFromBase64(headDataBase64: string): string | undefined {
+ const headData = JSON.parse(base64decode(headDataBase64).toString())
+ const headDataUrl = headData?.textures?.SKIN?.url
+ if (headDataUrl) {
+ const splitUrl = headDataUrl.split('/')
+ return splitUrl[splitUrl.length - 1]
+ }
+ return undefined
+}
+
function cleanItem(rawItem): Item | null {
// if the item doesn't have an id, it isn't an item
if (rawItem.id === undefined) return null
@@ -40,14 +50,8 @@ function cleanItem(rawItem): Item | null {
if (vanillaId === 397) {
const headDataBase64 = itemTag?.SkullOwner?.Properties?.textures?.[0]?.Value
- 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]
- }
- }
+ if (headDataBase64)
+ headId = headIdFromBase64(headDataBase64)
}
return {
diff --git a/src/cleaners/skyblock/itemList.ts b/src/cleaners/skyblock/itemList.ts
index 3d1cdce..3a166e3 100644
--- a/src/cleaners/skyblock/itemList.ts
+++ b/src/cleaners/skyblock/itemList.ts
@@ -1,4 +1,5 @@
import typedHypixelApi from 'typed-hypixel-api'
+import { headIdFromBase64 } from './inventory.js'
export interface ItemRequirement {
// idk what these do
@@ -42,7 +43,7 @@ function cleanItemListItem(item: typedHypixelApi.SkyBlockItemsResponse['items'][
const vanillaId = item.material.toLowerCase()
return {
id: item.id,
- headTexture: (item.material === 'SKULL_ITEM' && 'skin' in item) ? item.skin : undefined,
+ headTexture: (item.material === 'SKULL_ITEM' && 'skin' in item) ? headIdFromBase64(item.skin) : undefined,
vanillaId: item.durability ? `${vanillaId}:${item.durability}` : vanillaId,
tier: item.tier ?? null,
display: {