diff --git a/bin/generate-infobook-html.ts b/bin/generate-infobook-html.ts index d0edc76..ffe08da 100644 --- a/bin/generate-infobook-html.ts +++ b/bin/generate-infobook-html.ts @@ -6,7 +6,7 @@ import { InfoBookAppendixHandlerAdvancementRewards, } from "../lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards"; import {InfoBookAppendixHandlerCraftingRecipe} from "../lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe"; -import {InfoBookAppendixHandlerFurnaceRecipe} from "../lib/infobook/appendix/InfoBookAppendixHandlerFurnaceRecipe"; +import {InfoBookAppendixHandlerSmeltingRecipe} from "../lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe"; import {InfoBookAppendixHandlerImage} from "../lib/infobook/appendix/InfoBookAppendixHandlerImage"; import {InfoBookAppendixHandlerKeybinding} from "../lib/infobook/appendix/InfoBookAppendixHandlerKeybinding"; import {IInfoBook} from "../lib/infobook/IInfoBook"; @@ -67,11 +67,10 @@ async function create() { const infoBookInitializer = new InfoBookInitializer(config); infoBookInitializer.registerAppendixHandler('advancement_rewards', new InfoBookAppendixHandlerAdvancementRewards(resourceLoader.getResourceHandler())); - infoBookInitializer.registerAppendixHandler('crafting_recipe', - new InfoBookAppendixHandlerCraftingRecipe(resourceLoader.getResourceHandler(), - 'registries', config.recipeOverrides, config.recipePredefineds)); - infoBookInitializer.registerAppendixHandler('furnace_recipe', - new InfoBookAppendixHandlerFurnaceRecipe(resourceLoader.getResourceHandler(), 'registries')); + infoBookInitializer.registerAppendixHandler('minecraft:crafting', + new InfoBookAppendixHandlerCraftingRecipe(resourceLoader.getResourceHandler(), 'registries', config.recipeOverrides)); + infoBookInitializer.registerAppendixHandler('minecraft:smelting', + new InfoBookAppendixHandlerSmeltingRecipe(resourceLoader.getResourceHandler(), 'registries', config.recipeOverrides)); infoBookInitializer.registerAppendixHandler('image', new InfoBookAppendixHandlerImage(resourceLoader.getResourceHandler())); infoBookInitializer.registerAppendixHandler('keybinding', diff --git a/index.ts b/index.ts index fdf8400..a8cbc1b 100644 --- a/index.ts +++ b/index.ts @@ -1,8 +1,9 @@ export * from "./lib/infobook/appendix/IInfoBookAppendixHandler"; export * from "./lib/infobook/appendix/InfoBookAppendixAd"; +export * from "./lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe"; export * from "./lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards"; export * from "./lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe"; -export * from "./lib/infobook/appendix/InfoBookAppendixHandlerFurnaceRecipe"; +export * from "./lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe"; export * from "./lib/infobook/appendix/InfoBookAppendixHandlerImage"; export * from "./lib/infobook/appendix/InfoBookAppendixHandlerKeybinding"; export * from "./lib/infobook/appendix/InfoBookAppendixTagIndex"; diff --git a/lib/infobook/IItem.ts b/lib/infobook/IItem.ts index 98f3801..b3071c9 100644 --- a/lib/infobook/IItem.ts +++ b/lib/infobook/IItem.ts @@ -1,6 +1,5 @@ export interface IItem { item: string; - data: number; count?: number; nbt?: string; } diff --git a/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.ts b/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.ts new file mode 100644 index 0000000..8b18e45 --- /dev/null +++ b/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.ts @@ -0,0 +1,77 @@ +import * as fs from "fs"; +import {ResourceHandler} from "../../resource/ResourceHandler"; +import {HtmlInfoBookSerializer, ISerializeContext} from "../../serialize/HtmlInfoBookSerializer"; +import {IFileWriter} from "../IFileWriter"; +import {IInfoAppendix} from "../IInfoAppendix"; +import {IInfoBookAppendixHandler} from "./IInfoBookAppendixHandler"; +import {join} from "path"; + +/** + * Handles abstract recipe appendices. + */ +export abstract class InfoBookAppendixHandlerAbstractRecipe implements IInfoBookAppendixHandler { + + protected readonly id: string; + protected readonly resourceHandler: ResourceHandler; + protected readonly registry: IRecipeRegistryIndexed; + + constructor(id: string, resourceHandler: ResourceHandler, registriesPath: string, recipeOverrides: any) { + this.id = id; + this.resourceHandler = resourceHandler; + this.registry = InfoBookAppendixHandlerAbstractRecipe.indexRegistry(JSON.parse(fs.readFileSync(join(registriesPath, id.replace(/:/g, '__') + '.json'), "utf8"))); + if (recipeOverrides) { + this.registry = { ... this.registry, ...(recipeOverrides[id] || {}) }; + } + } + + public static indexRegistry(registryRead: IRecipeRegistryRead) : IRecipeRegistryIndexed { + const index: IRecipeRegistryIndexed = {}; + for (const recipe of registryRead.recipes) { + index[recipe.id] = recipe; + } + return index; + } + + public createAppendix(data: any): IInfoAppendix { + const recipeId = data._; + let recipes: R[] = []; + if (recipeId.includes('*')) { + const recipeRegex = new RegExp(recipeId); + for (const [k, v] of Object.entries(this.registry)) { + if (recipeRegex.exec(k)) { + recipes.push(v); + } + } + } else if (this.registry[recipeId]) { + recipes = [ this.registry[recipeId] ]; + } + if (recipes.length === 0) { + throw new Error(`Could not find ${this.id} recipe for ${recipeId}`); + } + + return { + getName: (context) => this.resourceHandler.getTranslation(this.getRecipeNameUnlocalized(), context.language), + toHtml: (context: ISerializeContext, fileWriter: IFileWriter, serializer: HtmlInfoBookSerializer) => { + return recipes.map((recipe) => this.serializeRecipe(recipe, context, fileWriter, serializer)).join('
'); + }, + }; + } + + protected abstract getRecipeNameUnlocalized(): string; + + protected abstract serializeRecipe(recipe: R, context: ISerializeContext, + fileWriter: IFileWriter, serializer: HtmlInfoBookSerializer): string; + +} + +export interface IRecipeRegistryRead { + recipes: [R]; +} + +export interface IRecipeRegistryIndexed { + [id: string]: R; +} + +export interface IRecipe { + id: string; +} diff --git a/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.ts b/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.ts index 2174d05..c1dc7fb 100644 --- a/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.ts +++ b/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.ts @@ -32,8 +32,7 @@ export class InfoBookAppendixHandlerAdvancementRewards implements IInfoBookAppen throw new Error(`Unknown achievement reward type '${rewardTag.$.type}'`); } const count = rewardTag.$.amount; - const meta = rewardTag.$.meta || 0; - rewardsData.push({ item: rewardTag._, data: meta, count }); + rewardsData.push({ item: rewardTag._, count }); } return { diff --git a/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.ts b/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.ts index 6d9d768..3739d6b 100644 --- a/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.ts +++ b/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.ts @@ -1,85 +1,30 @@ -import * as fs from "fs"; -import {join} from "path"; import {compileFile as compilePug, compileTemplate} from "pug"; import {ResourceHandler} from "../../resource/ResourceHandler"; import {HtmlInfoBookSerializer, ISerializeContext} from "../../serialize/HtmlInfoBookSerializer"; import {IFileWriter} from "../IFileWriter"; -import {IInfoAppendix} from "../IInfoAppendix"; import {IItem} from "../IItem"; -import {IInfoBookAppendixHandler} from "./IInfoBookAppendixHandler"; +import { + InfoBookAppendixHandlerAbstractRecipe, + IRecipe, +} from "./InfoBookAppendixHandlerAbstractRecipe"; /** * Handles crafting recipe appendices. */ -export class InfoBookAppendixHandlerCraftingRecipe implements IInfoBookAppendixHandler { +export class InfoBookAppendixHandlerCraftingRecipe extends InfoBookAppendixHandlerAbstractRecipe { - private readonly resourceHandler: ResourceHandler; - private readonly registry: IRecipeRegistry; - private readonly registryTagged: {[tag: string]: IRecipe[]}; - private readonly recipePredefineds: IRecipePredefineds; private readonly templateCraftingRecipe: compileTemplate; - constructor(resourceHandler: ResourceHandler, registriesPath: string, recipeOverrides: any, - recipePredefineds: IRecipePredefineds) { - this.resourceHandler = resourceHandler; - this.registry = JSON.parse(fs.readFileSync(join(registriesPath, 'crafting_recipe.json'), "utf8")); - if (recipeOverrides) { - this.registry = { ... this.registry, ...recipeOverrides }; - } - this.recipePredefineds = recipePredefineds; - this.registryTagged = {}; - for (const recipeId in this.registry) { - for (const recipe of this.registry[recipeId]) { - for (const tag of recipe.tags) { - let recipes = this.registryTagged[tag]; - if (!recipes) { - recipes = this.registryTagged[tag] = []; - } - recipes.push(recipe); - } - } - } + constructor(resourceHandler: ResourceHandler, registriesPath: string, recipeOverrides: any) { + super('minecraft:crafting', resourceHandler, registriesPath, recipeOverrides); this.templateCraftingRecipe = compilePug(__dirname + '/../../../template/appendix/crafting_recipe.pug'); } - public createAppendix(data: any): IInfoAppendix { - let index = data.$.index || 0; - // const meta = data.$.meta || 0; - // const count = data.$.count || 1; - const outputName = data._; - let recipes: IRecipe[]; - if (data.$.predefined) { - const predefined = this.recipePredefineds[outputName]; - if (!predefined) { - throw new Error(`Could not find any predefined recipe for ${outputName}`); - } - recipes = [predefined]; - } else { - recipes = this.registry[outputName]; - if (!recipes) { - recipes = this.registryTagged['crafting_recipe:' + outputName]; - index = -1; - } - } - if (!recipes) { - throw new Error(`Could not find any recipe for ${outputName}`); - } - if (index > -1) { - if (index >= recipes.length) { - throw new Error(`Could not find recipe ${index} for ${outputName} that only has ${recipes.length} recipes.`); - } - recipes = [recipes[index]]; - } - - return { - getName: (context) => this.resourceHandler.getTranslation('tile.workbench.name', context.language), - toHtml: (context: ISerializeContext, fileWriter: IFileWriter, serializer: HtmlInfoBookSerializer) => { - return recipes.map((recipe) => this.serializeRecipe(recipe, context, fileWriter, serializer)).join('
'); - }, - }; + protected getRecipeNameUnlocalized(): string { + return 'block.minecraft.crafting_table'; } - protected serializeRecipe(recipe: IRecipe, context: ISerializeContext, + protected serializeRecipe(recipe: IRecipeCrafting, context: ISerializeContext, fileWriter: IFileWriter, serializer: HtmlInfoBookSerializer) { // Prepare input array const inputs = "|".repeat(9).split("|").map(() => []); @@ -100,7 +45,7 @@ export class InfoBookAppendixHandlerCraftingRecipe implements IInfoBookAppendixH items = []; } if (!items.length) { - items.push({ item: 'minecraft:air', data: 0 }); + items.push({ item: 'minecraft:air' }); } const outputIndex = y * 3 + x; for (const item of items) { @@ -114,25 +59,16 @@ export class InfoBookAppendixHandlerCraftingRecipe implements IInfoBookAppendixH fileWriter, recipe.output, true); const appendixIcon = serializer.createItemDisplay(this.resourceHandler, context, - fileWriter, { item: 'minecraft:crafting_table', data: 0 }, false); + fileWriter, { item: 'minecraft:crafting_table' }, false); return this.templateCraftingRecipe({ inputs, output, appendixIcon }); } } - -export interface IRecipeRegistry { - [id: string]: [IRecipe]; -} - -export interface IRecipe { +export interface IRecipeCrafting extends IRecipe { + id: string; input: IItem[][]; output: IItem; - width: number; - height: number; - tags: string[]; -} - -export interface IRecipePredefineds { - [id: string]: IRecipe; + width?: number; + height?: number; } diff --git a/lib/infobook/appendix/InfoBookAppendixHandlerFurnaceRecipe.ts b/lib/infobook/appendix/InfoBookAppendixHandlerFurnaceRecipe.ts deleted file mode 100644 index 966f7b9..0000000 --- a/lib/infobook/appendix/InfoBookAppendixHandlerFurnaceRecipe.ts +++ /dev/null @@ -1,63 +0,0 @@ -import * as fs from "fs"; -import {join} from "path"; -import {compileFile as compilePug, compileTemplate} from "pug"; -import {ResourceHandler} from "../../resource/ResourceHandler"; -import {HtmlInfoBookSerializer, ISerializeContext} from "../../serialize/HtmlInfoBookSerializer"; -import {IFileWriter} from "../IFileWriter"; -import {IInfoAppendix} from "../IInfoAppendix"; -import {IItem} from "../IItem"; -import {IInfoBookAppendixHandler} from "./IInfoBookAppendixHandler"; - -/** - * Handles furnace recipe appendices. - */ -export class InfoBookAppendixHandlerFurnaceRecipe implements IInfoBookAppendixHandler { - - private readonly resourceHandler: ResourceHandler; - private readonly registry: IRecipeFurnace[]; - private readonly templateFurnaceRecipe: compileTemplate; - - constructor(resourceHandler: ResourceHandler, registriesPath: string) { - this.resourceHandler = resourceHandler; - this.registry = JSON.parse(fs.readFileSync(join(registriesPath, 'furnace_recipe.json'), "utf8")).elements; - this.templateFurnaceRecipe = compilePug(__dirname + '/../../../template/appendix/furnace_recipe.pug'); - } - - public createAppendix(data: any): IInfoAppendix { - // const meta = data.$.meta || 0; - // const count = data.$.count || 1; - const outputName = data._; - let recipe: IRecipeFurnace; - for (const recipeIt of this.registry) { - if (recipeIt.output.item === outputName) { - recipe = recipeIt; - break; - } - } - if (!recipe) { - throw new Error(`Could not find any recipe for ${outputName}`); - } - - return { - getName: (context) => this.resourceHandler.getTranslation('tile.furnace.name', context.language), - toHtml: (context: ISerializeContext, fileWriter: IFileWriter, serializer: HtmlInfoBookSerializer) => { - - const input = recipe.input.map((item) => serializer.createItemDisplay(this.resourceHandler, context, - fileWriter, item, true)); - const output = serializer.createItemDisplay(this.resourceHandler, context, - fileWriter, recipe.output, true); - - const appendixIcon = serializer.createItemDisplay(this.resourceHandler, context, - fileWriter, { item: 'minecraft:furnace', data: 0 }, false); - - return this.templateFurnaceRecipe({ input, output, appendixIcon }); - }, - }; - } - -} - -export interface IRecipeFurnace { - input: IItem[]; - output: IItem; -} diff --git a/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.ts b/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.ts new file mode 100644 index 0000000..a1b080e --- /dev/null +++ b/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.ts @@ -0,0 +1,44 @@ +import {compileFile as compilePug, compileTemplate} from "pug"; +import {ResourceHandler} from "../../resource/ResourceHandler"; +import {HtmlInfoBookSerializer, ISerializeContext} from "../../serialize/HtmlInfoBookSerializer"; +import {IFileWriter} from "../IFileWriter"; +import {IItem} from "../IItem"; +import { + InfoBookAppendixHandlerAbstractRecipe, + IRecipe, +} from "./InfoBookAppendixHandlerAbstractRecipe"; + +/** + * Handles furnace recipe appendices. + */ +export class InfoBookAppendixHandlerSmeltingRecipe extends InfoBookAppendixHandlerAbstractRecipe { + + private readonly templateFurnaceRecipe: compileTemplate; + + constructor(resourceHandler: ResourceHandler, registriesPath: string, recipeOverrides: any) { + super('minecraft:smelting', resourceHandler, registriesPath, recipeOverrides); + this.templateFurnaceRecipe = compilePug(__dirname + '/../../../template/appendix/furnace_recipe.pug'); + } + + protected getRecipeNameUnlocalized(): string { + return 'block.minecraft.furnace'; + } + + protected serializeRecipe(recipe: IRecipeSmelting, context: ISerializeContext, fileWriter: IFileWriter, serializer: HtmlInfoBookSerializer): string { + const input = recipe.input.map((item) => serializer.createItemDisplay(this.resourceHandler, context, + fileWriter, item, true)); + const output = serializer.createItemDisplay(this.resourceHandler, context, + fileWriter, recipe.output, true); + + const appendixIcon = serializer.createItemDisplay(this.resourceHandler, context, + fileWriter, { item: 'minecraft:furnace' }, false); + + return this.templateFurnaceRecipe({ input, output, appendixIcon }); + } + +} + +export interface IRecipeSmelting extends IRecipe { + input: IItem[]; + output: IItem; +} diff --git a/lib/infobook/appendix/InfoBookAppendixTagIndex.ts b/lib/infobook/appendix/InfoBookAppendixTagIndex.ts index 83c1da7..e41b44b 100644 --- a/lib/infobook/appendix/InfoBookAppendixTagIndex.ts +++ b/lib/infobook/appendix/InfoBookAppendixTagIndex.ts @@ -24,12 +24,12 @@ export class InfoBookAppendixTagIndex implements IInfoAppendix { // First try localizing as item, and if that fails, as fluid let icon: string; - const item = { item: tag, data: 0 }; + const item = { item: tag }; let translationKey = this.resourceHandler.getItemTranslationKey(item); if (translationKey) { icon = serializer.createItemDisplay(this.resourceHandler, context, fileWriter, item, false); } else { - const fluid = { fluid: tag.substr(tag.indexOf(':') + 1) }; + const fluid = { fluid: tag }; translationKey = this.resourceHandler.getFluidTranslationKey(fluid); icon = serializer.createFluidDisplay(this.resourceHandler, context, fileWriter, fluid, false); } diff --git a/lib/resource/ResourceHandler.ts b/lib/resource/ResourceHandler.ts index 2cdd391..f649227 100644 --- a/lib/resource/ResourceHandler.ts +++ b/lib/resource/ResourceHandler.ts @@ -37,23 +37,18 @@ export class ResourceHandler { * Add an entry to a {@llink IItemKeyedRegistry}. * @param {string} namespace The namespace. * @param {string} path The path. - * @param {number} meta The meta. * @param {string} nbt The NBT. (empty string represents no NBT) * @param {string} value The value. */ protected static addItemKeyedRegistryEntry(registry: IItemKeyedRegistry, namespace: string, path: string, - meta: number, nbt: string, value: string) { + nbt: string, value: string) { let paths = registry[namespace]; if (!paths) { paths = registry[namespace] = {}; } - let metas = paths[path]; - if (!metas) { - metas = paths[path] = {}; - } - let nbts = metas[meta]; + let nbts = paths[path]; if (!nbts) { - nbts = metas[meta] = {}; + nbts = paths[path] = {}; } nbts[nbt] = value; } @@ -62,21 +57,16 @@ export class ResourceHandler { * Get an value from a {@llink IItemKeyedRegistry}. * @param {string} namespace The namespace. * @param {string} path The path. - * @param {number} meta The meta. * @param {string} nbt The NBT. (empty string represents no NBT) * @return The value. */ - protected static getItemKeyedRegistryEntry(registry: IItemKeyedRegistry, namespace: string, path: string, - meta: number, nbt: string = ''): string { + protected static getItemKeyedRegistryEntry(registry: IItemKeyedRegistry, namespace: string, + path: string, nbt: string = ''): string { const paths = registry[namespace]; if (!paths) { return null; } - const metas = paths[path]; - if (!metas) { - return null; - } - const nbts = metas[meta]; + const nbts = paths[path]; if (!nbts) { return null; } @@ -164,24 +154,22 @@ export class ResourceHandler { * Add an item icon file. * @param {string} namespace The icon namespace. * @param {string} path The icon path. - * @param {number} meta The icon meta. * @param {string} nbt The icon NBT. (empty string represents no NBT) * @param {string} file The icon file path. */ - public addItemIcon(namespace: string, path: string, meta: number, nbt: string, file: string) { - ResourceHandler.addItemKeyedRegistryEntry(this.iconsItem, namespace, path, meta, nbt, file); + public addItemIcon(namespace: string, path: string, nbt: string, file: string) { + ResourceHandler.addItemKeyedRegistryEntry(this.iconsItem, namespace, path, nbt, file); } /** * Get an item icon file. * @param {string} itemId The icon namespace:path. - * @param {number} meta The icon meta. * @param {string} nbt The icon NBT. (empty string represents no NBT) * @return The icon file path or null. */ - public getItemIconFile(itemId: string, meta: number, nbt: string = ''): string { + public getItemIconFile(itemId: string, nbt: string = ''): string { const { namespace, path } = ResourceHandler.splitItemId(itemId); - return ResourceHandler.getItemKeyedRegistryEntry(this.iconsItem, namespace, path, meta, nbt); + return ResourceHandler.getItemKeyedRegistryEntry(this.iconsItem, namespace, path, nbt); } /** @@ -199,7 +187,7 @@ export class ResourceHandler { * @return The icon file path or null. */ public getFluidIconFile(fluidName: string): string { - return this.iconsFluid[fluidName]; + return this.iconsFluid[fluidName.replace(':', '__')]; } /** @@ -209,8 +197,7 @@ export class ResourceHandler { */ public addItemTranslationKey(item: IItem, translationKey: string) { const { namespace, path } = ResourceHandler.splitItemId(item.item); - ResourceHandler.addItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.data, item.nbt, - translationKey); + ResourceHandler.addItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.nbt, translationKey); } /** @@ -220,7 +207,7 @@ export class ResourceHandler { */ public getItemTranslationKey(item: IItem): string { const { namespace, path } = ResourceHandler.splitItemId(item.item); - return ResourceHandler.getItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.data, item.nbt); + return ResourceHandler.getItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.nbt); } /** @@ -294,7 +281,7 @@ export class ResourceHandler { } export interface IItemKeyedRegistry { - [namespace: string]: {[path: string]: {[meta: number]: {[nbt: string]: string}}}; + [namespace: string]: {[path: string]: {[nbt: string]: string}}; } export interface IAdvancement { diff --git a/lib/resource/ResourceLoader.ts b/lib/resource/ResourceLoader.ts index a731805..4b6aa81 100644 --- a/lib/resource/ResourceLoader.ts +++ b/lib/resource/ResourceLoader.ts @@ -34,14 +34,15 @@ export class ResourceLoader { } else { const split = iconName.split("__"); const namespace = split[0]; - const path = split[1]; - const meta = parseInt(split[2], 10); + let path = split[1]; let nbt = ''; - if (split.length > 3) { - nbt = split.slice(3, split.length).join(":"); + if (split.length > 2) { + nbt = split.slice(2, split.length).join(":"); nbt = nbt.substr(0, nbt.length - 4); + } else { + path = path.substr(0, path.length - 4); } - this.resourceHandler.addItemIcon(namespace, path, meta, nbt, iconFile); + this.resourceHandler.addItemIcon(namespace, path, nbt, iconFile); } } } @@ -153,18 +154,7 @@ export class ResourceLoader { * @returns {Promise} A promise resolving when loading is done. */ public async loadAssetsLangFile(modid: string, language: string, fullFilePath: string) { - const translations: {[translationKey: string]: string} = {}; - - const lines = (await fs.readFile(fullFilePath)).toString('utf8').split('\n'); - for (const line of lines) { - if (line.length > 0 && line[0] !== '#') { - const separatorIndex = line.indexOf('='); - const key = line.substr(0, separatorIndex); - const value = line.substr(separatorIndex + 1); - translations[key] = value; - } - } - + const translations: {[translationKey: string]: string} = JSON.parse((await fs.readFile(fullFilePath)).toString('utf8')); this.resourceHandler.addTranslations(language, translations); } diff --git a/lib/serialize/HtmlInfoBookSerializer.ts b/lib/serialize/HtmlInfoBookSerializer.ts index 7364fbb..b7f18a6 100644 --- a/lib/serialize/HtmlInfoBookSerializer.ts +++ b/lib/serialize/HtmlInfoBookSerializer.ts @@ -247,7 +247,7 @@ export class HtmlInfoBookSerializer { return slot ? '
 
' : '
 
'; } - const icon = resourceHandler.getItemIconFile(item.item, item.data, item.nbt); + const icon = resourceHandler.getItemIconFile(item.item, item.nbt); if (!icon) { throw new Error(`Could not find an icon for item ${JSON.stringify(item)}`); } @@ -298,11 +298,7 @@ export class HtmlInfoBookSerializer { } public tagFluid(context: ISerializeContext, fluidName: string): string { - if (fluidName === 'water' || fluidName === 'lava') { - return 'minecraft:' + fluidName; - } else { - return context.modId + ':' + fluidName; - } + return fluidName; } public getLanguagePath(language: string, path?: string): string {