Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
// @generated by cargo run -p xtask -- mod-api; do not edit.
use super::*;
pub trait Hooks: Send + Sync {
fn render(&self) -> Option<&dyn RenderHooks> {
None
}
/// Once a frame, in a world or not, after Horizon's extras.
fn frame(&self, host: &mut dyn Host, event: &mut FrameEvent) {
let _ = host;
let _ = event;
}
/// Once a tick, in every `Game`: the window's (in single player, on LAN
/// and on servers), and the server's own (`native_window` is false
/// there: the single player server thread, a dedicated server).
fn tick(&self, host: &mut dyn Host, event: &mut TickEvent) {
let _ = host;
let _ = event;
}
/// The world frame's local visual sources. Push requests; Horizon validates
/// and limits them before rendering. Called only while a world is visible.
fn visuals(&self, host: &dyn Host, event: &mut VisualsEvent<'_>) {
let _ = host;
let _ = event;
}
/// At most 32 pairs of already-loaded base and transparent overlay sprites.
/// Per-pixel alpha in the overlay marks full-bright material, without
/// illuminating the surrounding block or changing gameplay light.
///
/// Every mod gets `event.layers` in order and may add, change or remove layers.
fn emissive(&self, host: &dyn Host, event: &mut EmissiveEvent<'_>) {
let _ = host;
let _ = event;
}
/// The world's phases, read-only; `error_text` carries the engine's
/// own open-failure text, empty otherwise. Server-side; the deprecated
/// in-frame path delivers no lifecycle events. A server loop or final
/// save failure fires `WorldCloseFailed` with the error text.
fn world_lifecycle(&self, host: &mut dyn Host, event: &mut WorldLifecycleEvent<'_>) {
let _ = host;
let _ = event;
}
/// The server is about to open its worlds: nothing of the world is
/// loaded yet (NeoForge's `ServerAboutToStartEvent`, "called before the
/// server begins loading anything"). Vanilla's `MinecraftServer.loadLevel`
/// start. Server-side: the single player server thread once Play is
/// pressed, a dedicated server once its settings are read. Each is
/// followed by `native_world_lifecycle`'s `WorldOpenReady` or
/// `WorldOpenFailed`. `dedicated` tells a dedicated server from the single
/// player one. API 44.
fn server_about_to_start(&self, host: &mut dyn Host, event: &mut ServerAboutToStartEvent) {
let _ = host;
let _ = event;
}
/// The server begins an orderly stop (NeoForge's `ServerStoppingEvent`):
/// the start of vanilla's `MinecraftServer.stopServer`, with the worlds
/// still loaded and the players still connected and not yet saved, so a
/// mod can save its own data or tell them. `native_world_lifecycle`'s
/// `WorldCloseFinal` follows once the worlds are saved. A server whose loop
/// fails stops without this (`WorldCloseFailed` reports it). API 44.
fn server_stopping(&self, host: &mut dyn Host, event: &mut ServerStoppingEvent) {
let _ = host;
let _ = event;
}
/// The authoritative server tick's phases: `ServerTickStart` before any
/// level is ticked (NeoForge's `ServerTickEvent.Pre`), `ServerTickEnd`
/// after the last (`.Post`). Read blocks with `native_server_block`, by
/// dimension: which level `self.world` holds here is not defined. A paused
/// pass fires nothing; a frozen world carries `world_running` false except
/// during a requested step.
fn server_tick(&self, host: &mut dyn Host, event: &mut ServerTickEvent<'_>) {
let _ = host;
let _ = event;
}
/// Before an authoritative server level's tick pass. `dimension` is its ID.
fn level_tick_pre(&self, host: &mut dyn Host, event: &mut LevelTickPreEvent<'_>) {
let _ = host;
let _ = event;
}
/// After a successful authoritative server level tick pass.
fn level_tick_post(&self, host: &mut dyn Host, event: &mut LevelTickPostEvent<'_>) {
let _ = host;
let _ = event;
}
/// An authoritative server committed a changed state through `Level.setBlock`.
/// The world contains `new`; block side effects and neighbour updates follow.
fn block_changed(&self, level: &dyn LevelHost, event: &mut BlockChangedEvent) {
let _ = level;
let _ = event;
}
/// An authoritative server is about to deliver `neighborChanged`.
/// State and block IDs are valid in this level's registries for this call.
fn neighbor_changed(&self, level: &dyn LevelHost, event: &mut NeighborChangedEvent) {
let _ = level;
let _ = event;
}
/// An authoritative server's `ServerLevel.tickChunk` is about to
/// random-tick the block `state` at `pos` (`BlockState.randomTick`):
/// only blocks that tick randomly, a mod's as its vanilla template block
/// does. Bone meal's random ticks (`StemBlock.performBonemeal`) don't
/// fire it. Change the block with `native_set_block_property` and set
/// `handled` to skip the block's own random tick (a mod crop growing its
/// own way); a block changed without `handled` takes its own random tick
/// as it is now, if it still ticks randomly. Lava's fluid random tick
/// runs either way.
///
/// Return `Flow::Cancel` to take it: this sets `handled`, and later mods are skipped.
fn random_tick(&self, level: &mut dyn LevelWriteHost, event: &mut RandomTickEvent) -> Flow {
let _ = level;
let _ = event;
Flow::Continue
}
/// An authoritative server's `ServerLevel.tickBlock` is about to run a
/// due scheduled tick of the block `state` at `pos` (`BlockState.tick`):
/// the block is still the one the tick was scheduled for. Change the
/// block with `native_set_block_property` and set `handled` to skip the
/// block's own tick; a block changed without `handled` takes its own
/// tick as it is now, if it is still the tick's block.
///
/// Return `Flow::Cancel` to take it: this sets `handled`, and later mods are skipped.
fn tick_block(&self, level: &mut dyn LevelWriteHost, event: &mut TickBlockEvent) -> Flow {
let _ = level;
let _ = event;
Flow::Continue
}
/// An authoritative server is about to compute the state the block
/// `state` at `pos` takes now that its neighbour in `direction` is
/// `neighbour` (`BlockBehaviour.updateShape`). `state` may not be in the
/// world yet (a piston landing it): decide from `state`, not from the
/// block at `pos`. Answer only for your own blocks: put the new state in
/// `new` (`state` keeps the block as it is; air breaks it, with its drops,
/// on a neighbour update) and the block's own `updateShape` doesn't run,
/// nor the ticks it would schedule. The level is read-only, as vanilla's
/// `LevelReader`; ticks go through `native_schedule_block_tick` and
/// `native_schedule_fluid_tick` with `ticks` (`ScheduledTickAccess`). It
/// runs often, at least six times per `setBlock` that updates shapes
/// (more for redstone wire's diagonals and knock-on updates): keep it
/// short.
///
/// Return `Some` to set `new`; the first mod returning `Some` wins.
fn update_shape(
&self,
level: &mut dyn LevelTicksHost,
event: &mut UpdateShapeEvent,
) -> Option<BlockStateId> {
let _ = level;
let _ = event;
None
}
/// The HUD (not drawn under F1), after the minimap: place a box with
/// `corners.place` (boxes stack away from their edge) and draw it with
/// `native_fill` and `native_text`. Skip a corner `native_corner_shown`
/// says is taken.
fn hud(&self, host: &mut dyn Host, event: &mut HudEvent<'_>) {
let _ = host;
let _ = event;
}
/// A key or mouse button went down or up, by its vanilla name
/// (`key.keyboard.z`, `key.mouse.left`): keys on any screen (check
/// `native_playing`), mouse buttons while playing. Repeats are left out.
fn key(&self, host: &mut dyn Host, event: &mut KeyEvent<'_>) {
let _ = host;
let _ = event;
}
/// Wheel steps while playing: set `claimed` to keep them from the hotbar.
///
/// Return `Flow::Cancel` to take it: this sets `claimed`, and later mods are skipped.
fn wheel(&self, host: &mut dyn Host, event: &mut WheelEvent) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A command typed or clicked in chat, without its slash, before the
/// server and Horizon's commands see it: set `ran` when the mod ran it.
///
/// Return `Flow::Cancel` to take it: this sets `ran`, and later mods are skipped.
fn command(&self, host: &mut dyn Host, event: &mut CommandEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// The commands `native_command` runs, by name and without their slash:
/// push the ones that are yours. Asked when a connection starts and
/// again when the server sends its own tree, so the chat box colours,
/// completes and lists them as the game's own; a name the game already
/// has keeps that command's behaviour. API 35.
///
/// Every mod gets `event.commands` in order and may add, change or remove commands.
fn commands(&self, host: &mut dyn Host, event: &mut CommandsEvent<'_>) {
let _ = host;
let _ = event;
}
/// The zoom a native mod asks for, applied while playing (the spyglass's
/// own view wins): set `zoom` when it is none yet.
///
/// Return `Some` to set `zoom`; the first mod returning `Some` wins.
fn zoom(&self, host: &dyn Host, event: &mut ZoomEvent) -> Option<NativeZoom> {
let _ = host;
let _ = event;
None
}
/// The minimap a native mod shows: set `minimap` when it is none yet.
///
/// Return `Some` to set `minimap`; the first mod returning `Some` wins.
fn minimap(&self, host: &dyn Host, event: &mut MinimapEvent) -> Option<NativeMinimap> {
let _ = host;
let _ = event;
None
}
/// Options > Mods lists the native mods: push yours.
///
/// Every mod gets `event.mods` in order and may add, change or remove mods.
fn mods(&self, host: &mut dyn Host, event: &mut ModsEvent<'_>) {
let _ = host;
let _ = event;
}
/// The buttons of mod `mod_id`'s settings page, under its keys: push
/// their labels when it is yours. Asked again each time the page opens
/// and after each click.
///
/// Every mod gets `event.buttons` in order and may add, change or remove buttons.
fn settings(&self, host: &mut dyn Host, event: &mut SettingsEvent<'_>) {
let _ = host;
let _ = event;
}
/// Button `button` of mod `mod_id`'s settings page was clicked.
fn settings_click(&self, host: &mut dyn Host, event: &mut SettingsClickEvent<'_>) {
let _ = host;
let _ = event;
}
/// The player did `event` on mod `mod_id`'s panel (`native_panel_items`):
/// act on it when it is yours. API 2.
fn panel_event(&self, host: &mut dyn Host, event_: &mut PanelEventEvent<'_>) {
let _ = host;
let _ = event_;
}
/// Block `block` (`mymod:machine`) gets a block entity
/// (`EntityBlock.newBlockEntity`): set `entity` to its id and saved
/// compound when the block is yours and `entity` is none yet. It works on
/// any template: the engine removes the block entity when its block is
/// broken or replaced, no piston moves it, and a mod that draws it
/// (`native_block_entity_submit`) is asked for it. API 15; before
/// 129 the block's template had to have a
/// block entity of its own (a chest, a furnace...), or the block got none.
///
/// Return `Some` to set `entity`; the first mod returning `Some` wins.
fn block_entity(
&self,
host: &mut dyn Host,
event: &mut BlockEntityEvent<'_>,
) -> Option<(String, Compound)> {
let _ = host;
let _ = event;
None
}
/// Whether block `block`'s block entity ticks (`EntityBlock.getTicker`):
/// set `ticks` when it is yours. Asked for each of the block's states
/// when a world opens. API 15.
/// Set `ticks` to true to make it tick, and never clear a value an earlier mod or mixin set.
fn block_entity_ticks(&self, host: &dyn Host, event: &mut BlockEntityTicksEvent<'_>) {
let _ = host;
let _ = event;
}
/// A server tick of the block entity at `pos`, in vanilla's order among
/// the others (`Level.tickBlockEntities`), when its `id` is yours: read
/// and change its saved compound `nbt`, its item slots `items` (keep
/// their count: as many as its container has, none without one) and the
/// data slots its menu shows (`data`). It is out of the world during the
/// call (the block entity at `pos` reads as a `Mod` with an empty id, and
/// a save leaves it out); if the call removes or replaces it, `entity` is
/// dropped. Clients, the window's own in single player included, get
/// what `native_block_entity_update_tag` gives when its chunk is sent or
/// its block changes. API 17.
fn block_entity_tick(&self, host: &mut dyn Host, event: &mut BlockEntityTickEvent<'_>) {
let _ = host;
let _ = event;
}
/// What clients get of the block entity at `pos` when its `id` is
/// yours (`BlockEntity.getUpdateTag`): set `tag` to it, read from
/// `entity` alone. Asked on the server whenever a chunk holding it is
/// sent and whenever its block changes, on the server thread or, for a
/// saved chunk sent past the view distance (`lan::far`), another one; a client's copy of the block
/// entity (made by `native_block_entity` there) merges it into its `nbt`.
/// Leave it unset to send nothing. API 45.
///
/// Return `Some` to set `tag`; the first mod returning `Some` wins.
fn block_entity_update_tag(
&self,
event: &mut BlockEntityUpdateTagEvent<'_>,
) -> Option<Compound> {
let _ = event;
None
}
/// Block `block`'s block entity has item slots (a `WorldlyContainer`):
/// set `container` when the block is yours. Asked once for each mod
/// block when the ticking table is built; at most 256 slots, and slot
/// numbers past the count are left out. Its `menu`, one of
/// `containers::MOD_MENUS` or a content mod's menu type
/// (`data/<id>/horizon/menu/`, API 85) with as many
/// slots, opens when the block is used (its template must open a menu, as
/// a chest or a furnace does); another is left out. A mod menu type shows
/// on Horizon clients through the mod's `native_screen` only. API 17.
///
/// Return `Some` to set `container`; the first mod returning `Some` wins.
fn block_entity_container(
&self,
host: &dyn Host,
event: &mut BlockEntityContainerEvent<'_>,
) -> Option<ModContainer> {
let _ = host;
let _ = event;
None
}
/// A menu opens on this client for block `block`, a mod's: set `screen`
/// when the block is yours, to lay its screen out (`native_screen_draw`
/// draws it). The server asks it too: a slot it hides is not in the menu
/// there either, so shift-clicks never fill it. API 19.
///
/// Return `Some` to set `screen`; the first mod returning `Some` wins.
fn screen(&self, host: &dyn Host, event: &mut ScreenEvent<'_>) -> Option<NativeScreen> {
let _ = host;
let _ = event;
None
}
/// Draw block `block`'s screen at `origin` (its top left, GUI pixels),
/// over a plain panel with its slots' frames and under the items and
/// labels, from the menu's data slots `data` (the block entity's `data`
/// on the server): data slots are 16-bit on the wire as in vanilla (a
/// bigger value wraps), and `data` is empty until the server's first
/// values arrive, so read it with `get`. Draw with `native_sprite`, `native_fill` and
/// `native_text`. API 19.
fn screen_draw(&self, host: &dyn Host, event: &mut ScreenDrawEvent<'_>) {
let _ = host;
let _ = event;
}
/// A left or right (`right`) press at `at` (GUI pixels from the screen's
/// top left, so outside it too) on block `block`'s screen, a mod's, over
/// no slot: set `button` to a menu button id when it is on one of yours.
/// Horizon sends it to the server (`ContainerButtonClick`,
/// `native_menu_button` there) and the press goes no further. API 20.
///
/// Return `Some` to set `button`; the first mod returning `Some` wins.
fn screen_click(&self, host: &dyn Host, event: &mut ScreenClickEvent<'_>) -> Option<i32> {
let _ = host;
let _ = event;
None
}
/// The tooltip at `at` (as in `native_screen_click`) on block `block`'s
/// screen, a mod's, over no item: push its lines when it is over
/// something of yours. Legacy colour codes (§) work. API 20.
///
/// Every mod gets `event.lines` in order and may add, change or remove lines.
fn screen_tooltip(&self, host: &dyn Host, event: &mut ScreenTooltipEvent<'_>) {
let _ = host;
let _ = event;
}
/// A player pressed menu button `id` on the menu of the mod block entity
/// at `pos` (`AbstractContainerMenu.clickMenuButton`), on the server:
/// change `entity` when its id is yours. It is out of the world during
/// the call, as in `native_block_entity_tick`. API 20.
fn menu_button(&self, host: &mut dyn Host, event: &mut MenuButtonEvent<'_>) {
let _ = host;
let _ = event;
}
/// The commands native mods add to the server's command tree: push
/// yours. Asked once when a world opens to players (a dedicated
/// server, a LAN host, single player's server thread); every player's
/// chat box then completes them as vanilla's, within their level. A
/// name vanilla has is left out. API 8.
///
/// Every mod gets `event.commands` in order and may add, change or remove commands.
fn register_commands(&self, host: &mut dyn Host, event: &mut RegisterCommandsEvent<'_>) {
let _ = host;
let _ = event;
}
/// A player's command on the server (`Commands.performCommand`),
/// without its slash, for a command a mod registered and the player's
/// level allows: set `ran` when it is yours. The player's state is
/// swapped in for the call, so `native_player` and the other helpers
/// read that player; `native_feedback` answers them. A single player's
/// owner console (`horizon-ctl command`) reaches it too, as the owner at
/// level 4. API 8.
///
/// Return `Flow::Cancel` to take it: this sets `ran`, and later mods are skipped.
fn perform_command(&self, host: &mut dyn Host, event: &mut PerformCommandEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A click in a menu a mod opened (`native_open_menu`), which moved
/// nothing: the menu's `slot` (its own first, then the player's
/// inventory, `native_menu_inventory_slot`; -999 outside), the `button`
/// and the click's `mode` (`ClickType`'s id) of the player `uuid`.
/// No player's state is swapped in: the menu helpers take the player's
/// UUID. API 10.
fn menu_clicked(&self, host: &mut dyn Host, event: &mut MenuClickedEvent) {
let _ = host;
let _ = event;
}
/// A menu a mod opened closed: the player closed it, the server or a mod
/// opened another, or the player left. API 10.
fn menu_closed(&self, host: &mut dyn Host, event: &mut MenuClosedEvent) {
let _ = host;
let _ = event;
}
/// An item's tooltip, wherever the game shows one (slots, the creative
/// tabs, the recipe book, chat's hover): the stack, with its components
/// (`stack.data()`: a shulker box's contents...), and its lines, the name
/// first, each with a colour as `rgba` packs it (`u32::MAX` keeps the
/// text's own). Add, change or take out lines; `Text::legacy` reads `§`
/// codes. Asked each frame the tooltip shows, never for one the stack
/// hides. API 12.
///
/// Every mod gets `event.lines` in order and may add, change or remove lines.
fn tooltip(&self, host: &dyn Host, event: &mut TooltipEvent<'_>) {
let _ = host;
let _ = event;
}
/// A player uses `stack` (right click) with `self.hand` on the block at
/// `pos`, `face` the face clicked (`[0, 1, 0]` is the top), once the
/// block itself let the click through (a chest still opens): where
/// `ItemStack.useOn` starts. Set `claimed` to take the use: the hand
/// swings and neither the item's `useOn` nor its `use` runs.
/// Server-side, for every player of the world (the helpers read the
/// acting one); an item on cooldown is never used. API 13.
///
/// Return `Flow::Cancel` to take it: this sets `claimed`, and later mods are skipped.
fn use_item_on(&self, host: &mut dyn Host, event: &mut UseItemOnEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A player uses `stack` (right click) with `self.hand`: in the air, or
/// on a block once `native_use_item_on` let it through, where `Item.use`
/// starts. Each click reaches it once. Set `claimed` to take the use: the
/// hand swings and the item's own use doesn't run. Server-side, for every
/// player of the world; an item on cooldown is never used. API 13.
///
/// Return `Flow::Cancel` to take it: this sets `claimed`, and later mods are skipped.
fn use_item(&self, host: &mut dyn Host, event: &mut UseItemEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A player breaks the block `state` at `pos`, once the game allowed it
/// (the held item can break blocks, the debug stick didn't take the
/// click): where `ServerPlayerGameMode.destroyBlock` starts. Set
/// `canceled` to keep the block: nothing is destroyed or dropped, and a
/// guest sees it back. Server-side, for every player of the world (the
/// helpers read the acting one). API 14.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn destroy_block(&self, host: &mut dyn Host, event: &mut DestroyBlockEvent) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A player placed `stack` as the block `state` at `pos`: where
/// `BlockItem.place` set it, before the stack shrinks. It only hears; a
/// mod stops a placement by claiming `native_use_item_on`, which runs
/// before it. Server-side, for every player of the world. API 14.
fn place_block(&self, host: &mut dyn Host, event: &mut PlaceBlockEvent<'_>) {
let _ = host;
let _ = event;
}
/// A player right clicks the block at `pos` with `self.hand`, `face` the
/// face clicked: where `ServerPlayerGameMode.useItemOn` starts, before
/// the block's own use (a chest, a door, a lever) and before
/// `native_use_item_on`. Set `canceled` to stop the click: neither the
/// block nor the item acts, the hand doesn't swing, and a guest sees the
/// block as it is. Server-side, for every player of the world
/// (`native_acting_player` says who), once per hand. API 21.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn right_click_block(&self, host: &mut dyn Host, event: &mut RightClickBlockEvent) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// On an authoritative server, a fluid flows or fire spreads from `from`
/// into `to` (`kind` is `fluid` or `fire`): `FlowingFluid.spreadTo`, and
/// `FireBlock.tick` setting fire to `to` or burning it (`checkBurnOut`).
/// Set `canceled` to leave the block at `to` as it is. Fluids ask on
/// every flow: answer fast. API 22.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn block_spread(&self, level: &dyn LevelHost, event: &mut BlockSpreadEvent<'_>) -> Flow {
let _ = level;
let _ = event;
Flow::Continue
}
/// On an authoritative server, the piston at `piston` is about to push
/// the blocks at `push` one step `direction` (`[0, 1, 0]` is up; pulling
/// when it retracts) and destroy those at `destroy`:
/// `PistonBaseBlock.moveBlocks`, once its structure resolved. Set
/// `canceled` and nothing moves, as when the structure can't; a sticky
/// piston then retracts without its block, and clients are sent the
/// blocks rather than the retraction to replay. API 22.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn piston_move(&self, level: &dyn LevelHost, event: &mut PistonMoveEvent<'_>) -> Flow {
let _ = level;
let _ = event;
Flow::Continue
}
/// An explosion at `center` in `dimension` (`minecraft:overworld`) is
/// about to break `blocks`: `ServerExplosion.explode` with its `toBlow`,
/// before any block is hit. Take out the positions to spare; they keep
/// their block and get no fire. Entities are hurt as before. Server-side.
/// API 22.
///
/// Every mod gets `event.blocks` in order and may add, change or remove blocks.
fn explosion_detonate(&self, host: &mut dyn Host, event: &mut ExplosionDetonateEvent<'_>) {
let _ = host;
let _ = event;
}
/// A player fills (`stack` an empty bucket) or empties a bucket at `pos`:
/// `BucketItem.use`, where it asks `Level.mayInteract`. Set `canceled`
/// and the bucket does nothing. Server-side, for every player of the
/// world (`native_acting_player` says who). API 22.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn fill_bucket(&self, host: &mut dyn Host, event: &mut FillBucketEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A player attacks the entity `entity` (`Entity.getId`) of type `kind`
/// (`minecraft:item_frame`, `minecraft:cow`, `minecraft:player`) standing
/// at `pos`: `ServerGamePacketListenerImpl.handleInteract`'s attack, once
/// in reach, where `Player.attack` starts. Set `canceled` and the blow
/// does nothing (no damage, no knockback, the frame keeps its item).
/// Server-side, for every player of the world (`native_acting_player`
/// says who). API 22.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn attack_entity(&self, host: &mut dyn Host, event: &mut AttackEntityEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A message from `player`'s client on `channel` (`mod_id:name`), within
/// the caps (`native_net.rs`): check `channel`, and treat `data` as the
/// player's own bytes, checked by nothing. Runs in the tick after it
/// arrives, with no player's state swapped in. Server-side. API 40.
fn net_from_client(&self, host: &mut dyn Host, event: &mut NetFromClientEvent<'_>) {
let _ = host;
let _ = event;
}
/// A message from the server on `channel` (`mod_id:name`), whose `data`
/// is the sender's own bytes. The window's game only. API 40.
fn net_from_server(&self, host: &mut dyn Host, event: &mut NetFromServerEvent<'_>) {
let _ = host;
let _ = event;
}
/// `player` died: where `ServerPlayer.die` starts, with the death
/// message's key when the game knows it (`death.attack.lava`; none for a
/// message it builds from the combat). It only hears. Server-side, for
/// every player of the world, whether death messages are shown or not.
/// API 40.
fn player_died(&self, host: &mut dyn Host, event: &mut PlayerDiedEvent<'_>) {
let _ = host;
let _ = event;
}
/// A new mob of `kind` joined `dimension` at `pos`: `natural` when the
/// world's spawning made it, false when something else did (a breed, a
/// raid, a spawner, a conversion, `/summon`, and the second mob of a
/// jockey the world spawned). One call a mob: a `/summon` with passengers
/// tells each. Not told of a mob loaded with its chunk, leaving a hive or
/// changing level. It only hears; the mob is already among the game's
/// mobs. Server-side. API 40.
fn mob_spawned(&self, host: &mut dyn Host, event: &mut MobSpawnedEvent<'_>) {
let _ = host;
let _ = event;
}
/// `player`'s melee blow killed the mob `entity` of `kind` (other deaths
/// aren't told yet). It only hears, after the blow landed. Server-side.
/// API 40.
fn mob_killed(&self, host: &mut dyn Host, event: &mut MobKilledEvent<'_>) {
let _ = host;
let _ = event;
}
/// `player` threw `count` of `item` (`Player.drop`: the drop key, a
/// menu's throw...), not what scatters when they die. It only hears.
/// Server-side. API 40.
fn item_dropped(&self, host: &mut dyn Host, event: &mut ItemDroppedEvent<'_>) {
let _ = host;
let _ = event;
}
/// `player` is about to take `count` of `item` from the ground
/// (`ItemEntity.playerTouch`). Set `canceled` to leave it there: the
/// stack isn't offered again for 10 ticks. Server-side. API 40.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn item_picked_up(&self, host: &mut dyn Host, event: &mut ItemPickedUpEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A player's hit landed on the mob `entity` of type `kind`
/// (`minecraft:zombie`), holding `stack`: where `Item.hurtEnemy` is called,
/// before the post-attack enchantments and the weapon's wear. It only
/// hears. Another player as the target isn't told yet. Server-side, for
/// every player of the world (the helpers read the acting one). API 39.
fn hurt_enemy(&self, host: &mut dyn Host, event: &mut HurtEnemyEvent<'_>) {
let _ = host;
let _ = event;
}
/// A server tick of the stack a player carries in `slot`: where
/// `Inventory.tick` calls `Item.inventoryTick`, for every stack, each tick,
/// `/tick freeze` included (it stops the world, not the player). `slot` is
/// as `Inventory` saves it (0 to 35; the armour 100 feet to 103 head; -106
/// the off hand), and `selected` says it is the held slot.
/// `native_carried_stack` reads and changes the stack, which stays in its
/// slot, so the item helpers see it: a count of 0 empties the slot, and the
/// player's client gets the change. This runs often, so check the item
/// first. Server-side, for every living player of the world (the helpers
/// read the acting one). API 39.
fn inventory_tick(&self, host: &mut dyn Host, event: &mut InventoryTickEvent) {
let _ = host;
let _ = event;
}
/// A player's equipment slot `slot` (`head`, `chest`, `legs`, `feet`,
/// `offhand`, and `mainhand` on a swap of the hands or `/item`) took a different
/// item, `new` (none when it was emptied): `LivingEntity.onEquipItem`,
/// before the equip sound. It only hears. Never for a spectator.
/// Server-side, for every player of the world (the helpers read the
/// acting one). API 39.
fn on_equip(&self, host: &mut dyn Host, event: &mut OnEquipEvent<'_>) {
let _ = host;
let _ = event;
}
/// The redstone signal the block `state` at `pos` gives on its `face`, the
/// side that touches the block reading it: `BlockState.getDirectSignal`
/// when `direct` (what passes through a block it touches, as a lever's
/// does), else `getSignal`. `signal` holds vanilla's answer: change it when
/// the block is yours (0 to 15; anything else is clamped). Asked very often,
/// from inside the level's update, so answer from your own state: check the
/// block first, and don't read or change the world here. When the answer
/// changes, and once the block is placed, call
/// `native_update_signal_neighbors`. Authoritative servers only. API 38.
fn block_signal(&self, level: &dyn LevelHost, event: &mut BlockSignalEvent) {
let _ = level;
let _ = event;
}
/// `BlockState.isSignalSource`: set `source` for a block of yours that
/// gives a signal, so redstone wire beside it connects to it. Authoritative
/// servers only. API 38.
fn is_signal_source(&self, level: &dyn LevelHost, event: &mut IsSignalSourceEvent) {
let _ = level;
let _ = event;
}
/// The player-health HUD rows, once a frame the HUD draws them
/// (`HealthHud::layout`, not under F1): `inputs` carries the health,
/// food, air and vehicle state the layout reads, `wi`/`hi` the screen's
/// GUI size. A mod that sets `draws` replaces every row — armour,
/// hearts, food, air and the heights (`left_height`/`right_height`)
/// above the hotbar are the answer's to give; `bubble_pop_sound` too.
/// Nothing set draws Horizon's own.
///
/// Return `Some` to set `draws`; the first mod returning `Some` wins.
fn health_hud(
&self,
host: &mut dyn Host,
event: &mut HealthHudEvent<'_>,
) -> Option<Vec<horizon_client::hud_layout::GuiDraw>> {
let _ = host;
let _ = event;
None
}
/// A player right-clicks the entity `entity` (`Entity.getId`) of type
/// `kind` (`minecraft:cow`) with `self.hand`, holding `stack` (none in an
/// empty hand): where `Player.interactOn` starts, before the entity's own
/// `interact` and the item's `interactLivingEntity`. Set `claimed` to take
/// the click: the hand swings and neither runs. Asked once per hand, as
/// vanilla tries the main hand then the off hand. Server-side, for every
/// player of the world (the helpers read the acting one). API 29.
///
/// Return `Flow::Cancel` to take it: this sets `claimed`, and later mods are skipped.
fn interact_entity(&self, host: &mut dyn Host, event: &mut InteractEntityEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A player left-clicks the block `state` at `pos`, `face` the face hit
/// (`[0, 1, 0]` is the top): where `ServerPlayerGameMode.handleBlockBreakAction`
/// takes a dig's start, after its reach, spawn protection and world border
/// checks, before `Block.attack` (a note block plays) or a creative break.
/// Set `canceled` to ignore the click: the block isn't attacked, dug or
/// broken on the server, and the player's client gets it back (its own
/// predicted crack still shows to the clicking player). Server-side, for
/// every player of the world (the helpers read the acting one). API 30.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn left_click_block(&self, host: &mut dyn Host, event: &mut LeftClickBlockEvent) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A living player's server tick ends (`ServerPlayer.tick`): once a tick
/// for every player in the world, after their digging, item use,
/// cooldowns, statistics and advancements. The helpers read that player.
/// Players still tick under `/tick freeze`; a dead player doesn't, nor
/// does one killed earlier in the same tick. API 31.
fn player_tick(&self, host: &mut dyn Host, event: &mut PlayerTickEvent) {
let _ = host;
let _ = event;
}
/// An entity joins the server level `dimension` (NeoForge's
/// `EntityJoinLevelEvent`): vanilla's `PersistentEntitySectionManager.addEntity`.
/// `loaded_from_disk` is true for an entity coming back with its chunk,
/// false for one added fresh (`addFreshEntity`: a drop, an orb, `/summon`,
/// an arrival through a portal). `entity` is its ID and `kind` its type
/// (`minecraft:item`). It is already in the level's lists, so helpers that
/// take an entity ID find it. Set `canceled` to keep it out: it is taken
/// back out as if never added, and a `/summon` of it fails. 47 tells
/// item entities and experience orbs; later APIs add other kinds, so check
/// `kind`. Server-side.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn entity_join_level(&self, host: &mut dyn Host, event: &mut EntityJoinLevelEvent<'_>) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// `LivingEntity.hurtServer`, past its guards (invulnerable, dead, fire
/// with fire resistance), is about to hurt entity `entity` of type `kind`
/// (`minecraft:zombie`, `minecraft:player`) by `amount` of `damage_type`
/// (`minecraft:fall`), from the source's `causing` entity
/// (`DamageSource.getEntity`: the shooter of an arrow) and `direct` one
/// (`getDirectEntity`: the arrow), 0 for none or not known yet
/// (docs/native-mods.md, API 50). Change `amount`, or set `canceled`,
/// and nothing of `hurtServer` itself happens (no damage, hurt sound,
/// knockback, invulnerable time, statistics or criteria); the caller acts
/// as on a refused hit, except that a canceled hit on the ender dragon
/// still counts as landed (`EnderDragon.hurt` returns true whatever
/// `reallyHurt` did: the arrow is spent, the melee effects run). It runs
/// on the thread that ticks the world (the server thread; the window's
/// in-frame): state shared with render thread hooks needs synchronising.
/// No `self`: the game is in the middle of the hit. API 50.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn living_incoming_damage(&self, event: &mut LivingIncomingDamageEvent<'_>) -> Flow {
let _ = event;
Flow::Continue
}
/// `AbstractContainerMenu.clickMenuButton(Player, int)`'s other half:
/// the acting player's cursor stack, `getCarried()`/`setCarried()`,
/// which `native_menu_button` cannot reach. Fires right after it, same
/// moment, same `pos`/`entity`/`id`; change `carried` when its id is
/// yours. On the server. API 51.
fn menu_button_v2(&self, host: &mut dyn Host, event: &mut MenuButtonV2Event<'_>) {
let _ = host;
let _ = event;
}
/// An entity leaves the server level `dimension` (NeoForge's
/// `EntityLeaveLevelEvent`): vanilla's `onTrackingEnd`, when it is removed
/// for any reason (picked up, merged, despawned, burnt, blown up, killed,
/// taken by a hopper or a mob, gone through a portal) or its chunk unloads,
/// a level closing with nobody in it included. Not for the entities still
/// loaded when the server stops, as in vanilla. `entity` is its ID and
/// `kind` its type (`minecraft:item`); it is no longer in the level's lists.
/// It only hears. 53 tells item entities and experience orbs; later
/// APIs add other kinds, so check `kind`. Server-side.
fn entity_leave_level(&self, host: &mut dyn Host, event: &mut EntityLeaveLevelEvent<'_>) {
let _ = host;
let _ = event;
}
/// Block `block`'s block entity has fluid tanks: set `fluids` when the
/// block is yours, in the container's shape — each tank's capacity in
/// millibuckets, the tanks each face reaches, and the tanks a fill may
/// reach and a drain may take. Asked once for each mod block when the
/// ticking table is built; at most 16 tanks, capacities clamped to
/// 1..=1 000 000, and tank numbers past the count are left out. The tanks'
/// contents are kept in the entity's saved compound, under `fluids`, and
/// the fluid helpers below read and write them. API 54.
///
/// Return `Some` to set `fluids`; the first mod returning `Some` wins.
fn block_entity_fluids(
&self,
host: &dyn Host,
event: &mut BlockEntityFluidsEvent<'_>,
) -> Option<ModFluidTanks> {
let _ = host;
let _ = event;
None
}
/// `MobEffect.shouldApplyEffectTickThisTick` for a content mod's effect
/// `effect` (`ruby:bleeding`), each tick a player or a mob has it, in
/// `MobEffectInstance.tickServer` before it counts down: `tick_count` is
/// the ticks left (the entity's tick count when infinite). Set `apply`
/// and `native_apply_effect_tick` follows. Server-side. API 56.
fn should_apply_effect_tick_this_tick(
&self,
host: &dyn Host,
event: &mut ShouldApplyEffectTickThisTickEvent<'_>,
) {
let _ = host;
let _ = event;
}
/// `MobEffect.applyEffectTick`: the content mod's effect `effect` acts on
/// `entity` in `dimension` (`minecraft:overworld`). Clear `keep` and the
/// effect ends now, before it counts down. `entity` is a mob's
/// `Entity.getId`, None for a player (`native_acting_player` says who).
/// It runs inside the entity's tick: a mob's world borrows the game
/// there, so the game is read-only, and it does not hold the ticking
/// mobs, nor the player's effects. Server-side. API 56.
fn apply_effect_tick(&self, host: &dyn Host, event: &mut ApplyEffectTickEvent<'_>) {
let _ = host;
let _ = event;
}
/// `MobEffect.onEffectAdded`: `LivingEntity.addEffect` gave `entity`
/// (as in `native_apply_effect_tick`) the content mod's effect `effect`,
/// which it didn't have. Server-side. API 56.
fn on_effect_added(&self, host: &mut dyn Host, event: &mut OnEffectAddedEvent<'_>) {
let _ = host;
let _ = event;
}
/// NeoForge's `MobEffectEvent.Added`, vanilla's `MobEffect.onEffectStarted`:
/// every `LivingEntity.addEffect` of the content mod's effect `effect`,
/// new or not, changed or not, after `native_on_effect_added`.
/// Server-side. API 56.
fn mob_effect_added(&self, host: &mut dyn Host, event: &mut MobEffectAddedEvent<'_>) {
let _ = host;
let _ = event;
}
/// Chunk `chunk` (`[x, z]`, in chunks) of `dimension` came into the world
/// (NeoForge's `ChunkEvent.Load`): `new` when it was just generated, false
/// when read from the save. A flat world's chunk that leaves before it's
/// first lit isn't saved, so it's generated, and new, again; one generated
/// as the players left is new when it next comes, unless the server
/// restarts first, or the level closes for being empty, which drops its
/// memory of what never saved. Its blocks and block entities are there,
/// but its saved entities join afterwards and its light may not be ready:
/// change the world from a later tick. The chunks around the spawn come
/// before `WorldOpenReady`. Not told of a chunk a client receives.
/// Server-side. API 57.
fn chunk_load(&self, host: &mut dyn Host, event: &mut ChunkLoadEvent<'_>) {
let _ = host;
let _ = event;
}
/// Chunk `chunk` of `dimension` left the world (NeoForge's
/// `ChunkEvent.Unload`), with a level that closes for being empty too. Don't
/// read its blocks. Its block entities are still there for this call, so
/// `native_with_mod_block_entity` can change one and it's saved with the
/// chunk. Not told when the world closes, which `native_world_lifecycle`
/// tells. Server-side. API 57.
fn chunk_unload(&self, host: &mut dyn Host, event: &mut ChunkUnloadEvent<'_>) {
let _ = host;
let _ = event;
}
/// `player` (`name`) joined the game (NeoForge's
/// `PlayerLoggedInEvent`): placed in the world and listed in
/// `native_server_players`, so `native_net_send_to_player` reaches them.
/// Once a join, with no player's state swapped in. Server-side. API 57.
fn player_logged_in(&self, host: &mut dyn Host, event: &mut PlayerLoggedInEvent<'_>) {
let _ = host;
let _ = event;
}
/// `player` (`name`) left the game (NeoForge's `PlayerLoggedOutEvent`), by
/// any path: a lost connection, a kick, the server stopping or failing.
/// Once for each player `native_player_logged_in` told of. They've already
/// left `native_server_players`, except when the server stops, which tells
/// before it saves, with them still listed and able to get a last message.
/// Server-side. API 57.
fn player_logged_out(&self, host: &mut dyn Host, event: &mut PlayerLoggedOutEvent<'_>) {
let _ = host;
let _ = event;
}
/// The small bar `GuiGraphicsExtractor.itemDecorations` draws under an
/// item, wherever the game shows one: `bar` arrives holding vanilla's value
/// (the damage bar, or a bundle's fullness already applied) and may be
/// replaced (width `0..=13`, colour `rgb`) or set to `None` to hide it.
/// Asked each frame a stack is drawn. Client-side. 60.
fn item_bar(&self, host: &dyn Host, event: &mut ItemBarEvent<'_>) {
let _ = host;
let _ = event;
}
/// `BlockState.hasAnalogOutputSignal`: set `output` for a block of yours
/// that comparators read (how full or far along it is, as a composter's
/// level), so they ask `native_analog_output`. Asked from inside the
/// level's update: answer from `state` alone. Authoritative servers only.
/// API 64.
///
/// Every mod gets `event.output` in order and may add, change or remove output.
fn has_analog_output(&self, level: &dyn LevelHost, event: &mut HasAnalogOutputEvent) {
let _ = level;
let _ = event;
}
/// `BlockState.getAnalogOutputSignal`: the signal a comparator reads from
/// the block `state` at `pos`, `face` the side that touches the comparator
/// (or the conductor in front of it). `output` holds vanilla's answer:
/// change it when the block is yours (0 to 15; anything else is clamped).
/// Asked only for blocks `native_has_analog_output` answered for, from
/// inside the level's update: don't change the world here. When the
/// answer changes without the block's state changing, call
/// `native_update_output_neighbors`; a change of state through
/// `native_set_block` or `native_set_block_property` (neighbour updates
/// on) tells the comparators itself, as vanilla's `Level.setBlock` does.
/// Authoritative servers only. API 64.
///
/// Every mod gets `event.output` in order and may add, change or remove output.
fn analog_output(&self, level: &dyn LevelHost, event: &mut AnalogOutputEvent) {
let _ = level;
let _ = event;
}
/// Register namespaced NBT component types before content loads.
///
/// Every mod gets `event.types` in order and may add, change or remove types.
fn component_types(&self, event: &mut ComponentTypesEvent<'_>) {
let _ = event;
}
/// `DispenserBlock.getDispenseMethod`: choose a behaviour for any item,
/// including vanilla items, on the authoritative server (not droppers).
/// Leave answer None for vanilla. Otherwise answer `(remainder, event)`:
/// a remainder of None empties the slot, `Some(stack)` replaces it (the hook
/// owns consumption: no extra item is removed afterwards). `event` is the
/// level event the dispenser plays with its smoke: 1000 the click, 1001 the
/// fail sound (`OptionalDispenseItemBehavior` without success), or 0 for
/// nothing at all (`DispenseItemBehavior.NOOP`). To drop one normally,
/// answer `(native_dispense_default(..), 1000)`. API 67.
///
/// Return `Some` to set `answer`; the first mod returning `Some` wins.
fn dispense_item(
&self,
host: &mut dyn Host,
event: &mut DispenseItemEvent<'_>,
) -> Option<NativeDispensed> {
let _ = host;
let _ = event;
None
}
/// Client-side image component for this stack's tooltip. Answer its width/height
/// in GUI pixels; finite positive dimensions reserve space after text and any
/// vanilla bundle component. None keeps the vanilla tooltip unchanged.
///
/// Return `Some` to set `size`; the first mod returning `Some` wins.
fn tooltip_component(
&self,
host: &dyn Host,
event: &mut TooltipComponentEvent<'_>,
) -> Option<[f32; 2]> {
let _ = host;
let _ = event;
None
}
/// Render the measured component at origin, inside the tooltip background.
/// Stack is the component's data. Use native_sprite/native_fill/native_text;
/// size is the measurement returned by native_tooltip_component this frame.
fn tooltip_component_draw(&self, host: &dyn Host, event: &mut TooltipComponentDrawEvent<'_>) {
let _ = host;
let _ = event;
}
/// On an authoritative server, `BlockState.canSurvive` for `state` at
/// `pos` (`BlockBehaviour.canSurvive`), before the block answers it: as
/// it is placed (`BlockItem.canPlace`), from a shape update of a block
/// whose template checks it (a plant, a torch, a sign: false breaks the
/// block with its drops), and wherever else vanilla asks. `state` may not
/// be in the world yet, so decide from `state`. Answer only for your own
/// blocks: `Some(false)` refuses the spot, `Some(true)` allows it, and
/// the block's own rule doesn't run. The level is read-only. Asked on
/// every shape update of such a block: keep it short. API 70.
///
/// Return `Some` to set `survives`; the first mod returning `Some` wins.
fn can_survive(&self, level: &dyn LevelHost, event: &mut CanSurviveEvent) -> Option<bool> {
let _ = level;
let _ = event;
None
}
/// On an authoritative server, `VegetationBlock.mayPlaceOn` for the
/// plant `state` on `ground` at `ground_pos`, before the plant answers
/// it: the blocks a mod plant (one whose template is a vanilla plant,
/// such as a crop) can stand on. Its template's `canSurvive` asks it, so
/// the plant is refused there and pops off when its ground changes to
/// one it can't stand on. Answer only for your own blocks. The level is
/// read-only. API 70.
///
/// Return `Some` to set `may`; the first mod returning `Some` wins.
fn may_place_on(&self, level: &dyn LevelHost, event: &mut MayPlaceOnEvent) -> Option<bool> {
let _ = level;
let _ = event;
None
}
/// Draw the mod block entity at `pos`, of block `block`
/// (`mymod:machine`), on this client: once a frame while it is in view
/// (vanilla's `BlockEntityRenderer.submit`: within 64 blocks, its chunk
/// faded in, and its bounds, `native_block_entity_render_bounding_box`,
/// in the frustum), when its `id` is yours. `state` is the block's state
/// (`blockEntity.getBlockState()`: read its `facing` with
/// `native_block_state_property`), `entity` holds what the server sent
/// (`native_block_entity_update_tag`). Add geometry with
/// `native_draw_quad`, `native_draw_cube`, `native_draw_block` and
/// `native_draw_item` under `draw`'s pose stack, which starts at the
/// block's lower north-west corner, in blocks; `draw` also has the partial
/// tick, the game time and the block's light. API 71.
fn block_entity_submit(&self, host: &dyn Host, event: &mut BlockEntitySubmitEvent<'_>) {
let _ = host;
let _ = event;
}
/// Where the mod block entity at `pos` draws, for culling
/// (NeoForge's `getRenderBoundingBox`): `bounds` is min x, y, z then max
/// x, y, z, in blocks from the block's lower north-west corner. It starts
/// as the block with a block of margin around it; widen it when your
/// `native_block_entity_submit` draws further (a tall shaft, a beam), or
/// set an infinite value for one never culled. Asked once a frame for each
/// within 64 blocks whose chunk is drawn. API 71.
///
/// Every mod gets `event.bounds` in order and may add, change or remove bounds.
fn block_entity_render_bounding_box(
&self,
host: &dyn Host,
event: &mut BlockEntityRenderBoundingBoxEvent<'_>,
) {
let _ = host;
let _ = event;
}
/// A block nothing in Horizon knows a `BonemealableBlock` for is about to
/// take bone meal: vanilla's `BonemealableBlock.isValidBonemealTarget`,
/// `state` the block's own state at `pos`. Answer `valid` for your own
/// blocks: the meal is used up on one as vanilla uses it up (the growth
/// particles and the sound follow, whether or not the roll below grows
/// it), from a player's `BoneMealItem.useOn`, from a dispenser and, on a
/// crop (a villager bonemeals only a `CropBlock`), from a villager. Asked
/// on both sides, as vanilla asks it on both, so a client predicts the
/// use with your answer: say no where you can only grow on a server
/// (`is_client_side`). `Some(false)` refuses the meal, even on a block
/// whose template takes it (vanilla's `growCrop` then keeps the meal);
/// left `None`, the block keeps the `BonemealableBlock` its template gives
/// it, or takes no bone meal.
/// 72.
///
/// Return `Some` to set `valid`; the first mod returning `Some` wins.
fn is_valid_bonemeal_target(
&self,
level: &dyn LevelHost,
event: &mut IsValidBonemealTargetEvent,
) -> Option<bool> {
let _ = level;
let _ = event;
None
}
/// `BonemealableBlock.isBonemealSuccess` for a block that answered
/// `native_is_valid_bonemeal_target`, after it did: set `success` to grow
/// it this time. Vanilla draws the level's random here
/// (`isBonemealSuccess(Level, RandomSource, BlockPos, BlockState)`), so
/// draw from `native_level_random` to keep vanilla's order.
/// Authoritative servers only. 72.
///
/// Every mod gets `event.success` in order and may add, change or remove success.
fn is_bonemeal_success(
&self,
level: &mut dyn LevelRandomHost,
event: &mut IsBonemealSuccessEvent,
) {
let _ = level;
let _ = event;
}
/// `BonemealableBlock.performBonemeal` for a block that answered
/// `native_is_valid_bonemeal_target` and whose `native_is_bonemeal_success`
/// said yes: grow it here, `state` its state at `pos`. The meal is used up
/// either way. Change the block with the level's
/// `native_set_block_property`, and schedule with `native_schedule_block_tick`
/// (`ticks` is the hook's). Authoritative servers only. 72.
fn perform_bonemeal(&self, level: &mut dyn LevelWriteHost, event: &mut PerformBonemealEvent) {
let _ = level;
let _ = event;
}
/// `Block.stepOn` for a mod block, on its authoritative server level.
/// No self: the simulation owns the entity during this callback.
fn block_step_on(&self, event: &mut BlockStepOnEvent<'_>) {
let _ = event;
}
/// `Block.entityInside` for each mod block touched along the entity's movement.
/// Repeated sweep hits in one contact pass are suppressed; idle overlap still fires.
fn block_entity_inside(&self, event: &mut BlockEntityInsideEvent<'_>) {
let _ = event;
}
/// `Block.fallOn` for a mod block. Change calculated damage before generic fall sounds
/// and hurt handling; zero prevents both. Creative and fall-immune entities
/// notify with zero damage and retain their immunity. Server-side only.
///
/// Every mod gets `event.damage` in order and may add, change or remove damage.
fn block_fall_on(&self, event: &mut BlockFallOnEvent<'_>) {
let _ = event;
}
/// A consumable's effect of a mod's own kind: the item's `on_consume_effects`
/// entry is of a type in a namespace of its own, and the loader kept it
/// for this call. The kind and the JSON the file wrote are here; the acting
/// player is the one consuming, and the game's own effects,
/// sounds, teleports and drops are open. An unclaimed kind does
/// nothing. API 74.
fn consume_effect(&self, host: &mut dyn Host, event: &mut ConsumeEffectEvent<'_>) {
let _ = host;
let _ = event;
}
/// A native mod's hook point (docs/native-mods.md), listed in `native-hooks.json` with the game's:
/// the loot table `id` (`minecraft:chests/simple_dungeon`, `minecraft:blocks/stone`,
/// `minecraft:entities/zombie`) as it loads, its JSON after the data packs', before anything
/// rolls it (NeoForge's `LootTableLoadEvent`, Fabric's `LootTableEvents.MODIFY`). Add pools to
/// `table["pools"]` or entries to a pool's `entries`, change or replace it (no pools: it drops
/// nothing; keep its `random_sequence` when replacing it, as a mob's table without one drops
/// nothing). Called once per table and load, in id order, wherever the tables load: the server,
/// and a client too, so make the same change each time, and don't load loot tables from here.
/// Two loads may run at once on two threads. A `/reload` or a world opened with other packs
/// may load them again, or keep the tables already loaded from the same files. API
/// 75.
///
/// Every mod gets `event.table` in order and may add, change or remove table.
fn loot_table_load(&self, event: &mut LootTableLoadEvent<'_>) {
let _ = event;
}
/// A block broke or a mob died, and `drops` are the items about to drop, in
/// the order they drop: what the loot tables rolled (after
/// `native_loot_table_load`'s changes), and for a mob what it wore, held or
/// carried (a fox's mouth item, an allay's, piglin's or horse's inventory),
/// but not an enderman's carried block or a copper golem's preserved
/// equipment, which drop after. A charged creeper's head and a fox's mouth
/// item come before the mob's own table. A block's stacks get its block
/// entity's data (a shulker box's items) after this. Add, change or take out
/// stacks; empty ones don't drop (NeoForge's global loot modifiers, Fabric's
/// `LootTableEvents.MODIFY_DROPS`); `context` says what dropped them and
/// how, and it is called even when `drops` is empty. A player's use drops
/// through it too (`NativeLootDrops::used`: shears, a brush, an item
/// frame), with that player named. It hears blocks that a
/// player, an explosion or a mob breaks, not other breaks (leaves decaying,
/// a torch losing its wall, a piston, `/setblock ... destroy`), nor a
/// creative break or a tool that can't harvest the block, nor experience.
/// Server-side, for every player. API
/// 75.
///
/// Every mod gets `event.drops` in order and may add, change or remove drops.
fn loot_drops(&self, host: &mut dyn Host, event: &mut LootDropsEvent<'_>) {
let _ = host;
let _ = event;
}
/// A block is about to take the state it is placed in
/// (`Block.getStateForPlacement(BlockPlaceContext)`), `state` the block's
/// own default state. Answer only for your blocks: put the state you want
/// in `answer` as `Some(Some(state))` — a state of that block, as vanilla
/// sets properties on its own `defaultBlockState` (another block's is
/// ignored) — or refuse the placement with `Some(None)`: the block goes
/// nowhere and the stack is kept, as vanilla's `null`. Left empty, the
/// block's own placement runs. `context` is
/// vanilla's `BlockPlaceContext` (the clicked face, the placer's rotation,
/// the clicked position, whether the clicked block is being replaced, the
/// item in hand) and `fluid` the fluid in the position the block would go
/// in, which a waterlogged block reads. Build the state from `state` with
/// `native_state_with_property`, and know whether `state` is yours with
/// `native_state_block`. It is asked for every placer that goes
/// through vanilla's placement (a player's `BlockItem.place`, a
/// dispenser's `DirectionalPlaceContext`), and the answer still takes its
/// survival and entity obstruction checks. A trait mod returns
/// `Some(Some(state))` to choose a state, `Some(None)` to refuse, or
/// `None` to leave the answer to the next mod or vanilla.
/// Authoritative servers only. 76.
///
/// Return `Some` to set `answer`; the first mod returning `Some` wins.
fn state_for_placement(
&self,
level: &dyn LevelHost,
event: &mut StateForPlacementEvent<'_>,
) -> Option<Option<BlockStateId>> {
let _ = level;
let _ = event;
None
}
/// A `minecraft:post_attack` effect of a mod's own kind, on a mob a
/// player's weapon hit: the entry says `enchanted` attacker and `affected`
/// victim, its `requirements` passed, and its `effect` names a `type` in a
/// namespace outside `minecraft:`. Told the enchantment id, the kind, the
/// `effect` JSON, the level and the mob's id (it may have just died). The
/// acting player is the one whose weapon carries the enchantment. Each
/// such entry is told once a hit, and once for each mob a sweep lands on.
/// A hit on a player, and an entry inside `minecraft:all_of`, aren't told
/// yet. An unclaimed kind does nothing. API 77.
fn enchant_effect(&self, host: &mut dyn Host, event: &mut EnchantEffectEvent<'_>) {
let _ = host;
let _ = event;
}
/// The open screen has drawn itself and its tooltips (`Screen.render`,
/// the point of `ScreenEvent.Render.Post`): draw over it with
/// `native_fill`, `native_sprite` and `native_text`, `screen.rect` being
/// its container panel (or the whole window) and `screen.id` the screen
/// it is. Once a frame on the window, never while playing with no screen;
/// `&self`, so it reads and draws only. The Win and Options screens call
/// it on their own path, after their drawing.
/// It does not fire on the title screen, which returns before its point,
/// nor for the screens drawn over gameplay after it (a server dialog, the
/// server pack, link and code-of-conduct prompts, a book, a sign editor):
/// those keep `Screen::Playing`, which it skips (the server pack prompt
/// hides an open screen too, and that screen does not fire under it),
/// and draw over what it drew, while vanilla's `ScreenEvent.Render.Post`
/// fires for them.
/// API 78.
fn screen_render_post(&self, host: &dyn Host, event: &mut ScreenRenderPostEvent<'_>) {
let _ = host;
let _ = event;
}
/// Hook point for native mods (docs/native-mods.md, listed in `native-hooks.json`
/// with those of `horizon-client/src/game/native_hooks.rs`): `components` holds
/// `item`'s default components in `items.json`'s form (`"minecraft:max_stack_size": 16`,
/// `"minecraft:food": {"nutrition": 4, "saturation": 2.4}`); insert or replace one to
/// set it, remove it to take it away (a stack size outside 1 to 99 is brought back
/// into it). Asked for every item each time the game reads
/// the defaults, from any thread, several times as resources load and again when a
/// world's data packs load: answer the same each time. Client and server each ask
/// their own mods, as NeoForge does, so both sides need the mod.
/// 79.
///
/// Every mod gets `event.components` in order and may add, change or remove components.
fn modify_default_components(&self, event: &mut ModifyDefaultComponentsEvent<'_>) {
let _ = event;
}
/// A mouse button went down over the open screen
/// (`ScreenEvent.MouseButtonPressed.Pre`, vanilla's
/// `Screen.mouseClicked`): `screen` is the screen it is, `screen.mouse`
/// where the pointer is (so there is no position of its own), `button` the
/// button's GLFW index (0 left, 1 right, 2 middle, 3 back, 4 forward; a
/// button past those is the platform's own number, which differs between
/// systems) and `modifiers` GLFW's bits (shift 1, control 2,
/// alt 4, super 8). Set `canceled` and the press goes no further: no slot,
/// no screen button, no drag, no hotbar key, no sort or header button.
/// It fires before anything the screen does with the press, on the window
/// only, and only while a screen of the game's is open (Options and the
/// pack list opened from the title screen count, with no player and no
/// `menu`). It does not fire on the title screen itself, the connect and
/// loading screens, nor for a server
/// dialog, the server pack, link and code-of-conduct prompts, a book or a
/// sign editor drawn over gameplay, nor while a world loads or saves: the
/// click there stays the game's own. A gamepad click or a click the
/// keyboard's focus sends is not the mouse and fires nothing.
/// API 80.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn screen_mouse_button_pressed_pre(
&self,
host: &dyn Host,
event: &mut ScreenMouseButtonPressedPreEvent<'_>,
) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
/// A mouse button went up over the open screen
/// (`ScreenEvent.MouseButtonReleased.Pre`, vanilla's
/// `Screen.mouseReleased`), with the same `screen`, `button` and
/// `modifiers` as `native_screen_mouse_button_pressed_pre` and fired at
/// the same point. Set `canceled` and the release goes no further: a
/// pressed slot keeps what it took and no drag, slider or scrollbar lets
/// go.
/// Cancel a release only when the press it ends was cancelled too: a
/// release the screen took ends the drag or the scroll it began, as it
/// does in vanilla, and no guard here un-cancels it. Same screens as the
/// press; a press that opened another screen ends on that one.
/// API 80.
///
/// Return `Flow::Cancel` to take it: this sets `canceled`, and later mods are skipped.
fn screen_mouse_button_released_pre(
&self,
host: &dyn Host,
event: &mut ScreenMouseButtonReleasedPreEvent<'_>,
) -> Flow {
let _ = host;
let _ = event;
Flow::Continue
}
}
/// What [`Hooks::frame`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct FrameEvent {
pub elapsed: Duration,
}
pub fn dispatch_frame(host: &mut dyn Host, mods: &[Box<dyn Hooks>], elapsed: Duration) {
let mut event = FrameEvent { elapsed };
for mod_hook in mods {
mod_hook.frame(host, &mut event);
}
}
/// What [`Hooks::tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct TickEvent {}
pub fn dispatch_tick(host: &mut dyn Host, mods: &[Box<dyn Hooks>]) {
let mut event = TickEvent {};
for mod_hook in mods {
mod_hook.tick(host, &mut event);
}
}
/// What [`Hooks::visuals`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct VisualsEvent<'a> {
pub rims: &'a mut Vec<NativeBlockRim>,
pub lights: &'a mut Vec<NativeColoredLight>,
}
pub fn dispatch_visuals(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
rims: &mut Vec<NativeBlockRim>,
lights: &mut Vec<NativeColoredLight>,
) {
let mut event = VisualsEvent { rims, lights };
for mod_hook in mods {
mod_hook.visuals(host, &mut event);
}
}
/// What [`Hooks::emissive`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct EmissiveEvent<'a> {
pub layers: &'a mut Vec<(&'static str, &'static str)>,
}
pub fn dispatch_emissive(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
layers: &mut Vec<(&'static str, &'static str)>,
) {
let mut event = EmissiveEvent { layers };
for mod_hook in mods {
mod_hook.emissive(host, &mut event);
}
}
/// What [`Hooks::world_lifecycle`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct WorldLifecycleEvent<'a> {
pub context: &'a NativeLifecycleContext,
pub phase: WorldPhase,
pub error_text: &'a str,
}
pub fn dispatch_world_lifecycle(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
context: &NativeLifecycleContext,
phase: WorldPhase,
error_text: &str,
) {
let mut event = WorldLifecycleEvent {
context,
phase,
error_text,
};
for mod_hook in mods {
mod_hook.world_lifecycle(host, &mut event);
}
}
/// What [`Hooks::server_about_to_start`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ServerAboutToStartEvent {
pub dedicated: bool,
}
pub fn dispatch_server_about_to_start(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dedicated: bool,
) {
let mut event = ServerAboutToStartEvent { dedicated };
for mod_hook in mods {
mod_hook.server_about_to_start(host, &mut event);
}
}
/// What [`Hooks::server_stopping`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ServerStoppingEvent {
pub dedicated: bool,
}
pub fn dispatch_server_stopping(host: &mut dyn Host, mods: &[Box<dyn Hooks>], dedicated: bool) {
let mut event = ServerStoppingEvent { dedicated };
for mod_hook in mods {
mod_hook.server_stopping(host, &mut event);
}
}
/// What [`Hooks::server_tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ServerTickEvent<'a> {
pub context: &'a NativeLifecycleContext,
pub phase: ServerTickPhase,
}
pub fn dispatch_server_tick(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
context: &NativeLifecycleContext,
phase: ServerTickPhase,
) {
let mut event = ServerTickEvent { context, phase };
for mod_hook in mods {
mod_hook.server_tick(host, &mut event);
}
}
/// What [`Hooks::level_tick_pre`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct LevelTickPreEvent<'a> {
pub dimension: &'a str,
}
pub fn dispatch_level_tick_pre(host: &mut dyn Host, mods: &[Box<dyn Hooks>], dimension: &str) {
let mut event = LevelTickPreEvent { dimension };
for mod_hook in mods {
mod_hook.level_tick_pre(host, &mut event);
}
}
/// What [`Hooks::level_tick_post`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct LevelTickPostEvent<'a> {
pub dimension: &'a str,
}
pub fn dispatch_level_tick_post(host: &mut dyn Host, mods: &[Box<dyn Hooks>], dimension: &str) {
let mut event = LevelTickPostEvent { dimension };
for mod_hook in mods {
mod_hook.level_tick_post(host, &mut event);
}
}
/// What [`Hooks::block_changed`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockChangedEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub old: BlockStateId,
pub new: BlockStateId,
}
pub fn dispatch_block_changed(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
old: BlockStateId,
new: BlockStateId,
) {
let mut event = BlockChangedEvent {
dimension,
pos,
old,
new,
};
for mod_hook in mods {
mod_hook.block_changed(level, &mut event);
}
}
/// What [`Hooks::neighbor_changed`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct NeighborChangedEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
pub changed: BlockId,
pub moved: bool,
}
pub fn dispatch_neighbor_changed(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
changed: BlockId,
moved: bool,
) {
let mut event = NeighborChangedEvent {
dimension,
pos,
state,
changed,
moved,
};
for mod_hook in mods {
mod_hook.neighbor_changed(level, &mut event);
}
}
/// What [`Hooks::random_tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct RandomTickEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
}
pub fn dispatch_random_tick(
level: &mut dyn LevelWriteHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
handled: &mut bool,
) {
if *handled {
return;
}
let mut event = RandomTickEvent {
dimension,
pos,
state,
};
for mod_hook in mods {
if matches!(mod_hook.random_tick(level, &mut event), Flow::Cancel) {
*handled = true;
break;
}
}
}
/// What [`Hooks::tick_block`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct TickBlockEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
}
pub fn dispatch_tick_block(
level: &mut dyn LevelWriteHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
handled: &mut bool,
) {
if *handled {
return;
}
let mut event = TickBlockEvent {
dimension,
pos,
state,
};
for mod_hook in mods {
if matches!(mod_hook.tick_block(level, &mut event), Flow::Cancel) {
*handled = true;
break;
}
}
}
/// What [`Hooks::update_shape`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct UpdateShapeEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
pub direction: Direction,
pub neighbour_pos: BlockPos,
pub neighbour: BlockStateId,
}
pub fn dispatch_update_shape(
level: &mut dyn LevelTicksHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
direction: Direction,
neighbour_pos: BlockPos,
neighbour: BlockStateId,
new: &mut Option<BlockStateId>,
) {
if new.is_some() {
return;
}
let mut event = UpdateShapeEvent {
dimension,
pos,
state,
direction,
neighbour_pos,
neighbour,
};
for mod_hook in mods {
if let Some(replacement) = mod_hook.update_shape(level, &mut event) {
*new = Some(replacement);
break;
}
}
}
/// What [`Hooks::hud`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct HudEvent<'a> {
pub batch: &'a mut HudBatch,
pub corners: &'a mut Corners,
}
pub fn dispatch_hud(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
batch: &mut HudBatch,
corners: &mut Corners,
) {
let mut event = HudEvent { batch, corners };
for mod_hook in mods {
mod_hook.hud(host, &mut event);
}
}
/// What [`Hooks::key`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct KeyEvent<'a> {
pub key: &'a str,
pub pressed: bool,
}
pub fn dispatch_key(host: &mut dyn Host, mods: &[Box<dyn Hooks>], key: &str, pressed: bool) {
let mut event = KeyEvent { key, pressed };
for mod_hook in mods {
mod_hook.key(host, &mut event);
}
}
/// What [`Hooks::wheel`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct WheelEvent {
pub steps: f32,
}
pub fn dispatch_wheel(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
steps: f32,
claimed: &mut bool,
) {
if *claimed {
return;
}
let mut event = WheelEvent { steps };
for mod_hook in mods {
if matches!(mod_hook.wheel(host, &mut event), Flow::Cancel) {
*claimed = true;
break;
}
}
}
/// What [`Hooks::command`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct CommandEvent<'a> {
pub command: &'a str,
}
pub fn dispatch_command(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
command: &str,
ran: &mut bool,
) {
if *ran {
return;
}
let mut event = CommandEvent { command };
for mod_hook in mods {
if matches!(mod_hook.command(host, &mut event), Flow::Cancel) {
*ran = true;
break;
}
}
}
/// What [`Hooks::commands`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct CommandsEvent<'a> {
pub commands: &'a mut Vec<&'static str>,
}
pub fn dispatch_commands(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
commands: &mut Vec<&'static str>,
) {
let mut event = CommandsEvent { commands };
for mod_hook in mods {
mod_hook.commands(host, &mut event);
}
}
/// What [`Hooks::zoom`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ZoomEvent {}
pub fn dispatch_zoom(host: &dyn Host, mods: &[Box<dyn Hooks>], zoom: &mut Option<NativeZoom>) {
if zoom.is_some() {
return;
}
let mut event = ZoomEvent {};
for mod_hook in mods {
if let Some(replacement) = mod_hook.zoom(host, &mut event) {
*zoom = Some(replacement);
break;
}
}
}
/// What [`Hooks::minimap`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MinimapEvent {}
pub fn dispatch_minimap(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
minimap: &mut Option<NativeMinimap>,
) {
if minimap.is_some() {
return;
}
let mut event = MinimapEvent {};
for mod_hook in mods {
if let Some(replacement) = mod_hook.minimap(host, &mut event) {
*minimap = Some(replacement);
break;
}
}
}
/// What [`Hooks::mods`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ModsEvent<'a> {
pub mods: &'a mut Vec<NativeMod>,
}
pub fn dispatch_mods(host: &mut dyn Host, mods_: &[Box<dyn Hooks>], mods: &mut Vec<NativeMod>) {
let mut event = ModsEvent { mods };
for mod_hook in mods_ {
mod_hook.mods(host, &mut event);
}
}
/// What [`Hooks::settings`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct SettingsEvent<'a> {
pub mod_id: &'a str,
pub buttons: &'a mut Vec<String>,
}
pub fn dispatch_settings(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
mod_id: &str,
buttons: &mut Vec<String>,
) {
let mut event = SettingsEvent { mod_id, buttons };
for mod_hook in mods {
mod_hook.settings(host, &mut event);
}
}
/// What [`Hooks::settings_click`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct SettingsClickEvent<'a> {
pub mod_id: &'a str,
pub button: usize,
}
pub fn dispatch_settings_click(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
mod_id: &str,
button: usize,
) {
let mut event = SettingsClickEvent { mod_id, button };
for mod_hook in mods {
mod_hook.settings_click(host, &mut event);
}
}
/// What [`Hooks::panel_event`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PanelEventEvent<'a> {
pub mod_id: &'a str,
pub event: &'a NativePanelEvent,
}
pub fn dispatch_panel_event(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
mod_id: &str,
event: &NativePanelEvent,
) {
let mut event_ = PanelEventEvent { mod_id, event };
for mod_hook in mods {
mod_hook.panel_event(host, &mut event_);
}
}
/// What [`Hooks::block_entity`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityEvent<'a> {
pub block: &'a str,
}
pub fn dispatch_block_entity(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
entity: &mut Option<(String, Compound)>,
) {
if entity.is_some() {
return;
}
let mut event = BlockEntityEvent { block };
for mod_hook in mods {
if let Some(replacement) = mod_hook.block_entity(host, &mut event) {
*entity = Some(replacement);
break;
}
}
}
/// What [`Hooks::block_entity_ticks`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityTicksEvent<'a> {
pub block: &'a str,
pub ticks: bool,
}
pub fn dispatch_block_entity_ticks(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
ticks: &mut bool,
) {
let mut event = BlockEntityTicksEvent {
block,
ticks: *ticks,
};
for mod_hook in mods {
mod_hook.block_entity_ticks(host, &mut event);
}
*ticks = event.ticks;
}
/// What [`Hooks::block_entity_tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityTickEvent<'a> {
pub pos: [i32; 3],
pub entity: &'a mut ModBlockEntity,
}
pub fn dispatch_block_entity_tick(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
entity: &mut ModBlockEntity,
) {
let mut event = BlockEntityTickEvent { pos, entity };
for mod_hook in mods {
mod_hook.block_entity_tick(host, &mut event);
}
}
/// What [`Hooks::block_entity_update_tag`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityUpdateTagEvent<'a> {
pub pos: [i32; 3],
pub entity: &'a ModBlockEntity,
}
pub fn dispatch_block_entity_update_tag(
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
entity: &ModBlockEntity,
tag: &mut Option<Compound>,
) {
if tag.is_some() {
return;
}
let mut event = BlockEntityUpdateTagEvent { pos, entity };
for mod_hook in mods {
if let Some(replacement) = mod_hook.block_entity_update_tag(&mut event) {
*tag = Some(replacement);
break;
}
}
}
/// What [`Hooks::block_entity_container`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityContainerEvent<'a> {
pub block: &'a str,
}
pub fn dispatch_block_entity_container(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
container: &mut Option<ModContainer>,
) {
if container.is_some() {
return;
}
let mut event = BlockEntityContainerEvent { block };
for mod_hook in mods {
if let Some(replacement) = mod_hook.block_entity_container(host, &mut event) {
*container = Some(replacement);
break;
}
}
}
/// What [`Hooks::screen`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ScreenEvent<'a> {
pub block: &'a str,
}
pub fn dispatch_screen(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
screen: &mut Option<NativeScreen>,
) {
if screen.is_some() {
return;
}
let mut event = ScreenEvent { block };
for mod_hook in mods {
if let Some(replacement) = mod_hook.screen(host, &mut event) {
*screen = Some(replacement);
break;
}
}
}
/// What [`Hooks::screen_draw`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ScreenDrawEvent<'a> {
pub block: &'a str,
pub data: &'a [i32],
pub batch: &'a mut HudBatch,
pub origin: [f32; 2],
}
pub fn dispatch_screen_draw(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
data: &[i32],
batch: &mut HudBatch,
origin: [f32; 2],
) {
let mut event = ScreenDrawEvent {
block,
data,
batch,
origin,
};
for mod_hook in mods {
mod_hook.screen_draw(host, &mut event);
}
}
/// What [`Hooks::screen_click`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ScreenClickEvent<'a> {
pub block: &'a str,
pub data: &'a [i32],
pub at: [f32; 2],
pub right: bool,
}
pub fn dispatch_screen_click(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
data: &[i32],
at: [f32; 2],
right: bool,
button: &mut Option<i32>,
) {
if button.is_some() {
return;
}
let mut event = ScreenClickEvent {
block,
data,
at,
right,
};
for mod_hook in mods {
if let Some(replacement) = mod_hook.screen_click(host, &mut event) {
*button = Some(replacement);
break;
}
}
}
/// What [`Hooks::screen_tooltip`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ScreenTooltipEvent<'a> {
pub block: &'a str,
pub data: &'a [i32],
pub at: [f32; 2],
pub lines: &'a mut Vec<String>,
}
pub fn dispatch_screen_tooltip(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
data: &[i32],
at: [f32; 2],
lines: &mut Vec<String>,
) {
let mut event = ScreenTooltipEvent {
block,
data,
at,
lines,
};
for mod_hook in mods {
mod_hook.screen_tooltip(host, &mut event);
}
}
/// What [`Hooks::menu_button`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MenuButtonEvent<'a> {
pub pos: [i32; 3],
pub entity: &'a mut ModBlockEntity,
pub id: i32,
}
pub fn dispatch_menu_button(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
entity: &mut ModBlockEntity,
id: i32,
) {
let mut event = MenuButtonEvent { pos, entity, id };
for mod_hook in mods {
mod_hook.menu_button(host, &mut event);
}
}
/// What [`Hooks::register_commands`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct RegisterCommandsEvent<'a> {
pub commands: &'a mut Vec<NativeCommand>,
}
pub fn dispatch_register_commands(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
commands: &mut Vec<NativeCommand>,
) {
let mut event = RegisterCommandsEvent { commands };
for mod_hook in mods {
mod_hook.register_commands(host, &mut event);
}
}
/// What [`Hooks::perform_command`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PerformCommandEvent<'a> {
pub player: &'a NativeServerPlayer,
pub command: &'a str,
}
pub fn dispatch_perform_command(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: &NativeServerPlayer,
command: &str,
ran: &mut bool,
) {
if *ran {
return;
}
let mut event = PerformCommandEvent { player, command };
for mod_hook in mods {
if matches!(mod_hook.perform_command(host, &mut event), Flow::Cancel) {
*ran = true;
break;
}
}
}
/// What [`Hooks::menu_clicked`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MenuClickedEvent {
pub uuid: u128,
pub window: i32,
pub slot: i32,
pub button: i32,
pub mode: i32,
}
pub fn dispatch_menu_clicked(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
uuid: u128,
window: i32,
slot: i32,
button: i32,
mode: i32,
) {
let mut event = MenuClickedEvent {
uuid,
window,
slot,
button,
mode,
};
for mod_hook in mods {
mod_hook.menu_clicked(host, &mut event);
}
}
/// What [`Hooks::menu_closed`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MenuClosedEvent {
pub uuid: u128,
pub window: i32,
}
pub fn dispatch_menu_closed(host: &mut dyn Host, mods: &[Box<dyn Hooks>], uuid: u128, window: i32) {
let mut event = MenuClosedEvent { uuid, window };
for mod_hook in mods {
mod_hook.menu_closed(host, &mut event);
}
}
/// What [`Hooks::tooltip`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct TooltipEvent<'a> {
pub stack: &'a ItemStack,
pub lines: &'a mut Vec<(Text, u32)>,
}
pub fn dispatch_tooltip(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
lines: &mut Vec<(Text, u32)>,
) {
let mut event = TooltipEvent { stack, lines };
for mod_hook in mods {
mod_hook.tooltip(host, &mut event);
}
}
/// What [`Hooks::use_item_on`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct UseItemOnEvent<'a> {
pub stack: &'a ItemStack,
pub pos: [i32; 3],
pub face: [i32; 3],
}
pub fn dispatch_use_item_on(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
pos: [i32; 3],
face: [i32; 3],
claimed: &mut bool,
) {
if *claimed {
return;
}
let mut event = UseItemOnEvent { stack, pos, face };
for mod_hook in mods {
if matches!(mod_hook.use_item_on(host, &mut event), Flow::Cancel) {
*claimed = true;
break;
}
}
}
/// What [`Hooks::use_item`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct UseItemEvent<'a> {
pub stack: &'a ItemStack,
}
pub fn dispatch_use_item(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
claimed: &mut bool,
) {
if *claimed {
return;
}
let mut event = UseItemEvent { stack };
for mod_hook in mods {
if matches!(mod_hook.use_item(host, &mut event), Flow::Cancel) {
*claimed = true;
break;
}
}
}
/// What [`Hooks::destroy_block`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct DestroyBlockEvent {
pub pos: [i32; 3],
pub state: BlockStateId,
}
pub fn dispatch_destroy_block(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
state: BlockStateId,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = DestroyBlockEvent { pos, state };
for mod_hook in mods {
if matches!(mod_hook.destroy_block(host, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::place_block`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PlaceBlockEvent<'a> {
pub stack: &'a ItemStack,
pub pos: [i32; 3],
pub state: BlockStateId,
}
pub fn dispatch_place_block(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
pos: [i32; 3],
state: BlockStateId,
) {
let mut event = PlaceBlockEvent { stack, pos, state };
for mod_hook in mods {
mod_hook.place_block(host, &mut event);
}
}
/// What [`Hooks::right_click_block`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct RightClickBlockEvent {
pub pos: [i32; 3],
pub face: [i32; 3],
}
pub fn dispatch_right_click_block(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
face: [i32; 3],
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = RightClickBlockEvent { pos, face };
for mod_hook in mods {
if matches!(mod_hook.right_click_block(host, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::block_spread`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockSpreadEvent<'a> {
pub dimension: LevelDimension,
pub kind: &'a str,
pub from: BlockPos,
pub to: BlockPos,
}
pub fn dispatch_block_spread(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
kind: &str,
from: BlockPos,
to: BlockPos,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = BlockSpreadEvent {
dimension,
kind,
from,
to,
};
for mod_hook in mods {
if matches!(mod_hook.block_spread(level, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::piston_move`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PistonMoveEvent<'a> {
pub dimension: LevelDimension,
pub piston: BlockPos,
pub direction: [i32; 3],
pub push: &'a [BlockPos],
pub destroy: &'a [BlockPos],
}
pub fn dispatch_piston_move(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
piston: BlockPos,
direction: [i32; 3],
push: &[BlockPos],
destroy: &[BlockPos],
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = PistonMoveEvent {
dimension,
piston,
direction,
push,
destroy,
};
for mod_hook in mods {
if matches!(mod_hook.piston_move(level, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::explosion_detonate`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ExplosionDetonateEvent<'a> {
pub dimension: &'a str,
pub center: [f64; 3],
pub blocks: &'a mut Vec<[i32; 3]>,
}
pub fn dispatch_explosion_detonate(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dimension: &str,
center: [f64; 3],
blocks: &mut Vec<[i32; 3]>,
) {
let mut event = ExplosionDetonateEvent {
dimension,
center,
blocks,
};
for mod_hook in mods {
mod_hook.explosion_detonate(host, &mut event);
}
}
/// What [`Hooks::fill_bucket`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct FillBucketEvent<'a> {
pub stack: &'a ItemStack,
pub pos: [i32; 3],
}
pub fn dispatch_fill_bucket(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
pos: [i32; 3],
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = FillBucketEvent { stack, pos };
for mod_hook in mods {
if matches!(mod_hook.fill_bucket(host, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::attack_entity`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct AttackEntityEvent<'a> {
pub entity: i32,
pub kind: &'a str,
pub pos: [f64; 3],
}
pub fn dispatch_attack_entity(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
entity: i32,
kind: &str,
pos: [f64; 3],
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = AttackEntityEvent { entity, kind, pos };
for mod_hook in mods {
if matches!(mod_hook.attack_entity(host, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::net_from_client`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct NetFromClientEvent<'a> {
pub player: u128,
pub channel: &'a str,
pub data: &'a [u8],
}
pub fn dispatch_net_from_client(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: u128,
channel: &str,
data: &[u8],
) {
let mut event = NetFromClientEvent {
player,
channel,
data,
};
for mod_hook in mods {
mod_hook.net_from_client(host, &mut event);
}
}
/// What [`Hooks::net_from_server`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct NetFromServerEvent<'a> {
pub channel: &'a str,
pub data: &'a [u8],
}
pub fn dispatch_net_from_server(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
channel: &str,
data: &[u8],
) {
let mut event = NetFromServerEvent { channel, data };
for mod_hook in mods {
mod_hook.net_from_server(host, &mut event);
}
}
/// What [`Hooks::player_died`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PlayerDiedEvent<'a> {
pub player: u128,
pub cause: Option<&'a str>,
}
pub fn dispatch_player_died(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: u128,
cause: Option<&str>,
) {
let mut event = PlayerDiedEvent { player, cause };
for mod_hook in mods {
mod_hook.player_died(host, &mut event);
}
}
/// What [`Hooks::mob_spawned`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MobSpawnedEvent<'a> {
pub dimension: &'a str,
pub kind: &'a str,
pub pos: [f64; 3],
pub natural: bool,
}
pub fn dispatch_mob_spawned(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dimension: &str,
kind: &str,
pos: [f64; 3],
natural: bool,
) {
let mut event = MobSpawnedEvent {
dimension,
kind,
pos,
natural,
};
for mod_hook in mods {
mod_hook.mob_spawned(host, &mut event);
}
}
/// What [`Hooks::mob_killed`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MobKilledEvent<'a> {
pub player: u128,
pub entity: u32,
pub kind: &'a str,
}
pub fn dispatch_mob_killed(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: u128,
entity: u32,
kind: &str,
) {
let mut event = MobKilledEvent {
player,
entity,
kind,
};
for mod_hook in mods {
mod_hook.mob_killed(host, &mut event);
}
}
/// What [`Hooks::item_dropped`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ItemDroppedEvent<'a> {
pub player: u128,
pub item: &'a str,
pub count: u32,
}
pub fn dispatch_item_dropped(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: u128,
item: &str,
count: u32,
) {
let mut event = ItemDroppedEvent {
player,
item,
count,
};
for mod_hook in mods {
mod_hook.item_dropped(host, &mut event);
}
}
/// What [`Hooks::item_picked_up`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ItemPickedUpEvent<'a> {
pub player: u128,
pub item: &'a str,
pub count: u32,
}
pub fn dispatch_item_picked_up(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: u128,
item: &str,
count: u32,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = ItemPickedUpEvent {
player,
item,
count,
};
for mod_hook in mods {
if matches!(mod_hook.item_picked_up(host, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::hurt_enemy`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct HurtEnemyEvent<'a> {
pub stack: &'a ItemStack,
pub entity: u32,
pub kind: &'a str,
}
pub fn dispatch_hurt_enemy(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
entity: u32,
kind: &str,
) {
let mut event = HurtEnemyEvent {
stack,
entity,
kind,
};
for mod_hook in mods {
mod_hook.hurt_enemy(host, &mut event);
}
}
/// What [`Hooks::inventory_tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct InventoryTickEvent {
pub slot: i32,
pub selected: bool,
}
pub fn dispatch_inventory_tick(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
slot: i32,
selected: bool,
) {
let mut event = InventoryTickEvent { slot, selected };
for mod_hook in mods {
mod_hook.inventory_tick(host, &mut event);
}
}
/// What [`Hooks::on_equip`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct OnEquipEvent<'a> {
pub slot: &'a str,
pub new: Option<&'a ItemStack>,
}
pub fn dispatch_on_equip(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
slot: &str,
new: Option<&ItemStack>,
) {
let mut event = OnEquipEvent { slot, new };
for mod_hook in mods {
mod_hook.on_equip(host, &mut event);
}
}
/// What [`Hooks::block_signal`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockSignalEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
pub face: Direction,
pub direct: bool,
pub signal: i32,
}
pub fn dispatch_block_signal(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
face: Direction,
direct: bool,
signal: &mut i32,
) {
let mut event = BlockSignalEvent {
dimension,
pos,
state,
face,
direct,
signal: *signal,
};
for mod_hook in mods {
mod_hook.block_signal(level, &mut event);
}
*signal = event.signal;
}
/// What [`Hooks::is_signal_source`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct IsSignalSourceEvent {
pub state: BlockStateId,
pub source: bool,
}
pub fn dispatch_is_signal_source(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
state: BlockStateId,
source: &mut bool,
) {
let mut event = IsSignalSourceEvent {
state,
source: *source,
};
for mod_hook in mods {
mod_hook.is_signal_source(level, &mut event);
}
*source = event.source;
}
/// What [`Hooks::health_hud`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct HealthHudEvent<'a> {
pub inputs: &'a horizon_client::hud_layout::HealthInputs,
pub wi: i32,
pub hi: i32,
}
pub fn dispatch_health_hud(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
inputs: &horizon_client::hud_layout::HealthInputs,
wi: i32,
hi: i32,
draws: &mut Option<Vec<horizon_client::hud_layout::GuiDraw>>,
) {
if draws.is_some() {
return;
}
let mut event = HealthHudEvent { inputs, wi, hi };
for mod_hook in mods {
if let Some(replacement) = mod_hook.health_hud(host, &mut event) {
*draws = Some(replacement);
break;
}
}
}
/// What [`Hooks::interact_entity`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct InteractEntityEvent<'a> {
pub entity: i32,
pub kind: &'a str,
pub stack: Option<&'a ItemStack>,
}
pub fn dispatch_interact_entity(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
entity: i32,
kind: &str,
stack: Option<&ItemStack>,
claimed: &mut bool,
) {
if *claimed {
return;
}
let mut event = InteractEntityEvent {
entity,
kind,
stack,
};
for mod_hook in mods {
if matches!(mod_hook.interact_entity(host, &mut event), Flow::Cancel) {
*claimed = true;
break;
}
}
}
/// What [`Hooks::left_click_block`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct LeftClickBlockEvent {
pub pos: [i32; 3],
pub face: [i32; 3],
pub state: BlockStateId,
}
pub fn dispatch_left_click_block(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
face: [i32; 3],
state: BlockStateId,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = LeftClickBlockEvent { pos, face, state };
for mod_hook in mods {
if matches!(mod_hook.left_click_block(host, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::player_tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PlayerTickEvent {}
pub fn dispatch_player_tick(host: &mut dyn Host, mods: &[Box<dyn Hooks>]) {
let mut event = PlayerTickEvent {};
for mod_hook in mods {
mod_hook.player_tick(host, &mut event);
}
}
/// What [`Hooks::entity_join_level`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct EntityJoinLevelEvent<'a> {
pub dimension: &'a str,
pub entity: u32,
pub kind: &'a str,
pub pos: [f64; 3],
pub loaded_from_disk: bool,
}
pub fn dispatch_entity_join_level(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dimension: &str,
entity: u32,
kind: &str,
pos: [f64; 3],
loaded_from_disk: bool,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = EntityJoinLevelEvent {
dimension,
entity,
kind,
pos,
loaded_from_disk,
};
for mod_hook in mods {
if matches!(mod_hook.entity_join_level(host, &mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::living_incoming_damage`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct LivingIncomingDamageEvent<'a> {
pub entity: i32,
pub kind: &'a str,
pub damage_type: &'a str,
pub causing: i32,
pub direct: i32,
pub amount: f32,
}
pub fn dispatch_living_incoming_damage(
mods: &[Box<dyn Hooks>],
entity: i32,
kind: &str,
damage_type: &str,
causing: i32,
direct: i32,
amount: &mut f32,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = LivingIncomingDamageEvent {
entity,
kind,
damage_type,
causing,
direct,
amount: *amount,
};
for mod_hook in mods {
if matches!(mod_hook.living_incoming_damage(&mut event), Flow::Cancel) {
*canceled = true;
break;
}
}
*amount = event.amount;
}
/// What [`Hooks::menu_button_v2`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MenuButtonV2Event<'a> {
pub pos: [i32; 3],
pub entity: &'a mut ModBlockEntity,
pub id: i32,
pub carried: &'a mut Option<ItemStack>,
}
pub fn dispatch_menu_button_v2(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
entity: &mut ModBlockEntity,
id: i32,
carried: &mut Option<ItemStack>,
) {
let mut event = MenuButtonV2Event {
pos,
entity,
id,
carried,
};
for mod_hook in mods {
mod_hook.menu_button_v2(host, &mut event);
}
}
/// What [`Hooks::entity_leave_level`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct EntityLeaveLevelEvent<'a> {
pub dimension: &'a str,
pub entity: u32,
pub kind: &'a str,
}
pub fn dispatch_entity_leave_level(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dimension: &str,
entity: u32,
kind: &str,
) {
let mut event = EntityLeaveLevelEvent {
dimension,
entity,
kind,
};
for mod_hook in mods {
mod_hook.entity_leave_level(host, &mut event);
}
}
/// What [`Hooks::block_entity_fluids`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityFluidsEvent<'a> {
pub block: &'a str,
}
pub fn dispatch_block_entity_fluids(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
block: &str,
fluids: &mut Option<ModFluidTanks>,
) {
if fluids.is_some() {
return;
}
let mut event = BlockEntityFluidsEvent { block };
for mod_hook in mods {
if let Some(replacement) = mod_hook.block_entity_fluids(host, &mut event) {
*fluids = Some(replacement);
break;
}
}
}
/// What [`Hooks::should_apply_effect_tick_this_tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ShouldApplyEffectTickThisTickEvent<'a> {
pub effect: &'a str,
pub tick_count: i32,
pub amplifier: i32,
pub apply: bool,
}
pub fn dispatch_should_apply_effect_tick_this_tick(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
effect: &str,
tick_count: i32,
amplifier: i32,
apply: &mut bool,
) {
let mut event = ShouldApplyEffectTickThisTickEvent {
effect,
tick_count,
amplifier,
apply: *apply,
};
for mod_hook in mods {
mod_hook.should_apply_effect_tick_this_tick(host, &mut event);
}
*apply = event.apply;
}
/// What [`Hooks::apply_effect_tick`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ApplyEffectTickEvent<'a> {
pub effect: &'a str,
pub dimension: &'a str,
pub entity: Option<i32>,
pub amplifier: i32,
pub keep: bool,
}
pub fn dispatch_apply_effect_tick(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
effect: &str,
dimension: &str,
entity: Option<i32>,
amplifier: i32,
keep: &mut bool,
) {
let mut event = ApplyEffectTickEvent {
effect,
dimension,
entity,
amplifier,
keep: *keep,
};
for mod_hook in mods {
mod_hook.apply_effect_tick(host, &mut event);
}
*keep = event.keep;
}
/// What [`Hooks::on_effect_added`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct OnEffectAddedEvent<'a> {
pub effect: &'a str,
pub entity: Option<i32>,
pub amplifier: i32,
}
pub fn dispatch_on_effect_added(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
effect: &str,
entity: Option<i32>,
amplifier: i32,
) {
let mut event = OnEffectAddedEvent {
effect,
entity,
amplifier,
};
for mod_hook in mods {
mod_hook.on_effect_added(host, &mut event);
}
}
/// What [`Hooks::mob_effect_added`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MobEffectAddedEvent<'a> {
pub effect: &'a str,
pub entity: Option<i32>,
pub amplifier: i32,
}
pub fn dispatch_mob_effect_added(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
effect: &str,
entity: Option<i32>,
amplifier: i32,
) {
let mut event = MobEffectAddedEvent {
effect,
entity,
amplifier,
};
for mod_hook in mods {
mod_hook.mob_effect_added(host, &mut event);
}
}
/// What [`Hooks::chunk_load`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ChunkLoadEvent<'a> {
pub dimension: &'a str,
pub chunk: [i32; 2],
pub new: bool,
}
pub fn dispatch_chunk_load(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dimension: &str,
chunk: [i32; 2],
new: bool,
) {
let mut event = ChunkLoadEvent {
dimension,
chunk,
new,
};
for mod_hook in mods {
mod_hook.chunk_load(host, &mut event);
}
}
/// What [`Hooks::chunk_unload`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ChunkUnloadEvent<'a> {
pub dimension: &'a str,
pub chunk: [i32; 2],
}
pub fn dispatch_chunk_unload(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dimension: &str,
chunk: [i32; 2],
) {
let mut event = ChunkUnloadEvent { dimension, chunk };
for mod_hook in mods {
mod_hook.chunk_unload(host, &mut event);
}
}
/// What [`Hooks::player_logged_in`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PlayerLoggedInEvent<'a> {
pub player: u128,
pub name: &'a str,
}
pub fn dispatch_player_logged_in(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: u128,
name: &str,
) {
let mut event = PlayerLoggedInEvent { player, name };
for mod_hook in mods {
mod_hook.player_logged_in(host, &mut event);
}
}
/// What [`Hooks::player_logged_out`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PlayerLoggedOutEvent<'a> {
pub player: u128,
pub name: &'a str,
}
pub fn dispatch_player_logged_out(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
player: u128,
name: &str,
) {
let mut event = PlayerLoggedOutEvent { player, name };
for mod_hook in mods {
mod_hook.player_logged_out(host, &mut event);
}
}
/// What [`Hooks::item_bar`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ItemBarEvent<'a> {
pub stack: &'a ItemStack,
pub bar: &'a mut Option<(i32, u32)>,
}
pub fn dispatch_item_bar(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
bar: &mut Option<(i32, u32)>,
) {
let mut event = ItemBarEvent { stack, bar };
for mod_hook in mods {
mod_hook.item_bar(host, &mut event);
}
}
/// What [`Hooks::has_analog_output`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct HasAnalogOutputEvent {
pub state: BlockStateId,
pub output: bool,
}
pub fn dispatch_has_analog_output(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
state: BlockStateId,
output: &mut bool,
) {
let mut event = HasAnalogOutputEvent {
state,
output: *output,
};
for mod_hook in mods {
mod_hook.has_analog_output(level, &mut event);
}
*output = event.output;
}
/// What [`Hooks::analog_output`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct AnalogOutputEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
pub face: Direction,
pub output: i32,
}
pub fn dispatch_analog_output(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
face: Direction,
output: &mut i32,
) {
let mut event = AnalogOutputEvent {
dimension,
pos,
state,
face,
output: *output,
};
for mod_hook in mods {
mod_hook.analog_output(level, &mut event);
}
*output = event.output;
}
/// What [`Hooks::component_types`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ComponentTypesEvent<'a> {
pub types: &'a mut Vec<String>,
}
pub fn dispatch_component_types(mods: &[Box<dyn Hooks>], types: &mut Vec<String>) {
let mut event = ComponentTypesEvent { types };
for mod_hook in mods {
mod_hook.component_types(&mut event);
}
}
/// What [`Hooks::dispense_item`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct DispenseItemEvent<'a> {
pub dimension: &'a str,
pub pos: [i32; 3],
pub facing: Direction,
pub stack: &'a ItemStack,
}
pub fn dispatch_dispense_item(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
dimension: &str,
pos: [i32; 3],
facing: Direction,
stack: &ItemStack,
answer: &mut Option<NativeDispensed>,
) {
if answer.is_some() {
return;
}
let mut event = DispenseItemEvent {
dimension,
pos,
facing,
stack,
};
for mod_hook in mods {
if let Some(replacement) = mod_hook.dispense_item(host, &mut event) {
*answer = Some(replacement);
break;
}
}
}
/// What [`Hooks::tooltip_component`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct TooltipComponentEvent<'a> {
pub stack: &'a ItemStack,
}
pub fn dispatch_tooltip_component(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
size: &mut Option<[f32; 2]>,
) {
if size.is_some() {
return;
}
let mut event = TooltipComponentEvent { stack };
for mod_hook in mods {
if let Some(replacement) = mod_hook.tooltip_component(host, &mut event) {
*size = Some(replacement);
break;
}
}
}
/// What [`Hooks::tooltip_component_draw`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct TooltipComponentDrawEvent<'a> {
pub stack: &'a ItemStack,
pub batch: &'a mut HudBatch,
pub origin: [f32; 2],
pub size: [f32; 2],
}
pub fn dispatch_tooltip_component_draw(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
stack: &ItemStack,
batch: &mut HudBatch,
origin: [f32; 2],
size: [f32; 2],
) {
let mut event = TooltipComponentDrawEvent {
stack,
batch,
origin,
size,
};
for mod_hook in mods {
mod_hook.tooltip_component_draw(host, &mut event);
}
}
/// What [`Hooks::can_survive`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct CanSurviveEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
}
pub fn dispatch_can_survive(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
survives: &mut Option<bool>,
) {
if survives.is_some() {
return;
}
let mut event = CanSurviveEvent {
dimension,
pos,
state,
};
for mod_hook in mods {
if let Some(replacement) = mod_hook.can_survive(level, &mut event) {
*survives = Some(replacement);
break;
}
}
}
/// What [`Hooks::may_place_on`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct MayPlaceOnEvent {
pub dimension: LevelDimension,
pub state: BlockStateId,
pub ground: BlockStateId,
pub ground_pos: BlockPos,
}
pub fn dispatch_may_place_on(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
state: BlockStateId,
ground: BlockStateId,
ground_pos: BlockPos,
may: &mut Option<bool>,
) {
if may.is_some() {
return;
}
let mut event = MayPlaceOnEvent {
dimension,
state,
ground,
ground_pos,
};
for mod_hook in mods {
if let Some(replacement) = mod_hook.may_place_on(level, &mut event) {
*may = Some(replacement);
break;
}
}
}
/// What [`Hooks::block_entity_submit`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntitySubmitEvent<'a> {
pub pos: [i32; 3],
pub block: &'a str,
pub state: BlockStateId,
pub entity: &'a ModBlockEntity,
pub draw: &'a mut BlockEntityDraw,
}
pub fn dispatch_block_entity_submit(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
block: &str,
state: BlockStateId,
entity: &ModBlockEntity,
draw: &mut BlockEntityDraw,
) {
let mut event = BlockEntitySubmitEvent {
pos,
block,
state,
entity,
draw,
};
for mod_hook in mods {
mod_hook.block_entity_submit(host, &mut event);
}
}
/// What [`Hooks::block_entity_render_bounding_box`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityRenderBoundingBoxEvent<'a> {
pub pos: [i32; 3],
pub block: &'a str,
pub state: BlockStateId,
pub entity: &'a ModBlockEntity,
pub bounds: &'a mut [f32; 6],
}
pub fn dispatch_block_entity_render_bounding_box(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
pos: [i32; 3],
block: &str,
state: BlockStateId,
entity: &ModBlockEntity,
bounds: &mut [f32; 6],
) {
let mut event = BlockEntityRenderBoundingBoxEvent {
pos,
block,
state,
entity,
bounds,
};
for mod_hook in mods {
mod_hook.block_entity_render_bounding_box(host, &mut event);
}
}
/// What [`Hooks::is_valid_bonemeal_target`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct IsValidBonemealTargetEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
}
pub fn dispatch_is_valid_bonemeal_target(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
valid: &mut Option<bool>,
) {
if valid.is_some() {
return;
}
let mut event = IsValidBonemealTargetEvent {
dimension,
pos,
state,
};
for mod_hook in mods {
if let Some(replacement) = mod_hook.is_valid_bonemeal_target(level, &mut event) {
*valid = Some(replacement);
break;
}
}
}
/// What [`Hooks::is_bonemeal_success`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct IsBonemealSuccessEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
pub success: bool,
}
pub fn dispatch_is_bonemeal_success(
level: &mut dyn LevelRandomHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
success: &mut bool,
) {
let mut event = IsBonemealSuccessEvent {
dimension,
pos,
state,
success: *success,
};
for mod_hook in mods {
mod_hook.is_bonemeal_success(level, &mut event);
}
*success = event.success;
}
/// What [`Hooks::perform_bonemeal`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct PerformBonemealEvent {
pub dimension: LevelDimension,
pub pos: BlockPos,
pub state: BlockStateId,
}
pub fn dispatch_perform_bonemeal(
level: &mut dyn LevelWriteHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
pos: BlockPos,
state: BlockStateId,
) {
let mut event = PerformBonemealEvent {
dimension,
pos,
state,
};
for mod_hook in mods {
mod_hook.perform_bonemeal(level, &mut event);
}
}
/// What [`Hooks::block_step_on`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockStepOnEvent<'a> {
pub dimension: &'a str,
pub entity: i32,
pub kind: &'a str,
pub state: BlockStateId,
pub position: [i32; 3],
}
pub fn dispatch_block_step_on(
mods: &[Box<dyn Hooks>],
dimension: &str,
entity: i32,
kind: &str,
state: BlockStateId,
position: [i32; 3],
) {
let mut event = BlockStepOnEvent {
dimension,
entity,
kind,
state,
position,
};
for mod_hook in mods {
mod_hook.block_step_on(&mut event);
}
}
/// What [`Hooks::block_entity_inside`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockEntityInsideEvent<'a> {
pub dimension: &'a str,
pub entity: i32,
pub kind: &'a str,
pub state: BlockStateId,
pub position: [i32; 3],
}
pub fn dispatch_block_entity_inside(
mods: &[Box<dyn Hooks>],
dimension: &str,
entity: i32,
kind: &str,
state: BlockStateId,
position: [i32; 3],
) {
let mut event = BlockEntityInsideEvent {
dimension,
entity,
kind,
state,
position,
};
for mod_hook in mods {
mod_hook.block_entity_inside(&mut event);
}
}
/// What [`Hooks::block_fall_on`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct BlockFallOnEvent<'a> {
pub dimension: &'a str,
pub entity: i32,
pub kind: &'a str,
pub state: BlockStateId,
pub position: [i32; 3],
pub distance: f64,
pub damage: f32,
}
pub fn dispatch_block_fall_on(
mods: &[Box<dyn Hooks>],
dimension: &str,
entity: i32,
kind: &str,
state: BlockStateId,
position: [i32; 3],
distance: f64,
damage: &mut f32,
) {
let mut event = BlockFallOnEvent {
dimension,
entity,
kind,
state,
position,
distance,
damage: *damage,
};
for mod_hook in mods {
mod_hook.block_fall_on(&mut event);
}
*damage = event.damage;
}
/// What [`Hooks::consume_effect`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ConsumeEffectEvent<'a> {
pub kind: &'a str,
pub data: &'a serde_json::Value,
}
pub fn dispatch_consume_effect(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
kind: &str,
data: &serde_json::Value,
) {
let mut event = ConsumeEffectEvent { kind, data };
for mod_hook in mods {
mod_hook.consume_effect(host, &mut event);
}
}
/// What [`Hooks::loot_table_load`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct LootTableLoadEvent<'a> {
pub id: &'a str,
pub table: &'a mut Value,
}
pub fn dispatch_loot_table_load(mods: &[Box<dyn Hooks>], id: &str, table: &mut Value) {
let mut event = LootTableLoadEvent { id, table };
for mod_hook in mods {
mod_hook.loot_table_load(&mut event);
}
}
/// What [`Hooks::loot_drops`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct LootDropsEvent<'a> {
pub context: &'a NativeLootDrops<'a>,
pub drops: &'a mut Vec<ItemStack>,
}
pub fn dispatch_loot_drops(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
context: &NativeLootDrops<'_>,
drops: &mut Vec<ItemStack>,
) {
let mut event = LootDropsEvent { context, drops };
for mod_hook in mods {
mod_hook.loot_drops(host, &mut event);
}
}
/// What [`Hooks::state_for_placement`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct StateForPlacementEvent<'a> {
pub dimension: LevelDimension,
pub state: BlockStateId,
pub context: &'a PlacementContext,
pub fluid: FluidState,
}
pub fn dispatch_state_for_placement(
level: &dyn LevelHost,
mods: &[Box<dyn Hooks>],
dimension: LevelDimension,
state: BlockStateId,
context: &PlacementContext,
fluid: FluidState,
answer: &mut Option<Option<BlockStateId>>,
) {
if answer.is_some() {
return;
}
let mut event = StateForPlacementEvent {
dimension,
state,
context,
fluid,
};
for mod_hook in mods {
if let Some(replacement) = mod_hook.state_for_placement(level, &mut event) {
*answer = Some(replacement);
break;
}
}
}
/// What [`Hooks::enchant_effect`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct EnchantEffectEvent<'a> {
pub enchantment: &'a str,
pub kind: &'a str,
pub data: &'a serde_json::Value,
pub level: u32,
pub victim: u32,
}
pub fn dispatch_enchant_effect(
host: &mut dyn Host,
mods: &[Box<dyn Hooks>],
enchantment: &str,
kind: &str,
data: &serde_json::Value,
level: u32,
victim: u32,
) {
let mut event = EnchantEffectEvent {
enchantment,
kind,
data,
level,
victim,
};
for mod_hook in mods {
mod_hook.enchant_effect(host, &mut event);
}
}
/// What [`Hooks::screen_render_post`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ScreenRenderPostEvent<'a> {
pub batch: &'a mut HudBatch,
pub screen: &'a NativeScreenView<'a>,
}
pub fn dispatch_screen_render_post(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
batch: &mut HudBatch,
screen: &NativeScreenView<'_>,
) {
let mut event = ScreenRenderPostEvent { batch, screen };
for mod_hook in mods {
mod_hook.screen_render_post(host, &mut event);
}
}
/// What [`Hooks::modify_default_components`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ModifyDefaultComponentsEvent<'a> {
pub item: &'a str,
pub components: &'a mut Map<String, Value>,
}
pub fn dispatch_modify_default_components(
mods: &[Box<dyn Hooks>],
item: &str,
components: &mut Map<String, Value>,
) {
let mut event = ModifyDefaultComponentsEvent { item, components };
for mod_hook in mods {
mod_hook.modify_default_components(&mut event);
}
}
/// What [`Hooks::screen_mouse_button_pressed_pre`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ScreenMouseButtonPressedPreEvent<'a> {
pub screen: &'a NativeScreenView<'a>,
pub button: i32,
pub modifiers: u32,
}
pub fn dispatch_screen_mouse_button_pressed_pre(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
screen: &NativeScreenView<'_>,
button: i32,
modifiers: u32,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = ScreenMouseButtonPressedPreEvent {
screen,
button,
modifiers,
};
for mod_hook in mods {
if matches!(
mod_hook.screen_mouse_button_pressed_pre(host, &mut event),
Flow::Cancel
) {
*canceled = true;
break;
}
}
}
/// What [`Hooks::screen_mouse_button_released_pre`] is told. Fields may be added: the struct is `#[non_exhaustive]`.
#[non_exhaustive]
pub struct ScreenMouseButtonReleasedPreEvent<'a> {
pub screen: &'a NativeScreenView<'a>,
pub button: i32,
pub modifiers: u32,
}
pub fn dispatch_screen_mouse_button_released_pre(
host: &dyn Host,
mods: &[Box<dyn Hooks>],
screen: &NativeScreenView<'_>,
button: i32,
modifiers: u32,
canceled: &mut bool,
) {
if *canceled {
return;
}
let mut event = ScreenMouseButtonReleasedPreEvent {
screen,
button,
modifiers,
};
for mod_hook in mods {
if matches!(
mod_hook.screen_mouse_button_released_pre(host, &mut event),
Flow::Cancel
) {
*canceled = true;
break;
}
}
}