Add EntityPose
This commit is contained in:
parent
443febefdb
commit
7ed46e25a0
@ -1,6 +1,8 @@
|
|||||||
use entity_type::EntityType;
|
use entity_type::EntityType;
|
||||||
|
use pose::EntityPose;
|
||||||
|
|
||||||
pub mod entity_type;
|
pub mod entity_type;
|
||||||
|
pub mod pose;
|
||||||
|
|
||||||
pub type EntityId = i32;
|
pub type EntityId = i32;
|
||||||
|
|
||||||
@ -18,6 +20,7 @@ pub struct Entity {
|
|||||||
pub pitch: f32,
|
pub pitch: f32,
|
||||||
// TODO: Change this in diffrent poses
|
// TODO: Change this in diffrent poses
|
||||||
pub standing_eye_height: f32,
|
pub standing_eye_height: f32,
|
||||||
|
pub pose: EntityPose,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity {
|
impl Entity {
|
||||||
@ -35,6 +38,7 @@ impl Entity {
|
|||||||
head_yaw: 0.0,
|
head_yaw: 0.0,
|
||||||
pitch: 0.0,
|
pitch: 0.0,
|
||||||
standing_eye_height,
|
standing_eye_height,
|
||||||
|
pose: EntityPose::Standing,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
pumpkin-entity/src/pose.rs
Normal file
22
pumpkin-entity/src/pose.rs
Normal 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,
|
||||||
|
}
|
||||||
@ -5,14 +5,14 @@ use crate::VarInt;
|
|||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[packet(0x58)]
|
#[packet(0x58)]
|
||||||
pub struct CSetEntityMetadata {
|
pub struct CSetEntityMetadata<T> {
|
||||||
entity_id: VarInt,
|
entity_id: VarInt,
|
||||||
metadata: Metadata,
|
metadata: Metadata<T>,
|
||||||
end: u8,
|
end: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSetEntityMetadata {
|
impl<T> CSetEntityMetadata<T> {
|
||||||
pub fn new(entity_id: VarInt, metadata: Metadata) -> Self {
|
pub fn new(entity_id: VarInt, metadata: Metadata<T>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
entity_id,
|
entity_id,
|
||||||
metadata,
|
metadata,
|
||||||
@ -22,14 +22,14 @@ impl CSetEntityMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Metadata {
|
pub struct Metadata<T> {
|
||||||
index: u8,
|
index: u8,
|
||||||
typ: VarInt,
|
typ: VarInt,
|
||||||
value: u8,
|
value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Metadata {
|
impl<T> Metadata<T> {
|
||||||
pub fn new(index: u8, typ: VarInt, value: u8) -> Self {
|
pub fn new(index: u8, typ: VarInt, value: T) -> Self {
|
||||||
Self { index, typ, value }
|
Self { index, typ, value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use num_derive::FromPrimitive;
|
|||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use pumpkin_macros::packet;
|
use pumpkin_macros::packet;
|
||||||
|
|
||||||
use crate::{ServerPacket, VarInt};
|
use crate::{bytebuf::DeserializerError, ServerPacket, VarInt};
|
||||||
|
|
||||||
#[packet(0x16)]
|
#[packet(0x16)]
|
||||||
pub struct SInteract {
|
pub struct SInteract {
|
||||||
@ -20,7 +20,9 @@ impl ServerPacket for SInteract {
|
|||||||
) -> Result<Self, crate::bytebuf::DeserializerError> {
|
) -> Result<Self, crate::bytebuf::DeserializerError> {
|
||||||
let entity_id = bytebuf.get_var_int();
|
let entity_id = bytebuf.get_var_int();
|
||||||
let typ = 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 {
|
let target_position: Option<(f32, f32, f32)> = match action {
|
||||||
ActionType::Interact => None,
|
ActionType::Interact => None,
|
||||||
ActionType::Attack => None,
|
ActionType::Attack => None,
|
||||||
|
|||||||
@ -59,16 +59,16 @@ pub async fn authenticate(
|
|||||||
.authentication
|
.authentication
|
||||||
.prevent_proxy_connections
|
.prevent_proxy_connections
|
||||||
{
|
{
|
||||||
let test = format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}&ip={ip}");
|
format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}&ip={ip}")
|
||||||
dbg!(&test);
|
|
||||||
test
|
|
||||||
} else {
|
} else {
|
||||||
format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}")
|
format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}")
|
||||||
};
|
};
|
||||||
let response = server
|
let auth_client = server
|
||||||
.auth_client
|
.auth_client
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.ok_or(AuthError::MissingAuthClient)?;
|
||||||
|
|
||||||
|
let response = auth_client
|
||||||
.get(address)
|
.get(address)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
@ -109,6 +109,8 @@ pub fn is_texture_url_valid(url: Url, config: &TextureConfig) -> bool {
|
|||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum AuthError {
|
pub enum AuthError {
|
||||||
|
#[error("Missing auth client")]
|
||||||
|
MissingAuthClient,
|
||||||
#[error("Authentication servers are down")]
|
#[error("Authentication servers are down")]
|
||||||
FailedResponse,
|
FailedResponse,
|
||||||
#[error("Failed to verify username")]
|
#[error("Failed to verify username")]
|
||||||
|
|||||||
@ -3,13 +3,13 @@ use std::str::FromStr;
|
|||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use pumpkin_core::text::TextComponent;
|
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_inventory::player::PlayerInventory;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
bytebuf::{packet_id::Packet, DeserializerError},
|
bytebuf::{packet_id::Packet, DeserializerError},
|
||||||
client::play::{
|
client::play::{
|
||||||
CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSyncPlayerPosition,
|
CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSetEntityMetadata,
|
||||||
CSystemChatMessage, PlayerAction,
|
CSyncPlayerPosition, CSystemChatMessage, Metadata, PlayerAction,
|
||||||
},
|
},
|
||||||
position::WorldPosition,
|
position::WorldPosition,
|
||||||
server::play::{
|
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) {
|
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
|
// this is the ultra special magic code used to create the teleport id
|
||||||
self.teleport_id_count += 1;
|
self.teleport_id_count += 1;
|
||||||
@ -243,7 +252,7 @@ impl Player {
|
|||||||
&CPlayerInfoUpdate::new(
|
&CPlayerInfoUpdate::new(
|
||||||
0x04,
|
0x04,
|
||||||
&[pumpkin_protocol::client::play::Player {
|
&[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())],
|
actions: vec![PlayerAction::UpdateGameMode((self.gamemode as i32).into())],
|
||||||
}],
|
}],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
#![allow(clippy::await_holding_refcell_ref)]
|
#![allow(clippy::await_holding_refcell_ref)]
|
||||||
#![allow(clippy::await_holding_lock)]
|
#![allow(clippy::await_holding_lock)]
|
||||||
|
|
||||||
|
#[cfg(target_os = "wasi")]
|
||||||
|
compile_error!("Compiling for WASI targets is not supported!");
|
||||||
|
|
||||||
use mio::net::TcpListener;
|
use mio::net::TcpListener;
|
||||||
use mio::{Events, Interest, Poll, Token};
|
use mio::{Events, Interest, Poll, Token};
|
||||||
use std::io::{self};
|
use std::io::{self};
|
||||||
@ -26,7 +29,6 @@ pub mod rcon;
|
|||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
#[cfg(not(target_os = "wasi"))]
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
@ -227,8 +229,3 @@ fn next(current: &mut Token) -> Token {
|
|||||||
current.0 += 1;
|
current.0 += 1;
|
||||||
Token(next)
|
Token(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "wasi")]
|
|
||||||
fn main() {
|
|
||||||
panic!("can't bind to an address with wasi")
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user