Fix: Place block on correct side

This commit is contained in:
lukas0008 2024-08-17 20:40:18 +02:00
parent 94748859c6
commit fdb94d43fa
2 changed files with 21 additions and 4 deletions

View File

@ -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<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()
}
}

View File

@ -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()));
}