From 3b0d99b5ef41289bc3d5cf3e5c1d1c9d23881f93 Mon Sep 17 00:00:00 2001 From: Jason Gardner Date: Fri, 19 Jul 2024 11:14:47 -0500 Subject: [PATCH] fix: JSR publish types --- src/mcaddon/mod.ts | 51 +++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/mcaddon/mod.ts b/src/mcaddon/mod.ts index b85b68a..b44412e 100644 --- a/src/mcaddon/mod.ts +++ b/src/mcaddon/mod.ts @@ -101,9 +101,7 @@ function createBlock({ } function rotateVolume(volume: number[][][], axis: Axis): number[][][] { - const rotatedVolume = volume.map((z) => - z.map((y) => y.map(() => -1)) - ); + const rotatedVolume = volume.map((z) => z.map((y) => y.map(() => -1))); const depth = volume.length; const gridSize = volume[0].length; @@ -140,16 +138,20 @@ export default async function img2mcaddon( src: string | URL, gridSize: number, resolution: number, - axis: Axis = "z" + axis: Axis = "z", ): Promise { const jobId = nanoid(7); const addon = new JSZip(); const colorSrc = src instanceof URL ? src.href : src; - const blocksData = { - format_version: [1, 0, 0], - }; + const blocksData: Record< + string, + { + sound: string; + isotropic: boolean; + } + > = {}; const frames = await decode(colorSrc, false); @@ -185,7 +187,12 @@ export default async function img2mcaddon( const namespace = baseName.replace(/\W|\.\@\$\%/g, "_"); - const terrainData = {}; + const terrainData: Record< + string, + { + textures: string; + } + > = {}; const blockPalette: StructurePalette = []; @@ -282,14 +289,15 @@ export default async function img2mcaddon( textures: `textures/blocks/${sliceId}`, }; - const blockIdx =blockPalette.push({ - name: `${namespace}:${sliceId}`, - states: {}, - version: BLOCK_VERSION, - }) - 1 + const blockIdx = + blockPalette.push({ + name: `${namespace}:${sliceId}`, + states: {}, + version: BLOCK_VERSION, + }) - 1; volume[z][x][y] = blockIdx; - + blocksData[sliceId] = { sound: "stone", isotropic: false, @@ -299,7 +307,8 @@ export default async function img2mcaddon( } const rotatedVolume = rotateVolume(volume, axis); - const size: [number, number, number] = axis === "y" ? [gridSize, depth, gridSize] : [gridSize, gridSize, depth]; + const size: [number, number, number] = + axis === "y" ? [gridSize, depth, gridSize] : [gridSize, gridSize, depth]; const flatVolume = rotatedVolume.flat(2); @@ -307,7 +316,17 @@ export default async function img2mcaddon( throw new Error("Layer lengths do not match"); } - addon.file("rp/blocks.json", JSON.stringify(blocksData, null, 2)); + addon.file( + "rp/blocks.json", + JSON.stringify( + { + format_version: [1, 0, 0], + ...blocksData, + }, + null, + 2, + ), + ); const tag: IMcStructure = { format_version: 1,