Skip to content

Commit cdc85eb

Browse files
committed
🚧 More Locator Improvements
- Fixed entities stacked on top of locator entities not being removed when the rig is removed. - Fixed rig summon commands causing export crash. - Added `as_own_locator_entities` function to execute commands as all of a rig's locators. - Improved locator migration code.
1 parent 17bbc41 commit cdc85eb

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

src/systems/animated_java.mcb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ dir <%export_namespace%> {
396396
~<%roundTo(node.rot.x, 10)%> \
397397
~<%roundTo(node.rot.y, 10)%> \
398398
run {
399-
<%%emit.mcb(node.commands)%%>
399+
<%%
400+
emit.mcb(node.commands)
401+
%%>
400402
}
401403
}
402404
} ELSE IF (node.type === 'camera') {
@@ -532,7 +534,9 @@ dir <%export_namespace%> {
532534
data modify entity @s teleport_duration set value <%teleportation_duration%>
533535
execute on passengers run data modify entity @s teleport_duration set value <%teleportation_duration%>
534536
# Custom Summon Commands
535-
<%%if (custom_summon_commands) emit.mcb(custom_summon_commands)%%>
537+
<%%
538+
if (custom_summon_commands) emit.mcb(custom_summon_commands)
539+
%%>
536540
# Custom Summon Commands
537541

538542
# Run the on_summon function for the root entity.
@@ -548,6 +552,23 @@ dir <%export_namespace%> {
548552
}
549553
}
550554

555+
function as_own_locator_entities {
556+
#ARGS: {command: string}
557+
execute unless entity @s[type=item_display,tag=<%TAGS.PROJECT_ROOT(export_namespace)%>] run return run \
558+
function *global/errors/function_not_executed_as_root_entity \
559+
{'function_path': 'animated_java:<%export_namespace%>/as_all_locators'}
560+
$data modify storage aj:temp command set value '$(command)'
561+
execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run {
562+
REPEAT (Object.values(rig.nodeMap).filter(v => v.type === 'locator')) as locator {
563+
data modify storage aj:temp uuid set from entity @s data.positions.locators.<%locator.name%>.uuid
564+
block zzz/execute { with storage aj:temp
565+
$execute as $(uuid) run $(command)
566+
}
567+
}
568+
}
569+
}
570+
571+
551572
dir remove {
552573
# Removes all instances of this rig from the world.
553574
function all {
@@ -565,7 +586,11 @@ dir <%export_namespace%> {
565586
execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run {
566587
REPEAT (Object.values(rig.nodeMap).filter(v => v.type === 'locator' && v.config?.use_entity)) as locator {
567588
block zzz/kill { with entity @s data.positions.locators.<%locator.name%>
568-
$kill $(uuid)
589+
# Recursively remove any stacked locator entities
590+
$execute as $(uuid) run block kill_passengers {
591+
execute on passengers run function ^0
592+
kill @s
593+
}
569594
}
570595
}
571596
}

src/systems/modelDataFixerUpper.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ function updateModelTo1_0pre1(model: any) {
277277
if (element.entity_type) element.config.entity_type = element.entity_type
278278
if (element.nbt) {
279279
const summon_commands: string[] = []
280+
const nbt = NbtTag.fromString(element.nbt as string) as NbtCompound
281+
nbt.delete('Passengers')
282+
const tags = (nbt.get('Tags') as NbtList<NbtString>)?.map(t => t.getAsString())
283+
nbt.delete('Tags')
284+
summon_commands.push('data merge entity @s ' + nbt.toString())
285+
if (tags) summon_commands.push(...tags.map(t => `tag @s add ${t}`))
280286

281287
const recursePassengers = (stringNbt: string): string[] => {
282288
const nbt = NbtTag.fromString(stringNbt) as NbtCompound
@@ -287,15 +293,25 @@ function updateModelTo1_0pre1(model: any) {
287293
const commands = passengers.map(p => {
288294
const id = (p.get('id') as NbtString).getAsString()
289295
p.delete('id')
296+
const tags = (p.get('Tags') as NbtList<NbtString>).map(t =>
297+
t.getAsString()
298+
)
299+
p.delete('Tags')
290300
const data = p.toString()
291301
return `execute summon ${id} run {\n\t${[
292302
`data merge entity @s ${data}`,
303+
...tags.map(t => `tag @s add ${t}`),
293304
`tag @s add to_mount`,
294305
...recursePassengers(data),
295306
].join('\n\t')}\n}`
296307
})
297308
commands.push(
298-
`ride @e[tag=to_mount,distance=..0.01] mount @s`,
309+
`tag @s add vehicle`,
310+
`execute as @e[tag=to_mount,distance=..0.01] run {`,
311+
`\tride @s mount @e[tag=vehicle,limit=1]`,
312+
`\ttag @s remove to_mount`,
313+
`}`,
314+
`tag @s remove vehicle`,
299315
`execute on passengers run tag @s remove to_mount`
300316
)
301317
return commands
@@ -312,6 +328,7 @@ function updateModelTo1_0pre1(model: any) {
312328
if (summon_commands.length === 0) {
313329
summon_commands.push(`data merge entity @s ${element.nbt as string}`)
314330
}
331+
315332
element.config.summon_commands = summon_commands.join('\n')
316333
}
317334
}
@@ -395,9 +412,15 @@ function updateModelTo1_0pre1(model: any) {
395412
datapackExporterSettings?.root_entity_nbt &&
396413
datapackExporterSettings.root_entity_nbt !== '{}'
397414
) {
398-
blueprint.project_settings!.summon_commands = `data merge entity @s ${
415+
const commands: string[] = []
416+
const nbt = NbtTag.fromString(
399417
datapackExporterSettings.root_entity_nbt as string
400-
}`
418+
) as NbtCompound
419+
const tags = (nbt.get('Tags') as NbtList<NbtString>)?.map(t => t.getAsString())
420+
nbt.delete('Tags')
421+
if ([...nbt.keys()].length !== 0) commands.push('data merge entity @s ' + nbt.toString())
422+
if (tags) commands.push(...tags.map(t => `tag @s add ${t}`))
423+
blueprint.project_settings!.summon_commands = commands.join('\n')
401424
}
402425

403426
console.log('Finished Blueprint:', blueprint)

src/util/fileUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export function isJsonPath(path: string): boolean {
77
}
88

99
export function isFunctionTagPath(path: string): boolean {
10-
return path.endsWith('.json') && path.includes(`tags${PathModule.sep}functions`)
10+
return path.endsWith('.json') && path.includes(`tags${PathModule.sep}function`)
1111
}

0 commit comments

Comments
 (0)