Skip to content

Commit 7aeec46

Browse files
committed
🚧 1.21.4 Export
- Added 1.21.4 target MC version. - Changed missing assets and data folder for resource and data pack folder settings errors into warnings. - Added an action to extract all of a blueprint's export files from a data pack / resource pack. - Added support for item definitions (1.21.4). - Changed default resource pack structure: `animated_java:textures/item/export_namespace/` -> `animated_java:textures/blueprint/export_namespace/` `animated_java:models/item/export_namespace/` -> `animated_java:models/blueprint/export_namespace/`
1 parent efdc207 commit 7aeec46

19 files changed

+1993
-97
lines changed

src/components/blueprintSettingsDialog.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
}
243243
case !fs.existsSync(PathModule.join(path, 'data')):
244244
return {
245-
type: 'error',
245+
type: 'warning',
246246
message: translate(
247247
'dialog.blueprint_settings.data_pack.error.missing_data_folder',
248248
),
@@ -297,7 +297,7 @@
297297
}
298298
case !fs.existsSync(PathModule.join(path, 'assets')):
299299
return {
300-
type: 'error',
300+
type: 'warning',
301301
message: translate(
302302
'dialog.blueprint_settings.resource_pack.error.missing_assets_folder',
303303
),

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { BLOCKSTATE_REGISTRY } from './systems/minecraft/blockstateManager'
4141
import { exportProject } from './systems/exporter'
4242
import { openBlueprintLoadingDialog } from './interface/blueprintLoadingPopup'
4343
import { openInstallPopup } from './interface/installedPopup'
44+
import { cleanupExportedFiles } from './systems/cleaner'
4445

4546
// @ts-ignore
4647
globalThis.AnimatedJava = {
@@ -81,6 +82,7 @@ globalThis.AnimatedJava = {
8182
texture.remove()
8283
Undo.finishEdit('Remove Cubes Associated With Texture')
8384
},
85+
cleanupExportedFiles,
8486
},
8587
}
8688

src/interface/animatedJavaBarItem.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import AnimatedJavaIcon from '../assets/animated_java_icon.svg'
22
import { BLUEPRINT_FORMAT } from '../blueprintFormat'
33
import { PACKAGE } from '../constants'
4+
import { cleanupExportedFiles } from '../systems/cleaner'
45
import { exportProject } from '../systems/exporter'
5-
import { events } from '../util/events'
66
import { createAction, createBarMenu } from '../util/moddingTools'
77
import { translate } from '../util/translation'
88
import { openAboutDialog } from './aboutDialog'
@@ -74,6 +74,21 @@ MenuBar.addAction(
7474
MENU.id
7575
)
7676

