Skip to content

Commit d567389

Browse files
committed
Squashed commit of the following:
commit 7aeec46 Author: SnaveSutit <snavesutit@gmail.com> Date: Thu Nov 21 14:14:15 2024 -0500 🚧 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/` commit efdc207 Author: SnaveSutit <snavesutit@gmail.com> Date: Sat Nov 16 11:18:07 2024 -0500 🚧 Prevent exporting with invalid rotations. - Added a dialog and exception for exporting a blueprint with invalid cube rotations. commit fac53dc Author: SnaveSutit <snavesutit@gmail.com> Date: Sat Nov 16 11:09:30 2024 -0500 🚧 Enforce Per-Face UV when converting commit d285985 Author: SnaveSutit <snavesutit@gmail.com> Date: Sat Nov 2 17:37:32 2024 -0400 🚧 Squashed v1.5.0, v1.5.1, and v1.5.2. commit bcbb6f8 Author: SnaveSutit <snavesutit@gmail.com> Date: Sat Nov 2 17:33:16 2024 -0400 🛠️ Fix broken asset download on first startup. commit 9a3b525 Author: SnaveSutit <snavesutit@gmail.com> Date: Fri Nov 1 15:08:57 2024 -0400 ✨ Improved tellraw messages commit d8dbdbd Author: SnaveSutit <snavesutit@gmail.com> Date: Wed Oct 30 17:53:35 2024 -0400 Fix production build script issues. commit 2dce027 Author: SnaveSutit <snavesutit@gmail.com> Date: Tue Oct 29 11:10:47 2024 -0400 🛠️ Static Export Locator / Camera Fixes - Fixed use entity locators and cameras not summoning properly in static mode commit 66986b7 Author: SnaveSutit <snavesutit@gmail.com> Date: Wed Oct 23 09:58:02 2024 -0400 🚧 v1.5.1 commit 357bfa2 Author: SnaveSutit <snavesutit@gmail.com> Date: Wed Oct 23 09:57:52 2024 -0400 🛠️ Fix broken passengers from summon tp command commit 7d95287 Author: SnaveSutit <snavesutit@gmail.com> Date: Wed Oct 23 09:58:29 2024 -0400 🚧 Squashed v.1.5.1 commit 66986b7 Author: SnaveSutit <snavesutit@gmail.com> Date: Wed Oct 23 09:58:02 2024 -0400 🚧 v1.5.1 commit 357bfa2 Author: SnaveSutit <snavesutit@gmail.com> Date: Wed Oct 23 09:57:52 2024 -0400 🛠️ Fix broken passengers from summon tp command
1 parent bd7c6b1 commit d567389

23 files changed

+2055
-126
lines changed

src/blueprintFormat.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export interface IBlueprintFormatJSON {
150150
backgrounds?: Record<string, any>
151151
}
152152

153+
//region > Convert
153154
export function convertToBlueprint() {
154155
// Convert the current project to a Blueprint
155156
Project!.save_path = ''
@@ -162,6 +163,9 @@ export function convertToBlueprint() {
162163
animation.createUniqueName(Blockbench.Animation.all.filter(a => a !== animation))
163164
animation.name = toSafeFuntionName(animation.name)
164165
}
166+
for (const cube of Cube.all) {
167+
cube.setUVMode(false)
168+
}
165169
}
166170

167171
export function getDefaultProjectSettings(): ModelProject['animated_java'] {

src/components/blueprintSettingsDialog.svelte

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 16 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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
@@ -583,6 +584,12 @@ animated_java.misc.failed_to_export.custom_models.message: You have disabled res
583584
animated_java.misc.failed_to_export.blueprint_settings.message: There are errors in your blueprint settings! Please fix them before exporting.
584585
animated_java.misc.failed_to_export.blueprint_settings.error_item: 'Found an issue with {0}:'
585586
animated_java.misc.failed_to_export.button: Ok
587+
misc.failed_to_export.invalid_rotation.message: |-
588+
Some cubes in your model have an invalid rotations.
589+
Cubes must have a rotation of -45, -22.5, 0, 22.5, or 45 degrees, and can only be rotated on a single axis at a time.
590+
If you want to rotate a cube more precisely, or on multiple axes, you must put it into a bone and rotate the bone instead.
591+
All of the invalid cubes are outlined in red in the editor.
592+
Please fix these issues before exporting.
586593
587594
# Format Category
588595
animated_java.format_category.animated_java: Animated Java

src/mods/cubeOutlineMod.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,11 @@
11
import { isCurrentFormat } from '../blueprintFormat'
22
import { PACKAGE } from '../constants'
3+
import { isCubeValid } from '../systems/util'
34
import { createBlockbenchMod, createPropertySubscribable } from '../util/moddingTools'
45

56
const ERROR_OUTLINE_MATERIAL = Canvas.outlineMaterial.clone()
67
ERROR_OUTLINE_MATERIAL.color.set('#ff0000')
78

8-
function isCubeValid(cube: Cube) {
9-
// Cube is automatically valid if it has no rotation
10-
if (cube.rotation[0] === 0 && cube.rotation[1] === 0 && cube.rotation[2] === 0) {
11-
return true
12-
}
13-
const rotation = cube.rotation[0] + cube.rotation[1] + cube.rotation[2]
14-
// prettier-ignore
15-
if (
16-
// Make sure the cube is rotated in only one axis by adding all the rotations together, and checking if the sum is equal to one of the rotations.
17-
(
18-
rotation === cube.rotation[0] ||
19-
rotation === cube.rotation[1] ||
20-
rotation === cube.rotation[2]
21-
)
22-
&&
23-
// Make sure the cube is rotated in one of the allowed 22.5 degree increments
24-
(
25-
rotation === -45 ||
26-
rotation === -22.5 ||
27-
rotation === 0 ||
28-
rotation === 22.5 ||
29-
rotation === 45
30-
)
31-
) {
32-
return true
33-
}
34-
return false
35-
}
36-
379
createBlockbenchMod(
3810
`${PACKAGE.name}:cubeOutlineMod`,
3911
{

src/systems/cleaner.ts

Lines changed: 136 additions & 0 deletions
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)