跳到主要内容

Lua API 参考

Lua 脚本 API 的完整方法参考。所有方法均通过 context.table:method() 语法调用。

Global 方法(标记为 GLOBAL)来自共享核心库 Magmacore。它们适用于 FreeMinecraftModels 脚本以及其他 MagmaCore ScriptInstance 消费者。EliteMobs Boss 能力复用同一个 Lua 沙箱,但暴露的是 Boss 专属的 context 表和方法名;EliteMobs NPC 脚本运行在同一个 MagmaCore 运行时上,会接收完整的共享上下文外加 NPC 专属的 context.npc 表。这些变体请参阅下方的 EliteMobs 章节以及 NPC 脚本

EliteMobs 方法(标记为 ELITEMOBS)专用于 EliteMobs Boss 能力脚本和 NPC 脚本。

FMM 方法(标记为 FMM)专用于 FreeMinecraftModels 的物品和道具脚本。

当方法需要 Bukkit 枚举(Sound、Particle、Material 等)时,请参阅 Spigot Javadocs 查询有效值。枚举名称以全大写字符串传入(例如 "DIAMOND_SWORD""ENTITY_ARROW_SHOOT")。


Entity Table GLOBAL

所有实体表通用的基础字段 —— 玩家、生物、道具,任何实体都包含这些字段。

Properties

FieldTypeDescription
uuidstring实体的 UUID
entity_typestring实体类型(小写)
is_validbool实体在世界中仍然存在
is_deadbool实体已死亡
is_playerbool是否为玩家
is_hostilebool是否为怪物(Monster)
is_passivebool是否为动物(Animal)
current_locationlocation实体位置(x、y、z、yaw、pitch、world)
worldstring世界名称

当安装了相关插件时,插件专属的增强器可能会添加额外的顶层字段。EliteMobs 和 FreeMinecraftModels 的字段请参阅下方的桥接(bridge)章节。

Methods

MethodArgsReturnsDescription
teleport(location)location tablenil传送实体
remove()nil将实体从世界中移除
set_silent(enabled)boolnil设置是否静音
set_invulnerable(enabled)boolnil设置是否无敌
set_gravity(enabled)boolnil设置是否受重力影响
set_glowing(enabled)boolnil设置是否发光

Bridge: entity.elite

当安装了 EliteMobs 时,由 EliteMobs 的实体增强器添加。该增强器会添加以下顶层标志:

FieldTypeDescription
is_elitebool是否为 EliteMobs 实体
is_custom_bossbool是否为 EliteMobs 自定义 Boss
is_significant_bossbool生命值倍率大于 1 的自定义 Boss(设计过的遭遇战)

仅在 is_elite 为 true 时,entity.elite 才会存在。

FieldTypeDescription
levelint精英怪物等级
namestring精英的显示名称
healthdouble当前生命值
max_healthdouble最大生命值
is_custom_bossbool是否为自定义 Boss(顶层也可用)
health_multiplierdouble配置文件定义的生命值倍率
damage_multiplierdouble配置文件定义的伤害倍率
remove()method移除该精英实体

Bridge: entity.model

当安装了 FMM 时,由 FreeMinecraftModels 的实体增强器添加。该增强器会添加以下顶层标志:

FieldTypeDescription
is_modeledbool拥有 FMM 模型
is_propbool是否为 FMM 道具

仅在 is_modeled 为 true 时,entity.model 才会存在。

FieldTypeDescription
model_idstring模型蓝图名称
is_dynamicbool是否为 FMM DynamicEntity(true)或静态道具(false)
play_animation(name, blend?, loop?)method播放动画。blend 默认为 false,loop 默认为 false
stop_animations()method停止所有动画
remove()method移除该模型化实体

Bridge: player permissions

当安装了 FMM 时,由 FreeMinecraftModels 的实体增强器添加。以下字段只会出现在玩家实体表上:

Field / MethodArgsReturnsDescription
has_permission(node)stringbool玩家是否拥有指定的权限节点
is_opbool玩家是否为服务器管理员(OP)

Living Entity Table GLOBAL

继承自 Entity Table。适用于所有生物实体(生物和玩家)。

Properties

FieldTypeDescription
healthdouble当前生命值
maximum_healthdouble最大生命值
namestring实体显示名称
is_alivebool实体未死亡

Methods

MethodArgsReturnsDescription
damage(amount)doublenil对实体造成伤害
push(x, y, z)double, double, doublenil添加速度向量
set_facing(x, y, z)double, double, doublenil设置朝向方向
add_potion_effect(type, duration, amplifier)string (PotionEffectType), int, intnil按名称施加药水效果
remove_potion_effect(type)string (PotionEffectType)nil按名称移除药水效果
get_scale()number当前实体缩放比例(在不支持 generic.scale 属性的服务器上默认为 1.0)
set_scale(value)doublenil通过 generic.scale 属性设置实体缩放比例(在 1.20.5 之前的服务器上为空操作)

context.player GLOBAL

玩家实体表。继承所有 EntityLiving Entity 字段。

Properties

FieldTypeDescription
game_modestringsurvival、creative、adventure、spectator

Methods

