Skip to main content

Registry

Struct Registry 

Source
pub struct Registry { /* private fields */ }

Implementations§

Source§

impl Registry

Source

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.

Source

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.

Source

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.

Source

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

pub fn after<E: Event + 'static, R: IntoFlow + 'static>( &mut self, handler: impl Fn(&E, &EventCx) -> R + Send + Sync + 'static, )

Runs handler after the game did E.

Source

pub fn change<E: Event + 'static>( &mut self, handler: impl Fn(&mut E, &EventCx) + Send + Sync + 'static, )

Lets handler change every E before it’s used (a loot table’s items); each handler sees the one before’s result.

Source§

impl Registry

Source

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

Source

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

Source

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.

Source

pub fn on_command<F>(&mut self, name: impl AsRef<str>, handler: F)
where F: Fn(&CommandContext) -> Option<String> + Send + Sync + 'static,

Source

pub fn on_typed_command<F>( &mut self, name: impl AsRef<str>, schema: impl AsRef<str>, handler: F, )
where F: Fn(&CommandContext) -> Option<String> + Send + Sync + 'static,

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.

Source

pub fn on_packet<F>(&mut self, channel: impl AsRef<str>, handler: F)
where F: Fn(&PacketEvent) + Send + Sync + 'static,

Runs handler on every packet a client sends on channel (server side).

Source

pub fn on_client_packet<F>(&mut self, channel: impl AsRef<str>, handler: F)
where F: Fn(&ClientPacketEvent) + Send + Sync + 'static,

Runs handler on every packet the server sends on channel (client side).

Source

pub fn on_typed_packet<P, F>(&mut self, channel: impl AsRef<str>, handler: F)
where P: Packet + Send + Sync + 'static, F: Fn(&P) + Send + Sync + 'static,

Register a typed-packet handler.

The payload is read as P (a Packet: any Yog Data type). Malformed payloads are silently dropped.

Source

pub fn add_recipe(&mut self, recipe: Recipe)

Register a recipe (Yog’s format — see Recipe; the host writes its Minecraft version’s JSON).

Source

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.

Source

pub fn register_item(&mut self, def: ItemDef)

Source

pub fn register_block(&mut self, def: BlockDef)

Source

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

Source

pub fn register_entity_data(&mut self, id: &str, data: &[u8])

A compiled .yentity (the generated code calls this).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn register_startup_grant(&mut self, grant: StartupGrant)

Register a startup grant: items/books to give once when a player first joins.

Source

pub fn register_book(&mut self, book: &Book)

Register a book.

Source

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.

Source

pub fn register_font_data(&mut self, id: &str, data: &[u8])

Register a font given as a compiled .yfont Yog Data blob.

Source

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.

Source

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.

Source

pub fn register_chunk_generator<F>( &mut self, generator_type_id: &str, generator: F, )
where F: Fn(&mut GeneratedChunk) + Send + Sync + 'static,

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.

Source

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.

Source

pub fn raw_api(&self) -> *const YogApi

The raw YogApi table.

Source

pub fn register_menu_entry(&mut self, label: &str, ui_id: &str)

Source

pub fn register_ui<F, R>(&mut self, ui_id: &str, handler: F)
where F: Fn(&str, &str) -> R + Send + Sync + 'static, R: UiHandled,

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.

Source

pub fn on_ui_render<F>(&mut self, ui_id: &str, handler: F)
where F: Fn(&GfxContext) + Send + Sync + 'static,

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.

Source

pub fn on_book_page<F>(&mut self, drawer: &str, handler: F)
where F: Fn(&GfxContext, &Value, [f32; 4]) + Send + Sync + 'static,

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

pub fn on_item_tooltip<S, D>(&mut self, item: &str, size: S, draw: D)
where S: Fn(&str, &str) -> Option<(f32, f32)> + Send + Sync + 'static, D: Fn(&GfxContext, &str, &str, [f32; 4]) + Send + Sync + 'static,

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.

Source

pub fn on_item_text<F>(&mut self, item: &str, text: F)
where F: Fn(&str, &str) -> Option<(Option<String>, Vec<String>)> + Send + Sync + 'static,

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)]))
});
Source

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].

Source

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.

Source

pub fn on_body<F>(&mut self, handler: F)
where F: Fn(&Frame, &mut Ops) + Send + Sync + 'static,

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.

Source

pub fn add_loot_modifier(&mut self, modifier: LootModifier)

Change the loot of some tables as modifier says.

Source

pub fn register_attribute(&mut self, def: AttributeDef)

Register an attribute every player has — what effects change and yog_event::entity::attribute_value reads.

Source

pub fn register_effect(&mut self, def: EffectDef)

Register a mob effect.

Source

pub fn register_potion(&mut self, def: PotionDef)

Register a potion and its brewing.

Source

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.

Source

pub fn add_loot_modifier_data(&mut self, id: &str, data: &[u8])

A compiled .ydef loot modifier (the generated code calls this).

Source

pub fn loot_function<F>(&mut self, name: &str, function: F)
where F: Fn(&mut LootStack, &Loot) + Send + Sync + 'static,

Register loot function name (mymod:pattern_scroll): what loot modifiers naming it (function) run on each stack they add — set its custom data, say.

Source

pub fn on_camera<F>(&mut self, handler: F)
where F: Fn(&CameraFrame, &mut CameraOut) + Send + Sync + 'static,

Register a handler that moves, turns or zooms the camera each frame; it changes the crate::body::CameraOut the handlers before it made.

Source

pub fn on_travel<F>(&mut self, handler: F)
where F: Fn(&TravelFrame) -> Option<Vec3> + Send + Sync + 'static,

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.

Source

pub fn on_hud_render<F>(&mut self, handler: F)
where F: Fn(&GfxContext) + Send + Sync + 'static,

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.

Source

pub fn on_world_render<F>(&mut self, handler: F)
where F: Fn(&GfxContext) + Send + Sync + 'static,

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.

Source

pub fn key_binding<F>( &mut self, id: &str, name: &str, default_key: Option<i32>, handler: F, )
where F: Fn() + Send + Sync + 'static,

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

Source

pub fn schedule_once<F>(&self, delay_ticks: u64, handler: F)
where F: Fn() + Send + Sync + 'static,

Runs handler once, delay_ticks server ticks from now.

Source

pub fn schedule_repeating<F>(&self, period_ticks: u64, handler: F)
where F: Fn() + Send + Sync + 'static,

Runs handler every period_ticks server ticks.

Source§

impl Registry

Source

pub fn provide<S: Service + 'static>( &mut self, handler: impl Fn(&S, &EventCx) -> S::Reply + Send + Sync + 'static, ) -> bool

Answers every call to S — one provider per address: false if someone answers it already.

Source

pub fn provide_key<S: Service + 'static>( &mut self, key: &str, handler: impl Fn(&S, &EventCx) -> S::Reply + Send + Sync + 'static, ) -> bool

Registry::provide for a keyed service’s key only (S::KEY): the inserts into one block.

Source§

impl Registry

Source

pub fn call<S: Service>(&self, request: &S) -> Option<S::Reply>

call while registering.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Arg<T> for T

Source§

fn arg(self) -> T

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.