跳至主要內容

事件(Moment)

芒果凍布丁原創2025年3月29日大约 4 分鐘

1. 資料包登錄

範例
{
  "bar_render_type": {
    "type": "heaven_destiny_moment:default",
  },
  "area": {},
  "moment_data": {
    "effects": {
      "type": "single",
      "entries": [
        {
          "data": {
            "id": "minecraft:speed",
            "duration": 10,
            "neoforge:cures": [
              "milk",
              "protected_by_totem"
            ],
            "show_icon": true
          },
          "weight": 10
        },
        {
          "data": {
            "id": "minecraft:bad_omen",
            "duration": 10,
            "neoforge:cures": [
              "milk",
              "protected_by_totem"
            ],
            "show_icon": true
          },
          "weight": 40
        },
        {
          "data": {
            "id": "minecraft:glowing",
            "duration": 10,
            "neoforge:cures": [
              "milk",
              "protected_by_totem"
            ],
            "show_icon": true
          },
          "weight": 5
        }
      ]
    }
  },
  "tips": {
    "soundEvents": {
      "ready": "minecraft:item.goat_horn.sound.2"
    },
    "text": {
      "ready": {
        "color": "#FF0000",
        "translate": "moment.tooltip.text.ready.terra_moment.blood_moon"
      },
      "start": {
        "color": "#FF0000",
        "translate": "moment.tooltip.text.start.terra_moment.blood_moon"
      },
    }
  },
  "clientSettings": {
    "clientMoonSettings": {
      "moon_size": 25.0,
      "moon_texture": "terra_moment:textures/gui/blood_moon.png",
    },
    "environmentColor": 16711680
  }
}

2. KubeJS 登錄

StartupEvents.registry("heaven_destiny_moment:moment", (event) => {
  event.create("minecraft:night") // 創建一個 Moment
    // 設置 BossBar 顯示
    .barRenderType(new DefaultBarRenderType(BossBarOverlay.PROGRESS, BossBarColor.PURPLE))

    // 設置事件獎勵
    .momentData((data) => {
      data.addReward(
        new EffectReward.Builder()
          .addEffect(new EffectInstance(MobEffects.MOVEMENT_SPEED))
          .build(),
        new XpReward().add(10),
        new AttributeReward.Builder()
          .addAttribute(new AttributeElement(Attributes.ATTACK_DAMAGE, 1))
          .build(),
        new ItemReward.Builder()
          .add(new ItemStack(Items.DIAMOND))
          .build()
      )
    })

    // 設置提示設置
    .tipSettings((setting) => {
      setting
        .tooltip(MomentState.READY, TerraMoment.asDescriptionId("slime_rain"))
        .tooltip(MomentState.READY, SoundEvent.GOAT_HORN_SOUND_VARIANTS.get(2))
    })
    
    // 設置客戶端設置
    .clientSettings((setting) => {
      setting
        .environmentColor(16711680)
        .clientMoonSetting((moonSetting) => {
          moonSetting
            .moonColor(16711680)
            .moonSize(25)
            .moonTexture(TerraMoment.asResource("textures/gui/blood_moon.png"))
        })
    })
})

2.1. MomentBuilder

方法描述備註
barRenderType(type: BossBarRenderType)BossBar 顯示方式
area()事件所覆蓋的區域目前不推薦設置
momentData((data: MomentData) => {})事件資料
tipSettings((setting: TipSetting) => {})提示設置
clientSettings((setting: ClientSetting) => {})客戶端設置

類別參考

BossBarRenderType

BossBar 渲染類型

天命時刻內建一個渲染類型:DefaultBarRenderType,即為原版的 BossBar,可以使用原版進度條的樣式和顏色

通過以下方法建立:

new DefaultBarRenderType(overlay: BossBarOverlay, color: BossBarColor): MomentBuilder

附屬模組可以實現 IBarRenderType 介面達成自訂 BossBar,如:

CustomBarRenderTypeExample.png
CustomBarRenderTypeExample.png

BossBarOverlay

BossBar 的樣式

描述
BossBarOverlay.PROGRESS進度條
BossBarOverlay.NOTCHED_66格
BossBarOverlay.NOTCHED_1010格
BossBarOverlay.NOTCHED_1212格
BossBarOverlay.NOTCHED_2020格

BossBarColor

BossBar 的顏色

顏色
BossBarColor.PINK粉紅色
BossBarColor.BLUE藍色
BossBarColor.RED紅色
BossBarColor.GREEN綠色
BossBarColor.YELLOW黃色
BossBarColor.PURPLE紫色
BossBarColor.WHITE白色

MomentData

事件資料

