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§
Sourcefn fluid_type(&self) -> FluidRef
fn fluid_type(&self) -> FluidRef
Gets the fluid type for this behavior.
Sourcefn tick_delay(&self, world: &Arc<World>) -> i32
fn tick_delay(&self, world: &Arc<World>) -> i32
Gets the number of ticks between fluid updates.
Sourcefn drop_off(&self, world: &Arc<World>) -> u8
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.
Sourcefn slope_find_distance(&self, world: &Arc<World>) -> u8
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.
Sourcefn tick(
&self,
world: &Arc<World>,
pos: BlockPos,
block_state: BlockStateId,
fluid_state: FluidState,
)
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.
Sourcefn spread(
&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, )
Called to calculate fluid spreading each tick.
Sourcefn can_be_replaced_with(
&self,
fluid_state: FluidState,
world: &Arc<World>,
pos: BlockPos,
other_fluid: FluidRef,
direction: Direction,
) -> bool
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§
Sourcefn is_same(&self, other: FluidRef) -> bool
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
Sourcefn before_destroying_block(
&self,
_world: &Arc<World>,
_pos: BlockPos,
_replaced: BlockStateId,
)
fn before_destroying_block( &self, _world: &Arc<World>, _pos: BlockPos, _replaced: BlockStateId, )
Called before a block is destroyed by this fluid.
Sourcefn can_convert_to_source(&self, _world: &Arc<World>) -> bool
fn can_convert_to_source(&self, _world: &Arc<World>) -> bool
Checks if this fluid can convert to a source block at the given position.
Sourcefn entity_inside(
&self,
world: &Arc<World>,
pos: BlockPos,
entity: &dyn Entity,
effect_collector: &mut InsideBlockEffectCollector,
)
fn entity_inside( &self, world: &Arc<World>, pos: BlockPos, entity: &dyn Entity, effect_collector: &mut InsideBlockEffectCollector, )
Called when an entity is inside this fluid.
Sourcefn explosion_resistance(&self) -> f32
fn explosion_resistance(&self) -> f32
Gets the explosion resistance of this fluid.
Sourcefn random_tick(&self, world: &Arc<World>, pos: BlockPos)
fn random_tick(&self, world: &Arc<World>, pos: BlockPos)
Called on random tick for this fluid’s block. Used for lava fire spread.
Sourcefn get_spread_delay(
&self,
world: &Arc<World>,
_pos: BlockPos,
old_state: FluidState,
new_state: FluidState,
) -> i32
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".