diff options
author | mat <github@matdoes.dev> | 2021-12-30 16:18:57 -0600 |
---|---|---|
committer | mat <github@matdoes.dev> | 2021-12-30 16:18:57 -0600 |
commit | 342d31e99d1fbd7bcc941e34bb2a175382f3e26e (patch) | |
tree | c735fa67652d49386d3b55b42567ea3ebd57c5c4 /build/cleaners/skyblock/inventory.js | |
parent | f7d1263ea669968a4b69d80cede9b77f240de4b6 (diff) | |
download | skyblock-api-342d31e99d1fbd7bcc941e34bb2a175382f3e26e.tar.gz skyblock-api-342d31e99d1fbd7bcc941e34bb2a175382f3e26e.tar.bz2 skyblock-api-342d31e99d1fbd7bcc941e34bb2a175382f3e26e.zip |
remove build folder
Diffstat (limited to 'build/cleaners/skyblock/inventory.js')
-rw-r--r-- | build/cleaners/skyblock/inventory.js | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/build/cleaners/skyblock/inventory.js b/build/cleaners/skyblock/inventory.js deleted file mode 100644 index 714a302..0000000 --- a/build/cleaners/skyblock/inventory.js +++ /dev/null @@ -1,83 +0,0 @@ -// maybe todo?: create a fast replacement for prismarine-nbt -import * as nbt from 'prismarine-nbt'; -function base64decode(base64) { - return Buffer.from(base64, 'base64'); -} -function cleanItem(rawItem) { - // if the item doesn't have an id, it isn't an item - if (rawItem.id === undefined) - return null; - const vanillaId = rawItem.id; - const itemCount = rawItem.Count; - const damageValue = rawItem.Damage; - const itemTag = rawItem.tag; - const extraAttributes = itemTag?.ExtraAttributes ?? {}; - let headId; - 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]; - } - } - } - return { - id: extraAttributes?.id ?? null, - count: itemCount ?? 1, - vanillaId: damageValue ? `${vanillaId}:${damageValue}` : vanillaId.toString(), - display: { - name: itemTag?.display?.Name ?? 'null', - lore: itemTag?.display?.Lore ?? [], - // if it has an ench value in the tag, then it should have an enchant glint effect - glint: (itemTag?.ench ?? []).length > 0 - }, - reforge: extraAttributes?.modifier, - enchantments: extraAttributes?.enchantments, - anvil_uses: extraAttributes?.anvil_uses, - timestamp: extraAttributes?.timestamp, - head_texture: headId, - }; -} -function cleanItems(rawItems) { - return rawItems.map(cleanItem); -} -export function cleanInventory(encodedNbt) { - return new Promise(resolve => { - const base64Data = base64decode(encodedNbt); - nbt.parse(base64Data, false, (err, value) => { - const simplifiedNbt = nbt.simplify(value); - // do some basic cleaning on the items and return - resolve(cleanItems(simplifiedNbt.i)); - }); - }); -} -export const INVENTORIES = { - armor: 'inv_armor', - inventory: 'inv_contents', - ender_chest: 'ender_chest_contents', - talisman_bag: 'talisman_bag', - potion_bag: 'potion_bag', - fishing_bag: 'fishing_bag', - quiver: 'quiver', - trick_or_treat_bag: 'candy_inventory_contents', - wardrobe: 'wardrobe_contents' -}; -export async function cleanInventories(data) { - const cleanInventories = {}; - for (const cleanInventoryName in INVENTORIES) { - const hypixelInventoryName = INVENTORIES[cleanInventoryName]; - const encodedInventoryContents = data[hypixelInventoryName]?.data; - let inventoryContents; - if (encodedInventoryContents) { - inventoryContents = await cleanInventory(encodedInventoryContents); - if (cleanInventoryName === 'armor') - // the armor is sent from boots to head, the opposite makes more sense - inventoryContents.reverse(); - cleanInventories[cleanInventoryName] = inventoryContents; - } - } - return cleanInventories; -} |