Luaスクリプティング:ワールドと環境
このページでは、context.world、context.vectors、context.settings、context.eventで利用可能なすべてのメソッドを説明します。これらにより、LuaパワーがMinecraftワールドとやり取りできます -- エンティティのスポーン、エフェクトの再生、ブロックの照会など。Luaパワーが初めての場合は、まずはじめにから始めてください。
EliteMobs のボスパワーは MagmaCore の Lua サンドボックスを再利用しています。ボスの context.world は共有された MagmaCore の world テーブルを起点としているため、get_block_at(...)、set_block_at(...)、spawn_particle(...) といった汎用の座標ヘルパーも引き続き利用できます。このページでは、EliteMobs のボス固有の context.world、context.vectors、context.settings、context.event の追加分と上書き分を扱います。汎用のワールド API については MagmaCore Lua スクリプティングエンジンを参照してください。
同名のメソッドがある場合は EliteMobs 版が優先されます。以下のメソッドは落雷のスポーンキャンセル回避、拡張パーティクル仕様、一時ブロック管理などの動作を維持します。他の共有メソッドも利用でき、get_entity(uuid)、block_is_passable(x, y, z)、location_is_protected(location)、spawn_dust(...)、raycast(...) などが含まれます。引数と未ロードチャンクでの動作は共有 API リファレンスを参照してください。その保証が EliteMobs の上書きメソッドに自動適用されるわけではありません。
FreeMinecraftModels は、drop_elitemobs_procedural_loot、drop_elitemobs_random_loot、drop_elitemobs_custom_loot、start_elitemobs_transport を、自身のプロップスクリプトの context.world にのみ追加します。各プラグインは共有スクリプトライブラリの別々のコピーを持つため、FreeMinecraftModels がインストールされていても、これらのヘルパーは EliteMobs のボスパワーや NPC スクリプトには現れません。ボスパワーでは代わりに generate_player_loot と drop_bonus_coins を使ってください。
context.world
world テーブルはエンティティの生成、エフェクト、ブロックやワールド状態の変更を行います。メソッドはコロン構文(world:method())、または self 引数を明示しないドット構文で呼び出せます。
以下のボス用上書きメソッドは x、y、z、任意の yaw/pitch、ロード済みワールド名 world を持つ位置テーブルを変換します。座標の省略値は 0、ワールドの省略値はボスの現在のワールドです。明示したワールド名が不明なら変換に失敗します。入れ子の current_location テーブルも使用できます。位置が nil またはテーブル以外ならボスの位置を使用します。共有メソッドは別の位置仕様と、テーブル作成時に保持したワールドを使います。
Lua インスタンスを閉じてもワールド変更や生成したエンティティは自動で元に戻りません。スクリプト所有の監視処理は停止しますが、独立した削除タイマー、爆発の再生、強化落雷、金塊投射物のタスクには独自の寿命があります。ブロック・生成メソッドは location_is_protected や共有 API のロード済みチャンク検査を自動適用しません。ワールドを変更する前に必要な条件を確認してください。
world:spawn_particle_at_location(location, particleSpec)
指定位置にパーティクルを生成します。第2引数は名前または仕様テーブルです。任意の第3整数引数は amount がない場合の個数を指定し、既定値は 1 です。名前は大文字に変換して検索します。無効な名前や未対応のデータは警告を出し、パーティクルを生成しません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | パーティクルを生成する位置 |
particleSpec | string または table | パーティクル名 またはパーティクル仕様テーブル(下記参照) |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Simple particle by name
context.world:spawn_particle_at_location(context.boss:get_location(), "FLAME")
-- Full particle spec table with red dust
context.world:spawn_particle_at_location(context.boss:get_location(), {
particle = "DUST",
amount = 10,
x = 0.5,
y = 0.5,
z = 0.5,
speed = 0.02,
red = 255,
green = 0,
blue = 0,
})
end
}
パーティクル仕様テーブルの形式
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
particle | string | 必須 | パーティクル名 |
amount | int | 1 | パーティクルの数 |
x, y, z | number | 0 | 各軸方向の広がり/オフセット |
speed | number | 0 | パーティクルの速度 |
red, green, blue | int | 255 | DUST と DUST_COLOR_TRANSITION 用の RGB カラー |
toRed, toGreen, toBlue | int | 255 | DUST_COLOR_TRANSITION の遷移先カラー |
DUST_COLOR_TRANSITION は to_red、to_green、to_blue も使用できます。camelCase の値が優先されます。両方のダスト型のサイズは固定で 1、RGB は 0..255 です。他の粒子には追加データを渡さないため、データを必要とする粒子すべてに対応するわけではありません。
EliteScript YAMLの設定とは異なり、Luaのパーティクル名はレガシーパーティクル名の変換をサポートしていません。現在のSpigot API名を使用する必要があります(例:FIREWORKS_SPARK ではなく FIREWORK、SMOKE_NORMAL ではなく SMOKE、REDSTONE ではなく DUST)。現在の名前とレガシー名の対応表は有効なパーティクルリストを参照してください。
world:play_sound_at_location(location, sound, volume, pitch)
指定した位置でサウンドを再生します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | サウンドを再生する位置 | |
sound | string | Minecraftのサウンドキー(例:"entity.blaze.shoot")または Spigot の Sound enum 名。リソースパックのキーも使用できます。 | |
volume | number | 1.0 | 音量 |
pitch | number | 1.0 | ピッチ |
例
return {
api_version = 1,
on_spawn = function(context)
context.world:play_sound_at_location(
context.boss:get_location(),
"entity.wither.spawn",
1.0,
0.5
)
end
}
world:strike_lightning_at_location(location)
実際にダメージを与える落雷を生成し、EliteMobs の落雷スポーンキャンセル回避を有効にします。共有 API の視覚効果専用ヘルパーとは異なり、他のすべてのプラグインのダメージ・保護規則を無視する保証もありません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 落雷させる位置 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("lightning", 100) then return end
context.world:strike_lightning_at_location(context.player:get_location())
context.player:send_message("&eA bolt of lightning strikes you!")
end
}
world:spawn_entity_at_location(entityType, location, options)
指定ワールドにバニラエンティティを直接生成します。不明な名前は nil を返しますが、認識されても生成不可能な型はエラーになる場合があります。投射物の発射者設定やエリート増援への登録は自動では行いません。
| パラメータ | 型 | 備考 |
|---|---|---|
entityType | string | エンティティタイプ名(例:"FIREBALL"、"ARROW") |
location | locationテーブル | スポーンさせる位置 |
options | table(省略可) | スポーンオプション(下記参照) |
エンティティのスポーンオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
velocity | vectorテーブル | nil | 初速度 {x, y, z} |
effect | string | nil | スポーン時に再生する EntityEffect |
duration | int | 0 | 正数なら指定ティック後の削除を予約。0 以下では削除タイマーを追加しません |
on_land | function | nil | 接地、無効化、max_ticks 超過時の function(land_location, entity_ref)。投射物衝突イベントでも着地の保証でもありません |
max_ticks | int | 6000 | on_land コールバックを強制するまでに監視する最大ティック数 |
persistent | boolean | Minecraftのデフォルト | false にするとエンティティがチャンクの保存対象から外れ、効果の最中にシャットダウンやチャンクのアンロードが起きても、ワールドにエンティティが残りません |
エンティティのラッパーテーブルを返します。非生体型(FIREBALL、ARROW、TNT など)は
非生体参照ラッパーを使い、is_valid() はメソッドです。
生体型(ZOMBIE、GIANT など)は
生体ラッパーを使い、is_valid は真偽値フィールドです。
こちらで entity:is_valid() を呼ぶと attempt to call a boolean value になります。
着地監視はスクリプトが動作中の各ティックに実行され、所有タスクとともに停止します。正の duration タイマーは独立しており、スクリプト終了後も削除できます。不明な effect 名は無視されます。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("fireball_spawn", 100) then return end
-- Spawn a fireball aimed at the player
local boss_loc = context.boss:get_location()
local dir = context.vectors.get_vector_between_locations(boss_loc, context.player:get_location())
dir = context.vectors.normalize_vector(dir)
context.world:spawn_entity_at_location("FIREBALL", boss_loc, {
velocity = { x = dir.x * 2, y = dir.y * 2, z = dir.z * 2 },
duration = 100,
})
end
}
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Spawn a primed TNT with a landing callback
context.world:spawn_entity_at_location("TNT", context.boss:get_location(), {
velocity = { x = 0, y = 1.5, z = 0 },
on_land = function(land_location, entity_ref)
context.world:spawn_particle_at_location(land_location, {
particle = "EXPLOSION_EMITTER",
amount = 1,
})
end,
})
end
}
world:spawn_display_at_location(location, options)
アイテムディスプレイまたはブロックディスプレイを生成します。当たり判定も重力もAIもない、浮かぶだけの見た目です。周回する石や投げられた小道具など、見えさえすればよい演出には、アーマースタンドを装飾する代わりにこれを使ってください。ディスプレイは location を中心に置かれ、そのyawで向きが決まります。
| オプション | 型 | デフォルト | 備考 |
|---|---|---|---|
item | string | アイテムとして表示する素材。"AMETHYST_BLOCK" のようなブロックアイテムは、中央に置かれたブロックとして表示されます | |
block | string | ブロックディスプレイとして表示するブロック。素材名、または "lantern[hanging=true]" のようなブロックデータ | |
scale | number または vectorテーブル | 1 | 数値なら全軸を拡大縮小し、{x, y, z} なら軸ごとに指定します。1 ではブロックの幅が1ブロックになります |
duration | int | 0 | 正の値なら、そのティック数が経過するとディスプレイを削除します |
teleport_duration | int | 0 | クライアントが新しい位置へ滑らかに移動する間のティック数。0 から 59。ディスプレイを毎ティックテレポートさせる場合は 1 を使います |
billboard | string | FIXED | FIXED、VERTICAL、HORIZONTAL、CENTER |
glowing | boolean | false | アウトラインの発光 |
brightness | int | ワールドの明るさ | 0 から 15。ディスプレイ位置の明るさを上書きします |
bedrock_fallback | boolean | true | 下記を参照 |
item か block のどちらか一方だけを指定してください。item または block が未指定または不明な場合、両方を同時に指定した場合、scale が正でない場合は、nil を返し、パワー名を示す警告をログに出力します。不明な billboard の値は FIXED のままになります。
ディスプレイはチャンクと一緒に保存されることはありません。duration が尽きたとき、remove() を呼んだとき、パワーが終了したときのうち、最も早いものでディスプレイは削除されます。
Bedrock クライアントはディスプレイエンティティを描画できません。ディスプレイが生成された時点でワールドにいる Bedrock プレイヤーには、代わりに同じアイテム(ブロックディスプレイの場合はそのブロックのアイテム)を身につけた透明なアーマースタンドが表示され、ディスプレイ自体は見えなくなります。スタンドはディスプレイに追従し、ディスプレイと一緒に削除されます。あとからワールドに入った Bedrock プレイヤーにはスタンドは表示されず、fire のようにアイテムの形を持たないブロックにはスタンドが一切作られません。Bedrock プレイヤーに見せる必要のない演出では、bedrock_fallback = false でこれをオフにできます。
返されるラッパーには uuid と entity_type があり、次のメソッドを持ちます。
| メソッド | 備考 |
|---|---|
is_valid(), is_alive() | ディスプレイがまだ存在するか |
get_location() | 現在位置 |
teleport_to_location(location) | ディスプレイと、その Bedrock 用スタンドを移動します |
remove() | ディスプレイと、その Bedrock 用スタンドを削除します |
set_scale(scale) | scale オプションと同じ値 |
set_item(material) | アイテムディスプレイ専用。それ以外では false を返します |
set_block(block) | ブロックディスプレイ専用。それ以外では false を返します |
set_glowing(enabled) | アウトラインの発光 |
set_brightness(level) | 0 から 15。nil ならワールドの明るさに戻します |
set_teleport_duration(ticks) | teleport_duration オプションと同じ |
例
-- Three amethyst stones circle the target for three seconds.
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil or not context.cooldowns:check_local("orbit", 200) then return end
local target = context.player
local stones = {}
for i = 1, 3 do
stones[i] = context.world:spawn_display_at_location(target:get_location(), {
item = "AMETHYST_BLOCK", scale = 0.3, duration = 60, teleport_duration = 1
})
end
local elapsed = 0
local task
task = context.scheduler:run_every(1, function(context)
elapsed = elapsed + 1
if elapsed >= 60 then
context.scheduler:cancel_task(task)
return
end
local center = target:get_location()
for i = 1, 3 do
local angle = elapsed * 0.2 + i * (2 * math.pi / 3)
if stones[i] ~= nil and stones[i]:is_valid() then
stones[i]:teleport_to_location(em.create_location(
center.x + math.cos(angle) * 1.5, center.y + 1.2, center.z + math.sin(angle) * 1.5, center.world, 0, 0))
end
end
end)
end
}
world:spawn_falling_block_at_location(location, material, options)
ブロック素材から落下ブロックを生成します。on_land があると EliteMobs はブロック変更イベントを捕捉して設置をキャンセルし、function(land_location, entity_ref) を1回呼びます。コールバックがなければ通常の設置が起こり得ます。duration、max_ticks、無効化・時間切れ時のコールバックはありません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | スポーンさせる位置 |
material | string | マテリアル名(例:"STONE"、"MAGMA_BLOCK") |
options | table(省略可) | スポーンオプション(下記参照) |
落下ブロックのオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
velocity | vectorテーブル | nil | 初速度 {x, y, z} |
drop_item | boolean | false | ブロックがアイテムとしてドロップするかどうか |
hurt_entities | boolean | false | ブロックが着地先のエンティティにダメージを与えるかどうか |
on_land | function | nil | ブロックが着地したときのコールバック function(land_location, entity_ref) |
非生体参照テーブルを返し、位置・素材を解決できなければ nil です。認識された素材でもブロック以外ならブロックデータ作成時に失敗する場合があります。
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Rain magma blocks from above
local loc = context.boss:get_location()
for i = 1, 5 do
local offset_loc = {
x = loc.x + math.random(-3, 3),
y = loc.y + 10,
z = loc.z + math.random(-3, 3),
world = loc.world
}
context.world:spawn_falling_block_at_location(offset_loc, "MAGMA_BLOCK", {
velocity = { x = 0, y = -0.5, z = 0 },
hurt_entities = true,
on_land = function(land_location, entity_ref)
context.world:spawn_particle_at_location(land_location, { particle = "LAVA", amount = 8 })
end,
})
end
end
}
world:spawn_custom_boss_at_location(filename, location, options)
設定ファイルから EliteMobs のカスタムボスをスポーンさせます。
| パラメータ | 型 | 備考 |
|---|---|---|
filename | string | ボスの設定ファイル名(例:"my_boss.yml") |
location | locationテーブル | スポーンさせる位置 |
options | table(省略可) | スポーンオプション(下記参照) |
カスタムボスのスポーンオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
level | int | 生成するボスの設定レベル | レベルを上書きします。省略時は自身の設定と動的レベル規則に従い、呼び出し元ボスのレベルは継承しません。 |
silent | boolean | false | スポーンメッセージを抑制します |
velocity | vectorテーブル | nil | 初速度 |
add_as_reinforcement | boolean | false | 現在のボスの増援として登録します |
エンティティのラッパーテーブルを返します。ボスを生成できなかった場合は nil を返します。
例
return {
api_version = 1,
on_enter_combat = function(context)
local minion = context.world:spawn_custom_boss_at_location(
"skeleton_minion.yml",
context.boss:get_location(),
{ level = 10, add_as_reinforcement = true }
)
if minion ~= nil then
context.boss:send_message("&cMinions, arise!")
end
end
}
world:spawn_boss_at_location(filename, location, level)
簡易生成メソッドです。位置・レベルを省略すると呼び出し元ボスの値を使います。増援としては登録しません。既定のレベルを使うには第3引数を省略してください。明示的な nil は受け付けません。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
filename | string | ボスの設定ファイル名 | |
location | locationテーブル | ボスの位置 | スポーンさせる位置(省略可、既定ではボスの位置) |
level | int | ボスのレベル | スポーンレベルを上書きします(省略可) |
エンティティのラッパーテーブル、または nil を返します。
例
return {
api_version = 1,
on_enter_combat = function(context)
context.world:spawn_boss_at_location("zombie_guard.yml", context.boss:get_location(), 5)
context.boss:send_message("&cGuards, defend me!")
end
}
world:spawn_reinforcement_at_location(filename, location, duration, velocity)
増援システムを通してサイレント生成し、召喚元を記録します。召喚元のカスタムボスが正規化戦闘を使う場合はそれを継承します。増援自身の設定と動的レベル規則がレベルを決めます。duration は逃走タイマーであり、レベルではありません。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
filename | string | ボスの設定ファイル名 | |
location | locationテーブル | スポーンさせる位置 | |
duration | int | 0 | 逃走までのティック数。0 はタイマーを追加せず、増援レベルも上書きしません。 |
velocity | vectorテーブル | nil | 初速度(省略可) |
エンティティのラッパーテーブル、または nil を返します。
例
return {
api_version = 1,
on_enter_combat = function(context)
context.world:spawn_reinforcement_at_location(
"necro_skeleton.yml",
context.boss:get_location(),
0,
{ x = 0, y = 0.5, z = 0 }
)
context.boss:send_message("&5Rise, my servant!")
end
}
world:spawn_fireworks_at_location(location, spec)
実際の花火を生成し、ダメージは自動抑制しません。各効果に少なくとも1つの有効な色が必要です。色のない効果は作成時に失敗する場合があります。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | スポーンさせる位置 |
spec | table | 花火の仕様(下記参照) |
花火の仕様テーブル
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
power | int | 1 | 飛行力(高さ) |
velocity | vectorテーブル | nil | 初速度 |
shot_at_angle | boolean | true | 花火を角度をつけて打ち出すかどうか(velocity 設定時に使用) |
effects | テーブルのテーブル | nil | 花火エフェクト仕様の配列。省略した場合、トップレベルの仕様が単一のエフェクトとして扱われます。 |
花火エフェクトの仕様
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
type | string | "BALL_LARGE" | "BALL"、"BALL_LARGE"、"STAR"、"BURST"、"CREEPER" |
flicker | boolean | true | 明滅エフェクト |
trail | boolean | true | 軌跡エフェクト |
colors | table | 各効果で必須 | 色名または {red = 255, green = 0, blue = 0} テーブルの空でない配列 |
fade_colors | table | nil | フェード先のカラー名または {red, green, blue} テーブルの配列 |
カラー名: "WHITE", "SILVER", "GRAY", "BLACK", "RED", "MAROON", "YELLOW", "OLIVE", "LIME", "GREEN", "AQUA", "TEAL", "BLUE", "NAVY", "FUCHSIA", "PURPLE", "ORANGE"
非生体参照テーブルを返し、位置を解決できなければ nil です。:detonate() は爆発を要求します。型・色名は大文字小文字を区別せず、不明な型は BALL_LARGE、不明な色は白になります。RGB は 0..255 の範囲で指定してください。
例
return {
api_version = 1,
on_spawn = function(context)
local fw = context.world:spawn_fireworks_at_location(context.boss:get_location(), {
power = 0,
effects = {
{
type = "STAR",
flicker = true,
trail = true,
colors = { "RED", "ORANGE", { red = 255, green = 200, blue = 0 } },
fade_colors = { "YELLOW" },
},
},
})
if fw == nil then return end
-- Detonate on the next tick for a visual burst
context.scheduler:run_after(1, function()
fw:detonate()
end)
end
}
world:spawn_splash_potion_at_location(location, spec)
実際のスプラッシュポーションを生成します。不明な Bukkit 効果名は警告してスキップします。投げ手の設定やボスの直接効果メソッドのインスタンスフィルターは適用せず、通常のスプラッシュポーションの動作に従います。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | スポーンさせる位置 |
spec | table | ポーションの仕様(下記参照) |
スプラッシュポーションの仕様テーブル
| キー | 型 | 備考 |
|---|---|---|
velocity | vectorテーブル | 投げられるポーションの初速度 |
effects | テーブルのテーブル | ポーション効果仕様の配列 |
ポーション効果の仕様
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
type | string | 必須 | ポーション効果タイプ名(例:"SLOWNESS"、"POISON") |
duration | int | 0 | 持続時間(ティック) |
amplifier | int | 0 | 効果の強さ(0 = レベル I) |
overwrite | boolean | true | このポーションのメタデータ内の同型の先行効果を置換します。プレイヤーに既に付与された効果の規則ではありません。 |
エンティティ参照テーブル、または nil を返します。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("potion_throw", 200) then return end
local dir = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
dir = context.vectors.normalize_vector(dir)
context.world:spawn_splash_potion_at_location(context.boss:get_location(), {
velocity = { x = dir.x * 1.5, y = 0.5, z = dir.z * 1.5 },
effects = {
{ type = "SLOWNESS", duration = 100, amplifier = 1 },
{ type = "WEAKNESS", duration = 60, amplifier = 0 },
},
})
end
}
world:place_temporary_block_at_location(location, material, duration, requireAir)
管理対象のブロックを設置し、正の時間が経過すると以前のブロックデータを復元します。コンテナの中身は保存しません。元のブロックは、タイマー終了時、チャンクやワールドのアンロード時、またはプラグインの停止時に戻ります。ただし、そのブロックがまだ一時ブロックのままである場合に限るため、後からの編集が上書きされることはありません。まだ一時ブロックが置かれているブロックに再度設置すると、タイマーが再開され、最初に保存した元のブロックが維持されます。チェストや看板などのブロックエンティティを持つブロック、読み込まれていないチャンク、別の一時ブロック所有者が保持しているブロックはスキップされます。管理対象のブロックを壊しても何もドロップせず、復元されないまま管理が終了します。ブロック素材を使用してください。この上書き版は requireAir やスキップによる設置拒否を含め nil を返し、成功通知や領域保護の自動確認は行いません。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | 設置する位置 | |
material | string | マテリアル名 | |
duration | int | 0 | 復元までのティック数。0 以下では管理せずにブロックを恒久的に設置します。 |
requireAir | boolean | false | true の場合、そのブロックが現在空気のときにのみ設置します |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Create a temporary ice floor under the boss
local loc = context.boss:get_location()
for dx = -2, 2 do
for dz = -2, 2 do
context.world:place_temporary_block_at_location(
{ x = loc.x + dx, y = loc.y - 1, z = loc.z + dz, world = loc.world },
"PACKED_ICE",
100,
false
)
end
end
end
}
world:set_block_at_location(location, material, requireAir)
一時ブロック管理を通して、復元タイマーも管理もなしにブロックを恒久的に設置するため、変更はプラグインの停止後も残ります。そのブロックに現在時間制限付きの一時ブロックがある場合、その一時ブロックは管理対象から外れ、復元されません。別の一時ブロック所有者が保持しているブロックは変更されません。時間経過で元に戻すには place_temporary_block_at_location に正の時間を指定します。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | 設置する位置 | |
material | string | マテリアル名 | |
requireAir | boolean | false | true の場合、そのブロックが現在空気のときにのみ設置します |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Place fire at the boss's location
context.world:set_block_at_location(context.boss:get_location(), "FIRE", true)
end
}
world:get_block_type_at_location(location)
大文字の素材名を返し、位置を解決できなければ nil です。共有の座標照会と異なり、チャンクがロード済みか確認せず直接ブロックにアクセスします。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local block_type = context.world:get_block_type_at_location(context.boss:get_location())
if block_type == "WATER" then
context.boss:send_message("&bThe boss is empowered by water!")
context.boss:apply_potion_effect("SPEED", 200, 1)
end
end
}
world:get_highest_block_y_at_location(location)
Bukkit による指定 X/Z の最上位ブロック Y 座標を返し、位置を解決できなければ nil です。チャンクがロード済みか、テレポート先が安全かは確認しません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置(X と Z が使用されます) |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("skyport", 200) then return end
local loc = context.player:get_location()
local ground_y = context.world:get_highest_block_y_at_location(loc)
-- Teleport the player to the surface
context.player:teleport_to_location({
x = loc.x, y = ground_y + 1, z = loc.z, world = loc.world
})
context.player:send_message("&eYou are teleported to the surface!")
end
}
world:get_blast_resistance_at_location(location)
指定位置の素材の爆発耐性を返し、位置を解決できない場合は 0 です。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local resistance = context.world:get_blast_resistance_at_location(context.boss:get_location())
context.log:info("Blast resistance at boss: " .. resistance)
end
}
world:is_air_at_location(location)
指定位置のブロックが空気であれば true を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local loc = context.boss:get_location()
local above = { x = loc.x, y = loc.y + 2, z = loc.z, world = loc.world }
if context.world:is_air_at_location(above) then
-- There is space above the boss, launch upward
context.boss:set_velocity_vector({ x = 0, y = 1.5, z = 0 })
end
end
}
world:is_passable_at_location(location)
Bukkit の Block.isPassable() の結果を返し、位置を解決できなければ false です。単一ブロックの検査であり、エンティティ全体が収まるか、通行できるかは確認しません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
return {
api_version = 1,
on_enter_combat = function(context)
if context.world:is_passable_at_location(context.boss:get_location()) then
context.log:info("Boss is in a passable block")
end
end
}
world:is_passthrough_at_location(location)
指定位置のブロックが固体でなければ true を返します(passable に似ていますが、solid 判定に基づきます)。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local loc = context.boss:get_location()
local above = { x = loc.x, y = loc.y + 1, z = loc.z, world = loc.world }
if context.world:is_passthrough_at_location(above) then
context.log:info("Boss can move upward")
end
end
}
world:is_on_floor_at_location(location)
指定位置が非固体で、Y が1下のブロックが固体なら true を返します。エンティティの接地状態、当たり判定、頭上空間は検査しません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
例
return {
api_version = 1,
on_enter_combat = function(context)
if context.world:is_on_floor_at_location(context.boss:get_location()) then
context.boss:send_message("&aThe boss slams the ground!")
context.world:spawn_particle_at_location(context.boss:get_location(), {
particle = "CLOUD",
amount = 30,
})
end
end
}
world:is_standing_on_material(location, material)
指定位置の真下のブロックが指定したマテリアルと一致する場合に true を返します。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 照会する位置 |
material | string | 確認するマテリアル名 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if context.world:is_standing_on_material(context.player:get_location(), "SOUL_SAND") then
context.player:send_message("&8The soul sand saps your strength!")
context.player:apply_potion_effect("SLOWNESS", 60, 2)
end
end
}
world:set_world_time(time) / world:set_world_time(location, time)
ワールド全体の時刻を変更します。任意の位置でワールドを選べます。スクリプト終了時に元の時刻へ戻しません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル(省略可) | 対象とするワールド。既定ではボスのワールドです。 |
time | int | ワールド時間(ティック)(0 = 夜明け、6000 = 正午、13000 = 夜、18000 = 真夜中) |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Set to midnight when combat starts
context.world:set_world_time(18000)
context.boss:send_message("&8Darkness falls...")
end
}
world:set_world_weather(weather, duration) / world:set_world_weather(location, weather, duration)
ボス、または任意の位置のワールドの天候を変更します。名前は大文字小文字を区別せず、不明なら警告のみです。RAIN/CLEAR は天候タイマー、THUNDER は雷のタイマーを設定します。ワールド全体に作用し、スクリプト終了時に以前の状態へ戻しません。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル(省略可) | ボスのワールド | 対象とするワールド |
weather | string | "CLEAR"、"RAIN"(または "PRECIPITATION")、"THUNDER" | |
duration | int | 6000 | 天候の継続時間(ティック) |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Start a thunderstorm for 200 ticks
context.world:set_world_weather("THUNDER", 200)
context.boss:send_message("&eA storm gathers!")
end
}
world:generate_fake_explosion(blockLocations, sourceLocation)
EliteMobs の爆発再生システムで実際のブロックを除去し、落下する破片を生成します。破片はエンティティにダメージを与えられるため、無害な粒子演出ではありません。doExplosionRegen が必要で、発生源位置を渡すと WorldGuard の再生フラグを確認します。空気、火、液体、管理中の一時ブロックは除外され、依存する隣接ブロックが含まれる場合があります。1200 ティック後に復元を開始し、1ティックに1記録ブロックを処理します。全位置をボスと同じワールドにしてください。戻り値は nil で、スクリプトを閉じても取り消しません。
| パラメータ | 型 | 備考 |
|---|---|---|
blockLocations | locationテーブルのテーブル | 「爆発」させるブロック位置の配列 |
sourceLocation | locationテーブル(省略可) | 方向計算に使う爆発の発生源 |
例
return {
api_version = 1,
on_enter_combat = function(context)
local loc = context.boss:get_location()
local blocks = {}
for dx = -1, 1 do
for dz = -1, 1 do
table.insert(blocks, { x = loc.x + dx, y = loc.y, z = loc.z + dz, world = loc.world })
end
end
context.world:generate_fake_explosion(blocks, loc)
end
}
world:run_console_command(command)
サーバーとしてコンソールコマンドを即時実行し、成否を公開せず nil を返します。プレイヤーやボスのプレースホルダーを自動置換しません。
バニラのコマンドは実行結果を報告し、デフォルトの broadcast-console-to-ops=true では、サーバーがすべての結果をオンラインのオペレーター全員に表示します。data merge entity、kill、damage のように頻繁に実行されるコマンドは、オペレーターのチャットを埋め尽くします。代わりにネイティブのメソッドを使ってください。見た目には spawn_display_at_location、スタンドにはアーマースタンドのメソッド、スクリプトが生成したものの削除には entity:remove()、ボスからの正確なダメージには entity:deal_custom_damage(amount) を使います。
| パラメータ | 型 | 備考 |
|---|---|---|
command | string | 実行するコマンド(先頭の / は不要) |
例
return {
api_version = 1,
on_enter_combat = function(context)
context.world:run_console_command("say The boss has entered phase 2!")
end
}
world:run_empowered_lightning_task_at_location(location)
保持した位置で独立した Bukkit タスクを開始します。60回の SOUL_FIRE_FLAME 演出後、スポーンキャンセルを回避する実際の落雷と、爆発威力 5 の下向きの火球を生成します。火球には ender_dragon_empowered_lightning.yml の印が付きます。これはダメージを与える攻撃です。Lua の停止・一時停止でタスクは止まらず、警告エフェクト設定も確認しません。
| パラメータ | 型 | 備考 |
|---|---|---|
location | locationテーブル | 落雷させる位置 |
例
return {
api_version = 1,
on_enter_combat = function(context)
context.world:run_empowered_lightning_task_at_location(context.boss:get_location())
context.boss:send_message("&eFeel the power of the storm!")
end
}
world:spawn_fake_gold_nugget_at_location(location, velocity, hasGravity)
近くのプレイヤーにパケットで金塊の見た目を表示します。プレイヤーやホッパーは回収できません。生成だけでは移動もダメージ処理も始まりません。1つの集団として run_fake_gold_nugget_damage に1回渡すか、明示的に削除してください。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
location | locationテーブル | スポーン位置 | |
velocity | vectorテーブル | 初速度 | |
hasGravity | boolean | false | 投射物に重力を適用するかどうか |
get_location()、set_gravity(bool)、remove()、is_removed() を持つ偽投射物テーブルを返します。位置・ベクトルを解決できなければ nil です。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("nugget", 60) then return end
local dir = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
dir = context.vectors.normalize_vector(dir)
local nugget = context.world:spawn_fake_gold_nugget_at_location(
context.boss:get_location(),
{ x = dir.x, y = dir.y, z = dir.z }
)
if nugget ~= nil then
context.world:run_fake_gold_nugget_damage({ nugget })
end
end
}
world:run_fake_gold_nugget_damage(projectiles)
集団を毎ティック移動・検査する独立した Bukkit タスクを開始します。呼び出すたびにタスクが増えるため、1集団につき1回だけ呼んでください。移動先の各軸半幅 0.5 の箱で生体を照会し、元のボスと防御中のプレイヤーを除外して、ボスのダメージ規則を通じたカスタムダメージ 1 を要求します。ダメージが拒否されても衝突で弾が削除される場合があります。接地や100ティック経過でも削除します。移動経路全体のレイ判定ではなく位置ごとの検査です。Lua の停止・一時停止ではタスクを止めません。
| パラメータ | 型 | 備考 |
|---|---|---|
projectiles | table | spawn_fake_gold_nugget_at_location が返す偽投射物テーブルの配列 |
例
return {
api_version = 1,
on_enter_combat = function(context)
-- Keep this batch separate from later combat entries.
local projectiles = {}
local loc = context.boss:get_location()
for i = 1, 5 do
local angle = (i / 5) * math.pi * 2
local nugget = context.world:spawn_fake_gold_nugget_at_location(
loc,
{ x = math.cos(angle) * 0.5, y = 0.3, z = math.sin(angle) * 0.5 }
)
if nugget ~= nil then table.insert(projectiles, nugget) end
end
-- Start the batch once; the helper runs its own per-tick task.
context.world:run_fake_gold_nugget_damage(projectiles)
-- Remove any surviving projectiles after 3 seconds.
context.scheduler:run_after(60, function()
for _, projectile in ipairs(projectiles) do
projectile:remove()
end
end)
end
}
world:generate_player_loot(times)
通常の戦利品生成を times 回実行し、0 以下では何もしません。eliteLoot、不正利用対策が未発動であること、ロード済みプレイヤーデータ、最大体力の10%以上の記録ダメージが必要です。インスタンス報酬ロック中のプレイヤーは除外します。各回でコインを生成でき、ランダム戦利品が有効なら通常設定とパーティー規則に従ってランダム・特殊戦利品や巻物も生成できます。定義済みカスタムドロップ全体の再実行や1回1アイテムの保証ではありません。繰り返し呼ぶと報酬抽選が追加され、ボスごと1回という制限はありません。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
times | int | 1 | 戦利品の抽選回数 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
local pct = context.boss:get_health() / context.boss:get_maximum_health()
if pct < 0.5 and not context.boss:has_tag("bonus_loot") then
context.boss:add_tag("bonus_loot")
context.world:generate_player_loot(2)
context.boss:send_message("&6Bonus loot drops!")
end
end
}
world:drop_bonus_coins(multiplier)
最大体力の10%を超える記録ダメージを与えたプレイヤーに追加コインを落とします。NPC と EliteMobs データ未ロードのプレイヤーは除外します。金額は調整済み報酬レベルに multiplier を掛けた値です。
| パラメータ | 型 | デフォルト | 備考 |
|---|---|---|---|
multiplier | number | 2.0 | コイン量の倍率 |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
local pct = context.boss:get_health() / context.boss:get_maximum_health()
if pct < 0.25 and not context.boss:has_tag("bonus_coins") then
context.boss:add_tag("bonus_coins")
context.world:drop_bonus_coins(3.0)
context.boss:send_message("&6Gold spills everywhere!")
end
end
}
context.vectors
ベクトルヘルパーはドット・コロンの両構文に対応します。入力は x、y、z、数値添字 1..3、または入れ子の direction テーブルを受け付け、省略成分は 0 です。新しいテーブルを返し、入力は変更しません。
| メソッド | 戻り値 | 備考 |
|---|---|---|
vectors.get_vector_between_locations(loc1, loc2[, options]) | vectorテーブル | 変位 loc2 - loc1。既定では正規化しません。 |
vectors.normalize_vector(vec) | vectorテーブル | 非ゼロなら単位ベクトル。ゼロはゼロのままです。 |
vectors.rotate_vector(vec, pitch, yaw) | vectorテーブル | ワールド X 軸、次に Y 軸の順で度単位の回転を適用します。 |
すべての vector テーブルは x、y、z のフィールドを持ちます。
vectors.get_vector_between_locations(loc1, loc2, options)
| パラメータ | 型 | 備考 |
|---|---|---|
loc1 | locationテーブル | 始点 |
loc2 | locationテーブル | 終点 |
options | table(省略可) | 後処理オプション(下記参照) |
ベクトルのオプション
| キー | 型 | デフォルト | 備考 |
|---|---|---|---|
normalize | boolean | false | 結果のベクトルを正規化します |
multiplier | number | 1.0 | ベクトルをスケールします |
offset | vectorテーブル | nil | オフセットベクトルを加算します |
非ゼロ変位の正規化、乗算、ワールド軸のオフセット加算の順に適用します。位置を解決できない場合やワールドが異なる場合は、オプション適用前にゼロを返します。有効な同一位置ならオフセットを加算できます。
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("dash", 100) then return end
-- Compute a normalized direction from boss to player, scaled to speed 2
local dir = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location(),
{ normalize = true, multiplier = 2.0 }
)
-- Launch the boss toward the player
context.boss:set_velocity_vector(dir)
end
}
vectors.normalize_vector(vec)
| パラメータ | 型 | 備考 |
|---|---|---|
vec | vectorテーブル | 入力ベクトル |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
local raw = context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
local unit = context.vectors.normalize_vector(raw)
context.log:info("Direction: " .. unit.x .. ", " .. unit.y .. ", " .. unit.z)
end
}
vectors.rotate_vector(vec, pitch, yaw)
| パラメータ | 型 | 備考 |
|---|---|---|
vec | vectorテーブル | 入力ベクトル |
pitch | number | X 軸まわりの回転(度) |
yaw | number | Y 軸まわりの回転(度) |
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.player == nil then return end
if not context.cooldowns:check_local("spread_shot", 100) then return end
local forward = context.vectors.normalize_vector(
context.vectors.get_vector_between_locations(
context.boss:get_location(),
context.player:get_location()
)
)
-- Fire three fireballs in a spread pattern
for _, yaw_offset in ipairs({ -30, 0, 30 }) do
local dir = context.vectors.rotate_vector(forward, 0, yaw_offset)
context.boss:summon_projectile(
"FIREBALL",
context.boss:get_eye_location(),
{
x = context.boss:get_location().x + dir.x * 10,
y = context.boss:get_location().y + dir.y * 10,
z = context.boss:get_location().z + dir.z * 10,
world = context.boss:get_location().world
},
1.0
)
end
end
}
基準ベクトルをループで回転させることで、方向の扇状の広がりを作れます。
local base = context.vectors.normalize_vector(
context.vectors.get_vector_between_locations(boss_loc, target_loc)
)
for angle = 0, 330, 30 do
local dir = context.vectors.rotate_vector(base, 0, angle)
-- Use dir for spawning projectiles in a ring
end
context.settings
パワー設定の読み取り専用アクセスです。呼び出し時の最新設定を読み取りますが、粒子やエフェクトを自動抑制しません。結果を使って警告を表示するかをスクリプト側で決めます。
| メソッド | 戻り値 | 備考 |
|---|---|---|
settings:warning_visual_effects_enabled() | boolean | モブ戦闘設定で警告用の視覚エフェクトが有効かどうか |
例
return {
api_version = 1,
on_enter_combat = function(context)
if context.settings:warning_visual_effects_enabled() then
context.world:spawn_particle_at_location(context.boss:get_location(), {
particle = "DUST",
amount = 20,
red = 255, green = 0, blue = 0,
})
end
end
}
context.event
現在のフックのイベントデータです。基になるイベントによってフィールドが異なるため、省略可能なものは存在を確認してください。数値ダメージ変更はドット構文(event.set_damage_amount(value))が必要です。transfer_damage はドット・コロンの両方を受け付けます。このボス用テーブルには共有の cancel、uncancel、is_cancelled はありません。
| フィールドまたはメソッド | 利用できる場面 | 備考 |
|---|---|---|
event.damage_amount | ダメージ系フック | 遅延生成されるイベントテーブルの初回解決時点のダメージ |
event.get_damage_amount() | ダメージ系フック | 変更後の現在値を読み取ります |
event.damage_cause | ダメージ系フック | Bukkit の DamageCause enum 名(例:"ENTITY_ATTACK") |
event.cancel_event() | キャンセル可能なイベント | イベントをキャンセルします |
event.set_damage_amount(value) | EliteDamageEvent ベースのフック | ダメージを直接設定します |
event.multiply_damage_amount(multiplier) | EliteDamageEvent ベースのフック | 現在のダメージを乗算します |
event.damager | ダメージを与えたエンティティがいるダメージイベント | Bukkit の元の攻撃元。投射物命中なら発射者ではなく投射物そのものです。 |
event.projectile | ダメージを与えたのが投射物であるダメージイベント | 投射物のエンティティ参照ラッパー |
event.spawn_reason | on_spawn | スポーン理由の enum 名 |
event.entity | プレイヤーからボスへのダメージ、on_death、ゾーンイベント | 被害ボス、死亡個体、ゾーン通過個体。増援が被害を受けた場合はその増援です。 |
event.is_damage_transfer | 増援から転送されたものを含むプレイヤーからボスへのダメージ | 転送により作られた攻撃かどうか |
event:transfer_damage(target, amount) | 増援から転送されたものを含むプレイヤーからボスへのダメージ | 適格な別のエリートへ独立した攻撃を要求します。ダメージ転送の仕様を参照してください。 |
例: 受けるダメージを半減させる
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.event ~= nil then
local dmg = context.event.damage_amount
context.log:info("Boss took " .. dmg .. " damage, halving it")
context.event.multiply_damage_amount(0.5)
end
end
}
例: 投射物によるダメージをキャンセルする
例
return {
api_version = 1,
on_boss_damaged_by_player = function(context)
if context.event ~= nil and context.event.damage_cause == "PROJECTILE" then
context.event.cancel_event()
if context.player ~= nil then
context.player:send_message("&cThe boss deflects your projectile!")
end
end
end
}
例: ダメージ原因を読み取る
例
return {
api_version = 1,
on_player_damaged_by_boss = function(context)
if context.event ~= nil then
context.log:info("Damage cause: " .. (context.event.damage_cause or "unknown"))
end
end
}
damage_amountはスナップショットです。set_damage_amount()やmultiply_damage_amount()を呼び出した後も自動的には更新されません。- 予約コールバックに渡される新しいコンテキストの
eventはnilです。古いコンテキストを捕捉しても終了済みイベントを後から有効に変更できません。イベントのフック中に変更してください。 - setter は保留中のイベントを変更し、失われた体力を変更するものではありません。後続のリスナーが攻撃を変更・キャンセルできます。転送成功は追加攻撃の要求であり、元の攻撃を自動で減らしたりキャンセルしたりしません。
次のステップ
- はじめに | NPC スクリプト | フックとライフサイクル | ボスとエンティティ | ゾーンとターゲティング | サンプル | Enum | トラブルシューティング
- APIリファレンス | スクリプティングエンジン
