Skip to content

Commit 17bbc41

Browse files
committed
🚧 Locator Improvements / Fixes
- Fixed Locators not being migrated from `.ajmodel`s properly. (#188) - Added optional MC-Build syntax to all command inputs. - Fixed exportOver Action repeatedly prompting the user for save location.
1 parent d04c2cd commit 17bbc41

File tree

6 files changed

+100
-20
lines changed

6 files changed

+100
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"generic-stream": "^1.2.6",
9898
"marked": "^4.3.0",
9999
"marked-gfm-heading-id": "^3.0.0",
100-
"mc-build": "^3.3.1",
100+
"mc-build": "^3.3.2",
101101
"svelte-ace": "^1.0.21",
102102
"svelte-dnd-action": "^0.9.38"
103103
}

src/lang/en.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ animated_java.dialog.blueprint_settings.data_pack.error.missing_pack_mcmeta: The
114114
animated_java.dialog.blueprint_settings.data_pack.error.missing_data_folder: The selected Data Pack is missing a data folder!
115115

116116
animated_java.dialog.blueprint_settings.summon_commands.title: On-Summon Commands
117-
animated_java.dialog.blueprint_settings.summon_commands.description: Commands to run as the root entity when summoned. Treat this text input as a normal mcfunction.
117+
animated_java.dialog.blueprint_settings.summon_commands.description: |-
118+
Commands to run as the root entity when summoned.
119+
Treat this text input as a .mcfunction file. (Also supports MC-Build syntax!)
118120
119121
animated_java.dialog.blueprint_settings.interpolation_duration.title: Interp Duration
120122
animated_java.dialog.blueprint_settings.interpolation_duration.description: The duration of the smoothing between keyframes in ticks. This is the time it takes for the model to transition from one keyframe to the next. Higher values will cause animations to lose precision. Generally, you want this to have a value of 1 or 2.
@@ -189,12 +191,14 @@ animated_java.dialog.locator_config.entity_type.error.empty: Entity Type cannot
189191
animated_java.dialog.locator_config.entity_type.warning.invalid: The selected entity type doesn't exist in Minecraft {0}
190192

191193
animated_java.dialog.locator_config.summon_commands.title: On-Summon Commands
192-
animated_java.dialog.locator_config.summon_commands.description: Commands to run as the Locator's entity when summoned. Treat this text input as a normal mcfunction.
194+
animated_java.dialog.locator_config.summon_commands.description: |-
195+
Commands to run as the Locator's entity when summoned.
196+
Treat this text input as a .mcfunction file. (Also supports MC-Build syntax!)
193197
194198
animated_java.dialog.locator_config.ticking_commands.title: Ticking Commands
195199
animated_java.dialog.locator_config.ticking_commands.description: |-
196-
Commands to run every tick at the Locator's position. Treat this text input as a normal mcfunction.
197-
NOTE: These commands will only run while an animation is playing.
200+
Commands to run every tick at the Locator's position.
201+
Treat this text input as a .mcfunction file. (Also supports MC-Build syntax!)
198202
199203
## Text Display Config Dialog
200204
animated_java.dialog.text_display_config.title: Text Display Config
@@ -338,8 +342,9 @@ animated_java.panel.keyframe.variant.title: Variant
338342
animated_java.panel.keyframe.variant.description: The Variant to apply to the keyframe.
339343

340344
animated_java.panel.keyframe.commands.title: Commands
341-
animated_java.panel.keyframe.commands.description: Commands to run when the keyframe is reached. Treat this text input as a normal mcfunction.
342-
345+
animated_java.panel.keyframe.commands.description: |-
346+
Commands to run when the keyframe is reached.
347+
Treat this text input as a .mcfunction file. (Also supports MC-Build syntax!)
343348
animated_java.panel.keyframe.execute_condition.title: Execute Condition
344349
animated_java.panel.keyframe.execute_condition.description: A condition that must be met for the keyframe to execute. Treat this text input as the sub-commands of an execute command.
345350

src/mods/exportOverActionMod.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BLUEPRINT_CODEC, BLUEPRINT_FORMAT } from '../blueprintFormat'
22
import { PACKAGE } from '../constants'
33
import { createBlockbenchMod } from '../util/moddingTools'
4+
import { translate } from '../util/translation'
45

