diff --git a/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop.mcfunction b/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop.mcfunction index 3d42a73f9..4580e66cd 100644 --- a/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop.mcfunction +++ b/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop.mcfunction @@ -5,7 +5,7 @@ data merge storage utils:damage { damage: 2.5 } function entity:utils/damage with storage utils:damage # Bounce if hit edge of arena -execute unless entity @s[x=-21,dx=42,z=-3,dz=21] run function entity:hostile/omega-flowey/attack/dentata-snakes/bullet/loop/bounce +execute unless entity @s[x=-21,dx=42,z=-3,dz=21] run function entity:hostile/omega-flowey/attack/dentata-snakes/bullet/loop/maybe_bounce # Move forward at defined `attack.speed.z` velocity execute store result storage utils:move z float 0.01 run scoreboard players get @s attack.speed.z diff --git a/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/after_bounce_as_bullet_head.mcfunction b/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/after_bounce_as_bullet_head.mcfunction new file mode 100644 index 000000000..7b22d6b19 --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/after_bounce_as_bullet_head.mcfunction @@ -0,0 +1,4 @@ +# If we bounced, play bounce sound +# Only the bullet-head makes bounce sounds/shakes the player's screen (see `maybe_bounce.mcfunction`) +playsound omega-flowey:attack.dentata-snakes.bounce hostile @a ~ ~ ~ 5 1 +execute as @a unless entity @s[team=!player,team=!dead,team=!spectator] at @s run function entity:utils/shake_screen diff --git a/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/bounce.mcfunction b/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/bounce.mcfunction deleted file mode 100644 index a07574cd2..000000000 --- a/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/bounce.mcfunction +++ /dev/null @@ -1,34 +0,0 @@ -## Bounces the dentata-snake against the walls of the arena (flips x-direction/y-direction as necessary) - -# TODO(42): adjust arena bounds based on new animated java model (visually, it clips into the wall right now) - -# Don't bounce if we've already escaped the arena (past top wall) -execute if entity @s[x=-1000,dx=2000,y=30,dy=10,z=-4,dz=-1000,tag=can-escape-arena] run return 0 - -# Save initial yaw -execute store result score @s math.0 run data get entity @s Rotation[0] -scoreboard players operation @s math.1 = @s math.0 - -# Left wall facing flowey -execute unless entity @s[x=-21,dx=50,y=30,dy=10,z=-1000,dz=2000] if entity @s[y_rotation=0..180] run scoreboard players operation @s math.0 *= #-1 mathf.const - -# Right wall facing flowey -execute unless entity @s[x=21,dx=-50,y=30,dy=10,z=-1000,dz=2000] if entity @s[y_rotation=-180..0] run scoreboard players operation @s math.0 *= #-1 mathf.const - -# Top wall facing flowey -# disable top-wall bouncing if has `can-escape-arena` tag -execute unless entity @s[x=-25,dx=50,y=30,dy=10,z=-3,dz=25] unless entity @s[y_rotation=-90..90] unless entity @s[tag=can-escape-arena] run scoreboard players operation @s math.0 -= #180 mathf.const -execute unless entity @s[x=-25,dx=50,y=30,dy=10,z=-3,dz=25] unless entity @s[y_rotation=-90..90] unless entity @s[tag=can-escape-arena] run scoreboard players operation @s math.0 *= #-1 mathf.const - -# Bottom wall facing flowey -execute unless entity @s[x=-1000,dx=2000,y=30,dy=10,z=18,dz=-25] if entity @s[y_rotation=-90..90] run scoreboard players operation @s math.0 -= #180 mathf.const -execute unless entity @s[x=-1000,dx=2000,y=30,dy=10,z=18,dz=-25] if entity @s[y_rotation=-90..90] run scoreboard players operation @s math.0 *= #-1 mathf.const - -# Store bounced angle -execute store result entity @s Rotation[0] float 1 run scoreboard players get @s math.0 - -# If `math.0 != math.1`, we bounced -# If we bounced, play bounce sound -# Only the bullet-head makes bounce sounds/shakes the player's screen -execute unless score @s math.0 = @s math.1 if entity @s[tag=attack-bullet-head] run playsound omega-flowey:attack.dentata-snakes.bounce hostile @a ~ ~ ~ 5 1 -execute unless score @s math.0 = @s math.1 if entity @s[tag=attack-bullet-head] as @a unless entity @s[team=!player,team=!dead,team=!spectator] at @s run function entity:utils/shake_screen diff --git a/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/maybe_bounce.mcfunction b/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/maybe_bounce.mcfunction new file mode 100644 index 000000000..855658150 --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/hostile/omega-flowey/attack/dentata-snakes/bullet/loop/maybe_bounce.mcfunction @@ -0,0 +1,12 @@ +# Don't bounce if we've already escaped the arena (past top wall) +execute if entity @s[x=-1000,dx=2000,y=30,dy=10,z=-4,dz=-1000,tag=can-escape-arena] run return 0 + +# TODO(42): adjust arena bounds based on new animated java model (visually, it clips into the wall right now) +data merge storage attack:dentata-snakes.bounce { x_negative_x: -21, x_negative_dx: 50 } +data merge storage attack:dentata-snakes.bounce { x_positive_x: 21, x_positive_dx: -50 } +data merge storage attack:dentata-snakes.bounce { z_negative_z: -3, z_negative_dz: 25 } +data merge storage attack:dentata-snakes.bounce { z_positive_z: 18, z_positive_dz: -25 } +data merge storage attack:dentata-snakes.bounce { y: 30, dy: 10 } +data merge storage attack:dentata-snakes.bounce { command_after_bouncing: 'execute if entity @s[tag=attack-bullet-head] run function entity:hostile/omega-flowey/attack/dentata-snakes/bullet/loop/after_bounce_as_bullet_head' } + +function entity:utils/bounce with storage attack:dentata-snakes.bounce diff --git a/datapacks/omega-flowey/data/entity/functions/utils/bounce.mcfunction b/datapacks/omega-flowey/data/entity/functions/utils/bounce.mcfunction new file mode 100644 index 000000000..c533e8e1c --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/utils/bounce.mcfunction @@ -0,0 +1,36 @@ +## Reflects an entity's facing direction (yaw only) against the walls of a specified bounding box +# i.e. (flips x-direction/z-direction as necessary) +# --- +# params: +# * x_negative_x: x coordinate for the bounding box's safe region outside of the -X wall +# * x_negative_dx: x width for the bounding box's safe region outside of the -X wall +# * x_positive_x: x coordinate for the bounding box's safe region outside of the +X wall +# * x_positive_dx: x width for the bounding box's safe region outside of the +X wall +# * z_negative_z: z coordinate for the bounding box's safe region outside of the -Z wall +# * z_negative_dz: z width for the bounding box's safe region outside of the -Z wall +# * z_positive_z: z coordinate for the bounding box's safe region outside of the +Z wall +# * z_positive_dz: z width for the bounding box's safe region outside of the +Z wall +# * y/dy: generous y lower-bound + height for each bounding box +# (y/dy need to be generous because of target selectors being janky with volume selections) + +# Save initial yaw +execute store result score @s util.bounce.yaw.initial run data get entity @s Rotation[0] +scoreboard players operation @s util.bounce.yaw = @s util.bounce.yaw.initial + +# -X wall +$execute unless entity @s[x=$(x_negative_x),dx=$(x_negative_dx),y=$(y),dy=$(dy),z=-1000,dz=2000] if entity @s[y_rotation=0..180] run function entity:utils/bounce/x_negative + +# +X wall +$execute unless entity @s[x=$(x_positive_x),dx=$(x_positive_dx),y=$(y),dy=$(dy),z=-1000,dz=2000] if entity @s[y_rotation=-180..0] run function entity:utils/bounce/x_positive + +# -Z wall +$execute unless entity @s[x=-1000,dx=2000,y=$(y),dy=$(dy),z=$(z_negative_z),dz=$(z_negative_dz)] unless entity @s[y_rotation=-90..90] run function entity:utils/bounce/z_negative + +# +Z wall +$execute unless entity @s[x=-1000,dx=2000,y=$(y),dy=$(dy),z=$(z_positive_z),dz=$(z_positive_dz)] if entity @s[y_rotation=-90..90] run function entity:utils/bounce/z_positive + +# Store bounced angle +execute store result entity @s Rotation[0] float 1 run scoreboard players get @s util.bounce.yaw + +# If `util.bounce.yaw != util.bounce.yaw.initial`, we bounced +$execute unless score @s util.bounce.yaw = @s util.bounce.yaw.initial run $(command_after_bouncing) diff --git a/datapacks/omega-flowey/data/entity/functions/utils/bounce/shared/x.mcfunction b/datapacks/omega-flowey/data/entity/functions/utils/bounce/shared/x.mcfunction new file mode 100644 index 000000000..df2f8007e --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/utils/bounce/shared/x.mcfunction @@ -0,0 +1 @@ +scoreboard players operation @s util.bounce.yaw *= #-1 mathf.const diff --git a/datapacks/omega-flowey/data/entity/functions/utils/bounce/shared/z.mcfunction b/datapacks/omega-flowey/data/entity/functions/utils/bounce/shared/z.mcfunction new file mode 100644 index 000000000..5ae739e26 --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/utils/bounce/shared/z.mcfunction @@ -0,0 +1,2 @@ +scoreboard players operation @s util.bounce.yaw -= #180 mathf.const +scoreboard players operation @s util.bounce.yaw *= #-1 mathf.const diff --git a/datapacks/omega-flowey/data/entity/functions/utils/bounce/x_negative.mcfunction b/datapacks/omega-flowey/data/entity/functions/utils/bounce/x_negative.mcfunction new file mode 100644 index 000000000..6fb5552de --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/utils/bounce/x_negative.mcfunction @@ -0,0 +1 @@ +function entity:utils/bounce/shared/x diff --git a/datapacks/omega-flowey/data/entity/functions/utils/bounce/x_positive.mcfunction b/datapacks/omega-flowey/data/entity/functions/utils/bounce/x_positive.mcfunction new file mode 100644 index 000000000..6fb5552de --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/utils/bounce/x_positive.mcfunction @@ -0,0 +1 @@ +function entity:utils/bounce/shared/x diff --git a/datapacks/omega-flowey/data/entity/functions/utils/bounce/z_negative.mcfunction b/datapacks/omega-flowey/data/entity/functions/utils/bounce/z_negative.mcfunction new file mode 100644 index 000000000..f7d5b08f5 --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/utils/bounce/z_negative.mcfunction @@ -0,0 +1 @@ +function entity:utils/bounce/shared/z diff --git a/datapacks/omega-flowey/data/entity/functions/utils/bounce/z_positive.mcfunction b/datapacks/omega-flowey/data/entity/functions/utils/bounce/z_positive.mcfunction new file mode 100644 index 000000000..f7d5b08f5 --- /dev/null +++ b/datapacks/omega-flowey/data/entity/functions/utils/bounce/z_positive.mcfunction @@ -0,0 +1 @@ +function entity:utils/bounce/shared/z diff --git a/datapacks/omega-flowey/data/omega-flowey/functions/setup/objectives.mcfunction b/datapacks/omega-flowey/data/omega-flowey/functions/setup/objectives.mcfunction index 33cb23086..9592ee18d 100644 --- a/datapacks/omega-flowey/data/omega-flowey/functions/setup/objectives.mcfunction +++ b/datapacks/omega-flowey/data/omega-flowey/functions/setup/objectives.mcfunction @@ -90,3 +90,8 @@ scoreboard objectives add player.shake.yaw dummy scoreboard objectives add random dummy scoreboard objectives add random.min dummy scoreboard objectives add random.range dummy + +# the final yaw an entity has after running bounce calculations +scoreboard objectives add util.bounce.yaw dummy +# the initial yaw an entity starts with before running bounce calculations +scoreboard objectives add util.bounce.yaw.initial dummy