Skip to content

Commit

Permalink
entity: spawn with random yaw
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Jan 9, 2025
1 parent debb713 commit fcc3aae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pumpkin-util/src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub mod vector2;
pub mod vector3;
pub mod voxel_shape;

pub fn wrap_degrees(var: f32) -> f32 {
let mut var1 = var % 360.0;
pub fn wrap_degrees(degrees: f32) -> f32 {
let mut var1 = degrees % 360.0;
if var1 >= 180.0 {
var1 -= 360.0;
}
Expand Down
3 changes: 2 additions & 1 deletion pumpkin/src/entity/ai/goal/target_goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl Goal for TargetGoal {
let mob_pos = mob.living_entity.entity.pos.load();
let target_pos = target.living_entity.entity.pos.load();
let abilities = target.abilities.lock().await;
return !abilities.invulnerable && mob_pos.squared_distance_to_vec(target_pos) <= (self.range * self.range);
return !abilities.invulnerable
&& mob_pos.squared_distance_to_vec(target_pos) <= (self.range * self.range);
}
false
}
Expand Down
14 changes: 7 additions & 7 deletions pumpkin/src/net/packet/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,7 @@ impl Player {
face: &BlockFace,
) -> Result<bool, Box<dyn PumpkinError>> {
// checks if spawn egg has a corresponding entity name
if let Some(spawn_item_name) = get_entity_id(&item_t) {
let head_yaw = 10.0;
if let Some(spawn_item_id) = get_entity_id(&item_t) {
let world_pos = WorldPosition(location.0 + face.to_offset());
// align position like Vanilla does
let pos = Vector3::new(
Expand All @@ -1044,19 +1043,20 @@ impl Player {

// TODO: this should not be hardcoded
let (mob, uuid) = mob::from_type(EntityType::Zombie, server, pos, self.world()).await;
let yaw = wrap_degrees(rand::random::<f32>() * 360.0) % 360.0;
mob.living_entity.entity.set_rotation(yaw, 0.0);

let opposite_yaw = self.living_entity.entity.yaw.load() + 180.0;
server
.broadcast_packet_all(&CSpawnEntity::new(
VarInt(mob.living_entity.entity.entity_id),
uuid,
VarInt((*spawn_item_name).into()),
VarInt((*spawn_item_id).into()),
pos.x,
pos.y,
pos.z,
10.0,
head_yaw,
opposite_yaw,
0.0,
yaw,
yaw,
0.into(),
0.0,
0.0,
Expand Down

0 comments on commit fcc3aae

Please sign in to comment.