Skip to content

libraries

こま edited this page May 22, 2026 · 47 revisions

乱数ライブラリ

疑似乱数生成

乱数を取得します

使い方

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

固定確率 predicates

指定した確率で 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!

攻撃元 Entity 探索実装

その tick にそのプレイヤー攻撃した Entity を特定する実装です。
使用可能な個所にて@e[type=#lib:living,type=!player,tag=Attacker]
で対象にすることが可能です。

攻撃先 Entity 探索実装

その tick にそのプレイヤー攻撃した Entity を特定する実装です。
使用可能な個所にて@e[type=#lib:living,type=!player,tag=Victim]
で対象にすることが可能です。

天候チェック predicates

指定した天候の場合 true を返す predicate です。

使い方

execute if predicate lib:weather/is_<sunny|raining|thundering>

# 天候が雨の場合のみ「rain!」と出力するコマンド
    execute if predicate lib:weather/is_raining run say rain!

ディメンションチェック predicate

実行ワールドが指定したディメンションの場合 true を返す predicate です。

使い方

execute if predicate lib:dimension/is_<overworld|nether|end>

# ディメンションがendの場合のみ「ending!」と出力するコマンド
    execute if predicate lib:dimension/is_end run say ending!

MotionLib

実行 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

前方拡散 Lib

実行 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 拡散 Lib

実行 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/

スコア分移動 Lib

実行 Entity を指定したスコア分前進させます。 基となったライブラリ https://github.com/Ai-Akaishi/ScoreToMove

使い方

$Move Libに前進させたい距離(m)の 10000 倍をセットして、function lib:score_to_move/を実行

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

実行方向に回転する直方体状の範囲内のエンティティに"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 対象とするエンティティのセレクタ -

イメージ図

回転可能dxyz説明

# 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

直線当たり判定

ヒットボックスが直線に重なるエンティティに"CollisionLine"という tag を付けます。

使い方

ストレージ引数に各引数を指定して、 lib:collision_line/を実行

function lib:collision_line/

引数

要求データ 必須 説明 デフォルト
実行座標 o Pos 直線の始点
実行方向 o Rotation 直線の方向
lib: Argument.CollisionLine.Length o double 直線の長さ
lib: Argument.CollisionLine.Selector o string 対象とするエンティティのセレクタ

# 長さ10の直線に重なるプレイヤにtag付け
data modify storage lib: Argument.CollisionLine.Length set value 10
data modify storage lib: Argument.CollisionLine.Selector set value "@a[tag=!PlayerShouldInvulnerable]"
function lib:collision_line/
    
# tag付けされたプレイヤを表示
    say @a[tag=!PlayerShouldInvulnerable,tag=CollisionLine]

# tagリセット
    tag @a[tag=!PlayerShouldInvulnerable,tag=CollisionLine] remove CollisionLine

反射弾

実行者をブロックに反射する軌道で前進させます。
ブロックタグ#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/

ブロックに引っかかる移動

ブロックに引っかかって滑るような軌道で実行者を前進させます。
デフォルトではブロックタグ#lib:no_collision に登録されていないブロックに引っかかります。

使い方

ストレージに各引数を指定して、 function lib:slide_move/を実行

data modify storage lib: Argument.SlideMove set value {Speed:<前進させたい距離>}
function lib:slide_move/

引数

要求データ 必須 説明 デフォルト
実行者 o Entity 前進させたいエンティティ -
実行座標 o Pos 軌道の始点 -
実行方向 o Rotation 軌道の方向 -
storage lib: Argument.SlideMove.Speed o double 前進させたい距離 -
storage lib: Argument.SlideMove.Conditions string 引っかかるブロックの条件 "unless block ~ ~ ~ #lib:no_collision/"

# 実行者をスライド軌道で0.2m前進
    data modify storage lib: Argument.SlideMove set value {Speed:0.2}
    function lib:slide_move/
# ブロック条件を指定することも可能
    data modify storage lib: Argument.SlideMove set value {Speed:0.2,Conditions:"unless block ~ ~ ~ #no_collision_without_fluid/"}
    function lib:slide_move/

距離測定

実行者と実行座標の距離を測定します。

使い方

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/

Clone this wiki locally