From c1651ce3b55ec846fd459b9c61461ce3040211e2 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Mon, 13 May 2024 15:36:11 +0300 Subject: [PATCH] fix: some collision shapes were missing for 1.20.4 --- ...Shapes.mjs => generateMoreCollisionShapes.mjs} | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) rename scripts/{getMoreCollisionShapes.mjs => generateMoreCollisionShapes.mjs} (94%) diff --git a/scripts/getMoreCollisionShapes.mjs b/scripts/generateMoreCollisionShapes.mjs similarity index 94% rename from scripts/getMoreCollisionShapes.mjs rename to scripts/generateMoreCollisionShapes.mjs index 3f772af1..ee178478 100644 --- a/scripts/getMoreCollisionShapes.mjs +++ b/scripts/generateMoreCollisionShapes.mjs @@ -1,8 +1,11 @@ +//@ts-check import minecraftData from 'minecraft-data' import minecraftAssets from 'minecraft-assets' import fs from 'fs' -const latestData = minecraftData('1.20.2') +const latestVersion = minecraftData.versions.pc[0] + +const latestData = minecraftData(latestVersion.minecraftVersion) // dont touch, these are the ones that are already full box const fullBoxInteractionShapes = [ @@ -62,7 +65,7 @@ const fullBoxInteractionShapesTemp = [ 'white_wall_banner', ] -const shapes = latestData.blockCollisionShapes; +const shapes = latestData.blockCollisionShapes const fullShape = shapes.shapes[1] const outputJson = {} @@ -97,8 +100,8 @@ const interestedBlocks = latestData.blocksArray.filter(block => { const { blocksStates, blocksModels } = minecraftAssets(latestData.version.minecraftVersion) const getShapeFromModel = (block,) => { - const blockStates = JSON.parse(fs.readFileSync('./prismarine-viewer/public/blocksStates/1.19.1.json')) - const blockState = blockStates[block]; + const blockStates = JSON.parse(fs.readFileSync('./prismarine-viewer/public/blocksStates/1.19.1.json', 'utf8')) + const blockState = blockStates[block] const perVariant = {} for (const [key, variant] of Object.entries(blockState.variants)) { // const shapes = (Array.isArray(variant) ? variant : [variant]).flatMap((v) => v.model?.elements).filter(Boolean).map(({ from, to }) => [...from, ...to]).reduce((acc, cur) => { @@ -146,7 +149,7 @@ outer: for (const interestedBlock of [...interestedBlocksNoStates, ...interested } } - const hasStates = interestedBlocksStates.includes(interestedBlock); + const hasStates = interestedBlocksStates.includes(interestedBlock) if (hasStates) { const states = blocksStates[interestedBlock] if (!states) { @@ -159,7 +162,7 @@ outer: for (const interestedBlock of [...interestedBlocksNoStates, ...interested continue } let outputStates = {} - for (const {when} of states.multipart) { + for (const { when } of states.multipart) { if (when) { for (const [key, value] of Object.entries(when)) { if (key === 'OR') {