Skip to content

Commit 040b00d

Browse files
committed
✨ Add locator on-remove function
1 parent ea4cf39 commit 040b00d

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

src/components/locatorConfigDialog.svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
export let entityType: Valuable<string>
3535
export let syncPassengerRotation: Valuable<boolean>
3636
export let onSummonFunction: Valuable<string>
37+
export let onRemoveFunction: Valuable<string>
3738
export let onTickFunction: Valuable<string>
3839
</script>
3940

@@ -76,6 +77,17 @@
7677
bind:value={onSummonFunction}
7778
defaultValue=""
7879
/>
80+
81+
<CodeInput
82+
label={translate('dialog.locator_config.on_remove_function.title')}
83+
tooltip={$useEntity
84+
? translate(
85+
'dialog.locator_config.on_remove_function.description_with_use_entity'
86+
)
87+
: translate('dialog.locator_config.on_remove_function.description')}
88+
bind:value={onRemoveFunction}
89+
defaultValue=""
90+
/>
7991
{/if}
8092

8193
<CodeInput

src/formats/blueprint/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface IBlueprintLocatorConfigJSON {
6666
entity_type?: LocatorConfig['entityType']
6767
sync_passenger_rotation?: LocatorConfig['syncPassengerRotation']
6868
on_summon_function?: LocatorConfig['__onSummonFunction']
69+
on_remove_function?: LocatorConfig['__onRemoveFunction']
6970
on_tick_function?: LocatorConfig['__onTickFunction']
7071
}
7172

