aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock
diff options
context:
space:
mode:
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r--src/cleaners/skyblock/collections.ts113
-rw-r--r--src/cleaners/skyblock/inventory.ts4
-rw-r--r--src/cleaners/skyblock/itemId.ts73
-rw-r--r--src/cleaners/skyblock/member.ts7
4 files changed, 193 insertions, 4 deletions
diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts
new file mode 100644
index 0000000..a70d7b8
--- /dev/null
+++ b/src/cleaners/skyblock/collections.ts
@@ -0,0 +1,113 @@
+import { cleanItemId, cleanItemNames, hypixelItemNames } from "./itemId"
+
+const COLLECTIONS = {
+ 'farming': [
+ 'wheat',
+ 'carrot',
+ 'potato',
+ 'pumpkin',
+ 'melon_slice',
+ 'wheat_seeds',
+ 'red_mushroom',
+ 'cocoa_beans',
+ 'cactus',
+ 'sugar_cane',
+ 'feather',
+ 'leather',
+ 'porkchop',
+ 'chicken',
+ 'mutton',
+ 'rabbit',
+ 'nether_wart'
+ ],
+ 'mining': [
+ 'cobblestone',
+ 'coal',
+ 'iron_ingot',
+ 'gold_ingot',
+ 'diamond',
+ 'lapis_lazuli',
+ 'emerald',
+ 'redstone',
+ 'quartz',
+ 'obsidian',
+ 'glowstone_dust',
+ 'gravel',
+ 'ice',
+ 'netherrack',
+ 'sand',
+ 'end_stone'
+ ],
+ 'combat': [
+ 'rotten_flesh',
+ 'bone',
+ 'string',
+ 'spider_eye',
+ 'gunpowder',
+ 'ender_pearl',
+ 'ghast_tear',
+ 'slime_ball',
+ 'blaze_rod',
+ 'magma_cream'
+ ],
+ 'foraging': [
+ 'oak_log',
+ 'spruce_log',
+ 'birch_log',
+ 'jungle_log',
+ 'acacia_log',
+ 'dark_oak_log'
+ ],
+ 'fishing': [
+ 'cod',
+ 'salmon',
+ 'tropical_fish',
+ 'pufferfish',
+ 'prismarine_shard',
+ 'prismarine_crystals',
+ 'clay_ball',
+ 'lily_pad',
+ 'ink_sac',
+ 'sponge'
+ ]
+} as const
+
+export interface Collection {
+ name: string
+ xp: number
+ level: number
+}
+
+export function cleanCollections(data: any): Collection[] {
+ // collection tiers show up like this: [ GRAVEL_3, GOLD_INGOT_2, MELON_-1, LOG_2:1_7, RAW_FISH:3_-1]
+ // these tiers are the same for all players in a coop
+ const playerCollectionTiersRaw: string[] = data?.unlocked_coll_tiers ?? []
+ const playerCollectionTiers: { [ key: string ]: number } = {}
+
+ for (const collectionTierNameValueRaw of playerCollectionTiersRaw) {
+ const [ collectionTierNameRaw, collectionTierValueRaw ] = collectionTierNameValueRaw.split(/_(?=-?\d+$)/)
+ const collectionName = cleanItemId(collectionTierNameRaw)
+ // ensure it's at least 0
+ const collectionValue: number = Math.max(parseInt(collectionTierValueRaw), 0)
+
+ // if the collection hasn't been checked yet, or the new value is higher than the old, replace it
+ if (!playerCollectionTiers[collectionName] || collectionValue > playerCollectionTiers[collectionName])
+ playerCollectionTiers[collectionName] = collectionValue
+ }
+
+ // collection names show up like this: { LOG: 49789, LOG:2: 26219, MUSHROOM_COLLECTION: 2923}
+ // these values are different for each player in a coop
+ const playerCollectionValuesRaw: { [ key in hypixelItemNames ]: number } = data?.collection ?? {}
+ const playerCollectionValues: Collection[] = []
+
+ for (const collectionNameRaw in playerCollectionValuesRaw) {
+ const collectionValue: number = playerCollectionValuesRaw[collectionNameRaw]
+ const collectionName = cleanItemId(collectionNameRaw)
+ playerCollectionValues.push({
+ name: collectionName,
+ xp: collectionValue,
+ level: playerCollectionTiers[collectionName]
+ })
+ }
+ return playerCollectionValues
+} \ No newline at end of file
diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts
index 96cd629..ed9b5ed 100644
--- a/src/cleaners/skyblock/inventory.ts
+++ b/src/cleaners/skyblock/inventory.ts
@@ -21,7 +21,6 @@ interface Item {
enchantments?: { [ name: string ]: number }
skull_owner?: string
-
}
export type Inventory = Item[]
@@ -29,7 +28,8 @@ export type Inventory = Item[]
function cleanItem(rawItem): Item {
// if the item doesn't have an id, it isn't an item
if (rawItem.id === undefined) return null
- const vanillaId: number = rawItem.id && -1
+
+ const vanillaId: number = rawItem.id
const itemCount = rawItem.Count
const damageValue = rawItem.Damage
const itemTag = rawItem.tag
diff --git a/src/cleaners/skyblock/itemId.ts b/src/cleaners/skyblock/itemId.ts
new file mode 100644
index 0000000..20bea06
--- /dev/null
+++ b/src/cleaners/skyblock/itemId.ts
@@ -0,0 +1,73 @@
+// change weird item names to be more consistent with vanilla
+const ITEMS = {
+ 'log': 'oak_log',
+ 'log:1': 'spruce_log',
+ 'log:2': 'birch_log',
+ 'log:3': 'jungle_log',
+ 'log_2': 'acacia_log',
+ 'log_2:1': 'dark_oak_log',
+
+ 'ink_sack': 'ink_sac',
+ 'ink_sack:3': 'cocoa_beans',
+ 'ink_sack:4': 'lapis_lazuli',
+
+ 'cocoa': 'cocoa_beans',
+
+ 'raw_fish': 'cod',
+ 'raw_fish:1': 'salmon',
+ 'raw_fish:2': 'tropical_fish',
+ 'raw_fish:3': 'pufferfish',
+
+ 'raw_salmon': 'salmon',
+ 'cooked_fish': 'cooked_cod',
+
+ 'seeds': 'wheat_seeds',
+ 'sulphur': 'gunpowder',
+ 'raw_chicken': 'chicken',
+ 'pork': 'porkchop',
+ 'potato_item': 'potato',
+ 'carrot_item': 'carrot',
+ 'mushroom_collection': 'red_mushroom',
+ 'nether_stalk': 'nether_wart',
+ 'water_lily': 'lily_pad',
+ 'melon': 'melon_slice',
+ 'ender_stone': 'end_stone',
+
+ 'huge_mushroom_1': 'red_mushroom_block',
+ 'huge_mushroom_2': 'brown_mushroom_block',
+
+ 'iron_ingot': 'iron_ingot',
+
+ 'iron': 'iron_ingot',
+ 'gold': 'gold_ingot',
+
+ 'endstone': 'end_stone',
+ 'lapis_lazuli_block': 'lapis_block',
+ 'snow_ball': 'snowball',
+ 'raw_beef': 'beef',
+ 'eye_of_ender': 'ender_eye',
+ 'grilled_pork': 'cooked_porkchop',
+ 'glistering_melon': 'glistering_melon_slice',
+ 'cactus_green': 'green_dye',
+
+ 'enchanted_lapis_lazuli': 'enchanted_lapis_lazuli',
+ 'enchanted_potato': 'enchanted_potato',
+ 'enchanted_birch_log': 'enchanted_birch_log',
+ 'enchanted_gunpowder': 'enchanted_gunpowder',
+ 'enchanted_raw_salmon': 'enchanted_salmon',
+ 'enchanted_raw_chicken': 'enchanted_chicken',
+ 'enchanted_water_lily': 'enchanted_lily_pad',
+ 'enchanted_ink_sack': 'enchanted_ink_sac',
+ 'enchanted_melon': 'enchanted_melon_slice',
+ 'enchanted_glistering_melon': 'enchanted_glistering_melon_slice'
+} as const
+
+/** Weirdly named items by Hypixel */
+export type hypixelItemNames = keyof typeof ITEMS
+/** Cleaner names by us */
+export type cleanItemNames = (typeof ITEMS)[keyof typeof ITEMS]
+
+/** Clean an item with a weird name (log_2:1) and make it have a better name (dark_oak_log) */
+export function cleanItemId(itemId: string): cleanItemNames {
+ return ITEMS[itemId.toLowerCase()] ?? itemId.toLowerCase()
+}
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts
index e7e6250..f0d2cec 100644
--- a/src/cleaners/skyblock/member.ts
+++ b/src/cleaners/skyblock/member.ts
@@ -1,5 +1,5 @@
import { CleanProfileStats, cleanProfileStats } from './stats'
-import { cleanInventories, Inventories, INVENTORIES } from './inventory'
+import { cleanInventories, Inventories } from './inventory'
import { cleanFairySouls, FairySouls } from './fairysouls'
import { cleanObjectives, Objective } from './objectives'
import { CleanMinion, cleanMinions } from './minions'
@@ -10,6 +10,7 @@ import { Included } from '../../hypixel'
import { CleanPlayer } from '../player'
import { Bank } from './bank'
import { cleanVisitedZones, Zone } from './zones'
+import { cleanCollections, Collection } from './collections'
export interface CleanBasicMember {
uuid: string
@@ -27,6 +28,7 @@ export interface CleanMember extends CleanBasicMember {
objectives: Objective[]
skills: Skill[]
visited_zones: Zone[]
+ collections: Collection[]
}
export async function cleanSkyBlockProfileMemberResponseBasic(member, included: Included[] = null): Promise<CleanBasicMember> {
@@ -56,7 +58,8 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu
inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
objectives: cleanObjectives(member),
skills: cleanSkills(member),
- visited_zones: cleanVisitedZones(member)
+ visited_zones: cleanVisitedZones(member),
+ collections: cleanCollections(member)
}
}