API

Mga tunog at partikulo

Kasama sa loob ng mod ang sariling mga tunog at particle, gaya ng mga texture, at ginagamit mo ang mga ito ayon sa id gaya ng sa mismong laro. Idinedeklara mo ang mga ito gaya ng iba pang content.

Mga tunog

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 }
Katangian Mga value Default na halaga
file path ng file na walang extension: ang ruby/chime ay ang sounds/ruby/chime.ogg ng mod sounds/<id>.ogg
files ilang path; isa ang random na tumutunog bawat beses —
subtitle ang lumalabas kapag naka-on ang subtitle —
volume 0–1 1
pitch pitch; 1 ang orihinal 1

Tumutunog ito gaya ng anumang tunog ng laro: player.play_sound("rubies:ruby_chime") para sa isang player, world().play_sound(location, "rubies:ruby_chime") sa isang lokasyon. .ogg ang mga file.

Mga particle

content/particles.craftCraftScript
particle "ruby_spark" { textures: ["ruby_spark_0", "ruby_spark_1"], motion: "sparkle" }
Katangian Mga value Default na halaga
textures mga larawan mula sa textures/particle/, walang extension. Bumubuo ng animation ang ilan, ayon sa pagkakasunod na iyon textures/particle/<id>.png
motion float_up: umaangat at kumukupas. flame: halos hindi gumagalaw, lumiliit. sparkle: lumulutang-lutang at kumikislap. drift: lumulutang sa puwesto. float_up

Ini-spawn mo ito ayon sa id: world().spawn_particle("rubies:ruby_spark", location, 30, 1.5, 0.02), may count, spread at speed gaya ng mga particle ng laro. Para magpadala ng isang particle sa isang direksyon, magpasa ng velocity sa halip: world().spawn_particle("minecraft:end_rod", location, vector(0, 0.1, 0)), sa mga block bawat tick. Ang mga particle na hinihila patungo sa isang lugar, gaya ng minecraft:enchant, ay nagsisimula sa location + velocity at lumilipad papunta sa location.

Totoong gamit

Sa halimbawang mod, kapag nag-drop ng dagdag na ruby ang isang ore, tumutunog ang chime at lumilipad ang mga kislap kung saan naroon ang block:

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)
    }
}

Sa 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 } at particle(id) { texture(...); motion = ParticleMotion.SPARKLE } sa loob ng ContentBuilder. Para magpatunog at mag-spawn: player.playSound(id), world.playSound(at, id), world.spawnParticle(id, at, count, spread, speed) at world.spawnParticle(id, at, Vector(0.0, 0.1, 0.0)).

Mga file

Mod Saan
CraftScript (folder) 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