From 7ed46e25a0b8729b8c959aaf987901dc1e3a4cdb Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Thu, 29 Aug 2024 17:35:49 +0200 Subject: [PATCH] Add EntityPose --- pumpkin-entity/src/lib.rs | 4 ++++ pumpkin-entity/src/pose.rs | 22 +++++++++++++++++++ .../src/client/play/c_entity_metadata.rs | 16 +++++++------- .../src/server/play/s_interact.rs | 6 +++-- pumpkin/src/client/authentication.rs | 12 +++++----- pumpkin/src/entity/player.rs | 17 ++++++++++---- pumpkin/src/main.rs | 9 +++----- 7 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 pumpkin-entity/src/pose.rs diff --git a/pumpkin-entity/src/lib.rs b/pumpkin-entity/src/lib.rs index db2b0ebad..0e1c8338a 100644 --- a/pumpkin-entity/src/lib.rs +++ b/pumpkin-entity/src/lib.rs @@ -1,6 +1,8 @@ use entity_type::EntityType; +use pose::EntityPose; pub mod entity_type; +pub mod pose; pub type EntityId = i32; @@ -18,6 +20,7 @@ pub struct Entity { pub pitch: f32, // TODO: Change this in diffrent poses pub standing_eye_height: f32, + pub pose: EntityPose, } impl Entity { @@ -35,6 +38,7 @@ impl Entity { head_yaw: 0.0, pitch: 0.0, standing_eye_height, + pose: EntityPose::Standing, } } } diff --git a/pumpkin-entity/src/pose.rs b/pumpkin-entity/src/pose.rs new file mode 100644 index 000000000..c750821cc --- /dev/null +++ b/pumpkin-entity/src/pose.rs @@ -0,0 +1,22 @@ +#[derive(Clone, Copy)] +#[repr(i32)] +pub enum EntityPose { + Standing = 0, + FallFlying, + Sleeping, + Swimming, + SpinAttack, + Crouching, + LongJumping, + Dying, + Croaking, + UsingTongue, + Sitting, + Roaring, + Sniffing, + Emerging, + Digging, + Sliding, + Shooting, + Inhaling, +} diff --git a/pumpkin-protocol/src/client/play/c_entity_metadata.rs b/pumpkin-protocol/src/client/play/c_entity_metadata.rs index 82c8c1931..64d382938 100644 --- a/pumpkin-protocol/src/client/play/c_entity_metadata.rs +++ b/pumpkin-protocol/src/client/play/c_entity_metadata.rs @@ -5,14 +5,14 @@ use crate::VarInt; #[derive(Serialize)] #[packet(0x58)] -pub struct CSetEntityMetadata { +pub struct CSetEntityMetadata { entity_id: VarInt, - metadata: Metadata, + metadata: Metadata, end: u8, } -impl CSetEntityMetadata { - pub fn new(entity_id: VarInt, metadata: Metadata) -> Self { +impl CSetEntityMetadata { + pub fn new(entity_id: VarInt, metadata: Metadata) -> Self { Self { entity_id, metadata, @@ -22,14 +22,14 @@ impl CSetEntityMetadata { } #[derive(Serialize)] -pub struct Metadata { +pub struct Metadata { index: u8, typ: VarInt, - value: u8, + value: T, } -impl Metadata { - pub fn new(index: u8, typ: VarInt, value: u8) -> Self { +impl Metadata { + pub fn new(index: u8, typ: VarInt, value: T) -> Self { Self { index, typ, value } } } diff --git a/pumpkin-protocol/src/server/play/s_interact.rs b/pumpkin-protocol/src/server/play/s_interact.rs index 2ad5b496a..18e651163 100644 --- a/pumpkin-protocol/src/server/play/s_interact.rs +++ b/pumpkin-protocol/src/server/play/s_interact.rs @@ -2,7 +2,7 @@ use num_derive::FromPrimitive; use num_traits::FromPrimitive; use pumpkin_macros::packet; -use crate::{ServerPacket, VarInt}; +use crate::{bytebuf::DeserializerError, ServerPacket, VarInt}; #[packet(0x16)] pub struct SInteract { @@ -20,7 +20,9 @@ impl ServerPacket for SInteract { ) -> Result { let entity_id = bytebuf.get_var_int(); let typ = bytebuf.get_var_int(); - let action = ActionType::from_i32(typ.0).unwrap(); + let action = ActionType::from_i32(typ.0).ok_or(DeserializerError::Message( + "invalid action type".to_string(), + ))?; let target_position: Option<(f32, f32, f32)> = match action { ActionType::Interact => None, ActionType::Attack => None, diff --git a/pumpkin/src/client/authentication.rs b/pumpkin/src/client/authentication.rs index e4aa33996..d841756a3 100644 --- a/pumpkin/src/client/authentication.rs +++ b/pumpkin/src/client/authentication.rs @@ -59,16 +59,16 @@ pub async fn authenticate( .authentication .prevent_proxy_connections { - let test = format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}&ip={ip}"); - dbg!(&test); - test + format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}&ip={ip}") } else { format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}") }; - let response = server + let auth_client = server .auth_client .as_ref() - .unwrap() + .ok_or(AuthError::MissingAuthClient)?; + + let response = auth_client .get(address) .send() .await @@ -109,6 +109,8 @@ pub fn is_texture_url_valid(url: Url, config: &TextureConfig) -> bool { #[derive(Error, Debug)] pub enum AuthError { + #[error("Missing auth client")] + MissingAuthClient, #[error("Authentication servers are down")] FailedResponse, #[error("Failed to verify username")] diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index de433a9bd..970c22b0a 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -3,13 +3,13 @@ use std::str::FromStr; use num_derive::{FromPrimitive, ToPrimitive}; use num_traits::ToPrimitive; use pumpkin_core::text::TextComponent; -use pumpkin_entity::{entity_type::EntityType, Entity, EntityId}; +use pumpkin_entity::{entity_type::EntityType, pose::EntityPose, Entity, EntityId}; use pumpkin_inventory::player::PlayerInventory; use pumpkin_protocol::{ bytebuf::{packet_id::Packet, DeserializerError}, client::play::{ - CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSyncPlayerPosition, - CSystemChatMessage, PlayerAction, + CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSetEntityMetadata, + CSyncPlayerPosition, CSystemChatMessage, Metadata, PlayerAction, }, position::WorldPosition, server::play::{ @@ -167,6 +167,15 @@ impl Player { )); } + pub fn set_pose(&mut self, pose: EntityPose) { + self.entity.pose = pose; + let pose = self.entity.pose as i32; + self.client.send_packet(&CSetEntityMetadata::::new( + self.entity_id().into(), + Metadata::new(6, 10.into(), (pose).into()), + )) + } + pub fn teleport(&mut self, x: f64, y: f64, z: f64, yaw: f32, pitch: f32) { // this is the ultra special magic code used to create the teleport id self.teleport_id_count += 1; @@ -243,7 +252,7 @@ impl Player { &CPlayerInfoUpdate::new( 0x04, &[pumpkin_protocol::client::play::Player { - uuid: self.client.gameprofile.as_ref().unwrap().id, + uuid: self.gameprofile.id, actions: vec![PlayerAction::UpdateGameMode((self.gamemode as i32).into())], }], ), diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 69070306b..1a8aaa1e9 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -1,6 +1,9 @@ #![allow(clippy::await_holding_refcell_ref)] #![allow(clippy::await_holding_lock)] +#[cfg(target_os = "wasi")] +compile_error!("Compiling for WASI targets is not supported!"); + use mio::net::TcpListener; use mio::{Events, Interest, Poll, Token}; use std::io::{self}; @@ -26,7 +29,6 @@ pub mod rcon; pub mod server; pub mod util; -#[cfg(not(target_os = "wasi"))] fn main() -> io::Result<()> { use std::sync::{Arc, Mutex}; @@ -227,8 +229,3 @@ fn next(current: &mut Token) -> Token { current.0 += 1; Token(next) } - -#[cfg(target_os = "wasi")] -fn main() { - panic!("can't bind to an address with wasi") -}