From 3e3d7137177e74b887be35aa267c389825236997 Mon Sep 17 00:00:00 2001 From: Thanathor Date: Fri, 27 Oct 2023 12:02:24 +0200 Subject: [PATCH] macro's everywhere! --- .../type/guardian/damage_calc.mcfunction | 15 +++++----- .../modifier/type/half/damage.mcfunction | 7 ++--- .../type/reactive/add_level.mcfunction | 2 +- .../functions/player/damage.mcfunction | 24 ++-------------- .../functions/player/heal/activate.mcfunction | 26 ++--------------- .../functions/player/heal/eval.mcfunction | 6 ++++ .../functions/player/heal/revert.mcfunction | 12 -------- .../functions/player/process.mcfunction | 2 +- .../functions/player/shield/eval.mcfunction | 6 ++++ .../functions/player/shield/prep.mcfunction | 18 ++++++++++++ .../functions/player/shield_player.mcfunction | 28 ------------------- .../modifier/delay/explode_player.mcfunction | 17 ++++++----- 12 files changed, 56 insertions(+), 107 deletions(-) create mode 100644 gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/eval.mcfunction create mode 100644 gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/eval.mcfunction create mode 100644 gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/prep.mcfunction delete mode 100644 gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield_player.mcfunction diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/guardian/damage_calc.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/guardian/damage_calc.mcfunction index e8e8b0d483..0794353b59 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/guardian/damage_calc.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/guardian/damage_calc.mcfunction @@ -5,18 +5,17 @@ function gm4_combat_expanded:player/calculate_hp -# calculate amount of max_health to remove to get to new health -scoreboard players operation $remove_health gm4_ce_data = $max_health gm4_ce_data - -scoreboard players operation $remove_health gm4_ce_data -= @s gm4_ce_health -scoreboard players operation @s gm4_ce_guard /= #10 gm4_ce_data -scoreboard players operation $remove_health gm4_ce_data += @s gm4_ce_guard +# store damage in storage +execute store result storage gm4_combat_expanded:temp damage_player.damage int 1 run scoreboard players operation @s gm4_ce_guard /= #10 gm4_ce_data # sound execute at @s run playsound minecraft:item.shield.block player @s ~ ~ ~ 0.4 0 # damage player if they are alive -execute if score $remove_health gm4_ce_data < $max_health gm4_ce_data run function gm4_combat_expanded:player/damage/apply +execute if score @s gm4_ce_guard < @s gm4_ce_health run function gm4_combat_expanded:player/damage with storage gm4_combat_expanded:temp damage_player # kill player if health reached 0 (and player is alive) -execute if score @s gm4_ce_health matches 1.. if score $remove_health gm4_ce_data >= $max_health gm4_ce_data run function gm4_combat_expanded:armor/modifier/type/guardian/guard_death +execute if score @s gm4_ce_health matches 1.. if score @s gm4_ce_guard >= @s gm4_ce_health run function gm4_combat_expanded:armor/modifier/type/guardian/guard_death + +# cleanup +data remove storage gm4_combat_expanded:temp damage_player.damage diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/half/damage.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/half/damage.mcfunction index 2d01268ec8..ca62430747 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/half/damage.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/half/damage.mcfunction @@ -4,7 +4,6 @@ # run from armor/modifier/type/half/apply scoreboard players operation $remove_health gm4_ce_data = @s gm4_ce_health -scoreboard players operation $remove_health gm4_ce_data -= $half_health gm4_ce_data - -execute if score $remove_health gm4_ce_data matches 2.. run damage @s 2 out_of_world -execute if score $remove_health gm4_ce_data matches 1 run damage @s 1 out_of_world +execute store result storage gm4_combat_expanded:temp damage_player.damage int 1 run scoreboard players operation $remove_health gm4_ce_data -= $half_health gm4_ce_data +function gm4_combat_expanded:player/damage with storage gm4_combat_expanded:temp damage_player +data remove storage gm4_combat_expanded:temp damage_player.damage diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/reactive/add_level.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/reactive/add_level.mcfunction index f18cffb3c9..5395e3791d 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/reactive/add_level.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/armor/modifier/type/reactive/add_level.mcfunction @@ -31,4 +31,4 @@ scoreboard players operation @s gm4_ce_absorp += $level gm4_ce_data scoreboard players set @s gm4_ce_t_reactive 37 # grant effect -function gm4_combat_expanded:player/shield_player +function gm4_combat_expanded:player/shield/prep diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/damage.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/damage.mcfunction index 1f2272781e..7f3359b3bf 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/damage.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/damage.mcfunction @@ -1,26 +1,8 @@ -# damage player according to score +# damage player according to damage storage # @s = player that is taking damage # at unspecified # run from armor/modifier/type/guardian/damage_calc +# run from armor/modifier/type/half/damage # run from weapon/modifier/delay/explode_player -# lower player's health to their new health -execute if score $remove_health gm4_ce_data matches 512.. run damage @s 512 out_of_world -execute if score $remove_health gm4_ce_data matches 512.. run scoreboard players remove $remove_health gm4_ce_data 512 -execute if score $remove_health gm4_ce_data matches 256.. run damage @s 256 out_of_world -execute if score $remove_health gm4_ce_data matches 256.. run scoreboard players remove $remove_health gm4_ce_data 256 -execute if score $remove_health gm4_ce_data matches 128.. run damage @s 128 out_of_world -execute if score $remove_health gm4_ce_data matches 128.. run scoreboard players remove $remove_health gm4_ce_data 128 -execute if score $remove_health gm4_ce_data matches 64.. run damage @s 64 out_of_world -execute if score $remove_health gm4_ce_data matches 64.. run scoreboard players remove $remove_health gm4_ce_data 64 -execute if score $remove_health gm4_ce_data matches 32.. run damage @s 32 out_of_world -execute if score $remove_health gm4_ce_data matches 32.. run scoreboard players remove $remove_health gm4_ce_data 32 -execute if score $remove_health gm4_ce_data matches 16.. run damage @s 16 out_of_world -execute if score $remove_health gm4_ce_data matches 16.. run scoreboard players remove $remove_health gm4_ce_data 16 -execute if score $remove_health gm4_ce_data matches 8.. run damage @s 8 out_of_world -execute if score $remove_health gm4_ce_data matches 8.. run scoreboard players remove $remove_health gm4_ce_data 8 -execute if score $remove_health gm4_ce_data matches 4.. run damage @s 4 out_of_world -execute if score $remove_health gm4_ce_data matches 4.. run scoreboard players remove $remove_health gm4_ce_data 4 -execute if score $remove_health gm4_ce_data matches 2.. run damage @s 2 out_of_world -execute if score $remove_health gm4_ce_data matches 2.. run scoreboard players remove $remove_health gm4_ce_data 2 -execute if score $remove_health gm4_ce_data matches 1.. run damage @s 1 out_of_world +$damage @s $(damage) out_of_world diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/activate.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/activate.mcfunction index 89d880c734..2ff416c849 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/activate.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/activate.mcfunction @@ -6,30 +6,10 @@ # calculate max health to get player to new health scoreboard players operation $remove_health gm4_ce_data = $max_health gm4_ce_data scoreboard players operation $remove_health gm4_ce_data -= @s gm4_ce_health -scoreboard players operation $remove_health gm4_ce_data -= @s gm4_ce_healstore -execute if score $remove_health gm4_ce_data matches ..-1 run scoreboard players set $remove_health gm4_ce_data 0 +execute store result storage gm4_combat_expanded heal_player.remove_health int 1 run scoreboard players operation $remove_health gm4_ce_data -= @s gm4_ce_healstore -# lower player's max health to their new health -execute if score $remove_health gm4_ce_data matches 512.. run attribute @s minecraft:generic.max_health modifier add 8a3726c1-9a5c-4b10-86ba-b72a2540eeb2 "gm4_ce_remove_512" -512 add -execute if score $remove_health gm4_ce_data matches 512.. run scoreboard players remove $remove_health gm4_ce_data 512 -execute if score $remove_health gm4_ce_data matches 256.. run attribute @s minecraft:generic.max_health modifier add 8c30a1b2-d915-4d46-93cc-49470b558bf9 "gm4_ce_remove_256" -256 add -execute if score $remove_health gm4_ce_data matches 256.. run scoreboard players remove $remove_health gm4_ce_data 256 -execute if score $remove_health gm4_ce_data matches 128.. run attribute @s minecraft:generic.max_health modifier add 236c6079-0f55-4a22-b02d-2110b6a845fc "gm4_ce_remove_128" -128 add -execute if score $remove_health gm4_ce_data matches 128.. run scoreboard players remove $remove_health gm4_ce_data 128 -execute if score $remove_health gm4_ce_data matches 64.. run attribute @s minecraft:generic.max_health modifier add 3017b672-58d6-451a-97cf-c3f4b08f6282 "gm4_ce_remove_64" -64 add -execute if score $remove_health gm4_ce_data matches 64.. run scoreboard players remove $remove_health gm4_ce_data 64 -execute if score $remove_health gm4_ce_data matches 32.. run attribute @s minecraft:generic.max_health modifier add fc8491d8-e398-44ed-b79d-c0d6bc648501 "gm4_ce_remove_32" -32 add -execute if score $remove_health gm4_ce_data matches 32.. run scoreboard players remove $remove_health gm4_ce_data 32 -execute if score $remove_health gm4_ce_data matches 16.. run attribute @s minecraft:generic.max_health modifier add 17948ed4-e422-47af-880e-7cc1a09cac92 "gm4_ce_remove_16" -16 add -execute if score $remove_health gm4_ce_data matches 16.. run scoreboard players remove $remove_health gm4_ce_data 16 -execute if score $remove_health gm4_ce_data matches 8.. run attribute @s minecraft:generic.max_health modifier add edf68005-ec49-4e92-a311-2a54ea4870d9 "gm4_ce_remove_8" -8 add -execute if score $remove_health gm4_ce_data matches 8.. run scoreboard players remove $remove_health gm4_ce_data 8 -execute if score $remove_health gm4_ce_data matches 4.. run attribute @s minecraft:generic.max_health modifier add 4bd118d8-a5dd-4bec-a93b-8d4daeab14be "gm4_ce_remove_4" -4 add -execute if score $remove_health gm4_ce_data matches 4.. run scoreboard players remove $remove_health gm4_ce_data 4 -execute if score $remove_health gm4_ce_data matches 2.. run attribute @s minecraft:generic.max_health modifier add 0caacdc0-1ca3-4e75-90c4-2756efe9ca50 "gm4_ce_remove_2" -2 add -execute if score $remove_health gm4_ce_data matches 2.. run scoreboard players remove $remove_health gm4_ce_data 2 -execute if score $remove_health gm4_ce_data matches 1.. run attribute @s minecraft:generic.max_health modifier add cb62a34a-4a87-4c18-b0a0-6bb31d2e9300 "gm4_ce_remove_1" -1 add -execute if score $remove_health gm4_ce_data matches 1.. run scoreboard players remove $remove_health gm4_ce_data 1 +execute if score $remove_health gm4_ce_data matches 1.. run function gm4_combat_expanded:player/heal/eval with storage gm4_combat_expanded heal_player +data remove storage gm4_combat_expanded heal_player.remove_health # prepare reverting tag @s add gm4_ce_healed diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/eval.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/eval.mcfunction new file mode 100644 index 0000000000..c2c5ade710 --- /dev/null +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/eval.mcfunction @@ -0,0 +1,6 @@ +# reduce max health of player to their new health +# @s = player to heal +# at unspecified +# run from armor/type/heal/activate + +$attribute @s minecraft:generic.max_health modifier add 8a3726c1-9a5c-4b10-86ba-b72a2540eeb2 "gm4_ce_remove_health" -$(remove_health) add diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/revert.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/revert.mcfunction index 6570a2aac2..f3f8c20c78 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/revert.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/heal/revert.mcfunction @@ -5,16 +5,4 @@ # revert max health attribute @s minecraft:generic.max_health modifier remove 8a3726c1-9a5c-4b10-86ba-b72a2540eeb2 -attribute @s minecraft:generic.max_health modifier remove 8c30a1b2-d915-4d46-93cc-49470b558bf9 -attribute @s minecraft:generic.max_health modifier remove 236c6079-0f55-4a22-b02d-2110b6a845fc -attribute @s minecraft:generic.max_health modifier remove 3017b672-58d6-451a-97cf-c3f4b08f6282 -attribute @s minecraft:generic.max_health modifier remove fc8491d8-e398-44ed-b79d-c0d6bc648501 -attribute @s minecraft:generic.max_health modifier remove 17948ed4-e422-47af-880e-7cc1a09cac92 -attribute @s minecraft:generic.max_health modifier remove edf68005-ec49-4e92-a311-2a54ea4870d9 -attribute @s minecraft:generic.max_health modifier remove 4bd118d8-a5dd-4bec-a93b-8d4daeab14be -attribute @s minecraft:generic.max_health modifier remove 0caacdc0-1ca3-4e75-90c4-2756efe9ca50 -attribute @s minecraft:generic.max_health modifier remove cb62a34a-4a87-4c18-b0a0-6bb31d2e9300 - -attribute @s minecraft:generic.max_health modifier remove 971283fb-1c05-429c-a266-9564f36f6ec1 - tag @s remove gm4_ce_healed diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/process.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/process.mcfunction index 341d867b56..fde7095719 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/process.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/process.mcfunction @@ -35,6 +35,6 @@ execute if entity @s[tag=gm4_ce_immune_active] run function gm4_combat_expanded: execute if predicate gm4_combat_expanded:modified_armor/wearing run function gm4_combat_expanded:armor/process # shield players if they have stored shield -execute if score @s gm4_ce_absorp matches 1.. run function gm4_combat_expanded:player/shield_player +execute if score @s gm4_ce_absorp matches 1.. run function gm4_combat_expanded:player/shield/prep # heal players if they have stored health execute if score @s gm4_ce_healstore matches 1.. run function gm4_combat_expanded:player/heal/heal_calc diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/eval.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/eval.mcfunction new file mode 100644 index 0000000000..0659079b1f --- /dev/null +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/eval.mcfunction @@ -0,0 +1,6 @@ +# give player absorption effect based on their score in gm4_ce_absorp +# @s = player to grant shield +# at unspecified +# run from player/shield/prep + +$effect give @s absorption 30 $(shield) true diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/prep.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/prep.mcfunction new file mode 100644 index 0000000000..0a6a898368 --- /dev/null +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield/prep.mcfunction @@ -0,0 +1,18 @@ +# give player absorption effect based on their score in gm4_ce_absorp +# @s = player to grant shield +# at unspecified +# run from armor/modifier/type/reactive/add_level +# run from player/process + +# remove one to match absorption level and store +execute store result storage gm4_combat_expanded player_shield.shield int 1 run scoreboard players remove @s gm4_ce_absorp 1 + +# clear absorption to stop bug (MC-182497) +effect clear @s absorption + +# apply absorption +function gm4_combat_expanded:player/shield/eval with storage gm4_combat_expanded player_shield + +# cleanup +data remove storage gm4_combat_expanded player_shield.shield +scoreboard players reset @s gm4_ce_absorp diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield_player.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield_player.mcfunction deleted file mode 100644 index f271164e4b..0000000000 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/player/shield_player.mcfunction +++ /dev/null @@ -1,28 +0,0 @@ -# give player absorption effect based on their score in gm4_ce_absorp -# @s = player to grant shield -# at unspecified -# run from armor/modifier/type/reactive/add_level -# run from player/process - -# remove one to match absorption level -scoreboard players remove @s gm4_ce_absorp 1 - -# clear absorption to stop bug (MC-182497) -effect clear @s absorption - -# apply absorption -execute if score @s gm4_ce_absorp matches 0 run effect give @s absorption 30 0 true -execute if score @s gm4_ce_absorp matches 1 run effect give @s absorption 30 1 true -execute if score @s gm4_ce_absorp matches 2 run effect give @s absorption 30 2 true -execute if score @s gm4_ce_absorp matches 3 run effect give @s absorption 30 3 true -execute if score @s gm4_ce_absorp matches 4 run effect give @s absorption 30 4 true -execute if score @s gm4_ce_absorp matches 5 run effect give @s absorption 30 5 true -execute if score @s gm4_ce_absorp matches 6 run effect give @s absorption 30 6 true -execute if score @s gm4_ce_absorp matches 7 run effect give @s absorption 30 7 true -execute if score @s gm4_ce_absorp matches 8 run effect give @s absorption 30 8 true -execute if score @s gm4_ce_absorp matches 9 run effect give @s absorption 30 9 true -execute if score @s gm4_ce_absorp matches 10 run effect give @s absorption 30 10 true -execute if score @s gm4_ce_absorp matches 11 run effect give @s absorption 30 11 true - -# cleanup -scoreboard players reset @s gm4_ce_absorp diff --git a/gm4_combat_expanded/data/gm4_combat_expanded/functions/weapon/modifier/delay/explode_player.mcfunction b/gm4_combat_expanded/data/gm4_combat_expanded/functions/weapon/modifier/delay/explode_player.mcfunction index b9b48d04ce..9c7e1887a2 100644 --- a/gm4_combat_expanded/data/gm4_combat_expanded/functions/weapon/modifier/delay/explode_player.mcfunction +++ b/gm4_combat_expanded/data/gm4_combat_expanded/functions/weapon/modifier/delay/explode_player.mcfunction @@ -5,19 +5,15 @@ function gm4_combat_expanded:player/calculate_hp -# calculate amount of max_health to remove to get to new health -scoreboard players operation $remove_health gm4_ce_data = $max_health gm4_ce_data - -scoreboard players operation $remove_health gm4_ce_data -= @s gm4_ce_health -execute if entity @s[tag=gm4_cd_delay_lvl_1] run scoreboard players add $remove_health gm4_ce_data 6 -execute if entity @s[tag=gm4_cd_delay_lvl_2] run scoreboard players add $remove_health gm4_ce_data 9 -execute if entity @s[tag=gm4_cd_delay_lvl_3] run scoreboard players add $remove_health gm4_ce_data 12 +execute if entity @s[tag=gm4_cd_delay_lvl_1] store result storage gm4_combat_expanded:temp damage_player.damage int 1 run scoreboard players set $delay_damage gm4_ce_data 6 +execute if entity @s[tag=gm4_cd_delay_lvl_2] store result storage gm4_combat_expanded:temp damage_player.damage int 1 run scoreboard players set $delay_damage gm4_ce_data 9 +execute if entity @s[tag=gm4_cd_delay_lvl_3] store result storage gm4_combat_expanded:temp damage_player.damage int 1 run scoreboard players set $delay_damage gm4_ce_data 12 # damage player if they are alive -execute if score $remove_health gm4_ce_data < $max_health gm4_ce_data run function gm4_combat_expanded:player/damage/apply +execute if score $delay_damage gm4_ce_data < @s gm4_ce_health run function gm4_combat_expanded:player/damage with storage gm4_combat_expanded:temp damage_player # kill player if health reached 0 -execute if score $remove_health gm4_ce_data >= $max_health gm4_ce_data run function gm4_combat_expanded:weapon/modifier/delay/player_death +execute if score $delay_damage gm4_ce_data >= s gm4_ce_health run function gm4_combat_expanded:weapon/modifier/delay/player_death # reset entity scoreboard players reset @s gm4_ce_t_delay @@ -30,3 +26,6 @@ tag @s remove gm4_cd_delay_lvl_3 execute anchored eyes run particle minecraft:sweep_attack ^ ^ ^ 0.3 0.3 0.3 0.1 3 particle minecraft:cloud ~ ~0.5 ~ 0.4 0.2 0.4 0.2 8 playsound minecraft:block.bell.use player @a ~ ~ ~ 0.7 1.6 + +# cleanup +data remove storage gm4_combat_expanded:temp damage_player.damage