|
| 1 | +import ./global.mcbt |
| 2 | + |
| 3 | +dir global { |
| 4 | + function on_load minecraft:load { |
| 5 | + # Initialize Scoreboards |
| 6 | + scoreboard objectives add <%OBJECTIVES.I()%> dummy |
| 7 | + scoreboard objectives add <%OBJECTIVES.ID()%> dummy |
| 8 | + scoreboard objectives add <%OBJECTIVES.IS_RIG_LOADED()%> dummy |
| 9 | + scoreboard objectives add <%OBJECTIVES.TWEEN_DURATION()%> dummy |
| 10 | + |
| 11 | + scoreboard players add aj.last_id <%OBJECTIVES.ID()%> 0 |
| 12 | + |
| 13 | + # Purposefully load gu first, as other functions depend on it. |
| 14 | + function *global/gu/on_load |
| 15 | + IF (debug_mode) { |
| 16 | + scoreboard players reset * <%OBJECTIVES.IS_RIG_LOADED()%> |
| 17 | + execute as @e[type=item_display,tag=<%TAGS.GLOBAL_ROOT()%>] at @s run function *global/root/on_load |
| 18 | + } |
| 19 | + function #*global/on_load |
| 20 | + } |
| 21 | + |
| 22 | + IF (debug_mode) { |
| 23 | + function on_tick minecraft:tick { |
| 24 | + execute as @e[type=item_display,tag=<%TAGS.GLOBAL_ROOT()%>] at @s run function *global/root/on_tick |
| 25 | + } |
| 26 | + } ELSE { |
| 27 | + function on_tick minecraft:tick { |
| 28 | + execute as @e[type=item_display,tag=<%TAGS.GLOBAL_ROOT()%>] at @s run function #*global/root/on_tick |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + tag functions on_load { |
| 33 | + *<%export_namespace%>/on_load |
| 34 | + } |
| 35 | + |
| 36 | + dir root { |
| 37 | + tag functions on_tick { |
| 38 | + *<%export_namespace%>/root/on_tick |
| 39 | + } |
| 40 | + |
| 41 | + IF (debug_mode) { |
| 42 | + function on_tick { |
| 43 | + execute unless score @s <%OBJECTIVES.IS_RIG_LOADED()%> matches 1 run function *global/root/on_load |
| 44 | + function #*global/root/on_tick |
| 45 | + } |
| 46 | + |
| 47 | + function on_load { |
| 48 | + # Check if the rig is outdated by comparing the function's rig_hash of the rig to the rig_hash stored in the entity data. |
| 49 | + execute if function animated_java:global/util/is_rig_outdated run block outdated_warning/modify_rig { |
| 50 | + data remove storage <%temp_storage%> args |
| 51 | + function *global/gu/get_entity_uuid_string |
| 52 | + data modify storage <%temp_storage%> args.uuid set from storage <%gu_storage%> out |
| 53 | + # Get position |
| 54 | + execute store result storage <%temp_storage%> args.x double 1 run data get entity @s Pos[0] 1 |
| 55 | + execute store result storage <%temp_storage%> args.y double 1 run data get entity @s Pos[1] 1 |
| 56 | + execute store result storage <%temp_storage%> args.z double 1 run data get entity @s Pos[2] 1 |
| 57 | + execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run { |
| 58 | + # Get export namespace |
| 59 | + data modify storage <%temp_storage%> args.export_namespace set from entity @s data.export_namespace |
| 60 | + # Overwrite the rig hash so the warning doesn't show again. |
| 61 | + data modify entity @s data.rig_hash set value '<%rig_hash%>' |
| 62 | + } |
| 63 | + block print { with storage <%temp_storage%> args |
| 64 | + $tellraw @a <%TELLRAW.RIG_OUTDATED()%> |
| 65 | + } |
| 66 | + execute on passengers run data merge entity @s {Glowing: 1b, glow_color_override: <%0xff0000%>} |
| 67 | + summon minecraft:text_display ~ ~ ~ { \ |
| 68 | + Tags:[ \ |
| 69 | + '<%TAGS.GLOBAL_ENTITY()%>', \ |
| 70 | + '<%TAGS.OUTDATED_RIG_TEXT_DISPLAY()%>', \ |
| 71 | + '<%TAGS.NEW()%>' \ |
| 72 | + ], \ |
| 73 | + text:<%TELLRAW.RIG_OUTDATED_TEXT_DISPLAY()%>, \ |
| 74 | + alignment: 'center', \ |
| 75 | + billboard: 'vertical', \ |
| 76 | + shadow: true, \ |
| 77 | + transformation:{ \ |
| 78 | + translation:[0f,<%boundingBox[1]/16%>f,0f], \ |
| 79 | + left_rotation:[0f,0f,0f,1f], \ |
| 80 | + right_rotation:[0f,0f,0f,1f], \ |
| 81 | + scale:[1f,1f,1f] \ |
| 82 | + } \ |
| 83 | + } |
| 84 | + |
| 85 | + ride @n[ \ |
| 86 | + type=minecraft:text_display, \ |
| 87 | + tag=<%TAGS.OUTDATED_RIG_TEXT_DISPLAY()%>, tag=<%TAGS.NEW()%>, \ |
| 88 | + distance=..1 \ |
| 89 | + ] mount @s |
| 90 | + |
| 91 | + tag @n[ \ |
| 92 | + type=minecraft:text_display, \ |
| 93 | + tag=<%TAGS.OUTDATED_RIG_TEXT_DISPLAY()%>, tag=<%TAGS.NEW()%>, \ |
| 94 | + distance=..1 \ |
| 95 | + ] remove <%TAGS.NEW()%> |
| 96 | + } |
| 97 | + scoreboard players set @s <%OBJECTIVES.IS_RIG_LOADED()%> 1 |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + dir remove { |
| 103 | + # Removes every entity related to Animated Java. |
| 104 | + function everything { |
| 105 | + kill @e[tag=<%TAGS.GLOBAL_ENTITY()%>] |
| 106 | + } |
| 107 | + |
| 108 | + function entity_stack { |
| 109 | + execute on passengers if entity @s[type=!player] run function ^0 |
| 110 | + kill @s |
| 111 | + } |
| 112 | + |
| 113 | + function entity_stack_by_uuid { |
| 114 | + #ARGS: {uuid: string} |
| 115 | + $execute as $(uuid) run function ./entity_stack |
| 116 | + } |
| 117 | + |
| 118 | + # Removes locators and cameras owned by the rig, even if they're not included in the currently loaded export. |
| 119 | + function outdated_rig { |
| 120 | + # Assert that the function is being executed as a root entity. |
| 121 | + debug assert executed_as_root_entity |
| 122 | + |
| 123 | + execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run block as_data { |
| 124 | + data remove storage <%temp_storage%> args |
| 125 | + data remove storage <%temp_storage%> uuids |
| 126 | + data modify storage <%temp_storage%> uuids set from entity @s data.uuids |
| 127 | + execute store result score #aj.length <%OBJECTIVES.I()%> run data get storage <%temp_storage%> uuids |
| 128 | + |
| 129 | + execute if score #aj.length <%OBJECTIVES.I()%> matches 1.. run block loop_over_uuids { |
| 130 | + data modify storage <%temp_storage%> args.current_uuid set from storage <%temp_storage%> uuids[-1].uuid |
| 131 | + data remove storage <%temp_storage%> uuids[-1] |
| 132 | + function ./entity_stack_by_uuid with storage <%temp_storage%> args |
| 133 | + |
| 134 | + scoreboard players remove #aj.length <%OBJECTIVES.I()%> 1 |
| 135 | + execute if score #aj.length <%OBJECTIVES.I()%> matches 1.. run function ^0 |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + function ./entity_stack |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + dir util { |
| 144 | + # Recurses through the passengers of the context entity and appends their UUIDs to `storage <%temp_storage%> uuids`. |
| 145 | + function get_entity_stack_uuids { |
| 146 | + data remove storage <%temp_storage%> uuids |
| 147 | + execute on passengers run { |
| 148 | + function *global/gu/get_entity_uuid_string |
| 149 | + data modify storage <%temp_storage%> uuids append from storage <%gu_storage%> out |
| 150 | + execute on passengers run function ^0 |
| 151 | + } |
| 152 | + } |
| 153 | + # Returns 1 if the rig is outdated, else returns 0. |
| 154 | + function is_rig_outdated { |
| 155 | + execute on passengers if entity @s[tag=<%TAGS.GLOBAL_DATA()%>] run return run { with entity @s data |
| 156 | + # REVIEW - The replace here is a bit hacky. |
| 157 | + # Because this is a core function, I need to create a generic version of |
| 158 | + # project_storage that uses a macro to get the export namespace instead of hardcoding it. |
| 159 | + $execute if data storage <%project_storage.replace(export_namespace, '$(export_namespace)')%> {rig_hash:'$(rig_hash)'} run return 0 |
| 160 | + return 1 |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + # Thanks Gibbsly for this code! https://github.com/gibbsly/gu |
| 166 | + dir gu { |
| 167 | + function on_load { |
| 168 | + scoreboard players set 256 <%OBJECTIVES.I()%> 256 |
| 169 | + data modify storage <%gu_storage%> hex_chars set value \ |
| 170 | + <%JSON.stringify([...Array(0x100).keys()].map(v => {const x = v.toString(16); return x.length > 1 ? x : '0' + x}))%> |
| 171 | + } |
| 172 | + |
| 173 | + function get_entity_uuid_string { |
| 174 | + data modify storage <%gu_storage%> temp set value {0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,a:0,b:0,c:0,d:0,e:0,f:0} |
| 175 | + data modify storage <%gu_storage%> in set from entity @s UUID |
| 176 | + |
| 177 | + execute store result score 0= <%OBJECTIVES.I()%> store result score 1= <%OBJECTIVES.I()%> run data get storage <%gu_storage%> in[0] |
| 178 | + execute store result storage <%gu_storage%> temp.0 int 1 run scoreboard players operation 0= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 179 | + execute store result score 2= <%OBJECTIVES.I()%> run scoreboard players operation 1= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 180 | + execute store result storage <%gu_storage%> temp.1 int 1 run scoreboard players operation 1= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 181 | + execute store result score 3= <%OBJECTIVES.I()%> run scoreboard players operation 2= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 182 | + execute store result storage <%gu_storage%> temp.2 int 1 run scoreboard players operation 2= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 183 | + execute store result storage <%gu_storage%> temp.3 int 1 run scoreboard players operation 3= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 184 | + |
| 185 | + execute store result score 0= <%OBJECTIVES.I()%> store result score 1= <%OBJECTIVES.I()%> run data get storage <%gu_storage%> in[1] |
| 186 | + execute store result storage <%gu_storage%> temp.4 int 1 run scoreboard players operation 0= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 187 | + execute store result score 2= <%OBJECTIVES.I()%> run scoreboard players operation 1= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 188 | + execute store result storage <%gu_storage%> temp.5 int 1 run scoreboard players operation 1= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 189 | + execute store result score 3= <%OBJECTIVES.I()%> run scoreboard players operation 2= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 190 | + execute store result storage <%gu_storage%> temp.6 int 1 run scoreboard players operation 2= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 191 | + execute store result storage <%gu_storage%> temp.7 int 1 run scoreboard players operation 3= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 192 | + |
| 193 | + execute store result score 0= <%OBJECTIVES.I()%> store result score 1= <%OBJECTIVES.I()%> run data get storage <%gu_storage%> in[2] |
| 194 | + execute store result storage <%gu_storage%> temp.8 int 1 run scoreboard players operation 0= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 195 | + execute store result score 2= <%OBJECTIVES.I()%> run scoreboard players operation 1= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 196 | + execute store result storage <%gu_storage%> temp.9 int 1 run scoreboard players operation 1= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 197 | + execute store result score 3= <%OBJECTIVES.I()%> run scoreboard players operation 2= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 198 | + execute store result storage <%gu_storage%> temp.a int 1 run scoreboard players operation 2= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 199 | + execute store result storage <%gu_storage%> temp.b int 1 run scoreboard players operation 3= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 200 | + |
| 201 | + execute store result score 0= <%OBJECTIVES.I()%> store result score 1= <%OBJECTIVES.I()%> run data get storage <%gu_storage%> in[3] |
| 202 | + execute store result storage <%gu_storage%> temp.c int 1 run scoreboard players operation 0= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 203 | + execute store result score 2= <%OBJECTIVES.I()%> run scoreboard players operation 1= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 204 | + execute store result storage <%gu_storage%> temp.d int 1 run scoreboard players operation 1= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 205 | + execute store result score 3= <%OBJECTIVES.I()%> run scoreboard players operation 2= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 206 | + execute store result storage <%gu_storage%> temp.e int 1 run scoreboard players operation 2= <%OBJECTIVES.I()%> %= 256 <%OBJECTIVES.I()%> |
| 207 | + execute store result storage <%gu_storage%> temp.f int 1 run scoreboard players operation 3= <%OBJECTIVES.I()%> /= 256 <%OBJECTIVES.I()%> |
| 208 | + |
| 209 | + block { with storage <%gu_storage%> temp |
| 210 | + REPEAT (0, 15) as i { |
| 211 | + $data modify storage <%gu_storage%> temp.<%i.toString(16)%> set from storage <%gu_storage%> hex_chars[$(<%i.toString(16)%>)] |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + block { with storage <%gu_storage%> temp |
| 216 | + $data modify storage <%gu_storage%> out set value "$(3)$(2)$(1)$(0)-$(7)$(6)-$(5)$(4)-$(b)$(a)-$(9)$(8)$(f)$(e)$(d)$(c)" |
| 217 | + } |
| 218 | + } |
| 219 | + } |
| 220 | +} |
| 221 | + |
| 222 | +dir <%export_namespace%> { |
| 223 | + function on_load { |
| 224 | + function *<%export_namespace%>/invalid_version_warning |
| 225 | + } |
| 226 | + |
| 227 | + function invalid_version_warning { |
| 228 | + tellraw @a <%TELLRAW.INVALID_VERSION()%> |
| 229 | + } |
| 230 | +} |
0 commit comments