Skip to main content

FluidBehavior

Trait FluidBehavior 

Source
pub trait FluidBehavior: Send + Sync {
Show 15 methods // Required methods fn fluid_type(&self) -> FluidRef; fn tick_delay(&self, world: &Arc<World>) -> i32; fn drop_off(&self, world: &Arc<World>) -> u8; fn slope_find_distance(&self, world: &Arc<World>) -> u8; fn tick( &self, world: &Arc<World>, pos: BlockPos, block_state: BlockStateId, fluid_state: FluidState, ); fn spread( &self, world: &Arc<World>, pos: BlockPos, block_state: BlockStateId, fluid_state: FluidState, ); fn can_be_replaced_with( &self, fluid_state: FluidState, world: &Arc<World>, pos: BlockPos, other_fluid: FluidRef, direction: Direction, ) -> bool; // Provided methods fn is_same(&self, other: FluidRef) -> bool { ... } fn before_destroying_block( &self, _world: &Arc<World>, _pos: BlockPos, _replaced: BlockStateId, ) { ... } fn can_convert_to_source(&self, _world: &Arc<World>) -> bool { ... } fn entity_inside( &self, world: &Arc<World>, pos: BlockPos, entity: &dyn Entity, effect_collector: &mut InsideBlockEffectCollector, ) { ... } fn explosion_resistance(&self) -> f32 { ... } fn random_tick(&self, world: &Arc<World>, pos: BlockPos) { ... } fn get_spread_delay( &self, world: &Arc<World>, _pos: BlockPos, old_state: FluidState, new_state: FluidState, ) -> i32 { ... } fn get_flow( &self, world: &Arc<World>, pos: BlockPos, fluid_state: FluidState, ) -> DVec3 { ... }
}
Expand description

Trait for fluid behavior implementations. Conceptual equivalent of Minecraft’s Fluid class.

Required Methods§

Source

fn fluid_type(&self) -> FluidRef

Gets the fluid type for this behavior.

Source

fn tick_delay(&self, world: &Arc<World>) -> i32

Gets the number of ticks between fluid updates.

Source

fn drop_off(&self, world: &Arc<World>) -> u8

Gets the amount of fluid level drop per horizontal block. Takes world because some fluids (lava) differ by dimension.

Source

fn slope_find_distance(&self, world: &Arc<World>) -> u8

Gets the slope-search distance for horizontal spread. Takes world because some fluids (lava) differ by dimension.

Source

fn tick( &self, world: &Arc<World>, pos: BlockPos, block_state: BlockStateId, fluid_state: FluidState, )

Called every tick for fluid blocks.

The block and fluid states are the live states validated by the tick caller, matching Vanilla’s Fluid.tick callback contract.

Source

fn spread( &self, world: &Arc<World>, pos: BlockPos, block_state: BlockStateId, fluid_state: FluidState, )

Called to calculate fluid spreading each tick.

Source

fn can_be_replaced_with( &self, fluid_state: FluidState, world: &Arc<World>, pos: BlockPos, other_fluid: FluidRef, direction: Direction, ) -> bool

Checks if this fluid can be replaced by another fluid. This is used to determine if a fluid can flow into a block occupied by another fluid.

Provided Methods§

Source

fn is_same(&self, other: FluidRef) -> bool

Checks if this fluid is the same type as another fluid ref.

Used to determine if fluids can flow into each other.

Override required for any fluid that has both a source and a flowing variant

Source

fn before_destroying_block( &self, _world: &Arc<World>, _pos: BlockPos, _replaced: BlockStateId, )

Called before a block is destroyed by this fluid.

Source

fn can_convert_to_source(&self, _world: &Arc<World>) -> bool

Checks if this fluid can convert to a source block at the given position.

Source

fn entity_inside( &self, world: &Arc<World>, pos: BlockPos, entity: &dyn Entity, effect_collector: &mut InsideBlockEffectCollector, )

Called when an entity is inside this fluid.

Source

fn explosion_resistance(&self) -> f32

Gets the explosion resistance of this fluid.

Source

fn random_tick(&self, world: &Arc<World>, pos: BlockPos)

Called on random tick for this fluid’s block. Used for lava fire spread.

Source

fn get_spread_delay( &self, world: &Arc<World>, _pos: BlockPos, old_state: FluidState, new_state: FluidState, ) -> i32

Returns the tick delay to use when scheduling a newly-spread block, taking into account the old and new fluid states.

Source

fn get_flow( &self, world: &Arc<World>, pos: BlockPos, fluid_state: FluidState, ) -> DVec3

Returns this fluid state’s vanilla flow vector at a position.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§