Parts
Use a part to attach behavior to a specific registry type rather than listen to every event of that kind. You attach parts once, at startup, in Hooks::register. For example, this BlockPart gives minecraft:stone a comparator output of 15:
From Sunrise's modding bookead8a1e
use mod_api::{
AnalogOutputEvent, BlockPart, HasAnalogOutputEvent, Hooks, LevelHost, Registrar,
RegistrationContext,
};
#[derive(Default)]
struct MyMod;
struct Gauge;
#[mod_api::sunrise_part]
impl BlockPart for Gauge {
fn has_analog_output(&self, _: &dyn LevelHost, event: &mut HasAnalogOutputEvent) {
event.output = true;
}
fn analog_output(&self, _: &dyn LevelHost, event: &mut AnalogOutputEvent) {
event.output = 15;
}
}
#[mod_api::sunrise_mod]
impl Hooks for MyMod {
fn register(&self, r: &mut dyn Registrar, _: &RegistrationContext) {
let stone = r.block_key("minecraft:stone");
r.block_part(stone, Gauge);
}
}Part types
| Trait | Target |
|---|---|
BlockPart | A block type, your own or vanilla's |
BlockEntityPart | A block entity type, with block behavior through BlockPart |
ItemPart | An item type, your own or vanilla's |
MenuPart | A mod menu type |
FluidPart | A mod world fluid type |
EntityPart | An entity type, your own or vanilla's; registered through Registrar::; on wasm only its general_ crosses |
- Annotate each part trait implementation with
#[mod_api::sunrise_part]. For scoped hooks, the attribute subscribes the part only to the methods you implement. BlockEntityPartextendsBlockPart: provide a separateBlockPartimplementation and annotate both implementations.- Parts implement
Send + Sync + 'static. - In
has_analog_output, answer from the block state alone. Inanalog_output, do not change the world. The game clamps the comparator signal to the range 0 to 15.
Campfire smoke sources
BlockPart::smoke_source answers whether its block makes a campfire above it a signal fire. Return Some(true) to enable signal smoke, Some(false) to refuse it, or None to keep vanilla's hay-bale check. It runs on the server and during client placement prediction. Its LevelSide supplies a read-only level on the asking side: answer from the supplied state and level, with no authoritative writes. Parts attached by tag use that side's tag view.
Chapters
Edit this page on GitHub · Spotted something wrong? Open an issue or ask on Discord.



