Skip to main content

Animal

Trait Animal 

Source
pub trait Animal: AgeableMob {
Show 25 methods // Required method fn animal_base(&self) -> &AnimalBase; // Provided methods fn in_love_time(&self) -> i32 { ... } fn set_in_love_time(&self, in_love: i32) { ... } fn love_cause_uuid(&self) -> Option<Uuid> { ... } fn set_love_cause_uuid(&self, love_cause: Option<Uuid>) { ... } fn is_in_love(&self) -> bool { ... } fn can_fall_in_love(&self) -> bool { ... } fn set_in_love(&self, player: Option<&Player>) { ... } fn reset_love(&self) { ... } fn can_mate(&self, partner: &dyn Animal) -> bool { ... } fn is_food(&self, _item_stack: &ItemStack) -> bool { ... } fn base_experience_reward_animal(&self) -> i32 { ... } fn ambient_sound_interval_animal(&self) -> i32 { ... } fn animal_walk_target_value(&self, pos: BlockPos) -> f32 { ... } fn is_bright_enough_to_spawn( level: &(impl LevelReader + ?Sized), pos: BlockPos, ) -> bool where Self: Sized { ... } fn check_animal_spawn_rules( _entity_type: EntityTypeRef, level: &(impl LevelReader + ?Sized), spawn_reason: EntitySpawnReason, pos: BlockPos, _random: &mut dyn Rng, ) -> bool where Self: Sized { ... } fn play_eating_sound(&self) { ... } fn mob_interact_animal( &self, player: &Player, hand: InteractionHand, ) -> InteractionResult { ... } fn spawn_child_from_breeding( &self, world: &Arc<World>, partner: &dyn Animal, ) { ... } fn finalize_spawn_child_from_breeding( &self, world: &Arc<World>, partner: &dyn Animal, _offspring: Option<&dyn Animal>, ) { ... } fn tick_animal_love(&self) { ... } fn custom_server_ai_step_animal(&self) { ... } fn remove_when_far_away_animal(&self, _dist_sqr: f64) -> bool { ... } fn save_animal(&self, nbt: &mut NbtCompound) { ... } fn load_animal(&self, nbt: BorrowedNbtCompoundView<'_, '_>) { ... }
}
Expand description

Vanilla-shaped behavior shared by entities that extend Animal.

Required Methods§

Source

fn animal_base(&self) -> &AnimalBase

Returns shared animal runtime state.

Provided Methods§

Source

fn in_love_time(&self) -> i32

Ticks remaining in this animal’s in-love state.

Source

fn set_in_love_time(&self, in_love: i32)

Sets the ticks remaining in this animal’s in-love state.

Source

fn love_cause_uuid(&self) -> Option<Uuid>

Returns the UUID of the player who caused this animal to fall in love, if any.

Source

fn set_love_cause_uuid(&self, love_cause: Option<Uuid>)

Sets the UUID of the player who caused this animal to fall in love.

Source

fn is_in_love(&self) -> bool

Returns whether this animal is currently in love.

Source

fn can_fall_in_love(&self) -> bool

Returns whether this animal can currently be fed to fall in love.

Source

fn set_in_love(&self, player: Option<&Player>)

Sets vanilla love mode and records the player that caused it.

Source

fn reset_love(&self)

Resets vanilla love mode without clearing the stored love cause.

Source

fn can_mate(&self, partner: &dyn Animal) -> bool

Returns whether this animal and partner are eligible to breed: distinct entities of the same type, both currently in love.

Source

fn is_food(&self, _item_stack: &ItemStack) -> bool

Returns whether the stack is valid food for this animal.

Source

fn base_experience_reward_animal(&self) -> i32

Returns the base breeding experience reward: 1 to 3, randomly.

Source

fn ambient_sound_interval_animal(&self) -> i32

Returns the default ticks between ambient sounds for animals.

Source

fn animal_walk_target_value(&self, pos: BlockPos) -> f32

Returns how attractive pos is as an AI walk target: favors grass blocks, otherwise falls back to light-level pathfinding cost.

Source

fn is_bright_enough_to_spawn( level: &(impl LevelReader + ?Sized), pos: BlockPos, ) -> bool
where Self: Sized,

Returns whether light at pos is bright enough for an animal to naturally spawn.

Source

fn check_animal_spawn_rules( _entity_type: EntityTypeRef, level: &(impl LevelReader + ?Sized), spawn_reason: EntitySpawnReason, pos: BlockPos, _random: &mut dyn Rng, ) -> bool
where Self: Sized,

Returns whether an animal may naturally spawn at pos: the block below must allow animal spawning, and light must be sufficient unless the spawn reason ignores light requirements.

Source

fn play_eating_sound(&self)

Plays this animal’s vanilla eating sound.

Source

fn mob_interact_animal( &self, player: &Player, hand: InteractionHand, ) -> InteractionResult

Feeds this animal when holding valid food: triggers love mode for adults, or speeds up growth for babies; falls back to the ageable-mob interaction otherwise.

Source

fn spawn_child_from_breeding(&self, world: &Arc<World>, partner: &dyn Animal)

Creates, initializes, and inserts vanilla breeding offspring.

Source

fn finalize_spawn_child_from_breeding( &self, world: &Arc<World>, partner: &dyn Animal, _offspring: Option<&dyn Animal>, )

Applies vanilla breeding side effects after offspring creation.

Source

fn tick_animal_love(&self)

Ticks vanilla animal love state.

Source

fn custom_server_ai_step_animal(&self)

Clears this animal’s in-love state whenever its age isn’t exactly zero (adult).

Source

fn remove_when_far_away_animal(&self, _dist_sqr: f64) -> bool

Returns vanilla animal far-away despawn behavior.

Source

fn save_animal(&self, nbt: &mut NbtCompound)

Saves vanilla animal fields.

Source

fn load_animal(&self, nbt: BorrowedNbtCompoundView<'_, '_>)

Loads vanilla animal fields.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§