pub struct Registry { /* private fields */ }Implementations§
Source§impl Registry
impl Registry
Sourcepub fn on<E: Event + 'static, R: IntoFlow + 'static>(
&mut self,
handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static,
)
pub fn on<E: Event + 'static, R: IntoFlow + 'static>( &mut self, handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static, )
Runs handler on every E, before the game does it (if E can be
stopped — Flow::Cancel / false stops it) and after.
Sourcepub fn on_key<E: Event + 'static, R: IntoFlow + 'static>(
&mut self,
key: &str,
handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static,
)
pub fn on_key<E: Event + 'static, R: IntoFlow + 'static>( &mut self, key: &str, handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static, )
Registry::on for a keyed event’s key only (E::KEY): the ticks
of one entity type, the presses of one key binding.
Sourcepub fn before<E: Event + 'static, R: IntoFlow + 'static>(
&mut self,
handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static,
)
pub fn before<E: Event + 'static, R: IntoFlow + 'static>( &mut self, handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static, )
Runs handler before the game does E — it can cancel it. Nothing
for an event that can’t be stopped.
Sourcepub fn before_key<E: Event + 'static, R: IntoFlow + 'static>(
&mut self,
key: &str,
handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static,
)
pub fn before_key<E: Event + 'static, R: IntoFlow + 'static>( &mut self, key: &str, handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static, )
Registry::before for a keyed event’s key only.
Source§impl Registry
impl Registry
Sourcepub fn provide_mirror_of<M: Mirror>(
&mut self,
write: impl Fn(&mut MirrorWriter<'_, M>) + Send + Sync + 'static,
) -> bool
pub fn provide_mirror_of<M: Mirror>( &mut self, write: impl Fn(&mut MirrorWriter<'_, M>) + Send + Sync + 'static, ) -> bool
Provides mirror M: write fills what’s due each time it is.
Source§impl Registry
impl Registry
Sourcepub fn provide_mirror(
&mut self,
spec: &MirrorSpec,
write: impl Fn(&mut Writer) + Send + Sync + 'static,
) -> bool
pub fn provide_mirror( &mut self, spec: &MirrorSpec, write: impl Fn(&mut Writer) + Send + Sync + 'static, ) -> bool
Provides mirror spec: write fills what’s due each time it is.
Source§impl Registry
impl Registry
Sourcepub unsafe fn from_raw(api: *const YogApi) -> Self
pub unsafe fn from_raw(api: *const YogApi) -> Self
Build from the pointer passed by the runtime. Only called by export_mod!.
§Safety
api must point to the runtime’s YogApi table, valid for the rest of
the process.
pub fn on_command<F>(&mut self, name: impl AsRef<str>, handler: F)
Sourcepub fn on_typed_command<F>(
&mut self,
name: impl AsRef<str>,
schema: impl AsRef<str>,
handler: F,
)
pub fn on_typed_command<F>( &mut self, name: impl AsRef<str>, schema: impl AsRef<str>, handler: F, )
Register a command with Brigadier-typed arguments.
schema is a space-separated list of argument types:
int, float, word, string (greedy, must be last), player, blockpos.
In the handler use ctx.arg_int(0), ctx.arg_blockpos(1), etc.
Sourcepub fn on_packet<F>(&mut self, channel: impl AsRef<str>, handler: F)
pub fn on_packet<F>(&mut self, channel: impl AsRef<str>, handler: F)
Runs handler on every packet a client sends on channel (server side).
Sourcepub fn on_client_packet<F>(&mut self, channel: impl AsRef<str>, handler: F)
pub fn on_client_packet<F>(&mut self, channel: impl AsRef<str>, handler: F)
Runs handler on every packet the server sends on channel (client side).
Sourcepub fn on_typed_packet<P, F>(&mut self, channel: impl AsRef<str>, handler: F)
pub fn on_typed_packet<P, F>(&mut self, channel: impl AsRef<str>, handler: F)
Register a typed-packet handler.
The payload is read as P (a Packet: any Yog Data type).
Malformed payloads are silently dropped.
Sourcepub fn add_recipe(&mut self, recipe: Recipe)
pub fn add_recipe(&mut self, recipe: Recipe)
Register a recipe (Yog’s format — see Recipe; the host writes
its Minecraft version’s JSON).
Sourcepub fn add_recipe_data(&mut self, id: &str, data: &[u8])
pub fn add_recipe_data(&mut self, id: &str, data: &[u8])
Register a recipe given as Yog’s recipe in Yog Data, binary — how
yog build registers the mod’s own kinds ({type: "mymod:infusion", slots: …}), which stay the mod’s data: for its machines and its books.
pub fn register_item(&mut self, def: ItemDef)
pub fn register_block(&mut self, def: BlockDef)
Sourcepub fn register_entity(&mut self, def: EntityDef)
pub fn register_entity(&mut self, def: EntityDef)
Registers an entity type (what a .yentity makes). With a model,
the loader draws it — its body model with the clip of its state
(clips: idle, walk, or entity data yog:state).
Sourcepub fn register_entity_data(&mut self, id: &str, data: &[u8])
pub fn register_entity_data(&mut self, id: &str, data: &[u8])
A compiled .yentity (the generated code calls this).
Sourcepub fn add_biome_feature(&mut self, feature: &str, biomes: &str, step: &str)
pub fn add_biome_feature(&mut self, feature: &str, biomes: &str, step: &str)
Add placed feature feature (the mod’s datapack’s, like an ore’s
mymod:mythril_ore) to the biomes of tag biomes at generation
step (underground_ores). An ore .ydef does this for you.
Sourcepub fn register_tool_material(&mut self, material: ToolMaterial)
pub fn register_tool_material(&mut self, material: ToolMaterial)
Register a tool material — what tool items naming it
(ItemDef::tool) are made of. The game’s are built in.
Sourcepub fn register_armor_material(&mut self, material: ArmorMaterial)
pub fn register_armor_material(&mut self, material: ArmorMaterial)
Register an armor material — what armor items naming it
(ItemDef::armor) are made of. The game’s are built in.
Sourcepub fn register_sound_group(&mut self, group: SoundGroup)
pub fn register_sound_group(&mut self, group: SoundGroup)
Register a sound group — what blocks naming it (BlockDef::sound)
sound like. The game’s groups are built in.
Sourcepub fn register_inventory(&mut self, def: InventoryDef)
pub fn register_inventory(&mut self, def: InventoryDef)
Register a real Container/Menu inventory screen — see
yog_inventory::InventoryDef. Attach it to a block via
BlockDef::inventory(id).
Sourcepub fn register_startup_grant(&mut self, grant: StartupGrant)
pub fn register_startup_grant(&mut self, grant: StartupGrant)
Register a startup grant: items/books to give once when a player first joins.
Sourcepub fn register_book(&mut self, book: &Book)
pub fn register_book(&mut self, book: &Book)
Register a book.
Sourcepub fn register_book_data(&mut self, id: &str, data: &[u8])
pub fn register_book_data(&mut self, id: &str, data: &[u8])
Register a book given as Yog Data, binary — what yog build makes
of a content/**/*.ybook; the bytes go to the runtime as they are.
Sourcepub fn register_font_data(&mut self, id: &str, data: &[u8])
pub fn register_font_data(&mut self, id: &str, data: &[u8])
Register a font given as a compiled .yfont Yog Data blob.
Sourcepub fn register_dimension(&mut self, def: &YogDimensionDef)
pub fn register_dimension(&mut self, def: &YogDimensionDef)
Register (or patch) a dimension’s type (sky, lighting, physics, …).
def.id need not be a new custom id — pass a vanilla id
("minecraft:overworld", "minecraft:the_nether",
"minecraft:the_end") to patch that dimension’s type/generator
instead of creating a new one (e.g. to replace the overworld’s
terrain with your own generator type).
Must be called from register() — the same mod-init window as
blocks/items — so the host can declare/patch the dimension before
Minecraft’s registries freeze. See the yog-dimensions crate docs;
set def.generator_type (via YogDimensionDef::generator_type) to
pick a generator type registered with
Registry::register_chunk_generator.
Sourcepub fn register_dimension_data(&mut self, id: &str, data: &[u8])
pub fn register_dimension_data(&mut self, id: &str, data: &[u8])
Register a dimension given as Yog Data, binary — what yog build
makes of a .ydef of kind dimension (its terrain generated by
the runtime itself); the bytes go to the runtime as they are.
Sourcepub fn register_chunk_generator<F>(
&mut self,
generator_type_id: &str,
generator: F,
)
pub fn register_chunk_generator<F>( &mut self, generator_type_id: &str, generator: F, )
Register a named, reusable chunk-generator type under
generator_type_id (e.g. "mymod:custom_terrain") — analogous to
how Biomes O’Plenty registers selectable world-type presets. Any
dimension (custom or vanilla) can opt into this generator via
YogDimensionDef::generator_type; the platform host may also list
registered generator type ids as options on the world-creation screen.
generator is called once per chunk column that needs generating in
any dimension using this type — write whatever terrain logic you want
in the GeneratedChunk (combine as many noise layers as you like;
this crate doesn’t prescribe a generation style). Its terrain, if
declared, is in the column already; another mod’s handler for the
same type (ores, say) sees what this one placed.
Sourcepub fn installed_mods(&self) -> Vec<ModInfo>
pub fn installed_mods(&self) -> Vec<ModInfo>
Register a menu entry — the host renders a button on vanilla screens
(TitleScreen on Fabric, ModListScreen on Forge/NeoForge) that opens ui_id.
label is the human-readable button text (e.g. “Yog Mods”).
ui_id is the UI to open when clicked (e.g. “example:menu”).
See installed_mods. During register() the list only contains
mods loaded before this one.
Sourcepub fn register_ui<F, R>(&mut self, ui_id: &str, handler: F)
pub fn register_ui<F, R>(&mut self, ui_id: &str, handler: F)
Register a UI tree with an event callback.
ui_id is the unique identifier (e.g. “mymod:menu”).
handler receives (ui_id, event) for the screen’s input: click:X:Y,
drag:X:Y, release:X:Y, scroll:DY, key:KEY:MODS (GLFW key code
and modifier bits, on press and repeat) and char:CODEPOINT (a typed
character). It returns () or a bool: true marks a key:/char:
event as used, so the host skips its default handling of the key
(Esc closing the screen, …) — see UiHandled.
Sourcepub fn on_ui_render<F>(&mut self, ui_id: &str, handler: F)
pub fn on_ui_render<F>(&mut self, ui_id: &str, handler: F)
Register a render callback for a specific UI screen (ui_id).
Called from YogUIScreen.render() — i.e. AFTER renderBackground() darkens
the screen — so your UI draws on top of the dimmed world view.
Use this instead of on_hud_render for book/inventory screens.
Clicks are forwarded as "click:X:Y" via the register_ui handler so you
can do hit-testing on your own stored layout.
Sourcepub fn on_book_page<F>(&mut self, drawer: &str, handler: F)
pub fn on_book_page<F>(&mut self, drawer: &str, handler: F)
Draw the pictures of book pages of type drawn whose drawer is
drawer ("mymod:diagram"): handler gets the page’s data and
the picture’s box [x, y, w, h] in screen pixels, every frame the
page is open.
{ type: "drawn", drawer: "mymod:diagram", title: "Wiring", height: 64,
caption: "{u|in} → {u|out}", text: "…", data: { nodes: 3 } }Sourcepub fn on_item_tooltip<S, D>(&mut self, item: &str, size: S, draw: D)
pub fn on_item_tooltip<S, D>(&mut self, item: &str, size: S, draw: D)
A picture under the tooltips of item (as Hex Casting’s scrolls show
their pattern): size(item, snbt) says whether a stack — its custom
data as SNBT — gets one and its size in GUI pixels; draw draws it
in the box [x, y, w, h] (screen pixels) while the tooltip shows.
Sourcepub fn on_item_text<F>(&mut self, item: &str, text: F)
pub fn on_item_text<F>(&mut self, item: &str, text: F)
A stack’s own name and tooltip, from its custom data (SNBT): text(item, snbt) gives Some((name, lines)) — name None keeps the item’s;
lines stand instead of the item’s description — or None for the
item’s own. A written blueprint names its design:
registry.on_item_text(Items::BLUEPRINT, |_, snbt| {
let bp = Blueprint::from_nbt(snbt)?;
Some((Some(bp.name.clone()), vec![format!("{} ports", bp.ports)]))
});Sourcepub fn register_body_model(&mut self, id: &str, data: &[u8])
pub fn register_body_model(&mut self, id: &str, data: &[u8])
A compiled .ymodel (the generated code calls this): found later by
[crate::body::model].
Sourcepub fn register_body_anims(&mut self, id: &str, data: &[u8])
pub fn register_body_anims(&mut self, id: &str, data: &[u8])
A compiled .yanim (the generated code calls this): its clips found
later by crate::body::clip.
Sourcepub fn on_body<F>(&mut self, handler: F)
pub fn on_body<F>(&mut self, handler: F)
Register a handler asked each frame about the body of every tracked
entity (crate::body::track): it answers with crate::body::Ops
— pose vanilla parts, turn the body, draw meshes (rigs, morphs),
disguise, hide, capture. Every mod’s ops add up.
Sourcepub fn add_loot_modifier(&mut self, modifier: LootModifier)
pub fn add_loot_modifier(&mut self, modifier: LootModifier)
Change the loot of some tables as modifier says.
Sourcepub fn register_attribute(&mut self, def: AttributeDef)
pub fn register_attribute(&mut self, def: AttributeDef)
Register an attribute every player has — what effects change and
yog_event::entity::attribute_value reads.
Sourcepub fn register_effect(&mut self, def: EffectDef)
pub fn register_effect(&mut self, def: EffectDef)
Register a mob effect.
Sourcepub fn register_potion(&mut self, def: PotionDef)
pub fn register_potion(&mut self, def: PotionDef)
Register a potion and its brewing.
Sourcepub fn register_definition_data(&mut self, kind: &str, id: &str, data: &[u8])
pub fn register_definition_data(&mut self, kind: &str, id: &str, data: &[u8])
A compiled .ydef the game registers (attribute, effect,
potion) — the generated code calls this.
Sourcepub fn add_loot_modifier_data(&mut self, id: &str, data: &[u8])
pub fn add_loot_modifier_data(&mut self, id: &str, data: &[u8])
A compiled .ydef loot modifier (the generated code calls this).
Sourcepub fn loot_function<F>(&mut self, name: &str, function: F)
pub fn loot_function<F>(&mut self, name: &str, function: F)
Register loot function name (mymod:pattern_scroll): what loot
modifiers naming it (function) run on each stack they add — set
its custom data, say.
Sourcepub fn on_camera<F>(&mut self, handler: F)
pub fn on_camera<F>(&mut self, handler: F)
Register a handler that moves, turns or zooms the camera each frame;
it changes the crate::body::CameraOut the handlers before it made.
Sourcepub fn on_travel<F>(&mut self, handler: F)
pub fn on_travel<F>(&mut self, handler: F)
Register a handler that may replace the local player’s travel step:
Some(velocity) (blocks per tick, drag applied) moves the player by
it instead of vanilla’s walking, swimming, falling or gliding.
Sourcepub fn on_hud_render<F>(&mut self, handler: F)
pub fn on_hud_render<F>(&mut self, handler: F)
Register a handler called every frame when the HUD is rendered.
gfx provides full GPU pipeline access plus 2D convenience draw calls.
view_proj and camera_pos are zero in HUD context; use gfx.draw2d() for HUD elements.
Sourcepub fn on_world_render<F>(&mut self, handler: F)
pub fn on_world_render<F>(&mut self, handler: F)
Register a handler called every frame at the end of world rendering.
gfx.view_proj() is the combined projection × view matrix (camera-relative).
gfx.camera_pos() is the camera world position.
To render at world position P, translate by P - camera_pos before drawing.
Sourcepub fn key_binding<F>(
&mut self,
id: &str,
name: &str,
default_key: Option<i32>,
handler: F,
)
pub fn key_binding<F>( &mut self, id: &str, name: &str, default_key: Option<i32>, handler: F, )
A key binding the player sees in the game’s controls (under this
mod’s name) and can rebind there; the game keeps the key it’s bound
to. id names it (mymod:xray), name is its label’s translation
key (a .yres text’s …_KEY), default_key a GLFW key code
(crate::client::keys; None: unbound). handler runs on the
client thread at each press.
registry.key_binding("mymod:xray", Strings::KEY_XRAY_KEY, Some(keys::X), || toggle_xray());Source§impl Registry
impl Registry
Sourcepub fn schedule_once<F>(&self, delay_ticks: u64, handler: F)
pub fn schedule_once<F>(&self, delay_ticks: u64, handler: F)
Runs handler once, delay_ticks server ticks from now.