MethodArgsReturnsDescription
send_message(text)stringnil发送聊天消息。支持颜色代码
get_held_item()table or nil返回包含 type、amount、display_name 字段的表,或在手为空时返回 nil。type 为全大写的 Bukkit Material 名称
consume_held_item(amount?)int (default 1)nil减少手持物品堆叠数量
has_item(material, amount?)string (Material), int (default 1)bool检查背包中是否含有该材质
get_target_entity(range?)num (default 50)entity or nil通过射线检测获取玩家正在注视的实体
get_eye_location()location玩家眼部位置
get_look_direction()vector单位方向向量
send_block_change(x, y, z, material, ticks?)int, int, int, string (Material), int (optional)bool发送假方块。若指定 ticks,则在该时长后自动还原
reset_block(x, y, z)int, int, intbool将假方块还原为真实方块
sleep(x, y, z)num, num, numnil在指定位置播放床上睡眠动画
wake_up()nil从睡眠中唤醒
show_boss_bar(text, color?, progress, ticks?)string, string (BarColor, default WHITE), num, int (optional)nil显示 Boss 血条。在 ticks 后自动隐藏。支持颜色代码
hide_boss_bar()nil移除 Boss 血条
show_action_bar(text, ticks?)string, int (optional)nil显示动作栏。当 ticks 大于 0 时会重复显示。支持颜色代码
show_title(title, subtitle?, fadeIn, stay, fadeOut)string, string (default empty), int, int, intnil显示标题界面。支持颜色代码

context.world GLOBAL

面向 FreeMinecraftModels 脚本以及其他 Magmacore 支持的 ScriptInstance 运行时的世界操作。EliteMobs Boss 能力从这同一个基础表出发,并叠加下方列出的 EliteMobs context.world 新增项和重写项。

context.world 方法有两种可互换的形式:坐标式(x, y, z)和位置表式(*_at_location 变体)。两种形式在通用接口上都可用,而 EliteMobs Boss 能力在保留共享基础方法的同时,额外添加了 Boss 专属的位置表助手。

Properties

FieldTypeDescription
namestring世界名称

Methods

MethodArgsReturnsDescription
get_block_at(x, y, z)int, int, intstringMaterial 名称(小写)。若区块未加载则返回 "air"
set_block_at(x, y, z, material)int, int, int, string (Material)bool若材质有效则排队放置方块;未加载的区块会被跳过
get_highest_block_y(x, z)int, intint最高非空气方块的 Y 坐标
spawn_particle(particle, x, y, z, count?, dx?, dy?, dz?, speed?)string (Particle), num, num, num, int?=1, num?=0, num?=0, num?=0, num?=0nil生成粒子效果
play_sound(sound, x, y, z, volume?, pitch?)string (Sound), num, num, num, float?=1, float?=1nil播放声音
strike_lightning(x, y, z)num, num, numnil召唤闪电
get_time()int世界时间(以 tick 为单位)
set_time(ticks)longnil设置世界时间
get_nearby_entities(x, y, z, radius)num, num, num, numtable实体表数组
get_nearby_players(x, y, z, radius)num, num, num, numtable玩家实体表数组
spawn_entity(type, x, y, z)string (EntityType), num, num, numentity or nil生成原版实体;若实体类型无效则返回 nil
raycast(fx, fy, fz, dx, dy, dz, max?)num, num, num, num, num, num, num?=50table返回包含 hit_entity、hit_location、hit_block 字段的表
place_temporary_block(x, y, z, material, ticks?, require_air?)int, int, int, string (Material), int?=0, bool?=falsebool排队放置在 ticks 后自动还原的方块。若材质无效或区块未加载则返回 false
drop_item(x, y, z, material, amount?)num, num, num, string (Material), int?=1entity or nil在该位置自然地掉落物品实体;若材质无效则返回 nil
spawn_firework(x, y, z, colors, type?, power?)num, num, num, table, string (FireworkEffect.Type)?=BALL, int?=1nil生成烟花
strike_lightning_at_location(loc)locationnil召唤闪电
play_sound_at_location(loc, sound, volume?, pitch?)location, string (Sound), float?=1, float?=1nil播放声音
spawn_particle_at_location(loc, particle, count?, dx?, dy?, dz?, speed?)location, string (Particle), int?=1, num?=0, num?=0, num?=0, num?=0nil生成粒子效果
get_block_at_location(loc)locationstringMaterial 名称(小写)。若区块未加载则返回 "air"
set_block_at_location(loc, material)location, string (Material)bool若材质有效则排队放置方块;未加载的区块会被跳过
place_temporary_block_at_location(loc, material, ticks?, require_air?)location, string (Material), int?=0, bool?=falsebool排队放置在 ticks 后自动还原的方块。若材质无效或区块未加载则返回 false
get_highest_block_y_at_location(loc)locationint or nil最高非空气方块的 Y 坐标

em helpers GLOBAL

在所有 MagmaCore Lua 运行时中通过 em 表暴露的全局助手构造器。

Constructors

MethodArgsReturnsDescription
em.create_location(x, y, z, world?, yaw?, pitch?)num, num, num, string?, num?, num?location位置表,包含 xyz,可选的 worldyawpitch,以及一个原地修改的 add(dx, dy, dz) 方法
em.create_vector(x, y, z)num, num, numvector包含 xyz 的向量表

Zone Builders

区域构造器返回纯粹的区域定义表。球体、穹顶、圆柱体和长方体包含 :set_center(location)。锥体和射线区域包含 :set_origin(location):set_destination(location)

MethodArgsReturnsDescription
em.zone.create_sphere_zone(radius)numzone{ kind = "sphere", radius = ... }
em.zone.create_dome_zone(radius)numzone{ kind = "dome", radius = ... }
em.zone.create_cylinder_zone(radius, height)num, numzone{ kind = "cylinder", radius = ..., height = ... }
em.zone.create_cuboid_zone(x, y, z)num, num, numzone长方体的半边长
em.zone.create_cone_zone(length, radius)num, numzone带起点/终点设置器的锥体定义
em.zone.create_static_ray_zone(length, thickness)num, numzone静态射线定义
em.zone.create_rotating_ray_zone(length, point_radius, animation_duration)num, num, numzone旋转射线定义
em.zone.create_translating_ray_zone(length, point_radius, animation_duration)num, num, numzone平移射线定义

