pub trait Projectile: Entity + ProjectileEventSource {
Show 38 methods
// Required method
fn projectile_base(&self) -> &ProjectileBase;
// Provided methods
fn calculate_horizontal_hurt_knockback_direction(
&self,
_hurt_entity: &dyn LivingEntity,
_damage_source: &DamageSource,
) -> (f64, f64) { ... }
fn on_above_bubble_column_projectile(&self, drag_down: bool, pos: BlockPos) { ... }
fn on_inside_bubble_column_projectile(&self, drag_down: bool) { ... }
fn set_owner_uuid(&self, owner: Option<Uuid>) { ... }
fn set_owner_entity(&self, owner: Option<&SharedEntity>) { ... }
fn cache_owner_entity(&self, owner: &SharedEntity) { ... }
fn owner_uuid(&self) -> Option<Uuid> { ... }
fn get_owner(&self) -> Option<SharedEntity> { ... }
fn projectile_may_interact(&self, world: &World, pos: BlockPos) -> bool { ... }
fn may_break(&self, world: &World) -> bool { ... }
fn owned_by(&self, entity: &dyn Entity) -> bool { ... }
fn has_been_shot(&self) -> bool { ... }
fn set_has_been_shot(&self, value: bool) { ... }
fn left_owner(&self) -> bool { ... }
fn check_left_owner(&self) { ... }
fn reset_left_owner_checked(&self) { ... }
fn is_outside_owner_collision_range(&self) -> bool { ... }
fn can_hit_entity(&self, entity: &dyn Entity) -> bool { ... }
fn base_can_hit_entity(&self, entity: &dyn Entity) -> bool { ... }
fn get_movement_to_shoot(
&self,
direction: DVec3,
power: f32,
uncertainty: f32,
) -> DVec3 { ... }
fn shoot(&self, direction: DVec3, power: f32, uncertainty: f32) { ... }
fn shoot_from_rotation(
&self,
source: &dyn Entity,
x_rot: f32,
y_rot: f32,
y_offset: f32,
power: f32,
uncertainty: f32,
) { ... }
fn update_rotation(&self) { ... }
fn deflect(
&self,
deflection: ProjectileDeflection,
deflecting_entity: Option<&dyn Entity>,
new_owner: Option<EntityReference>,
by_attack: bool,
) -> bool { ... }
fn on_deflection(&self, _by_attack: bool) { ... }
fn should_bounce_on_world_border(&self) -> bool { ... }
fn get_hit_result_on_move_vector(&self) -> Option<ProjectileHit> { ... }
fn hit_target_or_deflect_self(
self: Arc<Self>,
hit: &ProjectileHit,
) -> ProjectileDeflection { ... }
fn on_hit(self: Arc<Self>, hit: &ProjectileHit) { ... }
fn projectile_on_hit(self: Arc<Self>, hit: &ProjectileHit) { ... }
fn on_hit_entity(self: Arc<Self>, _entity: &SharedEntity, _location: DVec3) { ... }
fn on_hit_block(self: Arc<Self>, hit: &ClipHitResult) { ... }
fn projectile_on_hit_block(&self, hit: &ClipHitResult) { ... }
fn hurt(&self, _world: &World, source: &DamageSource, _amount: f32) -> bool { ... }
fn projectile_base_tick(&self) { ... }
fn save_projectile(&self, nbt: &mut NbtCompound) { ... }
fn load_projectile(&self, nbt: BorrowedNbtCompoundView<'_, '_>) { ... }
}Expand description
Vanilla-shaped behavior shared by entities that extend Projectile.
Required Methods§
Sourcefn projectile_base(&self) -> &ProjectileBase
fn projectile_base(&self) -> &ProjectileBase
Returns shared projectile runtime state.
Provided Methods§
Sourcefn calculate_horizontal_hurt_knockback_direction(
&self,
_hurt_entity: &dyn LivingEntity,
_damage_source: &DamageSource,
) -> (f64, f64)
fn calculate_horizontal_hurt_knockback_direction( &self, _hurt_entity: &dyn LivingEntity, _damage_source: &DamageSource, ) -> (f64, f64)
Returns the horizontal hurt-knockback vector used for this projectile.
Sourcefn on_above_bubble_column_projectile(&self, drag_down: bool, pos: BlockPos)
fn on_above_bubble_column_projectile(&self, drag_down: bool, pos: BlockPos)
Applies bubble-column surface acceleration without clamping velocity.
Sourcefn on_inside_bubble_column_projectile(&self, drag_down: bool)
fn on_inside_bubble_column_projectile(&self, drag_down: bool)
Applies inside-bubble-column acceleration without clamping velocity.
Sourcefn set_owner_uuid(&self, owner: Option<Uuid>)
fn set_owner_uuid(&self, owner: Option<Uuid>)
Sets the persisted owner UUID and clears the live owner cache.
Sourcefn set_owner_entity(&self, owner: Option<&SharedEntity>)
fn set_owner_entity(&self, owner: Option<&SharedEntity>)
Sets the owning entity and caches its live reference.
Sourcefn cache_owner_entity(&self, owner: &SharedEntity)
fn cache_owner_entity(&self, owner: &SharedEntity)
Caches a live owner reference when it matches the saved owner UUID.
Sourcefn owner_uuid(&self) -> Option<Uuid>
fn owner_uuid(&self) -> Option<Uuid>
Returns the owner UUID, if any.
Sourcefn get_owner(&self) -> Option<SharedEntity>
fn get_owner(&self) -> Option<SharedEntity>
Resolves the cached owner, then looks up its UUID in the current domain.
Sourcefn projectile_may_interact(&self, world: &World, pos: BlockPos) -> bool
fn projectile_may_interact(&self, world: &World, pos: BlockPos) -> bool
Returns whether this projectile may interact with the block at pos:
defers to the owning player’s build permission, or the mobGriefing
rule for a non-player owner.
Sourcefn may_break(&self, world: &World) -> bool
fn may_break(&self, world: &World) -> bool
Returns whether this projectile type is allowed to break the blocks
it hits, per the mobGriefing-gated projectilesCanBreakBlocks game rule.
Sourcefn owned_by(&self, entity: &dyn Entity) -> bool
fn owned_by(&self, entity: &dyn Entity) -> bool
Returns whether entity is this projectile’s owner.
Sourcefn has_been_shot(&self) -> bool
fn has_been_shot(&self) -> bool
Returns whether this projectile has been shot, as opposed to just spawned.
Sourcefn set_has_been_shot(&self, value: bool)
fn set_has_been_shot(&self, value: bool)
Marks whether this projectile has been shot.
Sourcefn left_owner(&self) -> bool
fn left_owner(&self) -> bool
Returns whether this projectile has moved outside its owner’s collision range.
Sourcefn check_left_owner(&self)
fn check_left_owner(&self)
Updates whether this projectile has left its owner’s collision range, but only the first time it’s called each tick.
Sourcefn reset_left_owner_checked(&self)
fn reset_left_owner_checked(&self)
Resets the per-tick left-owner check flag (vanilla clears it after tick).
Sourcefn is_outside_owner_collision_range(&self) -> bool
fn is_outside_owner_collision_range(&self) -> bool
Returns whether this projectile’s expanded bounding box no longer overlaps its owner or any entity riding the same vehicle tree.
Sourcefn can_hit_entity(&self, entity: &dyn Entity) -> bool
fn can_hit_entity(&self, entity: &dyn Entity) -> bool
Returns vanilla Projectile.canHitEntity.
Use this if you don’t need to override.
Sourcefn base_can_hit_entity(&self, entity: &dyn Entity) -> bool
fn base_can_hit_entity(&self, entity: &dyn Entity) -> bool
Returns vanilla Projectile.canHitEntity.
We had to split this up, because Rust doesn’t allow for calling super trait fns (without causing unbounded recursion) for overrides, so otherwise vanilla behavior would not be achievable.
Sourcefn get_movement_to_shoot(
&self,
direction: DVec3,
power: f32,
uncertainty: f32,
) -> DVec3
fn get_movement_to_shoot( &self, direction: DVec3, power: f32, uncertainty: f32, ) -> DVec3
Returns the velocity vector for shooting toward direction at power,
with random spread scaled by uncertainty.
Sourcefn shoot(&self, direction: DVec3, power: f32, uncertainty: f32)
fn shoot(&self, direction: DVec3, power: f32, uncertainty: f32)
Sets this projectile’s velocity and facing rotation toward direction
at power, with random spread scaled by uncertainty.
Sourcefn shoot_from_rotation(
&self,
source: &dyn Entity,
x_rot: f32,
y_rot: f32,
y_offset: f32,
power: f32,
uncertainty: f32,
)
fn shoot_from_rotation( &self, source: &dyn Entity, x_rot: f32, y_rot: f32, y_offset: f32, power: f32, uncertainty: f32, )
Shoots this projectile from source’s rotation (offset by y_offset),
adding the source’s own movement on top.
Sourcefn update_rotation(&self)
fn update_rotation(&self)
Runs vanilla Projectile.updateRotation (lerped toward the movement vector).
Sourcefn deflect(
&self,
deflection: ProjectileDeflection,
deflecting_entity: Option<&dyn Entity>,
new_owner: Option<EntityReference>,
by_attack: bool,
) -> bool
fn deflect( &self, deflection: ProjectileDeflection, deflecting_entity: Option<&dyn Entity>, new_owner: Option<EntityReference>, by_attack: bool, ) -> bool
Applies a Vanilla projectile deflection.
Sourcefn on_deflection(&self, _by_attack: bool)
fn on_deflection(&self, _by_attack: bool)
Called after a successful Vanilla projectile deflection.
Sourcefn should_bounce_on_world_border(&self) -> bool
fn should_bounce_on_world_border(&self) -> bool
Returns whether this projectile bounces from the world border.
Sourcefn get_hit_result_on_move_vector(&self) -> Option<ProjectileHit>
fn get_hit_result_on_move_vector(&self) -> Option<ProjectileHit>
Casts the move vector and returns the nearest block/entity hit (vanilla
ProjectileUtil.getHitResultOnMoveVector with this::canHitEntity).
Sourcefn hit_target_or_deflect_self(
self: Arc<Self>,
hit: &ProjectileHit,
) -> ProjectileDeflection
fn hit_target_or_deflect_self( self: Arc<Self>, hit: &ProjectileHit, ) -> ProjectileDeflection
Handles a projectile hit, deflecting it off an entity or the world border instead of resolving the hit when deflection applies.
Sourcefn on_hit(self: Arc<Self>, hit: &ProjectileHit)
fn on_hit(self: Arc<Self>, hit: &ProjectileHit)
Vanilla Projectile.onHit. Subclasses override this and call
Projectile::projectile_on_hit for the base dispatch (super.onHit()).
Sourcefn projectile_on_hit(self: Arc<Self>, hit: &ProjectileHit)
fn projectile_on_hit(self: Arc<Self>, hit: &ProjectileHit)
The base Projectile.onHit dispatch to block/entity handlers. Not meant to
be overridden — override Projectile::on_hit and delegate here instead.
Sourcefn on_hit_entity(self: Arc<Self>, _entity: &SharedEntity, _location: DVec3)
fn on_hit_entity(self: Arc<Self>, _entity: &SharedEntity, _location: DVec3)
Vanilla Projectile.onHitEntity (no-op by default).
Sourcefn on_hit_block(self: Arc<Self>, hit: &ClipHitResult)
fn on_hit_block(self: Arc<Self>, hit: &ClipHitResult)
Default block-hit hook; concrete projectiles override this and call
Projectile::projectile_on_hit_block to preserve the base dispatch.
Sourcefn projectile_on_hit_block(&self, hit: &ClipHitResult)
fn projectile_on_hit_block(&self, hit: &ClipHitResult)
The base Projectile.onHitBlock implementation. Concrete projectiles
that override the hook call this to preserve the Java super dispatch.
Sourcefn hurt(&self, _world: &World, source: &DamageSource, _amount: f32) -> bool
fn hurt(&self, _world: &World, source: &DamageSource, _amount: f32) -> bool
Vanilla Projectile.hurtServer: marks hurt unless invulnerable to the
base checks, but never takes damage.
Sourcefn projectile_base_tick(&self)
fn projectile_base_tick(&self)
Vanilla Projectile.tick (the super.tick() reached from subclasses).
Sourcefn save_projectile(&self, nbt: &mut NbtCompound)
fn save_projectile(&self, nbt: &mut NbtCompound)
Saves vanilla Projectile fields (Owner, LeftOwner, HasBeenShot).
Sourcefn load_projectile(&self, nbt: BorrowedNbtCompoundView<'_, '_>)
fn load_projectile(&self, nbt: BorrowedNbtCompoundView<'_, '_>)
Loads vanilla Projectile fields (Owner, LeftOwner, HasBeenShot).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".