Skip to content

Commit 20de7bd

Browse files
committed
Improve activation logic and armor handling
- Refactored entity activation distance calculations to bundle and cache position data retrieval calls, and updated batch activation logic for better performance (up to 1ms faster per tick!) - Fixed v0 save format not correctly upgrading to v1 from 24w11a to 24w20a (affecting major releases 1.20.5 and 1.20.6) - Improved armor save/resolve functions to include the vanishing curse enchantment in the root proxy chest item
1 parent e03f846 commit 20de7bd

File tree

22 files changed

+68
-38
lines changed

22 files changed

+68
-38
lines changed

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
- **Added support for Minecraft 1.21.7** 💿
1+
- Improved performance by refactoring entity activation distance calculations to bundle and cache position data retrieval calls, and updating batch activation logic (up to 1 ms faster per tick!)
2+
- Fixed v0 save format not correctly upgrading to v1 from 24w11a to 24w20a (affecting major releases 1.20.5 and 1.20.6)
3+
- Improved armor save/resolve functions to include the vanishing curse enchantment in the root proxy chest item

data/spawnanimations/function/install.mcfunction

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ scoreboard objectives add ts.sa.timer dummy
55
scoreboard objectives add ts.sa.count dummy
66
scoreboard objectives add ts.sa.welcome trigger
77

8+
# Activation distance calculation
89
scoreboard objectives add ts.sa.x dummy
910
scoreboard objectives add ts.sa.y dummy
1011
scoreboard objectives add ts.sa.z dummy
12+
scoreboard players set #minus ts.sa.x -1
13+
14+
# Escape protection for shrunk/emissive entities (see emissive_layer)
15+
scoreboard objectives add ts.sa.prev_x dummy
16+
scoreboard objectives add ts.sa.prev_y dummy
17+
scoreboard objectives add ts.sa.prev_z dummy
1118

1219
# Entity properties
1320
scoreboard objectives add ts.sa.e.y dummy

data/spawnanimations/function/internal/calc_activation.mcfunction

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# @s/~ ~ ~ is tested entity; $global is player position
33

44
# Get position
5-
execute store result score @s ts.sa.x run data get entity @s Pos[0]
6-
execute store result score @s ts.sa.y run data get entity @s Pos[1]
7-
execute store result score @s ts.sa.z run data get entity @s Pos[2]
5+
data modify storage spawnanimations:temp Pos set from entity @s Pos
6+
execute store result score @s ts.sa.x run data get storage spawnanimations:temp Pos[0]
7+
execute store result score @s ts.sa.y run data get storage spawnanimations:temp Pos[1]
8+
execute store result score @s ts.sa.z run data get storage spawnanimations:temp Pos[2]
89

910
# Calculate diff
1011
scoreboard players operation @s ts.sa.x -= $global ts.sa.x
1112
scoreboard players operation @s ts.sa.y -= $global ts.sa.y
1213
scoreboard players operation @s ts.sa.z -= $global ts.sa.z
1314

1415
# Make sure value is positive
15-
scoreboard players set $minus ts.sa.x -1
16-
execute if score @s ts.sa.x matches ..0 run scoreboard players operation @s ts.sa.x *= $minus ts.sa.x
17-
execute if score @s ts.sa.y matches ..0 run scoreboard players operation @s ts.sa.y *= $minus ts.sa.x
18-
execute if score @s ts.sa.z matches ..0 run scoreboard players operation @s ts.sa.z *= $minus ts.sa.x
16+
execute if score @s ts.sa.x matches ..0 run scoreboard players operation @s ts.sa.x *= #minus ts.sa.x
17+
execute if score @s ts.sa.y matches ..0 run scoreboard players operation @s ts.sa.y *= #minus ts.sa.x
18+
execute if score @s ts.sa.z matches ..0 run scoreboard players operation @s ts.sa.z *= #minus ts.sa.x
1919

20-
# Add dis together
20+
# Add distances together
2121
scoreboard players operation @s ts.sa.x += @s ts.sa.y
2222
scoreboard players operation @s ts.sa.x += @s ts.sa.z
2323

data/spawnanimations/function/internal/entity/ehs/conflict/resolve.mcfunction

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ data modify storage spawnanimations:temp equipment set value {}
77
data modify storage spawnanimations:temp equipment set from entity @s equipment
88

99
# Build entity data
10-
data modify storage spawnanimations:temp equipment_build set value {body:{id:"minecraft:chest",count:1,components:{"minecraft:container":[{slot:0,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:1,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:2,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:3,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:4,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:5,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:6,item:{id:"minecraft:paper",count:1,components:{"minecraft:custom_data":{TsSaveFormat:2,TsSaRemove:1b}}}}],"minecraft:custom_data":{TsSaRemove:1b}}}}
10+
data modify storage spawnanimations:temp equipment_build set value {body:{id:"minecraft:chest",count:1,components:{"minecraft:container":[{slot:0,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:1,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:2,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:3,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:4,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:5,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:6,item:{id:"minecraft:paper",count:1,components:{"minecraft:custom_data":{TsSaveFormat:2,TsSaRemove:1b}}}}],"minecraft:enchantments":{"minecraft:vanishing_curse":1},"minecraft:custom_data":{TsSaRemove:1b}}}}
1111
data modify storage spawnanimations:temp equipment_build.body merge from storage spawnanimations:temp equipment.body
1212

1313
# Save new Armor Items

data/spawnanimations/function/internal/entity/ehs/save_armor.mcfunction

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data modify storage spawnanimations:temp equipment set value {}
88
data modify storage spawnanimations:temp equipment set from entity @s equipment
99

