API

Suoni e particelle

Suoni e particelle personalizzati sono inclusi nella mod, come le texture, e li usi tramite id proprio come quelli del gioco. Li dichiari come il resto dei contenuti.

Suoni

content/sounds.craftCraftScript
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 }
Proprietà Valori Predefinito
file percorso del file senza estensione: ruby/chime è il file sounds/ruby/chime.ogg della mod sounds/<id>.ogg
files più percorsi; ogni volta ne viene riprodotto uno a caso —
subtitle ciò che compare quando i sottotitoli sono attivi —
volume 0–1 1
pitch tonalità; 1 è l’originale 1

Si riproduce come qualsiasi suono del gioco: player.play_sound("rubies:ruby_chime") per un giocatore, world().play_sound(location, "rubies:ruby_chime") in una posizione. I file sono .ogg.

Particelle

content/particles.craftCraftScript
particle "ruby_spark" { textures: ["ruby_spark_0", "ruby_spark_1"], motion: "sparkle" }
Proprietà Valori Predefinito
textures immagini da textures/particle/, senza estensione. Più immagini formano un’animazione, in quell’ordine textures/particle/<id>.png
motion float_up: sale e svanisce. flame: quasi ferma, si rimpicciolisce. sparkle: fluttua e scintilla. drift: galleggia sul posto. float_up

La generi tramite id: world().spawn_particle("rubies:ruby_spark", location, 30, 1.5, 0.02), con quantità, dispersione e velocità come per le particelle del gioco. Per mandare una particella in una certa direzione, passa invece una velocità: world().spawn_particle("minecraft:end_rod", location, vector(0, 0.1, 0)), in blocchi per tick. Le particelle che vengono attirate verso un punto, come minecraft:enchant, partono da location + velocity e volano fino a location.

Un uso reale

Nella mod di esempio, quando un minerale rilascia un rubino in più, suona il rintocco e le scintille volano dove c’era il blocco:

events/mining.craftCraftScript
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)
    }
}

In Kotlin

content/Sounds.ktKotlin
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 }
    }
}
content/Particles.ktKotlin
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 } e particle(id) { texture(...); motion = ParticleMotion.SPARKLE } dentro il ContentBuilder. Per riprodurre e generare: player.playSound(id), world.playSound(at, id), world.spawnParticle(id, at, count, spread, speed) e world.spawnParticle(id, at, Vector(0.0, 0.1, 0.0)).

File

Mod Dove
CraftScript (cartella) 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