From fe18021f590a5110ea9be1c97f08b05e052bb19b Mon Sep 17 00:00:00 2001 From: Vitaly Date: Tue, 6 Aug 2024 02:27:43 +0300 Subject: [PATCH] fix: fix regression with item renderer chore: fix building on windows --- package.json | 2 +- src/arrangeLatestBlockEntities.ts | 2 +- src/atlasNode.ts | 1 - src/blockEntities.ts | 2 +- src/consumer/assetsParser.ts | 8 +++++--- src/consumer/itemsRenderer.ts | 9 ++++++--- src/copyOtherTextures.ts | 2 +- src/examples/getItem.ts | 6 +++--- src/genBlocks.ts | 2 +- src/genItems.ts | 2 +- src/genParticles.ts | 2 +- src/newAssetsBuilder.ts | 2 +- src/newInvsprite.ts | 2 +- src/versionedImages.ts | 2 +- 14 files changed, 24 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 26ccc3e16..0cd1b98a8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "regen-blockentities": "rm -f dist/blockStatesModels.json && tsx src/blockEntities.ts && tsx src/newAssetsBuilder.ts && tsx src/genBlocks.ts", "build-consumer": "tsc -p tsconfig.consumer.json", "watch-dist": "tsc -p tsconfig.consumer.json -w", - "build-web": "cd web-demo/ && pnpm build" + "build-web": "pnpm --dir web-demo build" }, "files": [ "dist", diff --git a/src/arrangeLatestBlockEntities.ts b/src/arrangeLatestBlockEntities.ts index 03ca6168c..a143504c5 100644 --- a/src/arrangeLatestBlockEntities.ts +++ b/src/arrangeLatestBlockEntities.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import path from 'path' +import path from 'path/posix' const dataPaths = JSON.parse(fs.readFileSync('./data/data-paths.json', 'utf8')) diff --git a/src/atlasNode.ts b/src/atlasNode.ts index 13a43f48c..c9f0c1711 100644 --- a/src/atlasNode.ts +++ b/src/atlasNode.ts @@ -1,5 +1,4 @@ import fs from 'fs' -import path from 'path' import { Canvas, Image } from 'canvas' import { AtlasCreatorOptions, JsonAtlas, makeTextureAtlas as makeAtlas } from './consumer/atlasCreator' diff --git a/src/blockEntities.ts b/src/blockEntities.ts index 1c7819456..d0ab1a2dd 100644 --- a/src/blockEntities.ts +++ b/src/blockEntities.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import path from 'path' +import path from 'path/posix' const dataPaths = JSON.parse(fs.readFileSync('./data/data-paths.json', 'utf8')) diff --git a/src/consumer/assetsParser.ts b/src/consumer/assetsParser.ts index 25be141dc..0ea05dfec 100644 --- a/src/consumer/assetsParser.ts +++ b/src/consumer/assetsParser.ts @@ -156,9 +156,11 @@ export class AssetsParser { if (model.textures) { this.resolvedModel.textures ??= {} for (let [key, value] of Object.entries(model.textures)) { - value = value.replace('blocks/', 'block/').replace('block/', '') - if (value.startsWith('#') && this.resolvedModel.textures[value.slice(1)]) { - value = this.resolvedModel.textures[value.slice(1)]! + if (value.includes('#')) { + const key = value.split('/').at(-1)!.slice(1) + if (this.resolvedModel.textures[key]) { + value = this.resolvedModel.textures[key]! + } } this.resolvedModel.textures[key] = value } diff --git a/src/consumer/itemsRenderer.ts b/src/consumer/itemsRenderer.ts index 9fa285bd1..e7330c243 100644 --- a/src/consumer/itemsRenderer.ts +++ b/src/consumer/itemsRenderer.ts @@ -67,9 +67,12 @@ export class ItemsRenderer { } } if (!model) return - const layer0 = model.textures?.layer0 - if (!layer0) return - return this.resolveTexture(layer0) + const texture = itemName.startsWith('block/') ? + // first defined block texture + Object.values(model.textures ?? {})[0] : + model.textures?.layer0 // classic item texture + if (!texture) return + return this.resolveTexture(texture) // const {resolvedModel} = this.assetsParser.getResolvedModelByModelName('item/' + itemName, itemName) ?? {} // resolvedModel?.textures['layer0'] } diff --git a/src/copyOtherTextures.ts b/src/copyOtherTextures.ts index f57016f45..f95e7b12a 100644 --- a/src/copyOtherTextures.ts +++ b/src/copyOtherTextures.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { join, dirname } from 'path' +import { join, dirname } from 'path/posix' const handledTextureKeys = [ 'blocks/', diff --git a/src/examples/getItem.ts b/src/examples/getItem.ts index 6eb7d508a..0703db87d 100644 --- a/src/examples/getItem.ts +++ b/src/examples/getItem.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { join } from 'path' +import { join } from 'path/posix' import { BlockModel, BlockStates, ItemModel } from '../consumer/types' import { VersionedStore } from '../consumer/versionedStore' import { AtlasParser } from '../consumer' @@ -15,5 +15,5 @@ const blockstatesModels = JSON.parse(fs.readFileSync('./dist/blockStatesModels.j const itemsAtlasParser = new AtlasParser(itemsAtlases, '') const blocksAtlasParser = new AtlasParser(blocksAtlases, '') -console.log(blocksAtlasParser.getTextureInfo("entity/decorated_pot/decorated_pot_base")) -// console.log(new ItemsRenderer('latest', blockstatesModels, itemsAtlasParser, blocksAtlasParser).getItemTexture('oak_sapling')) +// console.log(blocksAtlasParser.getTextureInfo("entity/decorated_pot/decorated_pot_base")) +console.log(new ItemsRenderer('latest', blockstatesModels, itemsAtlasParser, blocksAtlasParser).getItemTexture('block/errored')) diff --git a/src/genBlocks.ts b/src/genBlocks.ts index 8db20d76d..510510141 100644 --- a/src/genBlocks.ts +++ b/src/genBlocks.ts @@ -1,6 +1,6 @@ import fs from 'fs' import { makeTextureAtlas } from './atlasNode' -import { join } from 'path' +import { join } from 'path/posix' const rawData = JSON.parse(fs.readFileSync('./data/data-paths.json', 'utf8')) const blockstatesModels = JSON.parse( diff --git a/src/genItems.ts b/src/genItems.ts index 4399b0a69..83998d60f 100644 --- a/src/genItems.ts +++ b/src/genItems.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import { join } from 'path' +import { join } from 'path/posix' import { filesize } from 'filesize' // todo remove diff --git a/src/genParticles.ts b/src/genParticles.ts index 85fb42f44..a16d40391 100644 --- a/src/genParticles.ts +++ b/src/genParticles.ts @@ -1,6 +1,6 @@ import fs from 'fs' import { makeTextureAtlas } from './atlasNode' -import { join } from 'path' +import { join } from 'path/posix' const rawData = JSON.parse(fs.readFileSync('./data/data-paths.json', 'utf8')) diff --git a/src/newAssetsBuilder.ts b/src/newAssetsBuilder.ts index 9cad3635b..9b2869cba 100644 --- a/src/newAssetsBuilder.ts +++ b/src/newAssetsBuilder.ts @@ -1,7 +1,7 @@ import fs from 'fs' import { VersionedStore } from './consumer/versionedStore' import { versionToNumber } from './consumer/utils' -import path from 'path' +import path from 'path/posix' import { BlockModel, BlockStates, ItemModel } from './consumer/types' diff --git a/src/newInvsprite.ts b/src/newInvsprite.ts index 75292956b..332e3c493 100644 --- a/src/newInvsprite.ts +++ b/src/newInvsprite.ts @@ -1,5 +1,5 @@ import fs from 'fs' -import path from 'path' +import path from 'path/posix' import { createCanvas, Image } from 'canvas' import { makeTextureAtlas } from './atlasNode' diff --git a/src/versionedImages.ts b/src/versionedImages.ts index 79c16a5ea..4f5a9954b 100644 --- a/src/versionedImages.ts +++ b/src/versionedImages.ts @@ -1,6 +1,6 @@ import fs from 'fs' import looksSame from 'looks-same' -import { join } from 'path' +import { join } from 'path/posix' export const makeVersionedImages = async (rootDir: string, versions: string[], filterFiles = (file: string) => file.endsWith('.png')) => { let saving = 0