em.location GLOBAL

挂载在全局 em 表上的位置查询助手。底层由 Magmacore 的 LocationQueryRegistryLocationOwnership 服务支持,该服务汇集来自已注册提供方(EliteMobs 地下城/世界包区域、WorldGuard、GriefPrevention 等)的结果。所有函数都接受位置表({x, y, z, world}),在位置无效时返回安全的默认值。

MethodArgsReturnsDescription
em.location.is_in_dungeon(loc)locationbool该位置是否位于任意已注册地下城区域内
em.location.is_protected(loc)locationbool是否有任何提供方将该位置标记为受保护(WorldGuard、GriefPrevention、EM 区域等)
em.location.owned_by(loc, namespace)location, stringbool该位置是否归指定命名空间所有(例如 "EliteMobs"
em.location.owners(loc)locationtable声明拥有该位置的命名空间字符串数组
em.location.kinds_at(loc)locationtable该位置的类型标签数组(例如 "elitemobs""world_package""open_world_dungeon"、地下城规模分类)
em.location.has_kind(loc, kind)location, stringbool该位置是否带有指定的类型标签

context.boss ELITEMOBS

EliteMobs Lua 能力脚本中的 Boss 实体表。继承所有 EliteMobs Living Entity 方法。属性通过专用 getter 刷新。

Properties

FieldTypeDescription
namestringBoss 显示名称
uuidstring精英实体 UUID
healthdouble当前生命值(快照)
maximum_healthdouble最大生命值(快照)
current_locationlocationBoss 位置(快照)
levelintBoss 等级
damager_countint对该 Boss 造成过伤害的玩家数量
is_in_combatboolBoss 处于战斗中
existsboolBoss 实体存在

Methods

MethodArgsReturnsDescription
is_alive()boolBoss 实体是否存活(实时检查)
get_health()double当前生命值(实时)
get_maximum_health()double最大生命值(实时)
get_location()location当前位置(实时)
restore_health(amount)doublenil为 Boss 治疗
despawn()nil移除 Boss 实体
get_damager_count()int实时的造伤者数量
add_tag(tag, ticks?)string, int?=0nil添加标签,若指定 ticks 则到时自动移除
remove_tag(tag)stringnil移除标签
has_tag(tag)stringbool检查标签
reset_custom_name()nil将名称重置为配置文件默认值
play_sound_at_self(sound, volume?, pitch?)string(Minecraft 声音键,例如 "entity.wither.spawn"), float?=1, float?=1nil在 Boss 位置播放声音
play_sound_at_entity(sound, volume?, pitch?)string(Minecraft 声音键,例如 "entity.wither.spawn"), float?=1, float?=1nil在 Boss 位置播放声音(别名)
spawn_particle_at_self(particle, count?)string (Particle) or table, int?=1nil在 Boss 位置生成粒子
play_model_animation(name)stringnil播放 FMM 模型动画(需要 FMM 模型)
has_mount()-bool该 Boss 是否正骑乘一个坐骑实体
get_mount()-entity or nil当前坐骑实体的引用,带有 is_mount = true 标记
set_mount(entity)entity tablebool让 Boss 骑乘指定的实体
clear_mount()-bool让 Boss 离开其当前载具
dismount()-boolclear_mount() 的别名
navigate_to_location(location, speed?, force?, timeout?)location, double?=1, bool?=false, int?=0nil寻路前往该位置
send_message(text, range?)string, double?=20nil向附近玩家发送消息。支持颜色代码
get_nearby_players(range)doubletable范围内的玩家表数组
get_target_player()player or nil当前生物目标,如果是玩家的话
get_nearby_players_in_zone(zone)zone tabletable区域形状内的玩家
get_ender_dragon_phase()string or nilEnderDragon.Phase 名称
set_ender_dragon_phase(phase)string (EnderDragon.Phase)nil设置末影龙阶段
summon_reinforcement(file, zone?, level?)string, zone or nil, int?=0entity or nil召唤增援 Boss
summon_projectile(type, origin, dest, speed?, options?)string (EntityType), location, location, double?=1, tableentity or nil生成可跟踪的弹射物;若类型或位置无效则返回 nil

summon_projectile options

OptionTypeDefaultDescription
custom_damagenumber覆盖弹射物伤害
detonation_powerstring爆炸威力等级
yieldnumber火球当量
incendiarybooltrue火球点燃
gravitybool启用重力
glowingboolfalse设置发光
invulnerableboolfalse设置无敌
persistentbooltrue设置为持久化
durationint0在 ticks 后自动移除
effectstring生成时播放的 EntityEffect
spawn_at_originboolfalse在原点生成,而不是从 Boss 处发射
direction_onlyboolfalse仅设置方向而不设置速度(火球用)
trackbooltrue注册为精英弹射物
on_landfunction弹射物落地时的回调:function(location, entity)
max_ticksint6000强制触发落地回调前的最大 tick 数

Zone/Particle Methods

MethodArgsReturnsDescription
spawn_particles_in_zone(zone, particle, ...)zone, particle spec, coverage?=1.0nil用粒子填充区域
spawn_particles_in_zone_border(zone, particle, ...)zone, particle spec, coverage?=1.0nil用粒子勾勒区域轮廓
get_particles_from_self_toward_zone(zone, particle, speed?)zone, string, double?=0.1table从 Boss 指向区域的定向粒子
get_particles_toward_self(zone, particle, speed?)zone, string, double?=0.1table从区域指向 Boss 的定向粒子
spawn_particles_with_vector(particles)tablenil生成定向粒子数组

Special Power Support

MethodArgsReturnsDescription
start_tracking_fireball_system(speed?)double?=0.5nil启动跟踪火球 AI
handle_spirit_walk_damage(cause)string (DamageCause)nil根据伤害原因处理灵魂行走伤害
shield_wall_is_active()bool盾墙是否激活
initialize_shield_wall(charges?)int?=1nil激活盾墙
shield_wall_absorb_damage(player, damage)entity table, doublebool尝试吸收伤害
deactivate_shield_wall()nil关闭盾墙
start_zombie_necronomicon(target, file)entity table, stringnil对目标启动死灵之书

context.npc ELITEMOBS NPC

EliteMobs NPC Lua 脚本中的 NPC 表。NPC 脚本位于 plugins/EliteMobs/npc_scripts/,并通过 NPC 配置的 scripts: 列表挂接。NPC 脚本与其他所有接口运行在同一个 MagmaCore 运行时上,会接收完整的共享上下文 —— context.worldcontext.zonescontext.schedulercontext.cooldownscontext.logcontext.eventcontext.playercontext.state —— 外加此处记录的 NPC 专属 context.npc 表。

Properties

FieldTypeDescription
namestringNPC 显示名称
filenamestringNPC 配置文件名
uuidstring运行时 NPC 的 UUID
activation_radiusdouble配置的激活半径
current_locationlocationNPC 实体存在时的快照位置
entity_typestringNPC 实体存在时的 Bukkit 实体类型

Methods

MethodArgsReturnsDescription
is_valid()-boolNPC 背后的实体是否仍然有效
get_location()-location当前 NPC 位置,或生成位置作为后备
get_eye_location()-location当前眼部位置,或生成位置作为后备
get_activation_radius()-double当前配置的激活半径
get_nearby_players(radius)doubletableNPC 附近的玩家表
face_direction_or_location(target)vector or locationnil朝向某方向或望向某位置
say_greeting(player?)player、UUID、name 或 nilnil发送配置的问候语。在可用时默认发给触发的玩家
say_dialog(player?)player、UUID、name 或 nilnil发送配置的对话。在可用时默认发给触发的玩家
say_farewell(player?)player、UUID、name 或 nilnil发送配置的告别文本。在可用时默认发给触发的玩家
play_model_animation(name)stringnil若可用则播放自定义模型动画;否则为安全的空操作

NPC 专属的钩子包括 on_spawnon_removeon_game_tickon_npc_interacton_npc_proximity_enteron_npc_proximity_leave。完整的工作流和冷却细节请参阅 EliteMobs NPC 脚本


EliteMobs Living Entity Table ELITEMOBS

在 EliteMobs 能力脚本内创建的实体表(来自 context.boss、事件数据、区域回调和世界查询)使用扩展过的生物实体表,其方法在全局 Living Entity 之外还包含额外内容。context.boss 继承所有这些方法。

Properties

FieldTypeDescription
namestring实体显示名称
uuidstring实体 UUID
entity_typestring实体类型名称
is_playerbool是否为玩家
is_monsterbool是否为怪物(Monster)
is_elitebool是否为 EliteMobs 实体
is_validbool实体仍然存在
is_mountbool当此实体表代表一个 Boss 坐骑时为 true
healthdouble当前生命值(快照)
maximum_healthdouble最大生命值(快照)
current_locationlocation实体位置(快照)
game_modestring游戏模式(EliteMobs 中为大写:SURVIVAL、CREATIVE、ADVENTURE、SPECTATOR)

Methods

MethodArgsReturnsDescription
is_alive()bool实体是否存活(实时检查)
is_ai_enabled()boolAI 是否启用
is_frozen()boolBoss 是否被冻结(仅 CustomBossEntity)
is_on_ground()bool实体是否在地面上
is_healing()bool精英是否正在恢复
get_location()location当前位置(实时)
get_eye_location()location眼部位置(实时)
get_height()double实体高度
get_health()double当前生命值(实时)
get_maximum_health()double最大生命值(实时)
get_velocity()vector当前速度向量
deal_damage(amount)doublenil造成普通伤害
deal_custom_damage(amount)doublenil以该能力所属 Boss 的身份造成自定义攻击伤害
deal_damage_from_boss(amount)doublenil造成归属于该能力 Boss 实体的伤害
restore_health(amount)doublenil治疗实体(若为精英则使用 EliteMobs 的治疗机制)
play_sound_at_entity(sound, volume?, pitch?)string(Minecraft 声音键,例如 "entity.ender_dragon.growl"), float?=1, float?=1nil在实体位置播放声音
play_sound_at_self(sound, volume?, pitch?)string(Minecraft 声音键,例如 "entity.ender_dragon.growl"), float?=1, float?=1nil在实体位置播放声音(别名)
spawn_particle_at_self(particle, count?)string (Particle) or table, int?=1nil在实体位置生成粒子
spawn_particles_at_location(loc, particle, count?)location, particle spec, int?=1nil在指定位置生成粒子
teleport_to_location(location)locationnil传送实体
set_velocity_vector(vector)vectornil设置速度
set_gravity(enabled)boolnil设置是否受重力影响
apply_push_vector(vector, additive?, delay?)vector, bool?=false, int?=1nil延迟后施加速度。additive 表示叠加到现有速度上
push_relative_to(location, force?, extraX?, extraY?, extraZ?)location, double?=1, double?=0, double?=0, double?=0nil将实体从指定位置推开
set_custom_name(name)stringnil设置自定义显示名称。支持颜色代码
reset_custom_name()nil将名称重置为 EliteMobs 默认值
set_custom_name_visible(visible)boolnil切换名称是否可见
set_ai_enabled(enabled, duration?)bool, int?=0nil设置 AI 状态。在 duration ticks 后自动恢复
set_awareness_enabled(enabled, duration?)bool, int?=0nil设置生物的感知。在 duration ticks 后自动恢复
face_direction_or_location(target)vector or locationnil朝向某方向或望向某位置
play_model_animation(name)stringnil播放 FMM 模型动画(需要 FMM 模型)
is_inside_vehicle()-bool实体是否正骑乘另一个实体
has_vehicle()-bool实体是否拥有载具
get_vehicle()-entity or nil当前载具实体的引用
set_vehicle(entity)entity tablebool让此实体骑乘指定载具
leave_vehicle()-bool让此实体离开其当前载具
has_passengers()-bool此实体是否有乘客
get_passenger_count()-int乘客数量
get_passengers()-table乘客实体引用数组
add_passenger(entity)entity tablebool为此实体添加一名乘客
remove_passenger(entity)entity tablebool从此实体移除一名乘客
eject_passengers()-bool弹出所有乘客
set_scale(scale, duration?)double, int?=0nil设置实体缩放比例。在 duration ticks 后自动恢复为 1.0
set_invulnerable(enabled, duration?)bool, int?=0nil设置无敌。在 duration ticks 后自动恢复
set_healing(enabled)boolnil设置精英的治疗状态
navigate_to_location(location, speed?, force?, timeout?)location, double?=1, bool?=false, int?=0nil寻路前往该位置(仅 CustomBossEntity)
add_tag(tag, ticks?)string, int?=0nil添加标签,到时自动移除
remove_tag(tag)stringnil移除标签
has_tag(tag)stringbool检查标签
overlaps_box_at_location(center, halfX?, halfY?, halfZ?)location, double?=0.5, double?=halfX, double?=halfXbool实体的包围盒是否与某位置上的盒子重叠
remove_elite()nil通过 EliteMobs 的清理流程移除
apply_potion_effect(type, duration, amplifier?)string (PotionEffectType), int, int?=0nil施加药水效果
set_equipment(slot, material, options?)string (EquipmentSlot), string (Material), tablenil设置装备槽中的物品
set_fire_ticks(ticks)intnil设置着火 ticks
add_visual_freeze_ticks(ticks?)int?=1nil增加冻结视觉 ticks
place_temporary_block(material, ticks?, requireAir?)string (Material), int?=0, bool?=falsenil在实体位置放置临时方块

set_equipment options

OptionTypeDefaultDescription
unbreakableboolfalse设置物品为不可破坏
enchantmentstable{type = "ENCHANT_NAME", level = 1} 数组

EliteMobs Player Methods

EliteMobs 脚本中的玩家拥有所有 EliteMobs 生物实体方法,外加:

MethodArgsReturnsDescription
send_message(text)stringnil发送聊天消息。支持颜色代码
show_action_bar(text)stringnil显示动作栏文字。支持颜色代码
show_title(title, subtitle?, fadeIn?, stay?, fadeOut?)string, string?="", int?=10, int?=40, int?=10nil显示标题界面。支持颜色代码
show_boss_bar(title, color?, style?, duration?)string, string (BarColor)?=WHITE, string (BarStyle)?=SOLID, int?=40nil显示 Boss 血条。在 duration ticks 后自动隐藏。支持颜色代码
run_command(command)stringnil以玩家身份执行命令

EliteMobs Entity Reference Table

由 EliteMobs 生成方法返回的非生物实体(弹射物、坠落方块、烟花)会获得一个轻量级的引用表:

Field / MethodArgsReturnsDescription
namestring实体名称
uuidstring实体 UUID
entity_typestring实体类型名称
is_playerbool始终为 false
is_elitebool始终为 false
is_valid()bool实体是否仍然有效(实时检查)
current_locationlocation位置(快照)
get_location()location当前位置(实时)
get_velocity()vector当前速度向量
is_on_ground()bool实体是否在地面上
teleport_to_location(location)locationnil传送实体
set_velocity_vector(vector)vectornil设置速度
set_direction_vector(vector)vectornil设置方向(仅火球)
set_yield(amount)doublenil设置火球当量
set_gravity(enabled)boolnil设置是否受重力影响
detonate()nil引爆烟花
remove()nil移除实体
unregister(reason?)string?=OTHERnil从 EliteMobs 实体跟踪器中注销

context.players ELITEMOBS

EliteMobs 能力脚本中可用的玩家查询表。提供相对于 Boss 查找玩家的辅助方法。

MethodArgsReturnsDescription
current_target()player or nil若事件的当事者是玩家则返回该玩家,否则返回 Boss 当前的生物目标(若为玩家)
nearby_players(radius)doubletableBoss 周围 radius 范围内的玩家表数组
all_players_in_world()tableBoss 所在世界中所有玩家的表数组

context.entities ELITEMOBS

EliteMobs 能力脚本中可用的实体查询表。提供相对于 Boss 查找实体的辅助方法。所有查询都排除 Boss 自身。

MethodArgsReturnsDescription
get_nearby_entities(radius, filter?)double, string?="living"tableradius 范围内的实体。"all"/"entities" 返回所有实体(包括非生物);其他任意值则返回按类别过滤的生物实体:"player(s)""elite(s)""mob(s)",默认 = 所有生物实体
get_entities_in_box(center, halfX, halfY, halfZ, filter?)location, double, double, double, string?="living"table轴对齐盒子内的生物实体(过滤值同上;仅支持非 all 模式)
get_all_entities(filter?)string?="living"tableBoss 所在世界中的所有生物实体(过滤值同上)
get_direct_target_entity()entity or nil触发事件中的直接目标实体
get_boss_spawn_location()locationBoss 的原始生成位置

context.vectors ELITEMOBS

EliteMobs 能力脚本中可用的向量数学工具。

MethodArgsReturnsDescription
get_vector_between_locations(from, to, options?)location, location, tablevector从源指向目标的向量。Options 可修改结果
rotate_vector(vector, pitch?, yaw?)vector, double?=0, double?=0vector按 pitch 和 yaw(角度)旋转向量
normalize_vector(vector)vectorvector归一化为单位长度

context.state GLOBAL

一个在脚本实例的整个生命周期内持续存在的普通 Lua 表。用它来存储标志、计数器、任务 ID、开关状态以及任何你需要在钩子之间共享的数据。context.state 是脚本自有的持久化表;大多数其他 context 表会按需重建或惰性重新创建。FMM 出于性能考虑会按道具缓存 context.prop,但其 current_location 等实时字段在读取时仍会刷新。

context.state.counter = (context.state.counter or 0) + 1

context.cooldowns GLOBAL

冷却管理。本地冷却作用于单个脚本实例;全局冷却在同一实体/所有者上的所有脚本之间共享。如果未提供 key,则默认使用脚本文件名。

MethodArgsReturnsDescription
local_ready(key?)string (optional)bool本地冷却是否已经结束
local_remaining(key?)string (optional)int本地冷却剩余的 ticks(就绪时为 0)
check_local(key?, duration)string (optional), intbool若就绪,则开始冷却并返回 true;否则返回 false
set_local(duration, key?)long, string (optional)nil设置本地冷却,时长为 duration ticks
global_ready()bool全局冷却是否已经结束
set_global(duration)longnil设置全局冷却,时长为 duration ticks

在 EliteMobs 能力脚本中,本地冷却在同一 Boss 实体上的所有能力之间共享,而全局冷却使用 Boss 内置的能力冷却系统。

EliteMobs NPC 脚本使用共享的冷却参数顺序 check_local(key?, duration);参阅 NPC 脚本


context.scheduler GLOBAL

任务调度。所有任务在脚本关闭时会自动取消。

Global (Magmacore) variant

FreeMinecraftModels 脚本和 EliteMobs NPC 脚本使用此共享变体。下方 EliteMobs 风格的名称是同一调度器上的别名,因此在通用接口上两种命名风格都有效。

MethodArgsReturnsDescription
run_later(ticks, callback)int, functionintticks 后运行回调。返回任务 ID
run_repeating(delay, interval, callback)int, int, functionint在初始延迟后每 interval ticks 运行一次回调。返回任务 ID
cancel(taskId)intnil取消已调度的任务

EliteMobs variant

MethodArgsReturnsDescription
run_after(ticks, callback)int, functionintticks 后运行回调。返回任务 ID
run_every(ticks, callback)int, functionint每 N ticks 运行一次回调。返回任务 ID
cancel_task(taskId)intnil取消已调度的任务

context.log GLOBAL

用于脚本调试的日志工具。

Global (Magmacore / FMM) variant

MethodArgsReturnsDescription
info(message)stringnil记录 info 级消息
warn(message)stringnil记录 warning 级消息
error(message)stringnil记录 error/warning 级消息

EliteMobs variant

MethodArgsReturnsDescription
info(message)stringnil记录 info 级消息
warn(message)stringnil记录 warning 级消息
debug(message)stringnil记录 debug 级消息(以 debug 前缀作为 info 显示)

context.zones GLOBAL

面向 FreeMinecraftModels 脚本以及其他 Magmacore 支持的 ScriptInstance 运行时的区域创建与监控。EliteMobs Boss 能力使用下方的 EliteMobs context.zones 变体。

Global (Magmacore) variant

MethodArgsReturnsDescription
create_sphere(x, y, z, radius)num, num, num, numint创建球形区域,返回句柄
create_cylinder(x, y, z, radius, height)num, num, num, num, numint创建圆柱形区域,返回句柄
create_cuboid(x, y, z, xSize, ySize, zSize)num, num, num, num, num, numint创建长方体区域,返回句柄
watch(handle, on_enter?, on_leave?)int, function?, function?bool启用区域跟踪。传入函数参数会启用 on_zone_enter / on_zone_leave;函数体不会被直接调用。区域钩子会接收跨越边界的玩家对应的 context.player / context.event.player
unwatch(handle)intnil停止跟踪区域

EliteMobs variant

MethodArgsReturnsDescription
get_entities_in_zone(zone, options?)zone table, tabletable获取区域内的实体。Options:filter、mode
get_locations_in_zone(zone, options?)zone table, tabletable获取区域内的位置。Options:coverage、mode
zone_contains(zone, location, mode?)zone table, location, string?="full"bool位置是否位于区域内("full""border"
watch_zone(zone, callbacks, options?)zone table, table, table?nil监视区域的进入/离开。回调:{on_enter = fn, on_leave = fn}。Options 支持 filtermode

context.event GLOBAL

触发当前脚本执行的钩子对应的事件数据表。在事件驱动的钩子以及提供了玩家当事者的通用 MagmaCore 区域进入/离开钩子中存在;在 on_game_tick、调度回调或没有玩家的生命周期钩子中不存在。

Global (Magmacore) variant

Field / MethodTypeDescription
is_cancelledbool构建上下文时的取消状态;在 cancel() / uncancel() 之后不会刷新
cancel()method当底层 Bukkit 事件可取消时,取消该事件
uncancel()method当底层 Bukkit 事件可取消时,撤销取消
playerentity table参与事件的玩家(如有)

通用区域钩子会填充 player,但其背后并非可取消的 Bukkit 事件,因此那里不存在 cancel()uncancel()

关于 EliteMobs 的事件表(提供伤害值、伤害类型等),请参阅 EliteMobs Event Table


context.script ELITEMOBS

通往 EliteMobs Elite Script 系统的桥梁。让 Lua 能力可以通过与 Elite Script YAML 配置同名的 Lua 表使用基于 YAML 的目标、区域和相对向量系统。

Methods

MethodArgsReturnsDescription
target(spec)tabletarget handle从 Elite Script 目标规范表创建目标句柄
zone(spec)tablezone handle从 Elite Script 区域规范表创建区域句柄
relative_vector(spec, location?, zone?)table, location, zone handlevector handle从 Elite Script 向量规范创建相对向量
damage(target, amount?, multiplier?)target handle, double?=0, double?=1nil对目标中的所有实体造成伤害
push(target, vector, additive?)target handle, vector or vector handle, bool?=falsenil以速度推动目标实体
set_facing(target, vector)target handle, vector or vector handlenil设置目标实体的朝向
spawn_particles(target, particles)target handle, table or stringnil在目标位置生成粒子

Target Handle

context.script:target(spec) 返回。spec 表使用与 Elite Script YAML 目标配置相同的键名(例如 {targetType = "NEARBY_PLAYERS", range = 20})。

MethodArgsReturnsDescription
entities()table目标处的实体表数组
locations()table目标处的位置表数组
first_entity()entity or nil目标处的第一个实体
first_location()location or nil目标处的第一个位置

Zone Handle

context.script:zone(spec) 返回。spec 表使用与 Elite Script YAML 区域配置相同的键名(例如 {shape = "SPHERE", radius = 5, target = {targetType = "SELF"}})。

MethodArgsReturnsDescription
full_target(coverage?)numbertarget handle区域内部位置的目标句柄
border_target(coverage?)numbertarget handle区域边界位置的目标句柄
full_locations(coverage?)numbertable内部位置数组
border_locations(coverage?)numbertable边界位置数组
full_entities()table区域内部的实体
border_entities()table区域边界上的实体
contains(location, mode?)location, string?="full"bool位置是否位于区域内
watch(callbacks, mode?)table, string?="full"int监视进入/离开。返回任务 ID

Vector Handle

context.script:relative_vector(spec) 返回。spec 表使用与 Elite Script YAML 相对向量配置相同的键名。

MethodArgsReturnsDescription
resolve()vector为当前上下文计算向量

context.world (EliteMobs) ELITEMOBS

EliteMobs 能力脚本的 Boss 专属世界表。Boss 能力从通用的 MagmaCore world 表起步,因此 get_block_at(...)set_block_at(...)spawn_particle(...) 等坐标助手仍然可用。下方的方法是 EliteMobs 的新增项或 Boss 专属的重写项,主要是位置表形式和 Boss 助手。

Block Queries

MethodArgsReturnsDescription
get_block_type_at_location(loc)locationstring or nilMaterial 名称
get_highest_block_y_at_location(loc)locationint or nil最高方块的 Y 坐标
get_blast_resistance_at_location(loc)locationdouble爆炸抗性值
is_air_at_location(loc)locationbool方块是否为空气
is_passable_at_location(loc)locationbool方块是否可通过
is_passthrough_at_location(loc)locationbool方块是否非实心
is_on_floor_at_location(loc)locationbool该处为空气且下方为实心方块
is_standing_on_material(loc, material)location, string (Material)bool下方方块是否匹配指定材质

Block Manipulation

MethodArgsReturnsDescription
set_block_at_location(loc, material, requireAir?)location, string (Material), bool?=falsenil放置方块。若 requireAir 为 true,则只替换空气
place_temporary_block_at_location(loc, material, ticks?, requireAir?)location, string, int?=0, bool?=falsenil放置方块,在 ticks 后自动移除。若 requireAir 为 true,则只替换空气

Spawning

MethodArgsReturnsDescription
spawn_boss_at_location(file, loc?, level?)string, location?=boss loc, int?=boss levelentity or nil生成自定义 Boss
spawn_custom_boss_at_location(file, loc, options?)string, location, tableentity or nil带选项生成 Boss(level、silent、add_as_reinforcement、velocity)
spawn_entity_at_location(type, loc, options?)string (EntityType), location, tableentity or nil带选项生成原版实体(velocity、duration、effect、on_land、max_ticks)
spawn_falling_block_at_location(loc, material, options?)location, string (Material), tableentity or nil生成坠落方块(drop_item、hurt_entities、velocity、on_land)
spawn_reinforcement_at_location(file, loc, level?, velocity?)string, location, int?=0, vectorentity or nil生成绑定到 Boss 的增援
spawn_fireworks_at_location(loc, config)location, tableentity or nil生成烟花
spawn_splash_potion_at_location(loc, config)location, tableentity or nil生成喷溅药水

Effects and Utility

MethodArgsReturnsDescription
play_sound_at_location(loc, sound, volume?, pitch?)location, string(Minecraft 声音键,例如 "entity.blaze.shoot"), float?=1, float?=1nil播放声音
spawn_particle_at_location(loc, particle, count?)location, string (Particle) or table, int?=1nil生成粒子
strike_lightning_at_location(loc)locationnil召唤闪电(绕过 EM 保护)
run_empowered_lightning_task_at_location(loc)locationnil强化闪电特效
generate_fake_explosion(locations, center?)table of locations, locationnil无伤害的视觉爆炸
spawn_fake_gold_nugget_at_location(loc, velocity, gravity?)location, vector, bool?=falsefake projectile or nil生成视觉用的金粒弹射物
run_fake_gold_nugget_damage(projectiles)tablenil对假弹射物进行伤害检测
set_world_time(time) or (loc, time)long, or location + longnil设置世界时间
set_world_weather(weather, duration?) or (loc, weather, duration?)string (CLEAR, RAIN, PRECIPITATION, THUNDER), int?=6000nil设置天气
run_console_command(command)stringnil执行控制台命令
generate_player_loot(times?)int?=1nil为造伤玩家进行这么多次玩家战利品掷骰
drop_bonus_coins(multiplier?)double?=2nil在 Boss 处掉落额外金币

context.settings (EliteMobs)

MethodArgsReturnsDescription
warning_visual_effects_enabled()bool配置中是否启用了警告视觉特效

EliteMobs Event Table

context.event 表会传递给伤害和生成钩子。字段因事件类型而异。

Field / MethodTypePresent WhenDescription
damage_amountdouble伤害事件原始伤害值
damage_causestring伤害事件DamageCause 名称
damagerentity table实体造伤事件造成伤害的实体
projectileentity table弹射物伤害事件造成伤害的弹射物
spawn_reasonstring生成事件生成原因名称
entityentity table死亡/区域事件相关实体
cancel_event()method大多数事件取消事件
set_damage_amount(amount)method (double)伤害事件覆盖伤害值
multiply_damage_amount(multiplier)method (double)伤害事件乘上当前伤害

context.item FMM

在 FMM 物品脚本中访问。通过 PDC 标签从玩家装备槽中解析出对应的脚本物品。

读取方法在调用时检查当前装备的匹配物品。写入方法会将其变更排队到 Bukkit 主线程上并返回 nil

Properties

FieldTypeDescription
idstring物品的脚本标识符

Methods

MethodArgsReturnsDescription
material()stringMaterial 名称
get_amount()int堆叠数量
set_amount(n)intnil排队设置堆叠数量
consume(n?)int?=1nil排队减少 n 个数量,归零时移除
get_uses()intPDC 存储的使用计数器
set_uses(n)intnil排队设置 PDC 使用计数器
get_durability()table or nil返回包含 currentmax 字段的表,无耐久条时返回 nil
get_durability_percentage()number or nil0.0--1.0 的剩余比例,否则为 nil
use_durability(amount, can_break?)int, bool?=falsenil排队按固定值减少耐久。当为 false 时,会将耐久钳制在剩余 1
use_durability_percentage(fraction, can_break?)number, bool?=falsenil排队按最大耐久的比例减少(0.0--1.0)
get_name()string or nil显示名称
set_name(s)stringnil排队设置显示名称。支持颜色代码
get_lore()tablelore 字符串数组
set_lore(table)tablenil排队从字符串数组设置 lore

context.prop FMM

在 FMM 道具脚本中访问。继承自承载用盔甲架的所有 Entity 字段。

Properties

FieldTypeDescription
model_idstring蓝图模型名称
current_locationlocation道具当前位置

Methods

MethodArgsReturnsDescription
play_animation(name, blend?, loop?)string, bool?=true, bool?=truebool播放指定动画
stop_animation()nil停止当前所有动画
hurt_visual()nil红色受伤闪烁,无实际伤害
pickup()nil排队移除道具并掉落对应放置物品
has_mount_points()bool道具是否拥有挂载点骨骼
mount(player)entity tablebool排队挂载检查;返回 true 表示基本引用有效
dismount(player)entity tablebool排队卸载检查;返回 true 表示基本引用有效
get_passengers()table已挂载玩家的实体表数组
spawn_elitemobs_boss(file, x, y, z)string, num, num, numentity or nil生成 EliteMobs Boss(需要 EliteMobs)
open_inventory(player, title, rows?)entity table, string, int?=3bool排队打开持久化箱子界面(rows 钳制在 1--6)。标题支持颜色代码
place_book(player)entity tablebool排队将玩家手中的成书/可写书存储到道具上
read_book(player)entity tablebool排队打开已存储的书以供阅读
take_book(player)entity tablebool排队将存储的书归还给玩家
has_book()bool是否存有一本书
drop_inventory()bool排队掉落所有已存储物品并清空存储
drop_book()bool排队掉落已存储的书并清空存储
is_viewing_inventory(player)entity tablebool玩家是否正打开此道具的界面
set_persistent_data(key, value)string, stringbool在道具的 PDC 中存储字符串
get_persistent_data(key)stringstring or nil从道具的 PDC 中获取字符串

Color Codes

所有标注支持颜色代码的方法都使用 Magmacore 的 ChatColorConverter。这些格式可以在任何字符串中自由混用:

Legacy codes

使用 & 加颜色/格式字符:

CodeColorCodeFormat
&0黑色&l粗体
&1深蓝色&m删除线
&2深绿色&n下划线
&3深青色&o斜体
&4深红色&r重置
&5深紫色
&6金色
&7灰色
&8深灰色
&9蓝色
&a绿色
&b青色
&c红色
&d浅紫色
&e黄色
&f白色

Hex colors

使用 6 位十六进制指定精确的 RGB 颜色:

&#FF5500          -- ampersand prefix
<#FF5500> -- tag syntax

Gradients

在文本范围内于两种或多种颜色之间平滑插值:

<gradient:#FF0000:#0000FF>This text fades red to blue</gradient>
<g:#FF0000:#00FF00:#0000FF>Three-color gradient</g>

简写 ggradient 完全等价。你可以串联任意数量的颜色节点。

Rainbow

以全饱和度循环遍历完整的色相光谱。可选的数字参数会偏移起始色相(相位偏移):

<rainbow>Full rainbow text</rainbow>
<r:0.5>Rainbow with a shifted starting hue</r>

Common Types

location

{ x = number, y = number, z = number, yaw = number, pitch = number, world = string }

vector

{ x = number, y = number, z = number }

entity table

任何带有 uuid 字段的表。来自 context 的玩家与实体表可以直接使用:

context.player                              -- valid entity table
context.world:get_nearby_entities(x,y,z,r) -- returns array of entity tables

Next Steps