-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
TheSkyBlessing/data/lib/functions/array/core/math/max.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#> lib:array/core/math/max | ||
# @within function lib:array/**max | ||
|
||
# 取得/計算 | ||
execute if score $isNumeric Temporary matches 1 store result score $Temp Temporary run data get storage lib: Array[-1] 100 | ||
execute if score $isNumeric Temporary matches 0 store result score $Temp Temporary run data get storage lib: Array[-1] | ||
scoreboard players operation $Max Temporary > $Temp Temporary | ||
# 末尾削除 | ||
data remove storage lib: Array[-1] | ||
# 要素がまだあるなら再帰 | ||
execute if data storage lib: Array[0] run function lib:array/core/math/max |
11 changes: 11 additions & 0 deletions
11
TheSkyBlessing/data/lib/functions/array/core/math/min.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#> lib:array/core/math/min | ||
# @within function lib:array/**min | ||
|
||
# 取得/計算 | ||
execute if score $isNumeric Temporary matches 1 store result score $Temp Temporary run data get storage lib: Array[-1] 100 | ||
execute if score $isNumeric Temporary matches 0 store result score $Temp Temporary run data get storage lib: Array[-1] | ||
scoreboard players operation $Min Temporary < $Temp Temporary | ||
# 末尾削除 | ||
data remove storage lib: Array[-1] | ||
# 要素がまだあるなら再帰 | ||
execute if data storage lib: Array[0] run function lib:array/core/math/min |
32 changes: 32 additions & 0 deletions
32
TheSkyBlessing/data/lib/functions/array/math/max.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#> lib:array/math/max | ||
# | ||
# 配列の要素の最大値を計算します。 | ||
# | ||
# 配列の値の型がNumeric型ではない場合は、`data get`で取得されるint値を値として扱います。 | ||
# 例えば、`List[String]`をArrayに渡した場合、各文字列の長さの最大値を返します。 | ||
# | ||
# @input | ||
# T extends any | ||
# storage lib: Array: [T] | ||
# 配列データ | ||
# @output | ||
# storage lib: MaxResult: T extends Numeric ? double : int | ||
# 最大値 | ||
# @api | ||
|
||
# セッションチェック | ||
execute if data storage lib: {ArrayLibSessionOpened:false} run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"lib:array/のセッションが開かれずに利用されています。","color":"white"}] | ||
|
||
# 初期化 | ||
scoreboard players set $Max Temporary 0 | ||
# 配列が Numeric 型か検証する | ||
execute store success score $isNumeric Temporary run data get storage lib: Array[-1] 1 | ||
# 最大値を計算する | ||
function lib:array/core/math/max | ||
# 総和をSumResultに突っ込む | ||
execute if score $isNumeric Temporary matches 0 store result storage lib: SumResult int 1.00 run scoreboard players get $Max Temporary | ||
execute if score $isNumeric Temporary matches 1 store result storage lib: SumResult double 0.01 run scoreboard players get $Max Temporary | ||
# リセット | ||
scoreboard players reset $Max Temporary | ||
scoreboard players reset $Temp Temporary | ||
scoreboard players reset $isNumeric Temporary |
32 changes: 32 additions & 0 deletions
32
TheSkyBlessing/data/lib/functions/array/math/min.mcfunction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#> lib:array/math/min | ||
# | ||
# 配列の要素の最小値を計算します。 | ||
# | ||
# 配列の値の型がNumeric型ではない場合は、`data get`で取得されるint値を値として扱います。 | ||
# 例えば、`List[String]`をArrayに渡した場合、各文字列の長さの最小値を返します。 | ||
# | ||
# @input | ||
# T extends any | ||
# storage lib: Array: [T] | ||
# 配列データ | ||
# @output | ||
# storage lib: MaxResult: T extends Numeric ? double : int | ||
# 最小値 | ||
# @api | ||
|
||
# セッションチェック | ||
execute if data storage lib: {ArrayLibSessionOpened:false} run tellraw @a [{"storage":"global","nbt":"Prefix.ERROR"},{"text":"lib:array/のセッションが開かれずに利用されています。","color":"white"}] | ||
|
||
# 初期化 | ||
scoreboard players set $Min Temporary 0 | ||
# 配列が Numeric 型か検証する | ||
execute store success score $isNumeric Temporary run data get storage lib: Array[-1] 1 | ||
# 最小値を計算する | ||
function lib:array/core/math/min | ||
# 総和をSumResultに突っ込む | ||
execute if score $isNumeric Temporary matches 0 store result storage lib: SumResult int 1.00 run scoreboard players get $Min Temporary | ||
execute if score $isNumeric Temporary matches 1 store result storage lib: SumResult double 0.01 run scoreboard players get $Min Temporary | ||
# リセット | ||
scoreboard players reset $Min Temporary | ||
scoreboard players reset $Temp Temporary | ||
scoreboard players reset $isNumeric Temporary |