Skip to content

Commit

Permalink
Merge branch 'master' into rewrite/artifact-event-system
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenCMD committed Oct 20, 2024
2 parents ba9d8e2 + 29eee2d commit 8f615b8
Show file tree
Hide file tree
Showing 26 changed files with 296 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,8 @@
" data modify storage asset:object IsAbstract set value false",
"# ID (int)",
" data modify storage asset:object ID set value %id%",
"# Tickするかどうか(boolean) (オプション)",
" # data modify storage asset:object IsTicking set value ",
"# フィールド",
" # data modify storage asset:object Field.myValue set value "
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#> api:entity/player/absorption/add
#
# プレイヤーに緩衝体力を付与します
#
# 複数の緩衝体力がある際は、Argument.Priority が大きいものから消費されます。
# Argument.Priority 0 ~ 10 の整数である必要があります。
#
# また、その UUID の全ての緩衝体力が消費された時、Argument.WipedCallback が呼び出されます。
#
# @input
# as player
# storage api:
# Argument.Amount : double @ 0..
# Argument.UUID : [int] @ 4
# Argument.Priority? : int @ 1..10 (default: 0)
# Argument.WipedCallback? : string (function)
# @api

# Validation
execute unless data storage api: Argument.Amount run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"引数が足りません","color":"white"},{"text":" Amount","color":"red"}]
execute unless data storage api: Argument.Amount run return fail
execute unless data storage api: Argument.UUID run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"引数が足りません","color":"white"},{"text":" UUID","color":"red"}]
execute unless data storage api: Argument.UUID run return fail

# Default value
execute unless data storage api: Argument.Priority run data modify storage api: Argument.Priority set value 0

# Call core
function api:entity/player/absorption/core/upsert.m with storage api: Argument

# Reset
data remove storage api: Argument.Amount
data remove storage api: Argument.UUID
data remove storage api: Argument.Priority
data remove storage api: Argument.WipedCallback
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#> api:entity/player/absorption/core/get.m
# @input args UUID: [int] @ 4
# @within function api:entity/player/absorption/get

$data modify storage api: Return.Absorption set from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{UUID:$(UUID)}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#> api:entity/player/absorption/core/remove.m
# @input args UUID: [int] @ 4
# @within function api:entity/player/absorption/remove

$data remove storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{UUID:$(UUID)}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#> api:entity/player/absorption/core/upsert.m
# @input args UUID: [int] @ 4
# @within function api:entity/player/absorption/add

#> Private
# @private
#declare score_holder $ExistsAbsorption

# EntityStorage
function oh_my_dat:please

# InsertItem 作成
data modify storage api: InsertItem set value {}
execute store result storage api: InsertItem.Amount double 0.01 run data get storage api: Argument.Amount 100
data modify storage api: InsertItem.UUID set from storage api: Argument.UUID
data modify storage api: InsertItem.Priority set from storage api: Argument.Priority
data modify storage api: InsertItem.WipedCallback set from storage api: Argument.WipedCallback

# Upsert 処理
$execute store result score $ExistsAbsorption Temporary if data storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{UUID:$(UUID)}]
$execute if score $ExistsAbsorption Temporary matches 1.. run data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{UUID:$(UUID)}] set from storage api: InsertItem
execute unless score $ExistsAbsorption Temporary matches 1.. run data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions append from storage api: InsertItem

# リセット
scoreboard players reset $ExistsAbsorption Temporary
data remove storage api: InsertItem
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#> api:entity/player/absorption/get
#
# プレイヤーの緩衝体力を取得します
#
# @input
# as player
# storage api:
# Argument.UUID : [int] @ 4
# @api

# Validation
execute unless data storage api: Argument.UUID run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"引数が足りません","color":"white"},{"text":" UUID","color":"red"}]
execute unless data storage api: Argument.UUID run return fail

# Default value
function api:entity/player/absorption/core/get.m with storage api: Argument

# Reset
data remove storage api: Argument.UUID
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#> api:entity/player/absorption/remove
#
# プレイヤーの緩衝体力を削除します
#
# @input
# as player
# storage api:
# Argument.UUID : [int] @ 4
# @api

# Validation
execute unless data storage api: Argument.UUID run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"引数が足りません","color":"white"},{"text":" UUID","color":"red"}]
execute unless data storage api: Argument.UUID run return fail

# Default value
function api:entity/player/absorption/core/remove.m with storage api: Argument

# Reset
data remove storage api: Argument.UUID
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
# asset_manager:object/summon/init
#declare tag AssetObject

#> ObjectのTickを無効化するタグ
# @within
# core:tick/
# asset:object/*/register
# asset_manager:object/summon/init
#declare tag Object.DisableTicking

#> thisタグ
# @within function
# asset_manager:object/triggers/tick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# 共通タグ付与
tag @s add AssetObject

# Tickしたくないようであれば
execute if data storage asset:object {IsTicking:false} run tag @s add Object.DisableTicking

# Object側に実装されてるInitを実行
function asset_manager:object/init/ with storage asset:context

