API
Sonidos y partículas
Sonidos y partículas propios viajan dentro del mod, como las texturas, y se usan por su id igual que los del juego. Se declaran como el resto del contenido.
Sonidos
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 }| Propiedad | Valores | Por defecto |
|---|---|---|
file |
ruta del archivo sin extensión: ruby/chime es sounds/ruby/chime.ogg del mod |
sounds/<id>.ogg |
files |
varias rutas; cada vez suena una al azar | — |
subtitle |
lo que aparece con los subtítulos activados | — |
volume |
0–1 | 1 |
pitch |
tono; 1 es el original | 1 |
Se reproduce como cualquier sonido del juego: player.play_sound("rubies:ruby_chime") para un jugador, world().play_sound(location, "rubies:ruby_chime") en un lugar. Los archivos son .ogg.
Partículas
particle "ruby_spark" { textures: ["ruby_spark_0", "ruby_spark_1"], motion: "sparkle" }| Propiedad | Valores | Por defecto |
|---|---|---|
textures |
imágenes de textures/particle/, sin extensión. Varias forman una animación, en ese orden |
textures/particle/<id>.png |
motion |
float_up: sube y se desvanece. flame: casi quieta, se encoge. sparkle: va a la deriva y titila. drift: flota en el sitio. |
float_up |
Se genera por su id: world().spawn_particle("rubies:ruby_spark", location, 30, 1.5, 0.02), con cantidad, dispersión y velocidad como las partículas del juego. Para enviar una partícula en una dirección dada, pasa una velocidad en su lugar: world().spawn_particle("minecraft:end_rod", location, vector(0, 0.1, 0)), en bloques por tick. Las partículas que se dibujan hacia un lugar, como minecraft:enchant, empiezan en location + velocity y vuelan hasta location.
Un uso real
En el mod de ejemplo, cuando una mena suelta un rubí extra suena el timbre y saltan chispas donde estaba el bloque:
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)
}
}En 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 }
}
}sound(id) { file(...); subtitle; volume; pitch } y particle(id) { texture(...); motion = ParticleMotion.SPARKLE } dentro del ContentBuilder. Reproducir y generar: player.playSound(id), world.playSound(at, id), world.spawnParticle(id, at, count, spread, speed) y world.spawnParticle(id, at, Vector(0.0, 0.1, 0.0)).
Archivos
| Mod | Dónde |
|---|---|
| CraftScript (carpeta) | mods/rubies/sounds/ruby/chime.ogg, mods/rubies/textures/particle/ruby_spark_0.png |
| Kotlin o Java | src/main/resources/assets/rubies/sounds/ruby/chime.ogg, …/assets/rubies/textures/particle/ruby_spark_0.png |