77+
MenuBar.addAction(
78+
createAction(`${PACKAGE.name}:extract`, {
79+
icon: 'fa-trash-can',
80+
category: 'animated_java',
81+
name: translate('action.extract.name'),
82+
condition() {
83+
return Format === BLUEPRINT_FORMAT
84+
},
85+
click() {
86+
void cleanupExportedFiles()
87+
},
88+
}),
89+
MENU.id
90+
)
91+
7792
MenuBar.addAction(
7893
createAction(`${PACKAGE.name}:export`, {
7994
icon: 'insert_drive_file',

src/lang/en.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ animated_java.action.open_bone_config.name: Bone Config
66
animated_java.action.open_locator_config.name: Locator Config
77
animated_java.action.open_text_display_config.name: Text Display Config
88
animated_java.action.export.name: Export
9+
animated_java.action.extract.name: Extract
910
animated_java.action.create_text_display.title: Add Text Display
1011
animated_java.action.create_vanilla_item_display.title: Add Item Display
1112
animated_java.action.create_vanilla_block_display.title: Add Block Display

src/systems/cleaner.ts

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { isFunctionTagPath } from '../util/fileUtil'
2+
import { IFunctionTag, parseDataPackPath } from '../util/minecraftUtil'
3+
import { DataPackAJMeta } from './datapackCompiler'
4+
import { getExportPaths } from './exporter'
5+
import { ResourcePackAJMeta } from './resourcepackCompiler/global'
6+
import { replacePathPart } from './util'
7+
8+
export async function cleanupExportedFiles() {
9+
const aj = Project!.animated_java
10+
const {
11+
resourcePackFolder,
12+
dataPackFolder,
13+
// textureExportFolder,
14+
// modelExportFolder,
15+
// displayItemPath,
16+
} = getExportPaths()
17+
18+
if (aj.resource_pack_export_mode === 'raw') {
19+
const assetsMetaPath = PathModule.join(resourcePackFolder, 'assets.ajmeta')
20+
const assetsMeta = new ResourcePackAJMeta(
21+
assetsMetaPath,
22+
aj.export_namespace,
23+
Project!.last_used_export_namespace,
24+
resourcePackFolder
25+
)
26+
assetsMeta.read()
27+
28+
// PROGRESS_DESCRIPTION.set('Removing Old Data Pack Files...')
29+
// PROGRESS.set(0)
30+
// MAX_PROGRESS.set(assetsMeta.oldFiles.size)
31+
const removedFolders = new Set<string>()
32+
for (const file of assetsMeta.oldFiles) {
33+
if (!isFunctionTagPath(file)) {
34+
if (fs.existsSync(file)) await fs.promises.unlink(file)
35+
} else if (aj.export_namespace !== Project!.last_used_export_namespace) {
36+
const resourceLocation = parseDataPackPath(file)!.resourceLocation
37+
if (
38+
resourceLocation.startsWith(
39+
`animated_java:${Project!.last_used_export_namespace}/`
40+
) &&
41+
fs.existsSync(file)
42+
) {
43+
const newPath = replacePathPart(
44+
file,
45+
Project!.last_used_export_namespace,
46+
aj.export_namespace
47+
)
48+
await fs.promises.mkdir(PathModule.dirname(newPath), { recursive: true })
49+
await fs.promises.copyFile(file, newPath)
50+
await fs.promises.unlink(file)
51+
}
52+
}
53+
let folder = PathModule.dirname(file)
54+
while (
55+
!removedFolders.has(folder) &&
56+
fs.existsSync(folder) &&
57+
(await fs.promises.readdir(folder)).length === 0
58+
) {
59+
await fs.promises.rm(folder, { recursive: true })
60+
removedFolders.add(folder)
61+
folder = PathModule.dirname(folder)
62+
if (PathModule.basename(folder) === 'assets') break
63+
}
64+
// PROGRESS.set(PROGRESS.get() + 1)
65+
}
66+
67+
assetsMeta.write()
68+
}
69+
70+
if (aj.data_pack_export_mode === 'raw') {
71+
const dataMetaPath = PathModule.join(dataPackFolder, 'data.ajmeta')
72+
const dataMeta = new DataPackAJMeta(
73+
dataMetaPath,
74+
aj.export_namespace,
75+
Project!.last_used_export_namespace,
76+
dataPackFolder
77+
)
78+
dataMeta.read()
79+
80+
// PROGRESS_DESCRIPTION.set('Removing Old Data Pack Files...')
81+
// PROGRESS.set(0)
82+
// MAX_PROGRESS.set(dataMeta.oldFiles.size)
83+
const removedFolders = new Set<string>()
84+
for (const file of dataMeta.oldFiles) {
85+
if (isFunctionTagPath(file) && fs.existsSync(file)) {
86+
if (aj.export_namespace !== Project!.last_used_export_namespace) {
87+
const resourceLocation = parseDataPackPath(file)!.resourceLocation
88+
if (
89+
resourceLocation.startsWith(
90+
`animated_java:${Project!.last_used_export_namespace}/`
91+
)
92+
) {
93+
const newPath = replacePathPart(
94+
file,
95+
Project!.last_used_export_namespace,
96+
aj.export_namespace
97+
)
98+
await fs.promises.mkdir(PathModule.dirname(newPath), { recursive: true })
99+
await fs.promises.copyFile(file, newPath)
100+
await fs.promises.unlink(file)
101+
}
102+
}
103+
// Remove mentions of the export namespace from the file
104+
const content: IFunctionTag = JSON.parse(
105+
(await fs.promises.readFile(file)).toString()
106+
)
107+
content.values = content.values.filter(
108+
v =>
109+
typeof v === 'string' &&
110+
(!v.startsWith(`animated_java:${aj.export_namespace}/`) ||
111+
!v.startsWith(`animated_java:${Project!.last_used_export_namespace}/`))
112+
)
113+
await fs.promises.writeFile(file, autoStringify(content))
114+
} else {
115+
// Delete the file
116+
if (fs.existsSync(file)) await fs.promises.unlink(file)
117+
}
118+
let folder = PathModule.dirname(file)
119+
while (
120+
!removedFolders.has(folder) &&
121+
fs.existsSync(folder) &&
122+
(await fs.promises.readdir(folder)).length === 0
123+
) {
124+
await fs.promises.rm(folder, { recursive: true })
125+
removedFolders.add(folder)
126+
folder = PathModule.dirname(folder)
127+
if (PathModule.basename(folder) === 'data') break
128+
}
129+
// PROGRESS.set(PROGRESS.get() + 1)
130+
}
131+
132+
dataMeta.write()
133+
}
134+
135+
Blockbench.showQuickMessage('Exported files extracted successfully!', 2000)
136+
}

0 commit comments

Comments
 (0)