Skip to content

Commit

Permalink
エンティティのダメージ管理 (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
NePonpon authored Jan 15, 2025
1 parent 1848e52 commit 797fa07
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 8 deletions.
5 changes: 5 additions & 0 deletions data/entity/damage_type/magic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0,
"scaling": "never",
"message_id": "tusb:magic"
}
5 changes: 5 additions & 0 deletions data/entity/damage_type/physical.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0,
"scaling": "never",
"message_id": "tusb:physical"
}
5 changes: 5 additions & 0 deletions data/entity/damage_type/unreasonable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0,
"scaling": "never",
"message_id": "tusb:unreasonable"
}
11 changes: 11 additions & 0 deletions data/entity/function/damage/apply/.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#> entity:damage/apply/
# 設定された物理、魔法、理外のダメージを実行者に与える。

# 物理ダメージ
function entity:damage/apply/physical

# 魔法ダメージ
function entity:damage/apply/magic

# 理外ダメージ
function entity:damage/apply/unreasonable
15 changes: 15 additions & 0 deletions data/entity/function/damage/apply/core/.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#> entity:damage/apply/core/

## ダメージ処理の実行チェック
# ダメージ値が指定されていなければ中断
execute unless data storage entity:_ damage.value run return fail
# 実行者が死亡していれば中断
execute if predicate entity:damage/check_death run return fail


# ダメージ値が割合設定ならば解決する
execute if data storage entity:_ damage.value{} run function entity:damage/apply/core/resolve_percentage_damage/

# 実行者のentity_typeによって処理を変更する
execute if entity @s[type=player] run function entity:damage/apply/core/player
execute unless entity @s[type=player] run function entity:damage/apply/core/mob
3 changes: 3 additions & 0 deletions data/entity/function/damage/apply/core/apply.macro.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#> entity:damage/apply/core/apply.macro
# 受け取ったダメージ属性とダメージ値からdamageコマンドを実行する
$damage @s $(value) $(type)
11 changes: 11 additions & 0 deletions data/entity/function/damage/apply/core/mob.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#> entity:damage/apply/core/mob
# モブへダメージを与える

# damageコマンドを実行する
function entity:damage/apply/core/apply.macro with storage entity:_ damage

# HPを更新する
function enemy:damage/update_health

# Hitダメージフラグを付与
execute if data storage entity: damage{hit:1b} run tag @s add HitDamageTaken
12 changes: 12 additions & 0 deletions data/entity/function/damage/apply/core/player.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#> entity:damage/apply/core/player
# プレイヤーへダメージを与える

# カスタム死亡ログがあればそれを表示するためにデフォルト死亡ログを非表示
execute if data storage entity: damage.deathcause run gamerule showDeathMessages false

# damageコマンドを実行する
function entity:damage/apply/core/apply.macro with storage entity:_ damage

# カスタム死亡ログがあって死亡すればログを表示
execute if data storage entity: damage.deathcause if data entity @s {Health:0f} run tellraw @a {"storage":"entity:","nbt":"damage.deathcause","interpret":true}
execute if data storage entity: damage.deathcause run gamerule showDeathMessages true
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#> entity:damage/apply/core/resolve_percentage_damage/
# 割合ダメージを実際のダメージへ計算する

# 計算に必要な数値をentity_typeに合わせて取得する
execute if entity @s[type=player] run function entity:damage/apply/core/resolve_percentage_damage/player
execute unless entity @s[type=player] run function entity:damage/apply/core/resolve_percentage_damage/mob

# 計算
execute store result score _ _ run data get storage entity:_ damage.value.percent 100
scoreboard players operation _ HP *= _ _
data modify storage entity:_ damage.value set value 0d
execute store result storage entity:_ damage.value double 0.01 run scoreboard players get _ HP
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#> entity:damage/apply/core/resolve_percentage_damage/mob

# 現在HPを取得
execute if data storage entity:_ damage.value{select:"current"} run scoreboard players operation _ HP = @s HP
# 最大HPを取得
execute if data storage entity:_ damage.value{select:"max"} run scoreboard players operation _ HP = @s HPMax
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#> entity:damage/apply/core/resolve_percentage_damage/player

# 現在HPを取得
execute if data storage entity:_ damage.value{select:"current"} store result score _ HP run data get entity @s Health
# 最大HPを取得
execute if data storage entity:_ damage.value{select:"max"} store result score _ HP run attribute @s generic.max_health get
9 changes: 9 additions & 0 deletions data/entity/function/damage/apply/magic.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#> entity:damage/apply/magic
# 設定された魔法ダメージを実行者に与える

# このダメージについての指定
data modify storage entity:_ damage set value {type:"entity:magic"}
data modify storage entity:_ damage.value set from storage entity: damage.magic

# core処理を実行
function entity:damage/apply/core/
9 changes: 9 additions & 0 deletions data/entity/function/damage/apply/physical.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#> entity:damage/apply/physical
# 設定された物理ダメージを実行者に与える

# このダメージについての指定
data modify storage entity:_ damage set value {type:"entity:physical"}
data modify storage entity:_ damage.value set from storage entity: damage.physical

# core処理を実行
function entity:damage/apply/core/
9 changes: 9 additions & 0 deletions data/entity/function/damage/apply/unreasonable.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#> entity:damage/apply/unreasonable
# 設定された理外ダメージを実行者に与える

# このダメージについての指定
data modify storage entity:_ damage set value {type:"entity:unreasonable"}
data modify storage entity:_ damage.value set from storage entity: damage.unreasonable

# core処理を実行
function entity:damage/apply/core/
19 changes: 19 additions & 0 deletions data/entity/predicate/damage/check_death.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"condition": "any_of",
"terms": [
{
"condition": "entity_properties",
"entity": "this",
"predicate": {
"nbt": "{Health:0f}"
}
},
{
"condition": "entity_properties",
"entity": "this",
"predicate": {
"nbt": "{Tags:[Garbage]}"
}
}
]
}
8 changes: 4 additions & 4 deletions data/minecraft/tags/damage_type/bypasses_cooldown.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"values": [
"tusb:unreasonable",
"tusb:magic",
"tusb:physics"
"entity:physical",
"entity:magic",
"entity:unreasonable"
]
}
}
8 changes: 4 additions & 4 deletions data/minecraft/tags/damage_type/no_knockback.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"values": [
"tusb:unreasonable",
"tusb:magic",
"tusb:physics"
"entity:physical",
"entity:magic",
"entity:unreasonable"
]
}
}

0 comments on commit 797fa07

Please sign in to comment.