Skip to content

Commit

Permalink
fix: fix regression with item renderer
Browse files Browse the repository at this point in the history
chore: fix building on windows
  • Loading branch information
zardoy committed Aug 5, 2024
1 parent feb8b82 commit fe18021
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/arrangeLatestBlockEntities.ts
Original file line number Diff line number Diff line change
@@ -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'))

Expand Down
1 change: 0 additions & 1 deletion src/atlasNode.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/blockEntities.ts
Original file line number Diff line number Diff line change
@@ -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'))

Expand Down
8 changes: 5 additions & 3 deletions src/consumer/assetsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions src/consumer/itemsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down
2 changes: 1 addition & 1 deletion src/copyOtherTextures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { join, dirname } from 'path'
import { join, dirname } from 'path/posix'

const handledTextureKeys = [
'blocks/',
Expand Down
6 changes: 3 additions & 3 deletions src/examples/getItem.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'))
2 changes: 1 addition & 1 deletion src/genBlocks.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/genItems.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import { join } from 'path'
import { join } from 'path/posix'
import { filesize } from 'filesize'

// todo remove
Expand Down
2 changes: 1 addition & 1 deletion src/genParticles.ts
Original file line number Diff line number Diff line change
@@ -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'))

Expand Down
2 changes: 1 addition & 1 deletion src/newAssetsBuilder.ts
Original file line number Diff line number Diff line change
@@ -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'


Expand Down
2 changes: 1 addition & 1 deletion src/newInvsprite.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/versionedImages.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fe18021

Please sign in to comment.