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§
Sourcefn animal_base(&self) -> &AnimalBase
fn animal_base(&self) -> &AnimalBase
Returns shared animal runtime state.
Provided Methods§
Sourcefn in_love_time(&self) -> i32
fn in_love_time(&self) -> i32
Ticks remaining in this animal’s in-love state.
Sourcefn set_in_love_time(&self, in_love: i32)
fn set_in_love_time(&self, in_love: i32)
Sets the ticks remaining in this animal’s in-love state.
Sourcefn love_cause_uuid(&self) -> Option<Uuid>
fn love_cause_uuid(&self) -> Option<Uuid>
Returns the UUID of the player who caused this animal to fall in love, if any.
Sourcefn set_love_cause_uuid(&self, love_cause: Option<Uuid>)
fn set_love_cause_uuid(&self, love_cause: Option<Uuid>)
Sets the UUID of the player who caused this animal to fall in love.
Sourcefn is_in_love(&self) -> bool
fn is_in_love(&self) -> bool
Returns whether this animal is currently in love.
Sourcefn can_fall_in_love(&self) -> bool
fn can_fall_in_love(&self) -> bool
Returns whether this animal can currently be fed to fall in love.
Sourcefn set_in_love(&self, player: Option<&Player>)
fn set_in_love(&self, player: Option<&Player>)
Sets vanilla love mode and records the player that caused it.
Sourcefn reset_love(&self)
fn reset_love(&self)
Resets vanilla love mode without clearing the stored love cause.
Sourcefn can_mate(&self, partner: &dyn Animal) -> bool
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.
Sourcefn is_food(&self, _item_stack: &ItemStack) -> bool
fn is_food(&self, _item_stack: &ItemStack) -> bool
Returns whether the stack is valid food for this animal.
Sourcefn base_experience_reward_animal(&self) -> i32
fn base_experience_reward_animal(&self) -> i32
Returns the base breeding experience reward: 1 to 3, randomly.
Sourcefn ambient_sound_interval_animal(&self) -> i32
fn ambient_sound_interval_animal(&self) -> i32
Returns the default ticks between ambient sounds for animals.
Sourcefn animal_walk_target_value(&self, pos: BlockPos) -> f32
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.
Sourcefn is_bright_enough_to_spawn(
level: &(impl LevelReader + ?Sized),
pos: BlockPos,
) -> boolwhere
Self: Sized,
fn is_bright_enough_to_spawn(
level: &(impl LevelReader + ?Sized),
pos: BlockPos,
) -> boolwhere
Self: Sized,
Returns whether light at pos is bright enough for an animal to naturally spawn.
Sourcefn check_animal_spawn_rules(
_entity_type: EntityTypeRef,
level: &(impl LevelReader + ?Sized),
spawn_reason: EntitySpawnReason,
pos: BlockPos,
_random: &mut dyn Rng,
) -> boolwhere
Self: Sized,
fn check_animal_spawn_rules(
_entity_type: EntityTypeRef,
level: &(impl LevelReader + ?Sized),
spawn_reason: EntitySpawnReason,
pos: BlockPos,
_random: &mut dyn Rng,
) -> boolwhere
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.
Sourcefn play_eating_sound(&self)
fn play_eating_sound(&self)
Plays this animal’s vanilla eating sound.
Sourcefn mob_interact_animal(
&self,
player: &Player,
hand: InteractionHand,
) -> InteractionResult
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.
Sourcefn spawn_child_from_breeding(&self, world: &Arc<World>, partner: &dyn Animal)
fn spawn_child_from_breeding(&self, world: &Arc<World>, partner: &dyn Animal)
Creates, initializes, and inserts vanilla breeding offspring.
Sourcefn finalize_spawn_child_from_breeding(
&self,
world: &Arc<World>,
partner: &dyn Animal,
_offspring: Option<&dyn Animal>,
)
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.
Sourcefn tick_animal_love(&self)
fn tick_animal_love(&self)
Ticks vanilla animal love state.
Sourcefn custom_server_ai_step_animal(&self)
fn custom_server_ai_step_animal(&self)
Clears this animal’s in-love state whenever its age isn’t exactly zero (adult).
Sourcefn remove_when_far_away_animal(&self, _dist_sqr: f64) -> bool
fn remove_when_far_away_animal(&self, _dist_sqr: f64) -> bool
Returns vanilla animal far-away despawn behavior.
Sourcefn save_animal(&self, nbt: &mut NbtCompound)
fn save_animal(&self, nbt: &mut NbtCompound)
Saves vanilla animal fields.
Sourcefn load_animal(&self, nbt: BorrowedNbtCompoundView<'_, '_>)
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".