From fdb94d43faf77fd6d6d8cfca6a9c246682c6015a Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Sat, 17 Aug 2024 20:40:18 +0200 Subject: [PATCH] Fix: Place block on correct side --- pumpkin-world/src/block/mod.rs | 16 ++++++++++++++++ pumpkin/src/client/player_packet.rs | 9 +++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pumpkin-world/src/block/mod.rs b/pumpkin-world/src/block/mod.rs index a641d0eee..6840d84d5 100644 --- a/pumpkin-world/src/block/mod.rs +++ b/pumpkin-world/src/block/mod.rs @@ -1,5 +1,7 @@ use num_derive::FromPrimitive; +use crate::vector3::Vector3; + pub mod block_registry; #[derive(FromPrimitive)] @@ -11,3 +13,17 @@ pub enum BlockFace { West, East, } + +impl BlockFace { + pub fn to_offset(&self) -> Vector3 { + 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() + } +} diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 799ed4207..cd58f8f0c 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -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}, @@ -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())); }