Skip to content

Commit 00087ec

Browse files
committed
🚧 Fix Blueprint Codec Failing to Load Textures
Also Fixed #192
1 parent d50d066 commit 00087ec

File tree

4 files changed

+1313
-250
lines changed

4 files changed

+1313
-250
lines changed

src/blueprintFormat.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ export function updateBoundingBox() {
187187
scene.add(Project.visualBoundingBox)
188188
}
189189

190-
/**
191-
* The Animated Java Blueprint codec
192-
*/
190+
// region Codec
193191
export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
194192
name: 'Animated Java Blueprint',
195193
extension: 'ajblueprint',
@@ -254,8 +252,10 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
254252
)
255253
if (fs.existsSync(resolvedPath)) {
256254
newTexture.fromPath(resolvedPath)
255+
continue
257256
}
258-
} else if (texture.path && fs.existsSync(texture.path) && !model.meta.backup) {
257+
}
258+
if (texture.path && fs.existsSync(texture.path) && !model.meta.backup) {
259259
newTexture.fromPath(texture.path)
260260
} else if (texture.source && texture.source.startsWith('data:')) {
261261
newTexture.fromDataURL(texture.source)
@@ -495,9 +495,7 @@ export const BLUEPRINT_CODEC = new Blockbench.Codec('animated_java_blueprint', {
495495
},
496496
})
497497

498-
/** ANCHOR
499-
* The Animated Java Blueprint format
500-
*/
498+
// region Format
501499
export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
502500
id: 'animated_java_blueprint',
503501
name: 'Animated Java Blueprint',

src/interface/importAJModelLoader.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { createModelLoader } from '../util/moddingTools'
66
import { translate } from '../util/translation'
77
import { openUnexpectedErrorDialog } from './unexpectedErrorDialog'
88
import * as ModelDatFixerUpper from '../systems/modelDataFixerUpper'
9-
import { BLUEPRINT_CODEC } from '../blueprintFormat'
9+
import { BLUEPRINT_CODEC, IBlueprintFormatJSON } from '../blueprintFormat'
10+
import { toSafeFuntionName } from '../util/minecraftUtil'
1011

1112
let activeComponent: SvelteComponentDev | null = null
1213

@@ -43,12 +44,15 @@ createModelLoader(`${PACKAGE.name}-upgradeAJModelLoader`, {
4344
export function convertAJModelToBlueprint(path: string) {
4445
try {
4546
console.log(`Convert .ajmodel: ${path}`)
46-
const blueprint = ModelDatFixerUpper.process(JSON.parse(fs.readFileSync(path, 'utf8')))
47+
const blueprint = ModelDatFixerUpper.process(
48+
JSON.parse(fs.readFileSync(path, 'utf8'))
49+
) as IBlueprintFormatJSON
4750

4851
BLUEPRINT_CODEC.load(blueprint, {
4952
name: 'Upgrade .ajmodel to Blueprint',
50-
path: undefined,
53+
path,
5154
})
55+
blueprint.project_settings!.export_namespace ??= toSafeFuntionName(Project!.name)
5256

5357
requestAnimationFrame(() => {
5458
Project!.save_path = ''

src/systems/modelDataFixerUpper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BoneConfig } from '../nodeConfigs'
33
import { PACKAGE } from '../constants'
44
import { openUnexpectedErrorDialog } from '../interface/unexpectedErrorDialog'
55
import { NbtCompound, NbtList, NbtString, NbtTag } from 'deepslate'
6+
import { toSafeFuntionName } from '../util/minecraftUtil'
67

78
export function process(model: any): any {
89
if (model.meta.model_format === 'animatedJava/ajmodel') {

0 commit comments

Comments
 (0)