Skip to main content

Registry

Struct Registry 

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

Implementations§

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_block_break<F>(&mut self, handler: F)
where F: Fn(&BlockBreakEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_chat<F>(&mut self, handler: F)
where F: Fn(&ChatEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_player_join<F>(&mut self, handler: F)
where F: Fn(&PlayerJoinEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_player_leave<F>(&mut self, handler: F)
where F: Fn(&PlayerLeaveEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_use_item<F>(&mut self, handler: F)
where F: Fn(&UseItemEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_use_block<F>(&mut self, handler: F)
where F: Fn(&UseBlockEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_attack_entity<F>(&mut self, handler: F)
where F: Fn(&AttackEntityEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_entity_damage<F>(&mut self, handler: F)
where F: Fn(&EntityDamageEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_entity_death<F>(&mut self, handler: F)
where F: Fn(&EntityDeathEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_entity_spawn<F>(&mut self, handler: F)
where F: Fn(&EntitySpawnEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_player_place_block<F>(&mut self, handler: F)
where F: Fn(&PlaceBlockEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_player_death<F>(&mut self, handler: F)
where F: Fn(&PlayerDeathEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_player_respawn<F>(&mut self, handler: F)
where F: Fn(&PlayerRespawnEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_advancement<F>(&mut self, handler: F)
where F: Fn(&AdvancementEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_entity_interact<F>(&mut self, handler: F)
where F: Fn(&EntityInteractEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_item_craft<F>(&mut self, handler: F)
where F: Fn(&CraftEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_machine_craft<F>(&mut self, handler: F)
where F: Fn(&MachineCraftEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

A machine making a recipe — see MachineCraftEvent.

Source

pub fn on_explosion<F>(&mut self, handler: F)
where F: Fn(&ExplosionEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_item_pickup<F>(&mut self, handler: F)
where F: Fn(&ItemPickupEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_player_move<F>(&mut self, handler: F)
where F: Fn(&PlayerMoveEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_container_open<F>(&mut self, handler: F)
where F: Fn(&ContainerOpenEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_container_close<F>(&mut self, handler: F)
where F: Fn(&ContainerCloseEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_projectile_hit<F>(&mut self, handler: F)
where F: Fn(&ProjectileHitEvent, EventPhase, &dyn Server) -> bool + Send + Sync + 'static,

Source

pub fn on_tick<F>(&mut self, listener: F)
where F: Fn(&dyn Server) + Send + Sync + 'static,

Source

pub fn on_server_started<F>(&mut self, listener: F)
where F: Fn(&dyn Server) + Send + Sync + 'static,

Source

pub fn on_server_stopping<F>(&mut self, listener: F)
where F: Fn(&dyn Server) + Send + Sync + 'static,

Source

pub fn on_command<F>(&mut self, name: impl AsRef<str>, handler: F)
where F: Fn(&CommandContext, &dyn Server) -> 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, &dyn Server) -> 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, &dyn Server) + Send + Sync + 'static,

Source

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

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, &dyn Server) + Send + Sync + 'static,

Register a typed-packet handler.

The payload is decoded from raw bytes using P’s Packet impl. 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_json(&mut self, id: &str, json: &str)

Register a recipe given as Yog’s recipe JSON — 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 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_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(&ChunkWriter) + 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 using the ChunkWriter handle (combine as many noise layers as you like; this crate doesn’t prescribe a generation style).

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 interop(&self) -> Interop

Access the inter-mod communication layer.

Allows exporting function pointers from this mod and importing function pointers from other mods.

Source

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

Raw YogApi pointer — for passing to interop-imported functions that register content through the C ABI table directly.

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 schedule_once<F>(&self, delay_ticks: u64, handler: F)
where F: Fn(&dyn Server) + Send + Sync + 'static,

Source

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

Source

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

Register a handler called every client tick (render thread, no server).

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 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 on_key_press<F>(&mut self, handler: F)
where F: Fn(&KeyPressEvent) -> bool + Send + Sync + 'static,

Register a handler for keyboard input (client-side). Return false to prevent Minecraft from processing the key.

Source

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

Register a handler called when a GUI screen is opened.

Source

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

Register a handler called when a GUI screen is closed.

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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.