Skip to content

Commit

Permalink
Fix #652 add pack.mcmeta when downloading project zip
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Dec 10, 2024
1 parent 22d35ef commit 7ceb74f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/app/components/generator/ProjectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Identifier } from 'deepslate'
import { route } from 'preact-router'
import { useCallback, useEffect, useMemo, useRef, useState } from 'preact/hooks'
import config from '../../Config.js'
import { DRAFT_PROJECT, getProjectRoot, useLocale, useProject } from '../../contexts/index.js'
import { DRAFT_PROJECT, getProjectRoot, useLocale, useProject, useVersion } from '../../contexts/index.js'
import { useModal } from '../../contexts/Modal.jsx'
import { useSpyglass } from '../../contexts/Spyglass.jsx'
import { useFocus } from '../../hooks/useFocus.js'
Expand All @@ -17,6 +17,7 @@ import { ProjectCreation } from './ProjectCreation.jsx'
import { ProjectDeletion } from './ProjectDeletion.jsx'

export function ProjectPanel() {
const { version } = useVersion()
const { locale } = useLocale()
const { showModal } = useModal()
const { projects, project, projectUri, setProjectUri, changeProject } = useProject()
Expand Down Expand Up @@ -54,6 +55,12 @@ export function ProjectPanel() {
const data = await client.fs.readFile(projectRoot + e)
return [e, data] as [string, Uint8Array]
}))
if (!zipEntries.some(e => e[0] === 'pack.mcmeta')) {
const packFormat = config.versions.find(v => v.id === version)!.pack_format
const packMcmeta = { pack: { description: project.name, pack_format: packFormat } }
const data = new TextEncoder().encode(JSON.stringify(packMcmeta, null, 2))
zipEntries.push(['pack.mcmeta', data])
}
const url = await writeZip(zipEntries)
download.current.setAttribute('href', url)
download.current.setAttribute('download', `${project.name.replaceAll(' ', '_')}.zip`)
Expand Down
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"id": "1.21.4",
"dynamic": true,
"name": "1.21.4",
"pack_format": 58,
"pack_format": 61,
"show": true
}
],
Expand Down

0 comments on commit 7ceb74f

Please sign in to comment.