方法描述
MomentData.addReward(...rewards: IReward[]): MomentData添加獎勵
MomentData.addConditionGroup((group: ConditionGroup) => {}): MomentData添加條件組
MomentData.addEntitySpawnSettings(settings: EntitySpawnSettings): MomentData添加實體生成設置

IReward

獲勝後的獎勵

天命時刻內建獎勵類型:

EffectReward

藥水效果獎勵

方法描述
EffectReward.Builder(): EffectRewardBuilder創建建構子

EffectRewardBuilder

藥水效果獎勵建構子

方法描述
EffectRewardBuilder.randomType(randomType: RandomType): EffectRewardBuilder設置隨機類型
EffectRewardBuilder.add(effectInstance: MobEffectInstance): EffectRewardBuilder添加藥水效果,權重預設為 1
EffectRewardBuilder.add(effectInstance: MobEffectInstance, weight: number): EffectRewardBuilder添加藥水效果
EffectRewardBuilder.build(): EffectReward建構藥水效果獎勵

XpReward

經驗獎勵

方法描述
XpReward.add(xp: number): XpReward添加經驗
XpReward.add(xp: number, weight: number): XpReward添加經驗

AttributeReward

屬性獎勵

方法描述
AttributeReward.Builder(): AttributeRewardBuilder創建建構子

AttributeRewardBuilder

屬性獎勵建構子

方法描述
AttributeRewardBuilder.randomType(randomType: RandomType): AttributeRewardBuilder設置隨機類型
AttributeRewardBuilder.add(attribute: AttributeElement): AttributeRewardBuilder添加屬性,權重預設為 1
AttributeRewardBuilder.add(attribute: AttributeElement, weight: number): AttributeRewardBuilder添加屬性
AttributeRewardBuilder.build(): AttributeReward建構屬性獎勵

ItemReward

物品獎勵

方法描述
ItemReward.Builder(): ItemRewardBuilder創建建構子

ItemRewardBuilder

物品獎勵建構子

方法描述
ItemRewardBuilder.randomType(randomType: RandomType): ItemRewardBuilder設置隨機類型
ItemRewardBuilder.add(item: ItemStack, weight: number): ItemRewardBuilder添加物品
ItemRewardBuilder.build(): ItemReward建構物品獎勵

ConditionGroup

獲勝條件

方法描述
ConditionGroup.Builder(): ConditionGroupBuilder創建建構子

ConditionGroupBuilder

獲勝條件建構子

方法描述
ConditionGroupBuilder.create(auto: boolean, ...conditions: ICondition[]): ConditionGroupBuilder創建條件組
ConditionGroupBuilder.victory(...conditions: ICondition[]): ConditionGroupBuilder創建獲勝條件組
ConditionGroupBuilder.lose(...conditions: ICondition[]): ConditionGroupBuilder創建失敗條件組
ConditionGroupBuilder.end(...conditions: ICondition[]): ConditionGroupBuilder創建結束條件組

ICondition

條件

天命時刻內建條件類型:

LevelCondition

維度條件

(WIP)

LocationCondition

位置條件

(WIP)

PlayerCondition

玩家條件

(WIP)

AutoProbabilityCondition

自動概率條件

(WIP)

WorldUniqueCondition

世界唯一條件,世界內僅存在一種類型的事件

(WIP)

DifficultyCondition

難度條件

(WIP)

TimeCondition

時間條件

(WIP)

EntitySpawnSettings

每輪實體的生成設置

(WIP)

Weighted

加權

使用以下方法建立:

new Weighted(type: RandomType, totalWeight: number, list: WeightEntry[]): Weighted

RandomType

隨機類型

描述
RandomType.SINGLE輸出 1 個物品
RandomType.SUBSET根據每個資料獨立判斷
RandomType.ALL(預設值)忽略全重並全部輸出

TipSetting

事件提示的設置

方法描述
TipSetting.tooltip(state: MomentState, tooltip: TextComponent): void設置提示文字
TipSetting.tooltip(state: MomentState, soundEvent: SoundEvent): void設置聲音事件

MomentState

事件狀態

描述
MomentState.READY準備
MomentState.START開始
MomentState.ONGOING進行中
MomentState.VICTORY獲勝
MomentState.LOSE失敗
MomentState.END結束

ClientSetting

客戶端設置

方法描述
ClientSetting.environmentColor(color: number)設置環境顏色
ClientSetting.clientMoonSetting((setting: ClientMoonSetting) => {})設置月亮設置

ClientMoonSetting

客戶端顯示的月亮設置

方法描述
ClientMoonSetting.moonColor(color: number)設置月亮顏色
ClientMoonSetting.moonSize(size: number)設置月亮大小
ClientMoonSetting.moonTexture(texture: ResourceLocation)設置月亮材質
上次編輯於: 2025/3/29 上午5:04:42
貢獻者: Mango