diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 17:11:00 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-13 17:11:00 -0600 |
commit | 987fb43f5f0a724918c4e6094de08cdfbcb2ddf6 (patch) | |
tree | 4753c68bf60742fa79983f673da335c1bf9715d9 /src/cleaners/skyblock/inventory.ts | |
parent | 5c9ef89af1ee9af380ea82072a3a48d5db0f2c7a (diff) | |
download | skyblock-api-987fb43f5f0a724918c4e6094de08cdfbcb2ddf6.tar.gz skyblock-api-987fb43f5f0a724918c4e6094de08cdfbcb2ddf6.tar.bz2 skyblock-api-987fb43f5f0a724918c4e6094de08cdfbcb2ddf6.zip |
add inventories
Diffstat (limited to 'src/cleaners/skyblock/inventory.ts')
-rw-r--r-- | src/cleaners/skyblock/inventory.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts new file mode 100644 index 0000000..ac36d88 --- /dev/null +++ b/src/cleaners/skyblock/inventory.ts @@ -0,0 +1,41 @@ +import * as nbt from 'prismarine-nbt' + +function base64decode(base64: string): Buffer { + return Buffer.from(base64, 'base64') +} + +export function cleanInventory(encodedNbt: string): Promise<any> { + return new Promise(resolve => { + const base64Data = base64decode(encodedNbt) + nbt.parse(base64Data, false, (err, value) => { + const simplifiedNbt = nbt.simplify(value) + // .i because hypixel decided to do that + resolve(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: any): Promise<typeof INVENTORIES> { + const cleanInventories: any = {} + for (const cleanInventoryName in INVENTORIES) { + const hypixelInventoryName = INVENTORIES[cleanInventoryName] + const encodedInventoryContents = data[hypixelInventoryName]?.data + let inventoryContents + if (encodedInventoryContents) + inventoryContents = await cleanInventory(encodedInventoryContents) + cleanInventories[cleanInventoryName] = inventoryContents + } + return cleanInventories +}
\ No newline at end of file |