aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-14 14:07:10 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-14 14:07:10 -0600
commiteedd4ff7a3f2816c8e0d3f037c7a1acbb5988495 (patch)
tree39a5e242c360f735e28889da22187b9471ed8dc1
parenta12f0eaf3349160282bdc9f48cf9f253a154e500 (diff)
downloadskyblock-api-eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495.tar.gz
skyblock-api-eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495.tar.bz2
skyblock-api-eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495.zip
add collections
-rw-r--r--build/cleaners/skyblock/collections.js106
-rw-r--r--build/cleaners/skyblock/inventory.js2
-rw-r--r--build/cleaners/skyblock/itemId.js62
-rw-r--r--build/cleaners/skyblock/member.js4
-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
8 files changed, 365 insertions, 6 deletions
diff --git a/build/cleaners/skyblock/collections.js b/build/cleaners/skyblock/collections.js
new file mode 100644
index 0000000..def7140
--- /dev/null
+++ b/build/cleaners/skyblock/collections.js
@@ -0,0 +1,106 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.cleanCollections = void 0;
+const itemId_1 = require("./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'
+ ]
+};
+function cleanCollections(data) {
+ var _a, _b;
+ // 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 = (_a = data === null || data === void 0 ? void 0 : data.unlocked_coll_tiers) !== null && _a !== void 0 ? _a : [];
+ const playerCollectionTiers = {};
+ for (const collectionTierNameValueRaw of playerCollectionTiersRaw) {
+ const [collectionTierNameRaw, collectionTierValueRaw] = collectionTierNameValueRaw.split(/_(?=-?\d+$)/);
+ const collectionName = itemId_1.cleanItemId(collectionTierNameRaw);
+ // ensure it's at least 0
+ const collectionValue = 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 = (_b = data === null || data === void 0 ? void 0 : data.collection) !== null && _b !== void 0 ? _b : {};
+ const playerCollectionValues = [];
+ for (const collectionNameRaw in playerCollectionValuesRaw) {
+ const collectionValue = playerCollectionValuesRaw[collectionNameRaw];
+ const collectionName = itemId_1.cleanItemId(collectionNameRaw);
+ playerCollectionValues.push({
+ name: collectionName,
+ xp: collectionValue,
+ level: playerCollectionTiers[collectionName]
+ });
+ }
+ return playerCollectionValues;
+}
+exports.cleanCollections = cleanCollections;
diff --git a/build/cleaners/skyblock/inventory.js b/build/cleaners/skyblock/inventory.js
index c0c54ba..6892c6e 100644
--- a/build/cleaners/skyblock/inventory.js
+++ b/build/cleaners/skyblock/inventory.js
@@ -29,7 +29,7 @@ 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 && -1;
+ const vanillaId = rawItem.id;
const itemCount = rawItem.Count;
const damageValue = rawItem.Damage;
const itemTag = rawItem.tag;
diff --git a/build/cleaners/skyblock/itemId.js b/build/cleaners/skyblock/itemId.js
new file mode 100644
index 0000000..7bf5402
--- /dev/null
+++ b/build/cleaners/skyblock/itemId.js
@@ -0,0 +1,62 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.cleanItemId = void 0;
+// 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'
+};
+/** Clean an item with a weird name (log_2:1) and make it have a better name (dark_oak_log) */
+function cleanItemId(itemId) {
+ var _a;
+ return (_a = ITEMS[itemId.toLowerCase()]) !== null && _a !== void 0 ? _a : itemId.toLowerCase();
+}
+exports.cleanItemId = cleanItemId;
diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js
index bf1f908..41092e1 100644
--- a/build/cleaners/skyblock/member.js
+++ b/build/cleaners/skyblock/member.js
@@ -28,6 +28,7 @@ const minions_1 = require("./minions");
const skills_1 = require("./skills");
const cached = __importStar(require("../../hypixelCached"));
const zones_1 = require("./zones");
+const collections_1 = require("./collections");
async function cleanSkyBlockProfileMemberResponseBasic(member, included = null) {
return {
uuid: member.uuid,
@@ -53,7 +54,8 @@ async function cleanSkyBlockProfileMemberResponse(member, included = null) {
inventories: inventoriesIncluded ? await inventory_1.cleanInventories(member) : undefined,
objectives: objectives_1.cleanObjectives(member),
skills: skills_1.cleanSkills(member),
- visited_zones: zones_1.cleanVisitedZones(member)
+ visited_zones: zones_1.cleanVisitedZones(member),
+ collections: collections_1.cleanCollections(member)
};
}
exports.cleanSkyBlockProfileMemberResponse = cleanSkyBlockProfileMemberResponse;
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)
}
}