-
Notifications
You must be signed in to change notification settings - Fork 6
libraries
- 乱数ライブラリ
- 攻撃元Entity探索実装
- 攻撃先Entity探索実装
- 天候チェックpredicates
- ディメンションチェックpredicate
- MotionLib
- 前方拡散Lib
- Entity拡散Lib
- スコア分移動Lib
- 回転可能dxyz
- 円柱型当たり判定
- 扇型当たり判定
- 反射弾
- 距離測定
- ディスプレイ回転
乱数を取得します
execute store result ... run function lib:random/乱数として生成される値は
0~65535までの範囲です。
注: このライブラリはもやんのせいでfunction内以外から実行すると6しか取得できません。function内で実行する分には問題ないからバグ報告しないでね☆
# 25%の確率で「excellent!」,50%の確率で「great」,25%の確率で「miss」と出力するコマンド
# 疑似乱数取得
execute store result score $Random Temporary run function lib:random/
# ほしい範囲に剰余算
scoreboard players operation $Random Temporary %= $100 Const
# メッセージ出力
execute if score $Random Temporary matches 00..24 run say excellent!
execute if score $Random Temporary matches 25..74 run say great
execute if score $Random Temporary matches 75..99 run say miss
# リセット
scoreboard players reset $Random Temporary指定した確率でtrueを返すpredicateです。
execute if predicate lib:random_pass_per/<確率>@a[predicate=lib:random_pass_per/<確率>
確率に指定可能な値は
1~99までの範囲です。
# 30%の確率で「pass!」と出力するコマンド
execute if predicate lib:random_pass_per/30 run say pass!そのtickにそのプレイヤーを攻撃したEntityを特定する実装です。
使用可能な個所にて@e[type=#lib:living,type=!player,tag=Attacker]
で対象にすることが可能です。
そのtickにそのプレイヤーが攻撃したEntityを特定する実装です。
使用可能な個所にて@e[type=#lib:living,type=!player,tag=Victim]
で対象にすることが可能です。
指定した天候の場合trueを返すpredicateです。
execute if predicate lib:weather/is_<sunny|raining|thundering># 天候が雨の場合のみ「rain!」と出力するコマンド
execute if predicate lib:weather/is_raining run say rain!実行ワールドが指定したディメンションの場合trueを返すpredicateです。
execute if predicate lib:dimension/is_<overworld|nether|end># ディメンションがendの場合のみ「ending!」と出力するコマンド
execute if predicate lib:dimension/is_end run say ending!実行Entity(type=!player)に実行方向のArgument.VectorMagnitude分のMotionを付与します。
at,rotatedと併用してください
| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行者 | o | Entity | 動かす実行者 | - |
| Argument.VectorMagnitude | o | double | 実行位置からどのくらい離すか | - |
| Argument.KnockbackResist | × | boolean | ノックバック耐性を考慮するか | false |
function lib:motion/# 5m以内のEntityに1Block分の視点方向のMotionをかけるコマンド
data modify storage lib: Argument.VectorMagnitude set value 1
execute as @e[type=!player,distance=..5] at @s run function lib:motion/
data remove storage lib: Argument
# ノックバック耐性を考慮して5m以内のEntityが自分めがけて飛んでくるコマンド
data modify storage lib: Argument.VectorMagnitude set value 5
data modify storage lib: Argument.KnockbackResist set value true
execute as @e[type=!player,distance=..5] at @s facing entity @p feet run function lib:motion/
data remove storage lib: Argument実行entityを実行方向のランダムな位置に移動させます。
また、それ用途のスニペット(forwardSpreadLib)がTheSkyBlockリポジトリに登録されています
| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行者 | o | Entity | 動かす実行者 | - |
| Argument.Distance | o | double | 実行位置からどのくらい離すか | - |
| Argument.Spread | o | double | 離れた位置でどのくらい拡散するか | - |
note: Spreadの値が-4.634~4.634の範囲を出る場合、内部処理でオーバーフローし正常に動作しなくなります。
function lib:forward_spreader/<square|circle># 10mで2.5mのブレが発生する矢を放つコマンド
#> SpreadLib
# @private
#declare tag SpreadMarker
# 拡散させるEntityを召喚する
summon marker ~ ~ ~ {Tags:["SpreadMarker"]}
# ステータス設定
data modify storage lib: Argument.Distance set value 10
data modify storage lib: Argument.Spread set value 2.5
# 拡散
execute as @e[type=marker,tag=SpreadMarker,limit=1] run function lib:forward_spreader/circle
# 矢を召喚して飛ばす
execute anchored eyes run summon arrow ^ ^ ^ {Tags:[ArrowInit]}
scoreboard players set $VectorMagnitude 250
execute as @e[type=arrow,tag=ArrowInit,distance=..2] at @s facing entity @e[type=marker,tag=SpreadMarker,limit=1] feet anchored eyes positioned ^ ^ ^ run function lib:motion/
# リセット
tag @e[type=arrow,tag=ArrowInit,distance=..2] remove ArrowInit
kill @e[type=marker,tag=SpreadMarker]実行Entityを実行座標を中心としたランダムな座標へ移動させます。
| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行者 | o | Entity | 動かす対象Entity | - |
| 実行座標 | o | Pos | 移動の中心座標 | - |
| Argument.Bounds | o | double[2][3] | X,Y,Zの-,+方向の最大移動範囲 | - |
function function lib:spread_entity/# 実行座標を中心として-x方向に1、+x方向に1、-y方向に0.2、+y方向に0.8、-z方向に1、+z方向に1の立方体内のランダムな位置にmarkerを移動
summon marker ~ ~0.5 ~ {Tags:["Exemple"]}
data modify storage lib: Argument.Bounds set value [[1d,1d],[0.2d,0.8d],[1d,1d]]
execute as @e[type=marker,tag=Exemple] at @s run function lib:spread_entity/実行Entityを指定したスコア分前進させます。 基となったライブラリ https://github.com/Ai-Akaishi/ScoreToMove
エンティティのScoreToMoveに、前進させたい距離(m)の10000倍をセットして、function score_to_move:applyを実行
function function lib:score_to_move/| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行者 | o | Entity | 動かす実行者 | - |
| $Move | o | Scoreboard | 距離(m)の10000倍 | - |
# Targetというタグの付いたエンティティを12.3456m前進
scoreboard players set $Move Lib 123456
execute as @e[tag=Target] at @s run function lib:score_to_move/実行方向に回転する直方体状の範囲内のエンティティに"DXYZ"というtagを付けます。
注意:通常のdx,dy,dzとは以下の違いがあります。
・実行座標が直方体の中央となる。
・値は中央から辺までの距離を表す。(そのため直方体の大きさは倍になる)
・エンティティのヒットボックスの大きさは考慮しない。
マクロ引数に各引数を指定して、function lib:rotatable_dxyz/mを実行
function lib:rotatable_dxyz/m <マクロ引数指定>| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行座標 | o | Pos | 直方体範囲の中心 | - |
| 実行方向 | o | Rotation | 直方体範囲の方向 | - |
| dx | o | double | 中心からX軸方向の辺への距離 | - |
| dy | o | double | 中心からX軸方向の辺への距離 | - |
| dz | o | double | 中心からX軸方向の辺への距離 | - |
| selector | o | string | 対象とするエンティティのセレクタ | - |

# 1x2x3の直方体範囲内のプレイヤにtag付け
data modify storage lib: args.dx set value 0.5
data modify storage lib: args.dy set value 1.0
data modify storage lib: args.dz set value 1.5
data modify storage lib: args.selector set value "@a[tag=!PlayerShouldInvulnerable,distance=..5]"
function lib:rotatable_dxyz/m with storage lib: args
# tag付けされたプレイヤを表示
say @a[tag=!PlayerShouldInvulnerable,distance=..5,tag=DXYZ]
# tagリセット
tag @a[tag=!PlayerShouldInvulnerable,distance=..5,tag=DXYZ] remove DXYZ円柱型の範囲内のエンティティに"BoundingCylinder"というtagを付けます。
ストレージ引数に各引数を指定して、function lib:bounding_cylinder/を実行
function lib:bounding_cylinder/| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行座標 | o | Pos | 円柱の底面の中心 | - |
| lib: Argument.BoundingCylinder.Radius | o | double | 円柱の半径 | - |
| lib: Argument.BoundingCylinder.Height | o | double | 円柱の高さ | - |
| lib: Argument.BoundingCylinder.Selector | o | string | 対象とするエンティティのセレクタ | - |
# 半径5高さ1の円柱型範囲内のプレイヤにtag付け
data modify storage lib: Argument.BoundingCylinder.Radius set value 5
data modify storage lib: Argument.BoundingCylinder.Height set value 1
data modify storage lib: Argument.BoundingCylinder.Selector set value "@a[tag=!PlayerShouldInvulnerable,distance=..6]"
function lib:bounding_cylinder/
# tag付けされたプレイヤを表示
say @a[tag=!PlayerShouldInvulnerable,distance=..6,tag=BoundingCylinder]
# tagリセット
tag @a[tag=!PlayerShouldInvulnerable,distance=..6,tag=BoundingCylinder] remove BoundingCylinder厚みを持った扇型の範囲内のエンティティに"BoundingFan"というtagを付けます。
ストレージ引数に各引数を指定して、lib:bounding_fan/を実行
function lib:bounding_fan/| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行座標 | o | Pos | 底面の扇型の中心角 | - |
| 実行方向 | o | Rotation | 扇型が広がる方向(水平方向のみ反映) | - |
| lib: Argument.BoundingCylinder.Angle | o | double | 扇型の中心角の角度 | - |
| lib: Argument.BoundingCylinder.Radius | o | double | 扇型の半径 | - |
| lib: Argument.BoundingCylinder.Height | o | double | 扇型の厚み | - |
| lib: Argument.BoundingCylinder.Selector | o | string | 対象とするエンティティのセレクタ | - |
# 角度90半径5厚み1の扇型範囲内のプレイヤにtag付け
data modify storage lib: Argument.BoundingFan.Angle set value 90
data modify storage lib: Argument.BoundingFan.Radius set value 5
data modify storage lib: Argument.BoundingFan.Height set value 1
data modify storage lib: Argument.BoundingFan.Selector set value "@a[tag=!PlayerShouldInvulnerable,distance=..6]"
function lib:bounding_fan/
# tag付けされたプレイヤを表示
say @a[tag=!PlayerShouldInvulnerable,distance=..6,tag=BoundingFan]
# tagリセット
tag @a[tag=!PlayerShouldInvulnerable,distance=..6,tag=BoundingFan] remove BoundingFan実行者をブロックに反射する軌道で前進させます。
ブロックタグ#lib:no_collisionに登録されていないブロックに反射します。
マクロ引数に各引数を指定して、function lib:reflection_bulletを実行
scoreboard players set $Speed Lib <前進させたい距離(m)の10倍>
function lib:reflection_bullet/| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行者 | o | Entity | 前進させたいエンティティ | - |
| 実行座標 | o | Pos | 軌道の始点 | - |
| 実行方向 | o | Rotation | 軌道の方向 | - |
| $Speed | o | Scoreboard | 前進させたい距離(m)の10倍 | - |
# 実行者を反射軌道で0.8m前進
scoreboard players set $Speed Lib 8
function lib:reflection_bullet/実行者と実行座標の距離を測定します。
execute as <実行者> positioned <実行座標> function lib:distance/as_to_at# 実行者とワールド原点の距離を測定
execute positioned 0.0 0.0 0.0 run function lib:distance/as_to_at
data get storage lib: Return.Distanceディスプレイ系エンティティを実行方向へと正確に回転させます。
(エンティティの向きでディスプレイを回転させた場合に僅かに発生する誤差の対策です。)
注意:ディスプレイのscale[0]とscale[1]の値が異なるとせん断変形が起きます。
execute as <ディスプレイ> rotated <実行向き> run function lib:rotate_display/| 要求データ | 必須 | 型 | 説明 | デフォルト |
|---|---|---|---|---|
| 実行者 | o | Entity | 回転させたいディスプレイ | - |
| 実行方向 | o | Rotation | 向かせたい方向 | - |
# 実行者であるディスプレイを最寄りのプレイヤーに向ける
execute facing entity @p eyes run function lib:rotate_display/