Expand All @@ -28,5 +31,6 @@

# リセット
data remove storage asset:context this
data remove storage asset:context ID
data remove storage asset:context Field
data remove storage asset:object ID
data remove storage asset:object IsTicking
data remove storage asset:object Field
7 changes: 0 additions & 7 deletions TheSkyBlessing/data/core/functions/load_once.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,6 @@ team modify NoCollision collisionRule never
scoreboard objectives add LogRemoveTime dummy
scoreboard objectives add ScoreToHPFluc dummy

#> PlayerManager - 緩衝体力用スコアボード
# @within
# function
# player_manager:absorption/**
# lib:score_to_health_wrapper/core/absorb_damage
scoreboard objectives add PlayerAbsorption dummy {"text":"緩衝体力(e2)"}

#> PlayerManager - Motionチェック用スコアボード
# @within
# function
Expand Down
2 changes: 1 addition & 1 deletion TheSkyBlessing/data/core/functions/tick/.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
execute as @e[type=#lib:living,type=!player,tag=AlreadyInitMob,nbt=!{Health:512f}] run function mob_manager:fix_health

# Objects処理
execute as @e[tag=AssetObject] at @s run function asset_manager:object/triggers/tick
execute as @e[tag=AssetObject,tag=!Object.DisableTicking] at @s run function asset_manager:object/triggers/tick

# エフェクト処理
execute as @e[type=#lib:living,tag=HasAssetEffect] at @s run function asset_manager:effect/tick
Expand Down
12 changes: 12 additions & 0 deletions TheSkyBlessing/data/debug/functions/mob/summon.m.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#> debug:mob/summon.m
#
# マクロで指定されたIDのMobを召喚します
#
# @input args:
# ID : int
# @private
# @user

# マクロからIDを取得し召喚
$data modify storage api: Argument.ID set value $(ID)
function api:mob/summon

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#> lib:score_to_health_wrapper/core/absorb_damage/
# @within function lib:score_to_health_wrapper/proc

#> Private
# @within function
# lib:score_to_health_wrapper/core/absorb_damage/
# lib:score_to_health_wrapper/core/absorb_damage/foreach
#declare score_holder $BaseDamage

# EntityStorage 呼び出し
function oh_my_dat:please

# 計算用に値を移す
scoreboard players operation $BaseDamage Temporary = @s ScoreToHPFluc
scoreboard players operation $BaseDamage Temporary *= $-1 Const

# OMD から緩衝体力を Priority の昇順で取得する (OMD -> Absorptions)
function lib:score_to_health_wrapper/core/absorb_damage/get_absorptions
# ダメージを緩衝体力で軽減する (Absorptions -> NewAbsorptions)
data modify storage lib: NewAbsorptions set value []
execute if data storage lib: Absorptions[0] run function lib:score_to_health_wrapper/core/absorb_damage/foreach
# 残った緩衝体力を戻す (NewAbsorptions -> OMD)
function oh_my_dat:please
data modify storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions set from storage lib: NewAbsorptions

# ダメージを戻す
scoreboard players operation $BaseDamage Temporary *= $-1 Const
scoreboard players operation @s ScoreToHPFluc = $BaseDamage Temporary

# リセット
scoreboard players reset $BaseDamage Temporary
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#> lib:score_to_health_wrapper/core/absorb_damage/call_wiped_callback.m
# @input args
# WipedCallback: string (function)
# @within function lib:score_to_health_wrapper/core/absorb_damage/foreach

$function $(WipedCallback)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#> lib:score_to_health_wrapper/core/absorb_damage/foreach
# @within function
# lib:score_to_health_wrapper/core/absorb_damage/
# lib:score_to_health_wrapper/core/absorb_damage/foreach

#> Private
# @private
#declare score_holder $Absorption
#declare score_holder $isCompleteAbsorb

# データ取得
data modify storage lib: HeadAbsorption set from storage lib: Absorptions[-1]
data remove storage lib: Absorptions[-1]
# 緩衝体力を取得
execute store result score $Absorption Temporary run data get storage lib: HeadAbsorption.Amount 100

# 緩衝体力とダメージの数字を比較する
execute store result score $isCompleteAbsorb Temporary if score $BaseDamage Temporary < $Absorption Temporary
# ダメージよりも緩衝体力のほうが大きくない場合(同一も)、その分ダメージを軽減する
execute if score $isCompleteAbsorb Temporary matches 0 run scoreboard players operation $BaseDamage Temporary -= $Absorption Temporary
execute if score $isCompleteAbsorb Temporary matches 0 if data storage lib: HeadAbsorption.WipedCallback run function lib:score_to_health_wrapper/core/absorb_damage/call_wiped_callback.m with storage lib: HeadAbsorption
# ダメージよりも緩衝体力のほうが大きい場合、ダメージを全て削除し、その分緩衝体力を減少させる
execute if score $isCompleteAbsorb Temporary matches 1 run scoreboard players operation $Absorption Temporary -= $BaseDamage Temporary
execute if score $isCompleteAbsorb Temporary matches 1 run scoreboard players set $BaseDamage Temporary 0
execute if score $isCompleteAbsorb Temporary matches 1 run data modify storage lib: NewAbsorptions append from storage lib: HeadAbsorption
execute if score $isCompleteAbsorb Temporary matches 1 store result storage lib: NewAbsorptions[-1].Amount double 0.01 run scoreboard players get $Absorption Temporary

# リセット
data remove storage lib: HeadAbsorption
scoreboard players reset $Absorption Temporary
scoreboard players reset $isCompleteAbsorb Temporary

# ダメージを緩衝しきった場合、残っている緩衝体力を全て NewAbsorption に追加する
execute if score $BaseDamage Temporary matches ..0 if data storage lib: Absorptions[0] run function lib:score_to_health_wrapper/core/absorb_damage/revert
# ダメージを緩衝しきれず、かつまだ緩衝体力がある場合、再帰的に緩衝する
execute if score $BaseDamage Temporary matches 1.. if data storage lib: Absorptions[0] run function lib:score_to_health_wrapper/core/absorb_damage/foreach
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#> lib:score_to_health_wrapper/core/absorb_damage/get_absorptions
# @within function lib:score_to_health_wrapper/core/absorb_damage/

# セッション開く
function lib:array/session/open

# Priority 10 -> 0 の順に追加
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:10}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:9}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:8}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:7}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:6}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:5}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:4}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:3}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:2}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:1}]
data modify storage lib: Array append from storage oh_my_dat: _[-4][-4][-4][-4][-4][-4][-4][-4].Absorptions[{Priority:0}]
# 反転させる (0 -> 10)
function lib:array/reverse
# Absorptions に移す
data modify storage lib: Absorptions set from storage lib: Array

