Skip to content

Commit fc32715

Browse files
committed
Locators overhaul, and general fixes.
Added rotation support to locators Made locators and cameras UUID and origin based. No more entity selectors Added support for multiple locators in a single animation Added locator support for multi-instanced rigs Fixed predicates not merging properly
1 parent 72f9e03 commit fc32715

20 files changed

+611
-948
lines changed

exporters/datapackExporter/datapackExporter.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ export function loadExporter() {
3636
}
3737
}
3838
),
39-
interpolation_duration: new Settings.NumberSetting({
40-
id: 'animated_java:datapack_exporter/interpolation_duration',
41-
displayName: TRANSLATIONS.interpolation_duration.name,
42-
description: TRANSLATIONS.interpolation_duration.description,
43-
defaultValue: 1,
44-
min: 0,
45-
step: 1,
46-
// resettable: true,
47-
docsLink: '/docs/exporters/datapack_exporter/settings#interpolation_duration',
48-
}),
4939
outdated_rig_warning: new Settings.CheckboxSetting({
5040
id: 'animated_java:datapack_exporter/outdated_rig_warning',
5141
displayName: TRANSLATIONS.enable_outdated_rig_warning.name,
@@ -61,12 +51,6 @@ export function loadExporter() {
6151
docsLink:
6252
'/docs/exporters/datapack_exporter/settings#include_convenience_functions',
6353
}),
64-
// enable_single_rig_optimizations: new AJSettings.CheckboxSetting({
65-
// id: 'animated_java:datapack_exporter/enable_single_rig_optimizations',
66-
// displayName: TRANSLATIONS.enable_single_rig_optimizations.name,
67-
// description: TRANSLATIONS.enable_single_rig_optimizations.description,
68-
// defaultValue: false,
69-
// }),
7054
root_entity_nbt: new Settings.CodeboxSetting(
7155
{
7256
id: 'animated_java:datapack_exporter/root_entity_nbt',
@@ -91,10 +75,6 @@ export function loadExporter() {
9175
type: 'setting',
9276
settingId: 'animated_java:datapack_exporter/datapack_mcmeta',
9377
},
94-
{
95-
type: 'setting',
96-
settingId: 'animated_java:datapack_exporter/interpolation_duration',
97-
},
9878
{
9979
type: 'setting',
10080
settingId: 'animated_java:datapack_exporter/outdated_rig_warning',
@@ -103,10 +83,6 @@ export function loadExporter() {
10383
type: 'setting',
10484
settingId: 'animated_java:datapack_exporter/include_convenience_functions',
10585
},
106-
// {
107-
// type: 'setting',
108-
// settingId: 'animated_java:datapack_exporter/enable_single_rig_optimizations',
109-
// },
11086
{
11187
type: 'setting',
11288
settingId: 'animated_java:datapack_exporter/root_entity_nbt',

exporters/datapackExporter/exporter/datapackGen/animatedJavaFolderGen.ts

Lines changed: 133 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { NbtCompound } from 'deepslate'
2+
import { wrapNum } from '../util'
13
import { loadAnimationTreeGenerator } from './animationTreeGen'
24
import { Globals as G } from './globals'
35

@@ -6,15 +8,26 @@ function getExportVersionId() {
68
}
79

810
export function generateAnimatedJavaFolder() {
9-
const { formatStr, generateSearchTree } = AnimatedJava.API
10-
const { ajSettings, projectSettings, exporterSettings, renderedAnimations, rig } = G.exportData
11+
const { formatStr, generateSearchTree, roundToN } = AnimatedJava.API
12+
const { NbtString, NbtList, NbtTag } = AnimatedJava.API.deepslate
13+
const { exporterSettings, renderedAnimations, rig } = G.exportData
1114

1215
const internalFolder = G.DATA_FOLDER.newFolder(G.AJ_NAMESPACE)
1316
const [functionsFolder, applyVariantFolder, animationFunctionsFolder] =
1417
internalFolder.newFolders('functions', 'functions/apply_variant', 'functions/animations')
1518

1619
const { buildFrameTree } = loadAnimationTreeGenerator()
1720

21+
function locatorToString(node: AnimatedJava.IAnimationNode) {
22+
const pos = node.pos
23+
const euler = new THREE.Euler().setFromQuaternion(node.rot, 'YXZ')
24+
const rot = new THREE.Vector3(euler.x, euler.y, euler.z).multiplyScalar(180 / Math.PI)
25+
return `tp @s ^${roundToN(pos.x, 100000)} ^${roundToN(pos.y, 100000)} ^${roundToN(
26+
pos.z,
27+
100000
28+
)} ~${roundToN(wrapNum(-rot.y - 180, -180, 180), 100000)} ~${roundToN(-rot.x, 100000)}`
29+
}
30+
1831
functionsFolder
1932
// ANCHOR - func AJ_NAMESPACE:load
2033
.chainNewFile('load.mcfunction', [
@@ -32,7 +45,7 @@ export function generateAnimatedJavaFolder() {
3245
...G.VARIANTS.map((v, i) => `scoreboard players set $aj.${G.NAMESPACE}.variant.${v.name} ${G.SCOREBOARD.id} ${i}`),
3346
// Variable initialization
3447
`scoreboard players add .aj.last_id ${G.SCOREBOARD.id} 0`,
35-
`scoreboard players set $aj.default_interpolation_duration ${G.SCOREBOARD.i} ${exporterSettings.interpolation_duration.value}`,
48+
`scoreboard players set $aj.default_interpolation_duration ${G.SCOREBOARD.i} ${G.DEFAULT_INTERPOLATION_DURATION}`,
3649
// prettier-ignore
3750
...G.LOOP_MODES.map((mode, i) => `scoreboard players set $aj.loop_mode.${mode} ${G.SCOREBOARD.i} ${i}`),
3851
// version ID
@@ -63,7 +76,7 @@ export function generateAnimatedJavaFolder() {
6376
`function ${G.AJ_NAMESPACE}:animations/tick`,
6477
])
6578

66-
functionsFolder
79+
const summonFolder = functionsFolder
6780
.newFolder('summon')
6881
// ANCHOR - func AJ_NAMESPACE:summon/as_root
6982
.chainNewFile('as_root.mcfunction', [
@@ -82,8 +95,8 @@ export function generateAnimatedJavaFolder() {
8295
`execute store result score @s ${G.SCOREBOARD.id} run scoreboard players add .aj.last_id ${G.SCOREBOARD.id} 1`,
8396
`tp @s ~ ~ ~ ~ ~`,
8497
G.IS_SINGLE_ENTITY_RIG
85-
? `execute at @s run function ${G.AJ_NAMESPACE}:summon/as_bone`
86-
: `execute at @s on passengers run function ${G.AJ_NAMESPACE}:summon/as_bone`,
98+
? `execute at @s run function ${G.AJ_NAMESPACE}:summon/as_rig_entities`
99+
: `execute at @s on passengers run function ${G.AJ_NAMESPACE}:summon/as_rig_entities`,
87100
...G.VARIANTS.map(
88101
v =>
89102
`execute if score #variant ${G.SCOREBOARD.i} = $aj.${G.NAMESPACE}.variant.${v.name} ${G.SCOREBOARD.id} run function ${G.AJ_NAMESPACE}:apply_variant/${v.name}_as_root`
@@ -100,24 +113,135 @@ export function generateAnimatedJavaFolder() {
100113
)} = #frame ${G.SCOREBOARD.i}`,
101114
])
102115
.reduce((a, b) => a.concat(b), []),
103-
`execute at @s run function #${G.NAMESPACE}:on_summon`,
116+
`execute at @s run function #${G.NAMESPACE}:on_summon_as_root`,
104117
`tag @s remove ${G.TAGS.new}`,
105118
// Reset scoreboard arguemnts
106119
`scoreboard players reset #frame ${G.SCOREBOARD.i}`,
107120
`scoreboard players reset #variant ${G.SCOREBOARD.i}`,
108121
`scoreboard players reset #animation ${G.SCOREBOARD.i}`,
109122
])
110-
// ANCHOR - func AJ_NAMESPACE:summon/as_bone
111-
.chainNewFile('as_bone.mcfunction', [
123+
// ANCHOR - func AJ_NAMESPACE:summon/as_rig_entities
124+
.chainNewFile('as_rig_entities.mcfunction', [
112125
`scoreboard players operation @s ${G.SCOREBOARD.id} = .aj.last_id ${G.SCOREBOARD.id}`,
113126
`tag @s remove ${G.TAGS.new}`,
127+
`function #${G.NAMESPACE}:on_summon_as_rig_entities`,
128+
`execute if entity @s[tag=${G.TAGS.boneEntity}] run function ${G.AJ_NAMESPACE}:summon/as_bones`,
129+
`execute if entity @s[tag=${G.TAGS.locatorEntity}] run function ${G.AJ_NAMESPACE}:summon/as_locators`,
130+
`execute if entity @s[tag=${G.TAGS.cameraEntity}] run function ${G.AJ_NAMESPACE}:summon/as_cameras`,
131+
])
132+
// ANCHOR - func AJ_NAMESPACE:summon/as_bones
133+
.chainNewFile('as_bones.mcfunction', [
134+
// `say bone`,
135+
`function #${G.NAMESPACE}:on_summon_as_bones`,
136+
])
137+
// ANCHOR - func AJ_NAMESPACE:summon/as_locators
138+
.chainNewFile('as_locators.mcfunction', [
139+
// `say locator`,
140+
...Object.values(rig.nodeMap)
141+
.map(locator =>
142+
locator.type === 'locator'
143+
? `execute if entity @s[tag=${formatStr(G.TAGS.namedLocatorEntity, [
144+
locator.name,
145+
])}] run function ${G.AJ_NAMESPACE}:summon/locator_${
146+
locator.name
147+
}/as_origin`
148+
: ''
149+
)
150+
.filter(v => v),
151+
`function #${G.NAMESPACE}:on_summon_as_locators`,
152+
])
153+
// ANCHOR - func AJ_NAMESPACE:summon/as_cameras
154+
.chainNewFile('as_cameras.mcfunction', [
155+
// `say camera`,
156+
...Object.values(rig.nodeMap)
157+
.map(camera =>
158+
camera.type === 'camera'
159+
? `execute if entity @s[tag=${formatStr(G.TAGS.namedCameraEntity, [
160+
camera.name,
161+
])}] run function ${G.AJ_NAMESPACE}:summon/camera_${
162+
camera.name
163+
}/as_origin`
164+
: ''
165+
)
166+
.filter(v => v),
167+
`function #${G.NAMESPACE}:on_summon_as_cameras`,
114168
])
115169

170+
for (const [uuid, camera] of Object.entries(rig.nodeMap)) {
171+
if (camera.type !== 'camera') continue
172+
const cameraNbt = (NbtTag.fromString(camera.nbt) as NbtCompound).set(
173+
'Tags',
174+
new NbtList([
175+
new NbtString(G.TAGS.cameraTarget),
176+
new NbtString(formatStr(G.TAGS.namedCameraTarget, [camera.name])),
177+
new NbtString(G.TAGS.new),
178+
])
179+
)
180+
summonFolder
181+
.newFolder(`camera_${camera.name}`)
182+
// ANCHOR - func AJ_NAMESPACE:summon/camera_${camera.name}/as_origin
183+
.chainNewFile(`as_origin.mcfunction`, [
184+
// `say Camera Origin`,
185+
`summon ${camera.entity_type} ~ ~ ~ ${cameraNbt.toString()}`,
186+
`execute as @e[type=${camera.entity_type},tag=${formatStr(
187+
G.TAGS.namedCameraTarget,
188+
[camera.name]
189+
)},tag=${G.TAGS.new},limit=1,distance=..0.1] run function ${
190+
G.AJ_NAMESPACE
191+
}:summon/camera_${camera.name}/as_target`,
192+
`data modify entity @s Owner set from storage animated_java Owner`,
193+
`data remove storage animated_java Owner`,
194+
])
195+
// ANCHOR - func AJ_NAMESPACE:summon/camera_${camera.name}/as_target
196+
.chainNewFile(`as_target.mcfunction`, [
197+
// `say Camera Target`,
198+
locatorToString(rig.defaultPose.find(v => v.uuid === uuid)),
199+
`data modify storage animated_java Owner set from entity @s UUID`,
200+
`tag @s remove ${G.TAGS.new}`,
201+
])
202+
}
203+
204+
for (const [uuid, locator] of Object.entries(rig.nodeMap)) {
205+
if (locator.type !== 'locator') continue
206+
const locatorNbt = (NbtTag.fromString(locator.nbt) as NbtCompound).set(
207+
'Tags',
208+
new NbtList([
209+
new NbtString(G.TAGS.locatorTarget),
210+
new NbtString(formatStr(G.TAGS.namedLocatorTarget, [locator.name])),
211+
new NbtString(G.TAGS.new),
212+
])
213+
)
214+
summonFolder
215+
.newFolder(`locator_${locator.name}`)
216+
// ANCHOR - func AJ_NAMESPACE:summon/locator_${locator.name}/as_origin
217+
.chainNewFile(`as_origin.mcfunction`, [
218+
// `say Origin`,
219+
`summon ${locator.entity_type} ~ ~ ~ ${locatorNbt.toString()}`,
220+
`execute as @e[type=${locator.entity_type},tag=${formatStr(
221+
G.TAGS.namedLocatorTarget,
222+
[locator.name]
223+
)},tag=${G.TAGS.new},limit=1,distance=..0.1] run function ${
224+
G.AJ_NAMESPACE
225+
}:summon/locator_${locator.name}/as_target`,
226+
`data modify entity @s Owner set from storage animated_java Owner`,
227+
`data remove storage animated_java Owner`,
228+
// `execute on origin run say locatorTarget for ${locator.name}`,
229+
])
230+
// ANCHOR - func AJ_NAMESPACE:summon/locator_${locator.name}/as_target
231+
.chainNewFile(`as_target.mcfunction`, [
232+
// `say Target`,
233+
locatorToString(rig.defaultPose.find(v => v.uuid === uuid)),
234+
`data modify storage animated_java Owner set from entity @s UUID`,
235+
`tag @s remove ${G.TAGS.new}`,
236+
])
237+
}
238+
116239
functionsFolder
117240
.newFolder('remove')
118241
// ANCHOR - func AJ_NAMESPACE:remove/as_root
119242
.chainNewFile('as_root.mcfunction', [
120243
`execute at @s run function #${G.NAMESPACE}:on_remove`,
244+
G.IS_SINGLE_ENTITY_RIG ? undefined : `execute on passengers on origin run kill @s`,
121245
G.IS_SINGLE_ENTITY_RIG ? undefined : `execute on passengers run kill @s`,
122246
`kill @s`,
123247
])

0 commit comments

Comments
 (0)