add blocks generate script for resourcepack
This commit is contained in:
parent
1cca1897fe
commit
91bb1d75ff
4 changed files with 70 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -14,3 +14,4 @@ world
|
|||
out
|
||||
*.iml
|
||||
.vercel
|
||||
generated
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
"test:cypress": "cypress run",
|
||||
"test:e2e": "start-test http-get://localhost:8080 test:cypress",
|
||||
"prod-start": "node server.js",
|
||||
"postinstall": "node scripts/gen-texturepack-files.mjs",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"keywords": [
|
||||
|
|
@ -104,7 +105,7 @@
|
|||
"overrides": {
|
||||
"prismarine-block": "github:zardoy/prismarine-block#next-era",
|
||||
"prismarine-world": "github:zardoy/prismarine-world#next-era",
|
||||
"minecraft-data": "latest",
|
||||
"minecraft-data": "3.45.0",
|
||||
"prismarine-provider-anvil": "github:zardoy/prismarine-provider-anvil#everything",
|
||||
"minecraft-protocol": "github:zardoy/minecraft-protocol#custom-client-extra"
|
||||
}
|
||||
|
|
|
|||
51
scripts/gen-texturepack-files.mjs
Normal file
51
scripts/gen-texturepack-files.mjs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
//@ts-check
|
||||
import fs from 'fs'
|
||||
import minecraftAssets from 'minecraft-assets'
|
||||
|
||||
// why store another data?
|
||||
// 1. want to make it compatible (at least for now)
|
||||
// 2. don't want to read generated blockStates as it might change in future, and the current way was faster to implement
|
||||
|
||||
const blockNames = []
|
||||
const indexesPerVersion = {}
|
||||
/** @type {Map<string, number>} */
|
||||
const allBlocksMap = new Map()
|
||||
const getBlockIndex = (block) => {
|
||||
if (allBlocksMap.has(block)) {
|
||||
return allBlocksMap.get(block)
|
||||
}
|
||||
|
||||
const index = blockNames.length
|
||||
allBlocksMap.set(block, index)
|
||||
blockNames.push(block)
|
||||
return index
|
||||
}
|
||||
|
||||
// const blocksFull = []
|
||||
// const allBlocks = []
|
||||
// // we can even optimize it even futher by doing prev-step resolving
|
||||
// const blocksDiff = {}
|
||||
|
||||
for (const [i, version] of minecraftAssets.versions.reverse().entries()) {
|
||||
const assets = minecraftAssets(version)
|
||||
const blocksDir = assets.directory + '/blocks'
|
||||
const blocks = fs.readdirSync(blocksDir)
|
||||
indexesPerVersion[version] = blocks.map(block => {
|
||||
if (!block.endsWith('.png')) return undefined
|
||||
return getBlockIndex(block)
|
||||
}).filter(i => i !== undefined)
|
||||
|
||||
// if (!blocksFull.length) {
|
||||
// // first iter
|
||||
// blocksFull.push(...blocks)
|
||||
// } else {
|
||||
// const missing = blocksFull.map((b, i) => !blocks.includes(b) ? i : -1).filter(i => i !== -1)
|
||||
// const added = blocks.filter(b => !blocksFull.includes(b))
|
||||
// blocksDiff[version] = {
|
||||
// missing,
|
||||
// added
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fs.writeFileSync('./generated/blocks.json', JSON.stringify({ blockNames: blockNames, indexes: indexesPerVersion }))
|
||||
16
scripts/test-texturepack-files.mjs
Normal file
16
scripts/test-texturepack-files.mjs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import fs from 'fs'
|
||||
import minecraftAssets from 'minecraft-assets'
|
||||
|
||||
const gen = JSON.parse(fs.readFileSync('./blocks.json', 'utf8'))
|
||||
|
||||
const version = '1.8.8'
|
||||
const { blockNames, indexes } = gen
|
||||
|
||||
const blocksActual = indexes[version].map((i) => blockNames[i])
|
||||
|
||||
const blocksExpected = fs.readdirSync(minecraftAssets(version).directory + '/blocks')
|
||||
for (const [i, item] of blocksActual.entries()) {
|
||||
if (item !== blocksExpected[i]) {
|
||||
console.log('not equal at', i)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue