entity: spawn with random yaw
This commit is contained in:
parent
debb713f3b
commit
fcc3aaefe4
@ -6,8 +6,8 @@ pub mod vector2;
|
|||||||
pub mod vector3;
|
pub mod vector3;
|
||||||
pub mod voxel_shape;
|
pub mod voxel_shape;
|
||||||
|
|
||||||
pub fn wrap_degrees(var: f32) -> f32 {
|
pub fn wrap_degrees(degrees: f32) -> f32 {
|
||||||
let mut var1 = var % 360.0;
|
let mut var1 = degrees % 360.0;
|
||||||
if var1 >= 180.0 {
|
if var1 >= 180.0 {
|
||||||
var1 -= 360.0;
|
var1 -= 360.0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,8 @@ impl Goal for TargetGoal {
|
|||||||
let mob_pos = mob.living_entity.entity.pos.load();
|
let mob_pos = mob.living_entity.entity.pos.load();
|
||||||
let target_pos = target.living_entity.entity.pos.load();
|
let target_pos = target.living_entity.entity.pos.load();
|
||||||
let abilities = target.abilities.lock().await;
|
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
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1032,8 +1032,7 @@ impl Player {
|
|||||||
face: &BlockFace,
|
face: &BlockFace,
|
||||||
) -> Result<bool, Box<dyn PumpkinError>> {
|
) -> Result<bool, Box<dyn PumpkinError>> {
|
||||||
// checks if spawn egg has a corresponding entity name
|
// checks if spawn egg has a corresponding entity name
|
||||||
if let Some(spawn_item_name) = get_entity_id(&item_t) {
|
if let Some(spawn_item_id) = get_entity_id(&item_t) {
|
||||||
let head_yaw = 10.0;
|
|
||||||
let world_pos = WorldPosition(location.0 + face.to_offset());
|
let world_pos = WorldPosition(location.0 + face.to_offset());
|
||||||
// align position like Vanilla does
|
// align position like Vanilla does
|
||||||
let pos = Vector3::new(
|
let pos = Vector3::new(
|
||||||
@ -1044,19 +1043,20 @@ impl Player {
|
|||||||
|
|
||||||
// TODO: this should not be hardcoded
|
// TODO: this should not be hardcoded
|
||||||
let (mob, uuid) = mob::from_type(EntityType::Zombie, server, pos, self.world()).await;
|
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
|
server
|
||||||
.broadcast_packet_all(&CSpawnEntity::new(
|
.broadcast_packet_all(&CSpawnEntity::new(
|
||||||
VarInt(mob.living_entity.entity.entity_id),
|
VarInt(mob.living_entity.entity.entity_id),
|
||||||
uuid,
|
uuid,
|
||||||
VarInt((*spawn_item_name).into()),
|
VarInt((*spawn_item_id).into()),
|
||||||
pos.x,
|
pos.x,
|
||||||
pos.y,
|
pos.y,
|
||||||
pos.z,
|
pos.z,
|
||||||
10.0,
|
0.0,
|
||||||
head_yaw,
|
yaw,
|
||||||
opposite_yaw,
|
yaw,
|
||||||
0.into(),
|
0.into(),
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user