pub trait Leashable: Entity {
Show 26 methods
// Required method
fn leash_data(&self) -> &SyncMutex<Option<LeashData>>;
// Provided methods
fn is_leashed(&self) -> bool { ... }
fn may_be_leashed(&self) -> bool { ... }
fn leash_holder(&self) -> Option<SharedEntity> { ... }
fn leash_attachment(&self) -> Option<LeashAttachment> { ... }
fn set_delayed_leash_attachment(&self, attachment: LeashAttachment) { ... }
fn can_be_leashed(&self) -> bool { ... }
fn leash_distance_to(&self, holder: &dyn Entity) -> f64 { ... }
fn leash_snap_distance(&self) -> f64 { ... }
fn leash_elastic_distance(&self) -> f64 { ... }
fn when_leashed_to(&self, holder: &dyn Entity) { ... }
fn leash_too_far_behaviour(&self) { ... }
fn on_elastic_leash_pull(&self) { ... }
fn close_range_leash_behaviour(&self, _holder: &dyn Entity) { ... }
fn check_elastic_interactions(&self, holder: &dyn Entity) -> bool { ... }
fn apply_leash_angular_momentum(&self) -> bool { ... }
fn rotate_by_leash_angular_momentum(&self, angular_momentum: f64) { ... }
fn leash_angular_momentum(&self) -> Option<f64> { ... }
fn leash_angular_friction(&self) -> f64 { ... }
fn can_have_a_leash_attached_to(&self, holder: &dyn Entity) -> bool { ... }
fn set_leashed_to(&self, holder: &SharedEntity) -> bool { ... }
fn restore_leash_from_save(&self) { ... }
fn tick_leash(&self) { ... }
fn drop_leash(&self) { ... }
fn remove_leash(&self) { ... }
fn remove_leash_state(&self) -> Option<SharedEntity> { ... }
}Expand description
Vanilla behavior shared by entities that extend Leashable.
Leashable entities can be leashed to an entity holding a lead, or a fence holding a lead.
Required Methods§
Sourcefn leash_data(&self) -> &SyncMutex<Option<LeashData>>
fn leash_data(&self) -> &SyncMutex<Option<LeashData>>
Returns the shared leash data (if any).
Provided Methods§
Sourcefn is_leashed(&self) -> bool
fn is_leashed(&self) -> bool
Returns whether this entity is leashed.
Sourcefn may_be_leashed(&self) -> bool
fn may_be_leashed(&self) -> bool
Returns whether this entity can be leashed with respect to its leash state.
In other words, this returns false if the entity is already leashed and true if not.
See also: Leashable::can_be_leashed
Sourcefn leash_holder(&self) -> Option<SharedEntity>
fn leash_holder(&self) -> Option<SharedEntity>
Returns the entity holding this entity with a leash, if any.
fn leash_attachment(&self) -> Option<LeashAttachment>
fn set_delayed_leash_attachment(&self, attachment: LeashAttachment)
Sourcefn can_be_leashed(&self) -> bool
fn can_be_leashed(&self) -> bool
Returns whether this entity can be leashed with respect to the entity’s type or classification.
For example, mobs like dolphins and hoglins return true for this, while villagers return false.
See also: Leashable::may_be_leashed
Sourcefn leash_distance_to(&self, holder: &dyn Entity) -> f64
fn leash_distance_to(&self, holder: &dyn Entity) -> f64
Returns the distance between the bounding box’s center of the entity and that of holder.
Despite the same, this function does not check for any leash state.
Sourcefn leash_snap_distance(&self) -> f64
fn leash_snap_distance(&self) -> f64
Returns the minimum leash distance for which a leash will snap.
Sourcefn leash_elastic_distance(&self) -> f64
fn leash_elastic_distance(&self) -> f64
Returns the minimum leash distance for which a leash behaves elastically (it pulls the leashed entity towards the holder).
Sourcefn when_leashed_to(&self, holder: &dyn Entity)
fn when_leashed_to(&self, holder: &dyn Entity)
Called when this entity is leashed to holder.
Sourcefn leash_too_far_behaviour(&self)
fn leash_too_far_behaviour(&self)
Called every tick this entity’s leash is stretched too far (this entity is too far from its holder).
Sourcefn on_elastic_leash_pull(&self)
fn on_elastic_leash_pull(&self)
Called every tick this entity’s leash starts acting elastic (it pulls the leashed entity towards the holder).
Sourcefn close_range_leash_behaviour(&self, _holder: &dyn Entity)
fn close_range_leash_behaviour(&self, _holder: &dyn Entity)
Called every tick this leash is not elastic (pulling) or snappable.
Sourcefn check_elastic_interactions(&self, holder: &dyn Entity) -> bool
fn check_elastic_interactions(&self, holder: &dyn Entity) -> bool
Performs the calculations to pull this entity towards its leash holder and applies velocity to it.
Sourcefn apply_leash_angular_momentum(&self) -> bool
fn apply_leash_angular_momentum(&self) -> bool
Applies some angular momentum by the leash for rotation purposes.
Sourcefn rotate_by_leash_angular_momentum(&self, angular_momentum: f64)
fn rotate_by_leash_angular_momentum(&self, angular_momentum: f64)
Rotates this entity with the provided angular momentum value.
Sourcefn leash_angular_momentum(&self) -> Option<f64>
fn leash_angular_momentum(&self) -> Option<f64>
Returns the angular momentum experienced by this entity (if it is leashed).
Sourcefn leash_angular_friction(&self) -> f64
fn leash_angular_friction(&self) -> f64
Returns the friction multiplier for calculating the angular momentum of a leash.
This is multiplied with the base angular momentum to get the final angular momentum.
Sourcefn can_have_a_leash_attached_to(&self, holder: &dyn Entity) -> bool
fn can_have_a_leash_attached_to(&self, holder: &dyn Entity) -> bool
Returns whether this entity can have a leash attached to another. Mirrors Vanilla’s Leashable.canHaveALeashAttachedTo.
Sourcefn set_leashed_to(&self, holder: &SharedEntity) -> bool
fn set_leashed_to(&self, holder: &SharedEntity) -> bool
Sets this entity to be leashed to a holder, removing the old holder’s connection, if any.
Sourcefn restore_leash_from_save(&self)
fn restore_leash_from_save(&self)
Updates the delayed leash info to use the entity’s current context to resolve the entity’s actual leash connection (whether it be an external entity or a fence knot).
Sourcefn tick_leash(&self)
fn tick_leash(&self)
Ticks the leash holding this entity. Mirrors Vanilla’s Leashable.tickLeash.
Sourcefn drop_leash(&self)
fn drop_leash(&self)
Breaks the leash and drops a lead item. Mirrors Vanilla’s Leashable.dropLeash.
Sourcefn remove_leash(&self)
fn remove_leash(&self)
Removes the leash without dropping a lead item. Mirrors Vanilla’s Leashable.removeLeash.
Sourcefn remove_leash_state(&self) -> Option<SharedEntity>
fn remove_leash_state(&self) -> Option<SharedEntity>
Removes the leash state of this entity, returning its holder before the leash’s removal, if any.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".