Skip to main content

Registry

Struct Registry 

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

Wraps the YogApi table and provides an ergonomic registration API.

Obtained inside yog_mod_register via export_mod!. Closures registered here are boxed and leaked — they live as long as the process (which is the correct lifetime for a server mod).

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

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_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_shaped_recipe(&mut self, recipe: ShapedRecipe)

Register a shaped crafting recipe.

Source

pub fn add_shapeless_recipe(&mut self, recipe: ShapelessRecipe)

Register a shapeless crafting recipe.

Source

pub fn add_furnace_recipe(&mut self, recipe: FurnaceRecipe)

Register a furnace smelting recipe.

Source

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

Source

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

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 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_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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.