1010
# Build entity data
11-
data modify storage spawnanimations:temp equipment_build set value {body:{id:"minecraft:chest",count:1,components:{"minecraft:container":[{slot:0,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:1,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:2,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:3,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:4,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:5,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:6,item:{id:"minecraft:paper",count:1,components:{"minecraft:custom_data":{TsSaveFormat:2,TsSaRemove:1b}}}}],"minecraft:custom_data":{TsSaRemove:1b}}}}
11+
data modify storage spawnanimations:temp equipment_build set value {body:{id:"minecraft:chest",count:1,components:{"minecraft:container":[{slot:0,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:1,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:2,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:3,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:4,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:5,item:{id:"minecraft:chest",count:1,components:{"minecraft:custom_data":{TsSaRemove:1b}}}},{slot:6,item:{id:"minecraft:paper",count:1,components:{"minecraft:custom_data":{TsSaveFormat:2,TsSaRemove:1b}}}}],"minecraft:enchantments":{"minecraft:vanishing_curse":1},"minecraft:custom_data":{TsSaRemove:1b}}}}
1212

1313
# Copy Armor Items in correct order
1414
execute if data storage spawnanimations:temp equipment.feet.id run function spawnanimations:internal/entity/ehs/build_data_entry/armor_0

data/spawnanimations/function/internal/entity/get_animation_speed.mcfunction

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##by Tschipcraft
2-
# This function sets the ts.sa.e.speed scoreboard depending on speed and slowness effects of the current entity (@s)
2+
# Sets the ts.sa.e.speed scoreboard value depending on speed and slowness effects of the current entity (@s)
33

44
scoreboard players set @s ts.sa.e.speed 0
55
execute if predicate spawnanimations:animation_speed/speed0 run scoreboard players add @s ts.sa.e.speed 1
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
##by Tschipcraft
22

3-
# Get pos
4-
execute store result score $global ts.sa.x run data get entity @s Pos[0]
5-
execute store result score $global ts.sa.y run data get entity @s Pos[1]
6-
execute store result score $global ts.sa.z run data get entity @s Pos[2]
3+
# Get player position
4+
data modify storage spawnanimations:temp Pos set from entity @s Pos
5+
execute store result score $global ts.sa.x run data get storage spawnanimations:temp Pos[0]
6+
execute store result score $global ts.sa.y run data get storage spawnanimations:temp Pos[1]
7+
execute store result score $global ts.sa.z run data get storage spawnanimations:temp Pos[2]
78

89
# Activate entities
9-
execute as @e[type=!#spawnanimations:exclude,tag=ts.sa.to_verify,distance=..100,limit=10,sort=random] at @s run function spawnanimations:internal/calc_activation
10+
execute if score $activation_dist ts.sa.settings matches 25..100 as @e[type=!#spawnanimations:exclude,tag=ts.sa.to_verify,distance=..100,limit=5,sort=random] at @s run function spawnanimations:internal/calc_activation
11+
execute if score $activation_dist ts.sa.settings matches 1..24 as @e[type=!#spawnanimations:exclude,tag=ts.sa.to_verify,distance=..25,limit=1,sort=random] at @s run function spawnanimations:internal/calc_activation

data/spawnanimations/function/main.mcfunction

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ execute if score $version ts.sa.settings matches 2587.. as @e[type=#spawnanimati
1313
# Player nearby
1414
execute if score $global ts.sa.count matches ..100 as @a[gamemode=!spectator,sort=random,limit=5] at @s run function spawnanimations:internal/run_activation_batch
1515
# Exclusion criteria
16-
execute if score $global ts.sa.count matches ..100 as @e[type=!#spawnanimations:exclude,predicate=!spawnanimations:trigger,tag=ts.sa.to_verify,limit=10,sort=random] at @s run function spawnanimations:internal/animation/dig_up/start
16+
execute if score $global ts.sa.count matches ..100 as @e[type=!#spawnanimations:exclude,tag=ts.sa.to_verify,limit=10,sort=random] as @s[predicate=!spawnanimations:trigger] at @s run function spawnanimations:internal/animation/dig_up/start
1717

1818

1919
## Tick dig up animation

data/spawnanimations/function/uninstall.mcfunction

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ scoreboard objectives remove ts.sa.welcome
1717
scoreboard objectives remove ts.sa.x
1818
scoreboard objectives remove ts.sa.y
1919
scoreboard objectives remove ts.sa.z
20+
scoreboard objectives remove ts.sa.prev_x
21+
scoreboard objectives remove ts.sa.prev_y
22+
scoreboard objectives remove ts.sa.prev_z
2023

2124
scoreboard objectives remove ts.sa.settings
2225
scoreboard objectives remove ts.sa.distance

data/spawnanimations/functions/install.mcfunction

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ scoreboard objectives add ts.sa.timer dummy
55
scoreboard objectives add ts.sa.count dummy
66
scoreboard objectives add ts.sa.welcome trigger
77

8+
# Activation distance calculation
89
scoreboard objectives add ts.sa.x dummy
910
scoreboard objectives add ts.sa.y dummy
1011
scoreboard objectives add ts.sa.z dummy
12+
scoreboard players set #minus ts.sa.x -1
13+
14+
# Escape protection for shrunk/emissive entities (see emissive_layer in overlay_33)
15+
scoreboard objectives add ts.sa.prev_x dummy
16+
scoreboard objectives add ts.sa.prev_y dummy
17+
scoreboard objectives add ts.sa.prev_z dummy
1118

1219
# Entity properties
1320
scoreboard objectives add ts.sa.e.y dummy

0 commit comments

Comments
 (0)