Skip to content

Commit 7dc2a97

Browse files
committed
Merge branch 'experimental'
2 parents 971b274 + 53c80fd commit 7dc2a97

File tree

11 files changed

+166
-45
lines changed

11 files changed

+166
-45
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"setup": "yarn && yarn build:scripts && yarm build:worker",
7+
"setup": "yarn && yarn build:scripts && yarn build:worker",
88
"go": "yarn setup && yarn build:worker && yarn dev",
99
"build:scripts": "rollup --config ./config/tools.rollup.config.js",
1010
"rollup": "rollup --config ./config/dev.animated-java.rollup.config.js",

src/animatedJava.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const ANIMATED_JAVA = {
6262
store: store,
6363
format: modelFormat,
6464
registerSettingRenderer,
65+
get variants() {
66+
return store.get('states')
67+
},
6568
logging: false, //enable logging in production
6669
PromiseWrapper<T>(promise: Promise<T>): Promise<T> {
6770
return promise.catch((e) => {

src/animationRenderer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import events from './constants/events'
1313
import { tl } from './util/intl'
1414
import { format, safeFunctionName } from './util/replace'
1515
import { isSceneBased } from './util/hasSceneAsParent'
16+
import { CustomError } from './util/customError'
1617
store.set('static_animation_uuid', '138747e7-2de0-4130-b900-9275ca0e6333')
1718

1819
function setAnimatorTime(time) {
@@ -276,6 +277,29 @@ async function renderAnimation(options) {
276277
console.log('Rendered Groups:', renderedGroups)
277278

278279
for (const animation of Animator.animations.sort()) {
280+
if (animation.snapping != 20) {
281+
throw new CustomError('Invalid Snapping Value Error', {
282+
intentional: true,
283+
dialog: {
284+
id: 'animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue',
285+
title: tl(
286+
'animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue.title'
287+
),
288+
lines: format(
289+
tl(
290+
'animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue.body'
291+
),
292+
{
293+
animationName: animation.name,
294+
snapping: animation.snapping
295+
}
296+
)
297+
.split('\n')
298+
.map((line) => `<p>${line}</p>`),
299+
},
300+
})
301+
}
302+
279303
const value = Cache.hit(animation)
280304
if (!value) {
281305
let maxDistance = -Infinity

src/exporters/animationExporter.ts

Lines changed: 96 additions & 13 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

@@ -184,6 +198,7 @@ async function createMCFile(
184198
.join('\n')}
185199
scoreboard players add .aj.animation ${scoreboards.animatingFlag} 0
186200
scoreboard players add .aj.anim_loop ${scoreboards.animatingFlag} 0
201+
scoreboard players set .noScripts ${scoreboards.internal} 0
187202
}
188203
`)
189204
// prettier-ignore
@@ -223,7 +238,7 @@ async function createMCFile(
223238
function this {
224239
execute (if entity @s[tag=${tags.root}] at @s) {
225240
scoreboard players operation # ${scoreboards.id} = @s ${scoreboards.id}
226-
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
227242
kill @s
228243
} else {
229244
tellraw @s ${rootExeErrorJsonText.replace('%functionName', `${projectName}:remove/all`)}
@@ -390,7 +405,7 @@ async function createMCFile(
390405
# Summon all bone entities
391406
${summons.map(v => v.toString()).join('\n')}
392407
# Update rotation and ID of bone entities to match the root entity
393-
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 {
394409
scoreboard players operation @s ${scoreboards.id} = .aj.last_id ${scoreboards.internal}
395410
tp @s ~ ~ ~ ~ ~
396411
tag @s remove new
@@ -534,6 +549,23 @@ async function createMCFile(
534549
}
535550

536551
{
552+
if (!Object.keys(animations).length) {
553+
throw new CustomError('No Animations Error', {
554+
intentional: true,
555+
dialog: {
556+
id: 'animatedJava_exporter_animationExporter.popup.warning.noAnimations',
557+
title: tl(
558+
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.title'
559+
),
560+
lines: tl(
561+
'animatedJava_exporter_animationExporter.popup.warning.noAnimations.body'
562+
)
563+
.split('\n')
564+
.map((line: string) => `<p>${line}</p>`),
565+
},
566+
})
567+
}
568+
537569
//? Animation Dir
538570
FILE.push(`dir animations {`)
539571

@@ -681,9 +713,10 @@ async function createMCFile(
681713
# Reset animation time
682714
scoreboard players set @s ${scoreboards.frame} 0
683715
# load initial animation frame without running scripts
716+
scoreboard players operation .oldValue ${scoreboards.internal} = .noScripts ${scoreboards.internal}
684717
scoreboard players set .noScripts ${scoreboards.internal} 1
685718
function ${projectName}:animations/${animation.name}/next_frame
686-
scoreboard players set .noScripts ${scoreboards.internal} 0
719+
scoreboard players operation .noScripts ${scoreboards.internal} = .oldValue ${scoreboards.internal}
687720
# Reset animation time
688721
scoreboard players set @s ${scoreboards.frame} 0
689722
# If this entity is not the root
@@ -1025,6 +1058,56 @@ const Exporter = (AJ: any) => {
10251058
return typeof value === 'boolean'
10261059
},
10271060
},
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+
},
10281111
modelTag: {
10291112
type: 'text',
10301113
default: 'aj.%projectName',

src/exporters/statueExporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ const Exporter = (AJ: any) => {
686686
AJ.settings.animatedJava_exporter_statueExporter
687687
.exportMode === 'mcb' &&
688688
(value === '' ||
689-
b.base !== `${AJ.settings.animatedJava.projectName}.mc`)
689+
b.base === `${AJ.settings.animatedJava.projectName}.mc`)
690690
)
691691
},
692692
isVisible(settings: any) {

src/lang/en.yaml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,20 @@ animatedJava.customErrorReport.titleUndefined: Unknown Error
6868

6969
animatedJava.popup.error.unableToGenerateTexturePath.title: Invalid texture path
7070
animatedJava.popup.error.unableToGenerateTexturePath.body: |-
71-
The texture '%textureName' has an invalid location inside a resource pack
72-
Please make sure it is properly saved inside of a valid resource pack in a sub folder of 'assets/namespace/textures/'
71+
The texture '%textureName' has an invalid location inside a Resource Pack
72+
Please make sure it is properly saved inside of a valid Resource Pack in a sub folder of 'assets/namespace/textures/'
73+
eg. 'resources/assets/minecraft/textures/item/diamond.png'
7374
7475
animatedJava.popup.error.invalidCubeRotations.title: Invalid Element Rotations
7576
animatedJava.popup.error.invalidCubeRotations.body: |-
7677
The rotations of some cubes are invalid for the java model format.
77-
Please all invalid rotations before exporting
78+
Please fix all invalid rotations before exporting.
79+
80+
animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue.title: Invalid Animation Snapping Value
81+
animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue.body: |-
82+
The animation '%animationName' has a snapping value of %snapping!
83+
Due to how fast Minecraft ticks, Animated Java only supports a snapping value of 20.
84+
Please update your animations to reflect this limitation before you export.
7885
7986
animatedJava.popup.error.unsavedTexture.title: Unsaved Texture
8087
animatedJava.popup.error.unsavedTexture.body: |-
@@ -84,7 +91,7 @@ animatedJava.popup.error.unsavedTexture.body: |-
8491
animatedJava.popup.warning.rigFolderUnused.title: Unused rig folder
8592
animatedJava.popup.warning.rigFolderUnused.body: |-
8693
This folder does not contain any existing rigs.
87-
Are you sure you want to use this folder?
94+
Are you sure you want to overwrite this folder?
8895
8996
animatedJava.popup.error.rigFolderAlreadyUsedByOther.title: Chosen rig folder already in use
9097
animatedJava.popup.error.rigFolderAlreadyUsedByOther.body: |-
@@ -131,6 +138,7 @@ animatedJava.setting.predicateFilePath.description: The item model file of the r
131138

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

135143
animatedJava.setting.useCache.name: Use Animation Cache
136144
animatedJava.setting.useCache.description: Only re-render changed animations
@@ -196,7 +204,7 @@ animatedJava_exporter_statueExporter.setting.exportMode.vanilla.name: Vanilla
196204
animatedJava_exporter_statueExporter.setting.exportMode.mcb.name: MCB
197205

198206
animatedJava_exporter_statueExporter.setting.mcbFilePath.name: Lang-mc file
199-
animatedJava_exporter_statueExporter.setting.mcbFilePath.description: The path to export the .mc file to
207+
animatedJava_exporter_statueExporter.setting.mcbFilePath.description: The path to export the .mc file to\nYou will need to install mc-extra into your MCB workspace in order to build the exported data pack
200208

201209
animatedJava_exporter_statueExporter.setting.mcbConfigPath.name: Lang-mc config.json Path
202210
animatedJava_exporter_statueExporter.setting.mcbConfigPath.description: |-
@@ -232,6 +240,20 @@ animatedJava_exporter_animationExporter.setting.rootEntityNbt.description: The N
232240
animatedJava_exporter_animationExporter.setting.markerArmorStands.name: Marker Armor Stands
233241
animatedJava_exporter_animationExporter.setting.markerArmorStands.description: When enabled all armor_stands used to display the rig will have no hitbox or collision.
234242

243+
animatedJava_exporter_animationExporter.setting.autoDistance.name: Auto Distance
244+
animatedJava_exporter_animationExporter.setting.autoDistance.description: |-
245+
Automatically calculate the maximum distance required to animate all bones in the rig based on the rendered animations.
246+
247+
animatedJava_exporter_animationExporter.setting.autoDistanceMovementThreshold.name: Auto Distance Movement Threshold
248+
animatedJava_exporter_animationExporter.setting.autoDistanceMovementThreshold.description: |-
249+
How much distance to add to the calculated animation distance.
250+
The more distance you add the farther you can move the rig in a single tick without dropping bones
251+
252+
animatedJava_exporter_animationExporter.setting.manualDistance.name: Manual Animation Distance
253+
animatedJava_exporter_animationExporter.setting.manualDistance.description: |-
254+
How far away a bone can be from the root entity before it stops animating.
255+
This setting is intended for advanced users.
256+
235257
animatedJava_exporter_animationExporter.setting.modelTag.name: Model Tag
236258
animatedJava_exporter_animationExporter.setting.modelTag.description: The tag used to select the model
237259

@@ -268,14 +290,19 @@ animatedJava_exporter_animationExporter.setting.exportMode.vanilla.name: Vanilla
268290
animatedJava_exporter_animationExporter.setting.exportMode.mcb.name: MCB
269291

270292
animatedJava_exporter_animationExporter.setting.mcbFilePath.name: Lang-mc File Path
271-
animatedJava_exporter_animationExporter.setting.mcbFilePath.description: The path to export the .mc file to
293+
animatedJava_exporter_animationExporter.setting.mcbFilePath.description: The path to export the .mc file to\nYou will need to install mc-extra into your MCB workspace in order to build the exported data pack
272294
animatedJava_exporter_animationExporter.setting.mcbFilePath.invalidPopup.text: Invalid MCB File Path! The MCB file must be called %projectName.mc (project_name.mc)
273295

274296
animatedJava_exporter_animationExporter.setting.mcbConfigPath.name: Lang-mc config.json Path
275297
animatedJava_exporter_animationExporter.setting.mcbConfigPath.description: |-
276298
Exports the default MCB config for Animated Java
277299
WARNING! Will overwrite existing config.json
278300
301+
animatedJava_exporter_animationExporter.popup.warning.noAnimations.title: No Animations
302+
animatedJava_exporter_animationExporter.popup.warning.noAnimations.body: |-
303+
You haven't made any animations!
304+
You'll need to create some animations in the animation tab before you can export using the animation exporter.
305+
279306
animatedJava_exporter_animationExporter.setting.dataPackPath.name: Data Pack
280307
animatedJava_exporter_animationExporter.setting.dataPackPath.description: The path to export the generated Data Pack to.
281308
animatedJava_exporter_animationExporter.popup.error.dataPackPathNotDefined.title: Data Pack file path undefined

src/modelFormat.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ const format = new ModelFormat({
309309
uv_rotation: true,
310310
centered_grid: true,
311311
animation_files: true,
312+
animated_textures: true,
312313
icon: 'fa-cube',
313314
codec,
314315
onDeactivation() {

src/settings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const DefaultSettings = {
172172
},
173173
}
174174

175-
function evaluateSetting(namespace, name, value) {
175+
function evaluateSetting(event, namespace, name, value) {
176176
const setting = DefaultSettings[namespace]?.[name]
177177
if (setting) {
178178
if (setting.isValid) {
@@ -240,13 +240,15 @@ class Settings {
240240
Object.defineProperty(value, settings[i], {
241241
get: () => {
242242
return evaluateSetting(
243+
'get',
243244
namespace,
244245
settings[i],
245246
this.get(namespace + '.' + settings[i])
246247
)
247248
},
248249
set: (value) => {
249250
const validatedValue = evaluateSetting(
251+
'set',
250252
namespace,
251253
settings[i],
252254
value
@@ -294,6 +296,7 @@ class Settings {
294296
? DefaultSettings[namespace][name]
295297
.default
296298
: evaluateSetting(
299+
'update',
297300
namespace,
298301
name,
299302
settings[namespace][name]
@@ -410,6 +413,7 @@ class Settings {
410413
get() {
411414
if (_cached2 != UNASSIGNED) return _cached2
412415
_cached2 = evaluateSetting(
416+
'get',
413417
key,
414418
key2,
415419
value2

0 commit comments

Comments
 (0)