Skip to content

Commit f0b1dcd

Browse files
SnaveSutitgitbutler-client
authored andcommitted
✨ Add zip export format support
1 parent d0c1bfe commit f0b1dcd

4 files changed

Lines changed: 58 additions & 7 deletions

File tree

src/systems/datapackCompiler/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TextComponent } from 'book-and-quill'
22
import { NbtByte, NbtCompound, NbtFloat, NbtInt, NbtList, NbtString } from 'deepslate/lib/nbt'
3+
import type { AsyncZippable } from 'fflate/browser'
34
import { fs } from '../../constants'
45
import {
56
MAX_PROGRESS,
@@ -31,6 +32,7 @@ import {
3132
matrixToNbtFloatArray,
3233
replacePathPart,
3334
transformationToNbt,
35+
zip,
3436
} from '../util'
3537
import ENTITY_NAMES from './entityNames'
3638
import { compileMcbProject } from './mcbCompiler'
@@ -434,6 +436,30 @@ export default async function compileDataPack(version: string, options: CompileD
434436
console.time('Writing DataPack Files took')
435437
await writeFiles(exportedFiles, options.dataPackFolder)
436438
console.timeEnd('Writing DataPack Files took')
439+
} else if (aj.data_pack_export_mode === 'zip') {
440+
const data: AsyncZippable = {}
441+
442+
for (const [path, file] of coreFiles.entries()) {
443+
const content = Uint8Array.from(
444+
typeof file.content === 'string' ? Buffer.from(file.content) : file.content
445+
)
446+
data[path] = content
447+
}
448+
449+
for (const [path, file] of versionedFiles.entries()) {
450+
const content = Uint8Array.from(
451+
typeof file.content === 'string' ? Buffer.from(file.content) : file.content
452+
)
453+
data[path] = content
454+
}
455+
456+
data['pack.mcmeta'] = Uint8Array.from(
457+
Buffer.from(autoStringify(packMeta.toJSON()), 'utf-8')
458+
)
459+
460+
await fs.promises.rm(options.dataPackFolder, { recursive: true, force: true })
461+
const zipped = await zip(data, {})
462+
await fs.promises.writeFile(options.dataPackFolder, zipped)
437463
}
438464

439465
console.timeEnd('Data Pack Compilation took')

src/systems/resourcepackCompiler/index.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import type { AsyncZippable } from 'fflate/browser'
12
import { fs } from '../../constants'
23
import {
34
MAX_PROGRESS,
45
PROGRESS,
56
PROGRESS_DESCRIPTION,
67
} from '../../dialogs/exportProgress/exportProgress'
78
import { IntentionalExportError } from '../errors'
8-
import { type IRenderedRig } from '../rigRenderer'
9-
import type { ExportedFile } from '../util'
10-
119
import { AJMeta, PackMeta } from '../global'
1210
import { getMisodeVersion } from '../minecraft/versionManager'
11+
import { type IRenderedRig } from '../rigRenderer'
12+
import { zip, type ExportedFile } from '../util'
13+
1314
import EXPORT_1_20_4 from './1.20.4'
1415
import EXPORT_1_21_2 from './1.21.2'
1516
import EXPORT_1_21_4 from './1.21.4'
@@ -189,7 +190,29 @@ export default async function compileResourcePack(
189190
}
190191
PROGRESS.set(PROGRESS.get() + 1)
191192
}
192-
} else if (aj.resource_pack_export_mode === 'zip') {
193-
throw new IntentionalExportError('ZIP export is not yet implemented.')
193+
} else if (aj.data_pack_export_mode === 'zip') {
194+
const data: AsyncZippable = {}
195+
196+
for (const [path, file] of coreFiles.entries()) {
197+
const content = Uint8Array.from(
198+
typeof file.content === 'string' ? Buffer.from(file.content) : file.content
199+
)
200+
data[path] = content
201+
}
202+
203+
for (const [path, file] of versionedFiles.entries()) {
204+
const content = Uint8Array.from(
205+
typeof file.content === 'string' ? Buffer.from(file.content) : file.content
206+
)
207+
data[path] = content
208+
}
209+
210+
data['pack.mcmeta'] = Uint8Array.from(
211+
Buffer.from(autoStringify(packMeta.toJSON()), 'utf-8')
212+
)
213+
214+
await fs.promises.rm(options.resourcePackFolder, { recursive: true, force: true })
215+
const zipped = await zip(data, {})
216+
await fs.promises.writeFile(options.resourcePackFolder, zipped)
194217
}
195218
}

test-packs/latest/blueprints/armor_stand_latest.ajblueprint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
"blueprint_settings": {
1414
"blueprint_id": "aj_booth:rigs/armor_stand",
1515
"render_box": [95, 32],
16-
"resource_pack": "../resources",
17-
"data_pack": "../datapacks/animated_java",
16+
"resource_pack_export_mode": "zip",
17+
"data_pack_export_mode": "zip",
18+
"resource_pack": "/home/snavesutit/Prism Launcher Instances/AJ Testing 1.21.11/minecraft/resourcepacks/resources.zip",
19+
"data_pack": "../datapacks/animated_java.zip",
1820
"on_summon_function": "say On-Summon!",
1921
"on_remove_function": "say On-Remove!",
2022
"baked_animations": false,
204 KB
Binary file not shown.

0 commit comments

Comments
 (0)