Skip to content

Commit

Permalink
Allow entities to damage
Browse files Browse the repository at this point in the history
  • Loading branch information
drakeerv committed Jan 31, 2025
1 parent 3e614ae commit 052677c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion pumpkin/src/command/commands/damage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ impl CommandExecutor for DamageEntityExecutor {

target
.living_entity
.damage_with_context(amount, damage_type, None, source, cause)
.damage_with_context(
amount,
damage_type,
None,
source.as_ref().map(|e| &e.living_entity.entity),
cause.as_ref().map(|e| &e.living_entity.entity),
)
.await;

sender
Expand Down
12 changes: 6 additions & 6 deletions pumpkin/src/entity/living.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::{atomic::AtomicI32, Arc};
use std::sync::atomic::AtomicI32;

use async_trait::async_trait;
use crossbeam::atomic::AtomicCell;
Expand All @@ -7,7 +7,7 @@ use pumpkin_nbt::tag::NbtTag;
use pumpkin_protocol::client::play::{CDamageEvent, CEntityStatus, CSetEntityMetadata, Metadata};
use pumpkin_util::math::vector3::Vector3;

use super::{player::Player, Entity, EntityId, NBTStorage};
use super::{Entity, EntityId, NBTStorage};

/// Represents a living entity within the game world.
///
Expand Down Expand Up @@ -75,16 +75,16 @@ impl LivingEntity {
amount: f32,
damage_type: DamageType,
position: Option<Vector3<f64>>,
source: Option<Arc<Player>>,
cause: Option<Arc<Player>>,
source: Option<&Entity>,
cause: Option<&Entity>,
) {
self.entity
.world
.broadcast_packet_all(&CDamageEvent::new(
self.entity.entity_id.into(),
damage_type.data().id.into(),
source.map(|p| p.entity_id().into()),
cause.map(|p| p.entity_id().into()),
source.map(|e| e.entity_id.into()),
cause.map(|e| e.entity_id.into()),
position,
))
.await;
Expand Down

0 comments on commit 052677c

Please sign in to comment.