src/interface/dialog/locatorConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function openLocatorConfigDialog(locator: Locator) {
1515
const entityType = new Valuable(locatorConfig.entityType)
1616
const syncPassengerRotation = new Valuable(locatorConfig.syncPassengerRotation)
1717
const onSummonFunction = new Valuable(locatorConfig.onSummonFunction)
18+
const onRemoveFunction = new Valuable(locatorConfig.onRemoveFunction)
1819
const onTickFunction = new Valuable(locatorConfig.onTickFunction)
1920

2021
new SvelteDialog({
@@ -28,6 +29,7 @@ export function openLocatorConfigDialog(locator: Locator) {
2829
entityType,
2930
syncPassengerRotation,
3031
onSummonFunction,
32+
onRemoveFunction,
3133
onTickFunction,
3234
},
3335
},
@@ -37,6 +39,7 @@ export function openLocatorConfigDialog(locator: Locator) {
3739
locatorConfig.entityType = entityType.get()
3840
locatorConfig.syncPassengerRotation = syncPassengerRotation.get()
3941
locatorConfig.onSummonFunction = onSummonFunction.get()
42+
locatorConfig.onRemoveFunction = onRemoveFunction.get()
4043
locatorConfig.onTickFunction = onTickFunction.get()
4144

4245
locator.config = locatorConfig.toJSON()

src/lang/en.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ animated_java.dialog.locator_config.on_summon_function.description_with_use_enti
382382
383383
Supports [MC-Build](https://mcbuild.dev) syntax.
384384
385+
animated_java.dialog.locator_config.on_remove_function.title: On-Remove Function
386+
animated_java.dialog.locator_config.on_remove_function.description: |-
387+
Commands to run `as` the root entity and `at` the Locator's position when the rig is removed.
388+
389+
Supports [MC-Build](https://mcbuild.dev) syntax.
390+
animated_java.dialog.locator_config.on_remove_function.description_with_use_entity: |-
391+
Commands to run `as` and `at` the Locator's entity when removed.
392+
393+
Supports [MC-Build](https://mcbuild.dev) syntax.
394+
385395
animated_java.dialog.locator_config.on_tick_function.title: On-Tick Function
386396
animated_java.dialog.locator_config.on_tick_function.description: |-
387397
Commands to run `at` the Locator's position every tick.

src/nodeConfigs.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ export class LocatorConfig {
350350
private __entityType?: string
351351
private __syncPassengerRotation?: boolean
352352
private __onSummonFunction?: string
353+
private __onRemoveFunction?: string
353354
private __onTickFunction?: string
354355

355356
getDefault(): LocatorConfig {
@@ -358,6 +359,7 @@ export class LocatorConfig {
358359
entity_type: 'minecraft:pig',
359360
sync_passenger_rotation: false,
360361
on_summon_function: '',
362+
on_remove_function: '',
361363
on_tick_function: '',
362364
})
363365
}
@@ -398,6 +400,15 @@ export class LocatorConfig {
398400
this.__onSummonFunction = value
399401
}
400402

403+
get onRemoveFunction(): NonNullable<LocatorConfig['__onRemoveFunction']> {
404+
if (this.__onRemoveFunction !== undefined) return this.__onRemoveFunction
405+
const defaultConfig = this.getDefault()
406+
return defaultConfig.onRemoveFunction
407+
}
408+
set onRemoveFunction(value: NonNullable<LocatorConfig['__onRemoveFunction']>) {
409+
this.__onRemoveFunction = value
410+
}
411+
401412
get onTickFunction(): NonNullable<LocatorConfig['__onTickFunction']> {
402413
if (this.__onTickFunction !== undefined) return this.__onTickFunction
403414
const defaultConfig = this.getDefault()
@@ -413,6 +424,7 @@ export class LocatorConfig {
413424
entity_type: this.__entityType,
414425
sync_passenger_rotation: this.__syncPassengerRotation,
415426
on_summon_function: this.__onSummonFunction,
427+
on_remove_function: this.__onRemoveFunction,
416428
on_tick_function: this.__onTickFunction,
417429
})
418430
}
@@ -425,6 +437,8 @@ export class LocatorConfig {
425437
config.__syncPassengerRotation = json.sync_passenger_rotation
426438
if (json.on_summon_function !== undefined)
427439
config.__onSummonFunction = json.on_summon_function
440+
if (json.on_remove_function !== undefined)
441+
config.__onRemoveFunction = json.on_remove_function
428442
if (json.on_tick_function !== undefined) config.__onTickFunction = json.on_tick_function
429443
return config
430444
}
@@ -439,6 +453,7 @@ export class LocatorConfig {
439453
this.entityType === other.entityType &&
440454
this.syncPassengerRotation === other.syncPassengerRotation &&
441455
this.onSummonFunction === other.onSummonFunction &&
456+
this.onRemoveFunction === other.onRemoveFunction &&
442457
this.onTickFunction === other.onTickFunction
443458
)
444459
}

src/systems/datapackCompiler/1.20.4/animation.mcb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,35 @@ dir remove {
890890
if (on_remove_function) emit.mcb(on_remove_function)
891891
%%>
892892

893+
IF (has_entity_locators) {
894+
execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run block as_data {
895+
REPEAT (Object.values(rig.nodes).filter(node => node.type === 'locator')) as locator {
896+
IF (locator.config?.on_remove_function) {
897+
IF (locator.config.use_entity) {
898+
block as_locator_<%locator.storage_name%> { with entity @s data.locators.<%locator.storage_name%>
899+
$execute as $(uuid) at @s run block locator_<%locator.storage_name%>_on_remove {
900+
<%%
901+
emit.mcb(locator.config.on_remove_function)
902+
%%>
903+
}
904+
}
905+
} ELSE {
906+
block at_locator_<%locator.storage_name%> { with entity @s data.locators.<%locator.storage_name%>
907+
$execute \
908+
positioned ^$(px) ^$(py) ^$(pz) \
909+
rotated ~$(ry) ~$(rx) \
910+
run block locator_<%locator.storage_name%>_on_remove {
911+
<%%
912+
emit.mcb(locator.config.on_remove_function)
913+
%%>
914+
}
915+
}
916+
}
917+
}
918+
}
919+
}
920+
}
921+
893922
function ./this/without_on_remove_function
894923
}
895924

0 commit comments

Comments
 (0)