Skip to content

Commit

Permalink
fix: axes missing in farming tools (#1885)
Browse files Browse the repository at this point in the history
* fix: axes missing in farming tools

* style: `npm run prettier:fix`

* refactor: move line
  • Loading branch information
DuckySoLucky authored Mar 7, 2023
1 parent c503f5a commit 566da95
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/constants/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,20 @@ export const TYPE_TO_CATEGORIES = {
deployable: ["deployable"],
"trophy fish": ["trophy_fish"],
};

export const ENCHANTMENTS_TO_CATEGORIES = {
farming_tool: [
"delicate",
"harvesting",
"cultivating",
"replenish",
"turbo_cacti",
"turbo_cane",
"turbo_carrot",
"turbo_mushrooms",
"turbo_potato",
"turbo_warts",
"turbo_wheat",
"sunder",
],
};
18 changes: 14 additions & 4 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
RARITY_COLORS,
HOTM,
TYPE_TO_CATEGORIES,
ENCHANTMENTS_TO_CATEGORIES,
PET_DATA,
PET_RARITY_OFFSET,
PET_LEVELS,
Expand Down Expand Up @@ -915,7 +916,7 @@ export function convertHMS(seconds, format = "clock", alwaysTwoDigits = false) {
}
}

export function parseItemTypeFromLore(lore) {
export function parseItemTypeFromLore(lore, item) {
const regex = new RegExp(
`^(?<recomb>a )?(?<shiny>SHINY )?(?:(?<rarity>${RARITIES.map((x) => x.replaceAll("_", " ").toUpperCase()).join(
"|"
Expand Down Expand Up @@ -947,7 +948,7 @@ export function parseItemTypeFromLore(lore) {
// Parsing the match and returning data
const r = match.groups;
return {
categories: r.type ? getCategoriesFromType(r.type.trim().toLowerCase()) : [],
categories: r.type ? getCategories(r.type.trim().toLowerCase(), item) : [],
rarity: r.rarity.replaceAll(" ", "_").toLowerCase(),
recombobulated: !!r.recomb && !!r.recomb2,
dungeon: !!r.dungeon,
Expand Down Expand Up @@ -997,8 +998,17 @@ export function getCacheFilePath(dirPath, type, name, format = "png") {
return path.resolve(dirPath, `${subdirs.join("/")}/${type}_${name}.${format}`);
}

function getCategoriesFromType(type) {
return TYPE_TO_CATEGORIES[type] ?? ["unknown"];
function getCategories(type, item) {
const categories = [];

const enchantments = item?.tag?.ExtraAttributes?.enchantments || {};
Object.keys(enchantments).forEach((enchantment) =>
Object.entries(ENCHANTMENTS_TO_CATEGORIES).forEach(
([category, enchantmentList]) => enchantmentList.includes(enchantment) && categories.push(category)
)
);

return [...new Set(categories.concat(TYPE_TO_CATEGORIES[type]))];
}

export function generateDebugPets(type = "ALL") {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ async function processItems(base64, source, customTextures = false, packs, cache

if (lore.length > 0) {
// item categories, rarity, recombobulated, dungeon, shiny
const itemType = helper.parseItemTypeFromLore(lore);
const itemType = helper.parseItemTypeFromLore(lore, item);

for (const key in itemType) {
item[key] = itemType[key];
Expand Down

0 comments on commit 566da95

Please sign in to comment.