56
createBlockbenchMod(
67
`${PACKAGE.name}:exportOverAction`,
@@ -12,10 +13,23 @@ createBlockbenchMod(
1213
context.action.click = (event: Event) => {
1314
if (!Project || !Format) return
1415
if (Format.id === BLUEPRINT_FORMAT.id) {
15-
if (Project.save_path || Project.export_path) {
16-
Project.save_path = Project.save_path || Project.export_path
16+
const path = Project.save_path || Project.export_path
17+
if (path) {
18+
if (fs.existsSync(PathModule.dirname(path))) {
19+
Project.save_path = path
20+
BLUEPRINT_CODEC.write(BLUEPRINT_CODEC.compile(), path)
21+
} else {
22+
console.error(
23+
`Failed to export Animated Java Blueprint, file location '${path}' does not exist!`
24+
)
25+
Blockbench.showMessageBox({
26+
title: translate('error.blueprint_export_path_doesnt_exist.title'),
27+
message: translate('error.blueprint_export_path_doesnt_exist', path),
28+
})
29+
}
30+
} else {
31+
BLUEPRINT_CODEC.export()
1732
}
18-
BLUEPRINT_CODEC.export()
1933
} else {
2034
context.originalClick.call(context.action, event)
2135
}

src/systems/animated_java.mcb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,21 @@ dir <%export_namespace%> {
166166
execute on passengers if entity @s[tag=<%TAGS.PROJECT_DATA(export_namespace)%>] run { with entity @s data.positions.locators.<%node.name%>
167167
$execute as $(uuid) positioned ^$(posx) ^$(posy) ^$(posz) rotated ~$(roty) ~$(rotx) run {
168168
tp @s ~ ~ ~ ~ ~
169-
<%node.config?.ticking_commands || ''%>
169+
<%%
170+
if (node.config?.ticking_commands) {
171+
emit.mcb(node.config.ticking_commands)
172+
}
173+
%%>
170174
}
171175
}
172176
} ELSE IF (node.config?.ticking_commands) {
173177
execute on passengers if entity @s[tag=<%TAGS.PROJECT_DATA(export_namespace)%>] run { with entity @s data.positions.locators.<%node.name%>
174178
$execute positioned ^$(posx) ^$(posy) ^$(posz) rotated ~$(roty) ~$(rotx) run {
175-
<%node.config.ticking_commands%>
179+
<%%
180+
if (node.config?.ticking_commands) {
181+
emit.mcb(node.config.ticking_commands)
182+
}
183+
%%>
176184
}
177185
}
178186
}
@@ -388,7 +396,7 @@ dir <%export_namespace%> {
388396
~<%roundTo(node.rot.x, 10)%> \
389397
~<%roundTo(node.rot.y, 10)%> \
390398
run {
391-
<%node.commands%>
399+
<%%emit.mcb(node.commands)%%>
392400
}
393401
}
394402
} ELSE IF (node.type === 'camera') {
@@ -448,7 +456,11 @@ dir <%export_namespace%> {
448456
execute as @e[type=item_display,tag=<%TAGS.NEW()%>,limit=1,distance=..0.01] on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run {
449457
data modify entity @s data.positions.locators.<%locator.name%>.uuid set from storage aj:uuid main.out
450458
}
451-
<%locator.config.summon_commands%>
459+
<%%
460+
if (locator.config.summon_commands) {
461+
emit.mcb(locator.config.summon_commands)
462+
}
463+
%%>
452464
}
453465
}
454466
}
@@ -520,7 +532,7 @@ dir <%export_namespace%> {
520532
data modify entity @s teleport_duration set value <%teleportation_duration%>
521533
execute on passengers run data modify entity @s teleport_duration set value <%teleportation_duration%>
522534
# Custom Summon Commands
523-
<%custom_summon_commands%>
535+
<%%if (custom_summon_commands) emit.mcb(custom_summon_commands)%%>
524536
# Custom Summon Commands
525537

526538
# Run the on_summon function for the root entity.
@@ -552,7 +564,7 @@ dir <%export_namespace%> {
552564

553565
execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run {
554566
REPEAT (Object.values(rig.nodeMap).filter(v => v.type === 'locator' && v.config?.use_entity)) as locator {
555-
execute run block zzz/kill { with entity @s data.positions.locators.<%locator.name%>
567+
block zzz/kill { with entity @s data.positions.locators.<%locator.name%>
556568
$kill $(uuid)
557569
}
558570
}

src/systems/modelDataFixerUpper.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IBlueprintFormatJSON, getDefaultProjectSettings } from '../blueprintFor
22
import { BoneConfig } from '../nodeConfigs'
33
import { PACKAGE } from '../constants'
44
import { openUnexpectedErrorDialog } from '../interface/unexpectedErrorDialog'
5+
import { NbtCompound, NbtList, NbtString, NbtTag } from 'deepslate'
56

67
export function process(model: any): any {
78
if (model.meta.model_format === 'animatedJava/ajmodel') {
@@ -268,6 +269,54 @@ function updateModelTo1_0pre1(model: any) {
268269
model.outliner.forEach(recurseOutliner)
269270
blueprint.outliner = model.outliner
270271

272+
for (const element of blueprint.elements) {
273+
if (element.type === 'locator') {
274+
element.config = {
275+
use_entity: true,
276+
}
277+
if (element.entity_type) element.config.entity_type = element.entity_type
278+
if (element.nbt) {
279+
const summon_commands: string[] = []
280+
281+
const recursePassengers = (stringNbt: string): string[] => {
282+
const nbt = NbtTag.fromString(stringNbt) as NbtCompound
283+
if (!(nbt instanceof NbtCompound)) throw new Error('NBT is not a compound')
284+
const passengers = nbt.get('Passengers') as NbtList<NbtCompound>
285+
if (passengers) {
286+
console.log('Found passengers')
287+
const commands = passengers.map(p => {
288+
const id = (p.get('id') as NbtString).getAsString()
289+
p.delete('id')
290+
const data = p.toString()
291+
return `execute summon ${id} run {\n\t${[
292+
`data merge entity @s ${data}`,
293+
`tag @s add to_mount`,
294+
...recursePassengers(data),
295+
].join('\n\t')}\n}`
296+
})
297+
commands.push(
298+
`ride @e[tag=to_mount,distance=..0.01] mount @s`,
299+
`execute on passengers run tag @s remove to_mount`
300+
)
301+
return commands
302+
}
303+
return []
304+
}
305+
306+
try {
307+
summon_commands.push(...recursePassengers(element.nbt as string))
308+
} catch (e) {
309+
console.error('Failed to parse NBT', element.nbt)
310+
console.error(e)
311+
}
312+
if (summon_commands.length === 0) {
313+
summon_commands.push(`data merge entity @s ${element.nbt as string}`)
314+
}
315+
element.config.summon_commands = summon_commands.join('\n')
316+
}
317+
}
318+
}
319+
271320
for (const variant of variants) {
272321
const includedBones = variant.affectedBones.map((v: any) => v.value as string)
273322
let excludedBones: string[]

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,10 +2414,10 @@ matcher@^3.0.0:
24142414
dependencies:
24152415
escape-string-regexp "^4.0.0"
24162416

2417-
mc-build@^3.3.1:
2418-
version "3.3.1"
2419-
resolved "https://registry.yarnpkg.com/mc-build/-/mc-build-3.3.1.tgz#9eb10a18c465e1ff9c5e1ef5fe366f738d93aa4d"
2420-
integrity sha512-Na747ajLA47MW1vHieRNT0hKvjIWQhijMa0yHNowOxLiTn6nOqRWtVl1xt4uaxmP6cCV7uaAy+7CN7/dXqo0Gw==
2417+
mc-build@^3.3.2:
2418+
version "3.3.2"
2419+
resolved "https://registry.yarnpkg.com/mc-build/-/mc-build-3.3.2.tgz#0800825d3b9ac87a70abebc34ef3b26eb66b1c15"
2420+
integrity sha512-mOpTW2gXNLwOYlLRyIhItHROJGaRfWhWV4SdWNNFIwGUhzEkyew9sZuJZMUNaIC/kDblCb7FHlz1FHcn0ocXxA==
24212421
dependencies:
24222422
tsx "^4.7.2"
24232423

0 commit comments

Comments
 (0)