Skip to content

Commit dcfda71

Browse files
committed
Merge branch 'experimental' of https://github.com/Animated-Java/animated-java into experimental
2 parents d5367de + fd5749e commit dcfda71

File tree

15 files changed

+321
-131
lines changed

15 files changed

+321
-131
lines changed

env.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PLUGIN_DESCRIPTION: |-
44
PLUGIN_ABOUT: |-
55
Generates smooth animations for vanilla java edition using a data pack, a resource pack, and lots of armor stands.
66
"Let the java mobs dance too!"
7-
PLUGIN_VERSION: '0.2.0'
7+
PLUGIN_VERSION: '0.2.1'
88
IN_DEV: dbb29fae73ce8a216b2d4f4e0da42a36fd348983cae2e96587463def059fee9a
99
GLOBAL_SETTINGS_KEY: animated-java<settings.global>
1010
DISCORD_LINK: https://discord.gg/jFgY4PXZfp

src/animatedJava.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ const ANIMATED_JAVA = {
6262
store: store,
6363
format: modelFormat,
6464
registerSettingRenderer,
65+
exportInProgress: false,
6566
get variants() {
66-
return store.get('variants')
67+
return store.get('states')
6768
},
6869
logging: false, //enable logging in production
6970
PromiseWrapper<T>(promise: Promise<T>): Promise<T> {
@@ -74,6 +75,7 @@ const ANIMATED_JAVA = {
7475
},
7576
asyncError(e: Error) {
7677
showUnknownErrorDialog(e)
78+
ANIMATED_JAVA.exportInProgress = false
7779
throw e
7880
// console.error('CUSTOM ERROR HANDLING', e)
7981
},

src/exporters/animationExporter.ts

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ interface animationExporterSettings {
3232
rootTag: string
3333
rootEntityNbt: string
3434
mcbConfigPath: string
35+
autoDistance: number
36+
autoDistanceMovementThreshold: number
37+
manualDistance: number
3538
}
3639

3740
interface MCBConfig {
@@ -94,16 +97,27 @@ async function createMCFile(
9497

9598
const staticAnimationUuid = store.get('static_animation_uuid')
9699
const staticFrame = animations[staticAnimationUuid].frames[0].bones
97-
const staticDistance = roundToN(
98-
animations[staticAnimationUuid].maxDistance + -headYOffset,
99-
1000
100-
)
101-
const maxDistance = roundToN(
102-
Object.values(animations).reduce((o, n) => {
103-
return Math.max(o, n.maxDistance)
104-
}, -Infinity) + -headYOffset,
105-
1000
106-
)
100+
// let staticDistance = 10
101+
let maxDistance = 10
102+
if (exporterSettings.autoDistance) {
103+
// staticDistance = roundToN(
104+
// animations[staticAnimationUuid].maxDistance + -headYOffset,
105+
// 1000
106+
// )
107+
108+
maxDistance = roundToN(
109+
Object.values(animations).reduce((o, n) => {
110+
return Math.max(o, n.maxDistance)
111+
}, -Infinity) +
112+
exporterSettings.autoDistanceMovementThreshold +
113+
-headYOffset,
114+
1000
115+
)
116+
} else {
117+
// staticDistance = exporterSettings.manualDistance
118+
maxDistance = exporterSettings.manualDistance
119+
}
120+
107121
animations = removeKeyGently(staticAnimationUuid, animations)
108122
console.log(animations)
109123

@@ -224,7 +238,7 @@ async function createMCFile(
224238
function this {
225239
execute (if entity @s[tag=${tags.root}] at @s) {
226240
scoreboard players operation # ${scoreboards.id} = @s ${scoreboards.id}
227-
execute as @e[type=${entityTypes.bone},tag=${tags.model},distance=..${staticDistance}] if score @s ${scoreboards.id} = # ${scoreboards.id} run kill @s
241+
execute as @e[type=${entityTypes.bone},tag=${tags.model},distance=..${maxDistance}] if score @s ${scoreboards.id} = # ${scoreboards.id} run kill @s
228242
kill @s
229243
} else {
230244
tellraw @s ${rootExeErrorJsonText.replace('%functionName', `${projectName}:remove/all`)}
@@ -391,7 +405,7 @@ async function createMCFile(
391405
# Summon all bone entities
392406
${summons.map(v => v.toString()).join('\n')}
393407
# Update rotation and ID of bone entities to match the root entity
394-
execute as @e[type=${entityTypes.bone},tag=${tags.model},tag=new,distance=..${staticDistance}] positioned as @s run {
408+
execute as @e[type=${entityTypes.bone},tag=${tags.model},tag=new,distance=..${maxDistance}] positioned as @s run {
395409
scoreboard players operation @s ${scoreboards.id} = .aj.last_id ${scoreboards.internal}
396410
tp @s ~ ~ ~ ~ ~
397411
tag @s remove new
@@ -543,10 +557,9 @@ async function createMCFile(
543557
title: tl(
544558
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.title'
545559
),
546-
lines:
547-
tl(
548-
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.body'
549-
)
560+
lines: tl(
561+
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.body'
562+
)
550563
.split('\n')
551564
.map((line: string) => `<p>${line}</p>`),
552565
},
@@ -1045,6 +1058,56 @@ const Exporter = (AJ: any) => {
10451058
return typeof value === 'boolean'
10461059
},
10471060
},
1061+
autoDistance: {
1062+
type: 'checkbox',
1063+
default: true,
1064+
populate() {
1065+
return true
1066+
},
1067+
isValid(value: any) {
1068+
return typeof value === 'boolean'
1069+
},
1070+
},
1071+
autoDistanceMovementThreshold: {
1072+
type: 'number',
1073+
default: 1,
1074+
populate() {
1075+
return 1
1076+
},
1077+
isValid(value: any) {
1078+
return !isNaN(value) && value >= 0
1079+
},
1080+
onUpdate(value: any) {
1081+
return Number(value)
1082+
},
1083+
isVisible(settings: any) {
1084+
return settings.animatedJava_exporter_animationExporter
1085+
.autoDistance
1086+
},
1087+
dependencies: [
1088+
'animatedJava_exporter_animationExporter.autoDistance',
1089+
],
1090+
},
1091+
manualDistance: {
1092+
type: 'number',
1093+
default: 10,
1094+
populate() {
1095+
return 10
1096+
},
1097+
isValid(value: any) {
1098+
return !isNaN(value) && value >= 0
1099+
},
1100+
onUpdate(value: any) {
1101+
return Number(value)
1102+
},
1103+
isVisible(settings: any) {
1104+
return !settings.animatedJava_exporter_animationExporter
1105+
.autoDistance
1106+
},
1107+
dependencies: [
1108+
'animatedJava_exporter_animationExporter.autoDistance',
1109+
],
1110+
},
10481111
modelTag: {
10491112
type: 'text',
10501113
default: 'aj.%projectName',

src/exporters/statueExporter.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface statueExporterSettings {
2020
boneType: 'aecStack' | 'armorStand'
2121
internalScoreboardObjective: string
2222
idScoreboardObjective: string
23-
exportMode: 'datapack' | 'mcb'
23+
exportMode: 'vanilla' | 'mcb'
2424
mcbFilePath: string | undefined
2525
dataPackPath: string | undefined
2626
markerArmorStands: boolean
@@ -421,6 +421,10 @@ async function exportDataPack(
421421
})
422422
}
423423

424+
const translatedCompilationText = tl(
425+
'animatedJava_exporter_statueExporter.exportingDataPackProgress'
426+
)
427+
424428
function onMessage(message: {
425429
type: 'progress' | 'EVT' | 'ERR' | 'INF' | 'TSK'
426430
msg?: string
@@ -432,14 +436,9 @@ async function exportDataPack(
432436
if (message.type === 'progress') {
433437
Blockbench.setProgress(message.percent, 50)
434438
Blockbench.setStatusBarText(
435-
format(
436-
tl(
437-
'animatedJava_exporter_statueExporter.exportingDataPackProgress'
438-
),
439-
{
440-
progress: (message.percent * 100).toPrecision(4),
441-
}
442-
)
439+
format(translatedCompilationText, {
440+
progress: (message.percent * 100).toPrecision(4),
441+
})
443442
)
444443
}
445444
}
@@ -451,6 +450,7 @@ async function exportDataPack(
451450
onMessage
452451
)
453452
let fileQueue = []
453+
console.log('Vanilla Data Pack:', dataPack)
454454

455455
Blockbench.setProgress(0, 0)
456456
Blockbench.setStatusBarText()
@@ -467,7 +467,7 @@ async function exportDataPack(
467467

468468
const dataPackPath = exporterSettings.dataPackPath
469469
const totalFiles = dataPack.length
470-
const tldMessage = tl(
470+
const translatedWritingText = tl(
471471
'animatedJava_exporter_statueExporter.writingDataPackProgress'
472472
)
473473
const createdPaths = new Set()
@@ -478,7 +478,7 @@ async function exportDataPack(
478478
if (!timeOut) {
479479
Blockbench.setProgress(cur / max, 50)
480480
Blockbench.setStatusBarText(
481-
format(tldMessage, {
481+
format(translatedWritingText, {
482482
progress: ((cur / max) * 100).toPrecision(4),
483483
fileName,
484484
})
@@ -542,7 +542,7 @@ async function statueExport(data: any) {
542542
case 'mcb':
543543
await exportMCFile(generated, data.settings, exporterSettings)
544544
break
545-
case 'datapack':
545+
case 'vanilla':
546546
await exportDataPack(generated, data.settings, exporterSettings)
547547
break
548548
}
@@ -741,14 +741,7 @@ const Exporter = (AJ: any) => {
741741
return ''
742742
},
743743
isValid(value: any) {
744-
const p = new Path(value)
745-
const b = p.parse()
746-
return (
747-
AJ.settings.animatedJava_exporter_statueExporter
748-
.exportMode === 'vanilla' &&
749-
(value === '' ||
750-
b.base !== `${AJ.settings.animatedJava.projectName}`)
751-
)
744+
return value != ''
752745
},
753746
isVisible(settings: any) {
754747
return (

src/exporting.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { settings } from './settings'
44
import { mkdir } from './util/ezfs'
55
import { CustomError } from './util/customError'
66
import { tl } from './util/intl'
7+
import { getModelPath } from './util/minecraft/resourcepack'
78
// import { safeFunctionName } from './util'
89
import transparent from './assets/transparent.png'
910

@@ -103,6 +104,9 @@ async function exportRigModels(models, variantModels) {
103104
settings.animatedJava.rigModelsExportFolder,
104105
variantName
105106
)
107+
// Don't export empty variants
108+
if (Object.entries(variant).length < 1) continue
109+
106110
mkdir(variantFolderPath, { recursive: true })
107111

108112
for (const [modelName, model] of Object.entries(variant)) {
@@ -128,13 +132,6 @@ async function exportRigModels(models, variantModels) {
128132

129133
console.groupEnd('Export Rig Models')
130134
}
131-
function getMCPath(raw) {
132-
let list = raw.split(path.sep)
133-
console.log(list)
134-
const index = list.indexOf('assets')
135-
list = list.slice(index + 1, list.length)
136-
return `${list[0]}:${list.slice(2).join('/')}`
137-
}
138135

139136
async function exportPredicate(models, variantModels, ajSettings) {
140137
console.groupCollapsed('Export Predicate Model')
@@ -147,20 +144,18 @@ async function exportPredicate(models, variantModels, ajSettings) {
147144
overrides: [],
148145
}
149146

150-
const modelPath = getMCPath(ajSettings.rigModelsExportFolder)
151-
console.log(modelPath)
152147
for (const [modelName, model] of Object.entries(models)) {
153148
predicateJSON.overrides.push({
154149
predicate: { custom_model_data: model.aj.customModelData },
155-
model: modelPath + '/' + modelName,
150+
model: getModelPath(path.join(ajSettings.rigModelsExportFolder, modelName)),
156151
})
157152
}
158153

159154
for (const [variantName, variant] of Object.entries(variantModels))
160155
for (const [modelName, model] of Object.entries(variant)) {
161156
predicateJSON.overrides.push({
162157
predicate: { custom_model_data: model.aj.customModelData },
163-
model: [modelPath, variantName, `${modelName}`].join('/'),
158+
model: getModelPath(path.join(modelPath, variantName, modelName), modelName),
164159
})
165160
}
166161

src/lang/en.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ animatedJava.dialog.miscError.body: |-
6464

6565
animatedJava.exportCancelled: Export Cancelled
6666

67+
animatedJava.error.exportInProgress: Export in Progress
68+
6769
animatedJava.customErrorReport.titleUndefined: Unknown Error
6870

6971
animatedJava.popup.error.unableToGenerateTexturePath.title: Invalid texture path
@@ -72,6 +74,12 @@ animatedJava.popup.error.unableToGenerateTexturePath.body: |-
7274
Please make sure it is properly saved inside of a valid Resource Pack in a sub folder of 'assets/namespace/textures/'
7375
eg. 'resources/assets/minecraft/textures/item/diamond.png'
7476
77+
animatedJava.popup.error.unableToGenerateModelPath.title: Invalid texture path
78+
animatedJava.popup.error.unableToGenerateModelPath.body: |-
79+
The model '%modelName' has an invalid location inside a Resource Pack
80+
Please make sure it is properly saved inside of a valid Resource Pack in a sub folder of 'assets/namespace/models/'
81+
eg. 'resources/assets/minecraft/models/item/diamond.json'
82+
7583
animatedJava.popup.error.invalidCubeRotations.title: Invalid Element Rotations
7684
animatedJava.popup.error.invalidCubeRotations.body: |-
7785
The rotations of some cubes are invalid for the java model format.
@@ -91,7 +99,7 @@ animatedJava.popup.error.unsavedTexture.body: |-
9199
animatedJava.popup.warning.rigFolderUnused.title: Unused rig folder
92100
animatedJava.popup.warning.rigFolderUnused.body: |-
93101
This folder does not contain any existing rigs.
94-
Are you sure you want to use this folder?
102+
Are you sure you want to overwrite this folder?
95103
96104
animatedJava.popup.error.rigFolderAlreadyUsedByOther.title: Chosen rig folder already in use
97105
animatedJava.popup.error.rigFolderAlreadyUsedByOther.body: |-
@@ -138,6 +146,7 @@ animatedJava.setting.predicateFilePath.description: The item model file of the r
138146

139147
animatedJava.setting.transparentTexturePath.name: Transparent Texture Path
140148
animatedJava.setting.transparentTexturePath.description: A transparent texture for adding transparency to variants. Only needed if you're using transparency in your variants.
149+
animatedJava.setting.transparentTexturePath.error.invalidPath: Transparent texture path must be defined if your are using the transparency feature of variants
141150

142151
animatedJava.setting.useCache.name: Use Animation Cache
143152
animatedJava.setting.useCache.description: Only re-render changed animations
@@ -239,6 +248,20 @@ animatedJava_exporter_animationExporter.setting.rootEntityNbt.description: The N
239248
animatedJava_exporter_animationExporter.setting.markerArmorStands.name: Marker Armor Stands
240249
animatedJava_exporter_animationExporter.setting.markerArmorStands.description: When enabled all armor_stands used to display the rig will have no hitbox or collision.
241250

251+
animatedJava_exporter_animationExporter.setting.autoDistance.name: Auto Distance
252+
animatedJava_exporter_animationExporter.setting.autoDistance.description: |-
253+
Automatically calculate the maximum distance required to animate all bones in the rig based on the rendered animations.
254+
255+
animatedJava_exporter_animationExporter.setting.autoDistanceMovementThreshold.name: Auto Distance Movement Threshold
256+
animatedJava_exporter_animationExporter.setting.autoDistanceMovementThreshold.description: |-
257+
How much distance to add to the calculated animation distance.
258+
The more distance you add the farther you can move the rig in a single tick without dropping bones
259+
260+
animatedJava_exporter_animationExporter.setting.manualDistance.name: Manual Animation Distance
261+
animatedJava_exporter_animationExporter.setting.manualDistance.description: |-
262+
How far away a bone can be from the root entity before it stops animating.
263+
This setting is intended for advanced users.
264+
242265
animatedJava_exporter_animationExporter.setting.modelTag.name: Model Tag
243266
animatedJava_exporter_animationExporter.setting.modelTag.description: The tag used to select the model
244267

0 commit comments

Comments
 (0)