API
サウンドとパーティクル
カスタムサウンドとパーティクルはテクスチャと同じく Mod の中に入れて配布し、ゲーム本体のものと同じように id で使います。宣言の仕方は他のコンテンツと同じです。
サウンド
sound "ruby_chime" { file: "ruby/chime", subtitle: "A ruby chimes", pitch: 1.2 }
sound "ruby_crumble" { files: ["ruby/crumble_1", "ruby/crumble_2"], subtitle: "Ruby ore crumbles", volume: 0.8 }| プロパティ | 値 | デフォルト |
|---|---|---|
file |
拡張子なしのファイルパス:ruby/chime は Mod の sounds/ruby/chime.ogg |
sounds/<id>.ogg |
files |
複数のパス。毎回ランダムに 1 つが再生されます | — |
subtitle |
字幕がオンのときに表示されるもの | — |
volume |
0–1 | 1 |
pitch |
ピッチ。1 が元の高さ | 1 |
ゲームのサウンドと同じように再生します。1 人のプレイヤーには player.play_sound("rubies:ruby_chime")、ある場所では world().play_sound(location, "rubies:ruby_chime")。ファイルは .ogg です。
パーティクル
particle "ruby_spark" { textures: ["ruby_spark_0", "ruby_spark_1"], motion: "sparkle" }| プロパティ | 値 | デフォルト |
|---|---|---|
textures |
textures/particle/ の画像、拡張子なし。複数指定すると、その順でアニメーションになります |
textures/particle/<id>.png |
motion |
float_up:上昇して消える。flame:ほぼ静止して縮む。sparkle:漂ってきらめく。drift:その場で浮かぶ。 |
float_up |
id で出現させます:world().spawn_particle("rubies:ruby_spark", location, 30, 1.5, 0.02)。数、広がり、速さはゲームのパーティクルと同じです。パーティクル 1 つを決まった方向に飛ばすには、代わりに速度を渡します:world().spawn_particle("minecraft:end_rod", location, vector(0, 0.1, 0))。単位は 1 ティックあたりのブロック数です。minecraft:enchant のように、ある場所へ引き寄せられて描かれるパーティクルは、location + velocity から始まり、location へ飛んでいきます。
実際の使用例
サンプルの Mod では、鉱石が追加のルビーをドロップすると、チャイムが鳴り、ブロックがあった場所に火花が飛びます。
import { give_rubies } from "/lib/rewards"
import { SETTINGS } from "/settings"
on break(e) {
let p = e.player
if p == null { return }
if e.block.type == "minecraft:diamond_ore" and chance(SETTINGS["bonus_chance"]) {
give_rubies(p, 1)
p.play_sound("rubies:ruby_chime")
p.world.spawn_particle("rubies:ruby_spark", e.block.location, 12, 0.4, 0.02)
}
}Kotlin では
package com.example.rubies.content
object Sounds {
const val CHIME = "rubies:ruby_chime"
fun register(content: ContentBuilder) {
content.sound("ruby_chime") { file("ruby/chime"); subtitle = "A ruby chimes"; pitch = 1.2f }
content.sound("ruby_crumble") { file("ruby/crumble_1"); file("ruby/crumble_2"); subtitle = "Ruby ore crumbles"; volume = 0.8f }
}
}package com.example.rubies.content
object Particles {
const val SPARK = "rubies:ruby_spark"
fun register(content: ContentBuilder) {
content.particle("ruby_spark") { texture("ruby_spark_0"); texture("ruby_spark_1"); motion = ParticleMotion.SPARKLE }
}
}ContentBuilder の中で sound(id) { file(...); subtitle; volume; pitch } と particle(id) { texture(...); motion = ParticleMotion.SPARKLE }。再生と出現には player.playSound(id)、world.playSound(at, id)、world.spawnParticle(id, at, count, spread, speed)、world.spawnParticle(id, at, Vector(0.0, 0.1, 0.0)) を使います。
ファイル
| Mod | 場所 |
|---|---|
| CraftScript(フォルダー) | mods/rubies/sounds/ruby/chime.ogg、mods/rubies/textures/particle/ruby_spark_0.png |
| Kotlin または Java | src/main/resources/assets/rubies/sounds/ruby/chime.ogg、…/assets/rubies/textures/particle/ruby_spark_0.png |