forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add blocks generate script for resourcepack
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ world | |
out | ||
*.iml | ||
.vercel | ||
generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |