Skip to content

Commit

Permalink
Align entity position when spawned
Browse files Browse the repository at this point in the history
Fixes: #456.
This also fixes the issue that the spawned position is wrong and does not match the saved one
  • Loading branch information
Snowiiii committed Jan 7, 2025
1 parent f80cdf6 commit 8721576
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pumpkin/src/net/packet/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ impl Player {
let entity = &self.living_entity.entity;
let world = &entity.world;
let slot_id = inventory.get_selected();
let cursor_pos = use_item_on.cursor_pos;
let mut state_id = inventory.state_id;
let item_slot = inventory.held_item_mut();

Expand Down Expand Up @@ -853,7 +852,7 @@ impl Player {
// check if item is a spawn egg
if let Some(item_t) = get_spawn_egg(item_stack.item_id) {
should_try_decrement = self
.run_is_spawn_egg(item_t, server, location, cursor_pos, &face)
.run_is_spawn_egg(item_t, server, location, &face)
.await?;
};

Expand Down Expand Up @@ -999,17 +998,17 @@ impl Player {
item_t: String,
server: &Server,
location: WorldPosition,
cursor_pos: Vector3<f32>,
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;
let world_pos = WorldPosition(location.0 + face.to_offset());
// align position like Vanilla does
let pos = Vector3::new(
f64::from(world_pos.0.x),
f64::from(world_pos.0.x) + 0.5,
f64::from(world_pos.0.y),
f64::from(world_pos.0.z),
f64::from(world_pos.0.z) + 0.5,
);

// TODO: this should not be hardcoded
Expand All @@ -1021,9 +1020,9 @@ impl Player {
VarInt(mob.living_entity.entity.entity_id),
uuid,
VarInt((*spawn_item_name).into()),
pos.x + f64::from(cursor_pos.x),
pos.x,
pos.y,
pos.z + f64::from(cursor_pos.z),
pos.z,
10.0,
head_yaw,
opposite_yaw,
Expand Down

0 comments on commit 8721576

Please sign in to comment.