Skip to content

libraries

quikku edited this page Jun 18, 2021 · 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)に実行方向の$VectorMagnitude*0.01Block分のMotionを付与します。
at,rotatedと併用してください

使い方

function lib:motion/

# 5m以内のEntityに1Block分の視点方向のMotionをかけるコマンド
    scoreboard players set $VectorMagnitude Lib 100
    execute as @e[type=!player,distance=..5] at @s run function lib:motion/

# 5m以内のEntityが自分めがけて飛んでくるコマンド
    scoreboard players set $VectorMagnitude Lib 500
    execute as @e[type=!player,distance=..5] at @s facing entity @p feet run function lib:motion/

前方拡散Lib

汎用Entity(0-0-0-0-0)を実行方向のランダムな位置に移動させます。

引数

要求データ 必須 説明 デフォルト
Argument.Distance o double 実行位置からどのくらい離すか -
Argument.Spread o double 離れた位置でどのくらい拡散するか -

note: Spreadの値が-4.634~4.634の範囲を出る場合、内部処理でオーバーフローし正常に動作しなくなります。

使い方

function lib:forward_spreader/<square|circle>

# 10mで2.5mのブレが発生する矢を放つコマンド
    # 0-0-0-0-0を視点10m先の2.5m以内のランダムな位置に移動させる
        data modify storage lib: Argument.Distance set value 10.0
        data modify storage lib: Argument.Spread set value 2.5
        function lib:forward_spreader/circle
    # 矢を召喚して飛ばす
        execute anchor eyes run summon arrow ^ ^ ^ {Tags:[ArrowInit]}
        scoreboard players set $VectorMagnitude 250
        execute as @e[type=arrow,tag=ArrowInit,distance=..2] at @s facing entity 0-0-0-0-0 feet run function lib:motion/
    # リセット
        tag @e[type=arrow,tag=ArrowInit,distance=..2] remove ArrowInit

Clone this wiki locally