# セッション閉じる
function lib:array/session/close
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#> lib:score_to_health_wrapper/core/absorb_damage/revert
# @within function lib:score_to_health_wrapper/core/absorb_damage/foreach

# セッション開ける
function lib:array/session/open

# 残っている Absorptions を移す
data modify storage lib: Array set from storage lib: Absorptions
# 反転させる
function lib:array/reverse
# NewAbsorptions に追加する
data modify storage lib: NewAbsorptions append from storage lib: Array[]

# セッション閉じる
function lib:array/session/close
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# 体力>=1 & 差分<=-1: ダメージ演出
execute if score @s ScoreToHPFluc matches ..-1 if score @s ScoreToHealth matches 1.. run summon area_effect_cloud ~ ~ ~ {Duration:6,Age:4,effects:[{id:"unluck",amplifier:127b,duration:1,show_particles:0b},{id:"resistance",amplifier:127b,duration:1,show_particles:0b},{id:"instant_damage",amplifier:0b,duration:1,show_particles:0b}]}
# ダメージの場合は金ハートを消費する
execute if score @s ScoreToHPFluc matches ..-1 run function lib:score_to_health_wrapper/core/absorb_damage
execute if score @s ScoreToHPFluc matches ..-1 run function lib:score_to_health_wrapper/core/absorb_damage/
# 回復/ダメージを適用
execute if score @s ScoreToHPFluc matches -2147483648..2147483647 run function lib:score_to_health_wrapper/core/calc
# 体力>=1 & 差分 = 0: リセット
Expand Down
7 changes: 4 additions & 3 deletions TheSkyBlessing/data/minecraft/functions/test.mcfunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data modify storage api: Argument.UUID set value [I; -1,0,0,0]
data modify storage api: Argument.Amount set value 100
data modify storage api: Argument.Operation set value "add"

data modify storage api: Argument.ID set value 65533
data modify storage api: Argument.Duration set value 200
function api:entity/mob/effect/give
function api:modifier/max_health/add
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#> minecraft:tests/absorption_api/callback1
# @within function minecraft:test
say callback1 called
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#> minecraft:tests/absorption_api/callback2
# @within function minecraft:test
say callback2 called
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#> minecraft:tests/absorption_api/callback3
# @within function minecraft:test
say callback3 called
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data modify storage api: Argument.Amount set value 4
data modify storage api: Argument.UUID set value [I; -1, 0, 0, 3]
data modify storage api: Argument.Priority set value 1
data modify storage api: Argument.WipedCallback set value "minecraft:callback3"
function api:entity/player/absorption/add

data modify storage api: Argument.Amount set value 4
data modify storage api: Argument.UUID set value [I; -1, 0, 0, 2]
data modify storage api: Argument.Priority set value 1
data modify storage api: Argument.WipedCallback set value "minecraft:callback2"
function api:entity/player/absorption/add

data modify storage api: Argument.Amount set value 4
data modify storage api: Argument.UUID set value [I; -1, 0, 0, 1]
data modify storage api: Argument.Priority set value 10
data modify storage api: Argument.WipedCallback set value "minecraft:callback1"
function api:entity/player/absorption/add
Loading

0 comments on commit 8f615b8

Please sign in to comment.