Skip to content

Commit

Permalink
Add EntityPose
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 29, 2024
1 parent 443febe commit 7ed46e2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 25 deletions.
4 changes: 4 additions & 0 deletions pumpkin-entity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use entity_type::EntityType;
use pose::EntityPose;

pub mod entity_type;
pub mod pose;

pub type EntityId = i32;

Expand All @@ -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 {
Expand All @@ -35,6 +38,7 @@ impl Entity {
head_yaw: 0.0,
pitch: 0.0,
standing_eye_height,
pose: EntityPose::Standing,
}
}
}
22 changes: 22 additions & 0 deletions pumpkin-entity/src/pose.rs
Original file line number Diff line number Diff line change
@@ -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,
}
16 changes: 8 additions & 8 deletions pumpkin-protocol/src/client/play/c_entity_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }
}
}
6 changes: 4 additions & 2 deletions pumpkin-protocol/src/server/play/s_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions pumpkin/src/client/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")]
Expand Down
17 changes: 13 additions & 4 deletions pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())],
}],
),
Expand Down
9 changes: 3 additions & 6 deletions pumpkin/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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};

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

0 comments on commit 7ed46e2

Please sign in to comment.