Add EntityPose

This commit is contained in:
Snowiiii 2024-08-29 17:35:49 +02:00
parent 443febefdb
commit 7ed46e25a0
7 changed files with 61 additions and 25 deletions

View File

@ -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,
}
}
}

View File

@ -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,
}

View File

@ -5,14 +5,14 @@ use crate::VarInt;
#[derive(Serialize)]
#[packet(0x58)]
pub struct CSetEntityMetadata {
pub struct CSetEntityMetadata<T> {
entity_id: VarInt,
metadata: Metadata,
metadata: Metadata<T>,
end: u8,
}
impl CSetEntityMetadata {
pub fn new(entity_id: VarInt, metadata: Metadata) -> Self {
impl<T> CSetEntityMetadata<T> {
pub fn new(entity_id: VarInt, metadata: Metadata<T>) -> Self {
Self {
entity_id,
metadata,
@ -22,14 +22,14 @@ impl CSetEntityMetadata {
}
#[derive(Serialize)]
pub struct Metadata {
pub struct Metadata<T> {
index: u8,
typ: VarInt,
value: u8,
value: T,
}
impl Metadata {
pub fn new(index: u8, typ: VarInt, value: u8) -> Self {
impl<T> Metadata<T> {
pub fn new(index: u8, typ: VarInt, value: T) -> Self {
Self { index, typ, value }
}
}

View File

@ -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<Self, crate::bytebuf::DeserializerError> {
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,

View File

@ -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")]

View File

@ -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::<VarInt>::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())],
}],
),

View File

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