Skip to main content

ResultHandler

Trait ResultHandler 

Source
pub trait ResultHandler: Send + Sync {
    // Required methods
    fn result_container(&self) -> ContainerRef;
    fn dependencies(&self) -> Vec<ContainerRef>;
    fn update_result(&self, guard: &mut ContainerLockGuard);
    fn on_result_taken(
        &self,
        guard: &mut ContainerLockGuard,
        player: &Player,
    ) -> Option<ItemStack>;
    fn is_result_valid(
        &self,
        guard: &ContainerLockGuard,
        player: &Player,
    ) -> bool;
}
Expand description

A trait for recipe handlers that update slots in containers according to recipes

Required Methods§

Source

fn result_container(&self) -> ContainerRef

The container the result is written to and read from.

ResultSlot::new derives the slot’s container from this. Menu builders reuse that exact reference for validation and locking, so handler writes and slot reads cannot target different containers.

Source

fn dependencies(&self) -> Vec<ContainerRef>

Auxiliary containers accessed while validating or taking the result.

The result container itself is already supplied by result_container and must not be repeated.

Source

fn update_result(&self, guard: &mut ContainerLockGuard)

Recalculate the result based on current inputs.

Source

fn on_result_taken( &self, guard: &mut ContainerLockGuard, player: &Player, ) -> Option<ItemStack>

Consume inputs when the result is taken. Return overflow remainders.

Source

fn is_result_valid(&self, guard: &ContainerLockGuard, player: &Player) -> bool

Whether the stored result still matches the current inputs.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: ResultHandler + ?Sized> ResultHandler for Arc<T>

Implementors§