Fix: Serverbound Interact
This commit is contained in:
parent
7b9b35e437
commit
c7b3ce6391
@ -10,8 +10,8 @@ pub mod packet_decoder;
|
||||
pub mod packet_encoder;
|
||||
pub mod position;
|
||||
pub mod server;
|
||||
pub mod uuid;
|
||||
pub mod slot;
|
||||
pub mod uuid;
|
||||
|
||||
pub const CURRENT_MC_PROTOCOL: u32 = 767;
|
||||
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
use std::char::MAX;
|
||||
|
||||
use num_derive::FromPrimitive;
|
||||
use num_traits::FromPrimitive;
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{ServerPacket, VarInt};
|
||||
@ -6,19 +10,45 @@ use crate::{ServerPacket, VarInt};
|
||||
pub struct SInteract {
|
||||
pub entity_id: VarInt,
|
||||
pub typ: VarInt,
|
||||
pub target_x: Option<f32>,
|
||||
// don't ask me why, adding more values does not work :c
|
||||
pub target_position: Option<(f32, f32, f32)>,
|
||||
pub hand: Option<VarInt>,
|
||||
pub sneaking: bool,
|
||||
}
|
||||
|
||||
// TODO
|
||||
// Great job Mojang ;D
|
||||
impl ServerPacket for SInteract {
|
||||
fn read(
|
||||
bytebuf: &mut crate::bytebuf::ByteBuffer,
|
||||
) -> Result<Self, crate::bytebuf::DeserializerError> {
|
||||
let entity_id = bytebuf.get_var_int();
|
||||
let typ = bytebuf.get_var_int();
|
||||
let action = ActionType::from_i32(typ.0 as i32).unwrap();
|
||||
let target_position: Option<(f32, f32, f32)> = match action {
|
||||
ActionType::Interact => None,
|
||||
ActionType::Attack => None,
|
||||
ActionType::InteractAt => {
|
||||
Some((bytebuf.get_f32(), bytebuf.get_f32(), bytebuf.get_f32()))
|
||||
}
|
||||
};
|
||||
let hand = match action {
|
||||
ActionType::Interact => Some(bytebuf.get_var_int()),
|
||||
ActionType::Attack => None,
|
||||
ActionType::InteractAt => Some(bytebuf.get_var_int()),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
entity_id: bytebuf.get_var_int(),
|
||||
typ: bytebuf.get_var_int(),
|
||||
target_x: bytebuf.get_option(|v| v.get_f32()),
|
||||
entity_id,
|
||||
typ,
|
||||
target_position,
|
||||
hand,
|
||||
sneaking: bytebuf.get_bool(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromPrimitive, PartialEq, Eq)]
|
||||
pub enum ActionType {
|
||||
Interact,
|
||||
Attack,
|
||||
InteractAt,
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@ use pumpkin_protocol::{
|
||||
},
|
||||
position::WorldPosition,
|
||||
server::play::{
|
||||
Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
|
||||
SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
|
||||
SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn,
|
||||
Action, ActionType, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport,
|
||||
SInteract, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation,
|
||||
SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn,
|
||||
},
|
||||
};
|
||||
use pumpkin_text::TextComponent;
|
||||
@ -268,6 +268,8 @@ impl Client {
|
||||
}
|
||||
|
||||
pub fn handle_interact(&mut self, server: &mut Server, interact: SInteract) {
|
||||
let action = ActionType::from_i32(interact.typ.0).unwrap();
|
||||
if action == ActionType::Attack {
|
||||
let attacker_player = self.player.as_ref().unwrap();
|
||||
let entity_id = interact.entity_id;
|
||||
// TODO: do validation and stuff
|
||||
@ -315,6 +317,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn handle_player_action(&mut self, _server: &mut Server, player_action: SPlayerAction) {}
|
||||
|
||||
pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user