Skip to content

Commit

Permalink
Fix: Place block on correct side
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas0008 committed Aug 17, 2024
1 parent 9474885 commit fdb94d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions pumpkin-world/src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use num_derive::FromPrimitive;

use crate::vector3::Vector3;

pub mod block_registry;

#[derive(FromPrimitive)]
Expand All @@ -11,3 +13,17 @@ pub enum BlockFace {
West,
East,
}

impl BlockFace {
pub fn to_offset(&self) -> Vector3<i32> {
match self {
BlockFace::Bottom => (0, -1, 0),
BlockFace::East => (1, 0, 0),
BlockFace::North => (0, 0, -1),
BlockFace::South => (0, 0, 1),
BlockFace::Top => (0, 1, 0),
BlockFace::West => (-1, 0, 0),
}
.into()
}
}
9 changes: 5 additions & 4 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use pumpkin_protocol::{
client::play::{
Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
CSystemChatMessge, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot,
},
server::play::{
}, position::WorldPosition, server::play::{
Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
SSetHeldItem, SSwingArm, SUseItemOn,
},
}
};
use pumpkin_text::TextComponent;
use pumpkin_world::block::BlockFace;

use crate::{
commands::{handle_command, CommandSender},
Expand Down Expand Up @@ -317,7 +317,8 @@ impl Client {

pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) {
let mut location = use_item_on.location;
location.y += 2;
let face = BlockFace::from_i32(use_item_on.face.0).unwrap();
let location = WorldPosition(location.0 + face.to_offset());
server.broadcast_packet(self, &CBlockUpdate::new(location, 11.into()));
}

Expand Down

0 comments on commit fdb94d4

Please sign in to comment.