Skip to content

Commit

Permalink
Handle new model structure in 1.21.4 (#61)
Browse files Browse the repository at this point in the history
* Handle new model structure in 1.21.4

* Fix lint
  • Loading branch information
SuperGamerTron authored Feb 9, 2025
1 parent 1406937 commit 51aab33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions image_names.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ function extractModel (name, path, full = false) {
} else {
try {
name = name.replace(/^(?:block\/)?minecraft:/, '')
path = path.replace('items/', 'models/')
if (!fs.existsSync(path + name + '.json')) {
name = name.replace('block/', '').replace('item/', '')
path = path.replace('models/', 'items/')
}
const t = JSON.parse(fs.readFileSync(path + name + '.json', 'utf8'))
if (full) return t
if (t.textures) {
Expand All @@ -240,6 +245,16 @@ function extractModel (name, path, full = false) {
}
return extractModel(t.parent, path)
}
if (t.model) {
switch (t.model.type) {
case 'minecraft:special': return extractModel(t.model.base, path)
case 'minecraft:select': return extractModel(t.model.fallback.model || t.model.fallback.entries[0].model.model, path)
case 'minecraft:model': return extractModel(t.model.model, path)
case 'minecraft:condition': return extractModel(t.model.on_false.fallback.model || t.model.on_false.fallback.entries[0].model.model, path)
case 'minecraft:range_dispatch': return extractModel(t.model.entries[0].model.model, path)
default: throw new Error('Unhandled type ' + t.model.type)
}
}
return null
} catch (err) {
console.log(err.stack)
Expand Down Expand Up @@ -270,7 +285,7 @@ function getBlocks (unzippedFilesDir, blocksTexturesPath, blockMapping, version)
const texture = extractModel(!model ? null : (model.startsWith('block/') ? model : 'block/' + model), unzippedFilesDir + '/assets/minecraft/models/')
return {
name: block.name,
blockState: blockState,
blockState,
model: !model ? null : model.replace('block/', 'blocks/'),
texture: !texture ? null : texture.replace('block/', 'blocks/')
}
Expand Down Expand Up @@ -313,7 +328,7 @@ function generateTextureContent (outputDir) {
const blocksItems = require(outputDir + '/items_textures.json').concat(require(outputDir + '/blocks_textures.json'))
const arr = blocksItems.map(b => ({
name: b.name,
texture: b.texture == null
texture: b.texture == null || b.texture === 'minecraft:missingno'
? null
: ('data:image/png;base64,' + fs.readFileSync(outputDir + '/' + b.texture.replace('item/', 'items/').replace('block/', 'blocks/').replace(/minecraft:/, '') + '.png', 'base64'))
}))
Expand Down
2 changes: 1 addition & 1 deletion protocol_extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function linesToProtocol (cleanLines, cb) {
const theClass = results[2]
const id = idToHexString(direction === 'toClient' ? currentToClientId : currentToServerId)
if (protocol[currentState][direction] === undefined) { protocol[currentState][direction] = {} }
protocol[currentState][direction][theClass] = { id: id, fields: getFields(theClass) }
protocol[currentState][direction][theClass] = { id, fields: getFields(theClass) }
if (direction === 'toClient') currentToClientId++
else currentToServerId++
}
Expand Down

0 comments on commit 51aab33

Please sign in to comment.