跳至主要內容

Lua 腳本:列舉與值

webapp_banner.jpg

本頁連結到 EliteMobs Lua 方法使用的每個列舉類型的 Spigot Javadocs。在 Lua 程式碼中使用精確的列舉常數名稱(如 "FLAME""ZOMBIE""STONE")作為字串。

  • 拼寫必須與列舉常數名稱完全匹配
  • 大小寫通常在內部標準化,但為了安全起見請匹配 Javadoc 的拼寫
  • 無效值的處理方式取決於具體方法:有些會記錄警告,有些會傳回 nil 或不執行任何操作,具有輸入驗證的 API 則可能引發 Lua 錯誤

Enum Reference

EnumUsed forJavadoc
BarColorBoss bar colorBarColor
BarStyleBoss bar styleBarStyle
EntityEffectEntity visual effectsEntityEffect
EntityTypeEntity spawningEntityType
FireworkEffect.TypeFirework shapeFireworkEffect.Type
MaterialBlocks and itemsMaterial
ParticleParticle effectsParticle — 舊名稱轉換另見有效粒子清單
PotionEffectTypePotion effectsPotionEffectType
Sound音效播放Sound
Sounds accept two formats

每個 Lua 音效輔助方法(boss:play_sound_at_selfentity:play_sound_at_entityworld:play_sound_at_location)都會分兩步解析該字串:先嘗試 Spigot Sound 列舉名稱(會轉成大寫,所以 "entity_blaze_shoot" 可用),若失敗則把該字串視為具命名空間的音效鍵(會轉成小寫,所以 "entity.blaze.shoot" 與你自己資源包的鍵 "mypack:boss.roar" 都可用)。

這代表你不必再挑選格式 —— 但兩種形式的拼字錯誤都會被靜默忽略,因為後備路徑無法分辨錯誤的列舉名稱與一個單純尚未安裝的自訂資源包音效。

Non-Spigot Values

Zone shapes

Used by native zone definitions (kind field) and script utility zone specs (shape field).

Native (kind)Script Utility (shape)
sphereSPHERE
domeDOME
cylinderCYLINDER
cuboidCUBOID
coneCONE
static_raySTATIC_RAY
rotating_rayROTATING_RAY
translating_rayTRANSLATING_RAY

Entity filters

Used by context.zones and context.entities query options. 不區分大小寫,且每個都有複數別名。

FilterMatches
player / playersPlayers only
elite / elitesElite mobs only
mob / mobsNon-player living entities(包含精英)
livingAll living entities,包含玩家(預設)
all / entities所有實體,包含非生物實體。context.entities:get_nearby_entities 會辨識

非上述字串的任何值都會退回為 living 的行為而不會報錯,因此像 "playr" 這樣的拼字錯誤會靜默地傳回所有生物實體。

context.script:zone({...}) 使用的是另一組大寫的篩選條件(PLAYERELITELIVING),因為它執行的是 EliteScript 引擎。

Weather values

Used by context.world:set_weather(weather).

ValueEffect
CLEARClear skies
RAINRain
THUNDERThunderstorm

Target types

Used by context.script:target() specs.

ValueResolves to
SELFThe boss entity
SELF_SPAWNThe boss's spawn location
DIRECT_TARGETThe entity involved in the current event
NEARBY_PLAYERSPlayers within range of the boss
NEARBY_MOBSNon-player mobs within range
NEARBY_ELITESElite mobs within range
ALL_PLAYERSAll online players
WORLD_PLAYERSAll players in the boss's world
ZONE_FULLEntities/locations inside a zone volume
ZONE_BORDEREntities/locations on a zone border
LOCATIONA specific location from the spec's location field
LOCATIONSSeveral specific locations from the spec's locations list
LANDING_LOCATIONWhere a falling block or summoned entity landed
ACTION_TARGETInherits the targets of the surrounding EliteScript action
INHERIT_SCRIPT_TARGETInherits the target of the calling EliteScript
INHERIT_SCRIPT_ZONE_FULLInside the calling EliteScript's zone
INHERIT_SCRIPT_ZONE_BORDEROn the border of the calling EliteScript's zone

最後四項只有在有外圍 EliteScript 可供繼承時才會解析,因此從 Lua 使用它們實際意義不大。完整語意請參閱 EliteScript 目標 —— context.script 使用的正是那套實作。


後續步驟