API
소리와 입자
사용자 정의 소리와 입자는 텍스처처럼 모드 안에 담기며, 게임 자체의 것처럼 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은 모드의 sounds/ruby/chime.ogg |
sounds/<id>.ogg |
files |
여러 경로. 매번 그중 하나가 무작위로 재생됩니다 | — |
subtitle |
자막이 켜져 있을 때 표시되는 내용 | — |
volume |
0–1 | 1 |
pitch |
음높이. 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). 게임의 입자처럼 개수, 퍼짐, 속도를 지정합니다. 입자 하나를 정해진 방향으로 보내려면 대신 속도를 넘기세요: world().spawn_particle("minecraft:end_rod", location, vector(0, 0.1, 0)), 단위는 틱당 블록 수입니다. minecraft:enchant처럼 어떤 장소로 빨려 들어가며 그려지는 입자는 location + velocity에서 시작해 location으로 날아갑니다.
실제 사용 예
예제 모드에서는 광석이 루비를 하나 더 떨어뜨리면, 블록이 있던 자리에서 차임 소리가 나고 불꽃이 튑니다.
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)).
파일
| 모드 | 위치 |
|---|---|
| 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 |