Skip to content

Commit

Permalink
🧑‍💻 API からの攻撃にメタデータを付与できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenCMD committed Oct 22, 2024
1 parent 3ee00d5 commit dd022fa
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion TheSkyBlessing/data/api/functions/damage/.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# 実行者はHealthを持つEntityである必要があります。
#
# Metadata に指定したデータは、artifact, mob の関連トリガーに渡されます。
#
# @input
# as entity
# storage api:
Expand All @@ -19,6 +21,7 @@
# Argument.BypassDifficulty? : boolean
# Argument.ReduceEnchantment? : id(minecraft:enchantment) | { id: id(minecraft:enchantment), modifier?: int }
# Argument.DeathMessage? : TextComponent || TextComponent[]
# Argument.Metadata? : any
# @api

# 引数チェック
Expand All @@ -39,4 +42,4 @@
execute unless data storage api: Argument.BypassDifficulty run data modify storage api: Argument.BypassDifficulty set value false

# Healthを持つ干渉可能なEntityかつ死んでいなければ実行
execute if entity @s[type=#lib:living,tag=!Uninterferable,tag=!Death] at @s run function api:damage/core/attack
execute if entity @s[type=#lib:living,tag=!Uninterferable,tag=!Death] at @s run function api:damage/core/attack
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data remove storage api: Argument.BypassEnchantments
data remove storage api: Argument.BypassResistance
data remove storage api: Argument.DisableParticle
data remove storage api: Argument.ReduceEnchantment
data remove storage api: Argument.Metadata

scoreboard players reset $LatestModifiedUser UserID
scoreboard players reset $LatestModifiedEntity MobUUID
scoreboard players reset $LatestModifiedEntity MobUUID
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Attack[-1].Amount double 0.01 run scoreboard players get $Damage Temporary
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Attack[-1].AttackType set from storage api: Argument.AttackType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Attack[-1].ElementType set from storage api: Argument.ElementType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Attack[-1].Metadata set from storage api: Argument.Metadata
# Mob にもイベントを追加する
function oh_my_dat:please
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Hurt append value {Type: "api",IsVanilla:false}
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Hurt[-1].From int 1 run scoreboard players get @p[tag=TargetAttacker] UserID
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Hurt[-1].Amount double 0.01 run scoreboard players get $Damage Temporary
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Hurt[-1].AttackType set from storage api: Argument.AttackType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Hurt[-1].ElementType set from storage api: Argument.ElementType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Hurt[-1].Metadata set from storage api: Argument.Metadata
# リセット
tag @a[tag=TargetAttacker] remove TargetAttacker
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Kill[-1].Amount double 0.01 run scoreboard players get $Damage Temporary
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Kill[-1].AttackType set from storage api: Argument.AttackType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Kill[-1].ElementType set from storage api: Argument.ElementType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Kill[-1].Metadata set from storage api: Argument.Metadata
# Mob にもイベントを追加する
function oh_my_dat:please
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Death append value {Type: "api",IsVanilla:false}
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Death[-1].From int 1 run scoreboard players get @p[tag=TargetAttacker] UserID
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Death[-1].Amount double 0.01 run scoreboard players get $Damage Temporary
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Death[-1].AttackType set from storage api: Argument.AttackType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Death[-1].ElementType set from storage api: Argument.ElementType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Death[-1].Metadata set from storage api: Argument.Metadata
# リセット
tag @a[tag=TargetAttacker] remove TargetAttacker
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Damage[-1].Amount double 0.0001 run scoreboard players get $Damage Temporary
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Damage[-1].AttackType set from storage api: Argument.AttackType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Damage[-1].ElementType set from storage api: Argument.ElementType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].ArtifactEvents.Damage[-1].Metadata set from storage api: Argument.Metadata
# モブ側から行う処理
tag @s add Damager
execute as @e[type=!player,distance=..150] if score @s MobUUID = $LatestModifiedEntity MobUUID run function api:damage/core/trigger_events/player/push_from_attacker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
execute store result storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Attack[-1].Amount double 0.0001 run scoreboard players get $Damage Temporary
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Attack[-1].AttackType set from storage api: Argument.AttackType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Attack[-1].ElementType set from storage api: Argument.ElementType
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].MobEvents.Attack[-1].Metadata set from storage api: Argument.Metadata
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
data modify storage api: DamageLibModified set value true
# 補正
execute if entity @s[type=player] run function api:damage/core/modify/player
execute if entity @s[type=!player] run function api:damage/core/modify/non-player
execute if entity @s[type=!player] run function api:damage/core/modify/non-player
4 changes: 3 additions & 1 deletion TheSkyBlessing/data/lib/functions/damage/.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ data modify storage api: Argument.BypassEnchantments set from storage lib: Argum
data modify storage api: Argument.BypassResistance set from storage lib: Argument.BypassResistance
data modify storage api: Argument.ReduceEnchantment set from storage lib: Argument.ReduceEnchantment
data modify storage api: Argument.DeathMessage set from storage lib: Argument.DeathMessage
execute if data storage lib: Argument.Metadata run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"Metadata を ","color":"white"},{"text":"lib:damage/","color":"gold"},{"text":" で使うことは出来ません。","color":"white"}]
execute if data storage lib: Argument.Metadata run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"api:damage/","color":"gold"},{"text":" への移行を検討してください。","color":"white"}]

function api:damage/
function api:damage/

0 comments on commit dd022fa

Please sign in to comment.