diff --git a/pumpkin-protocol/src/server/mod.rs b/pumpkin-protocol/src/server/mod.rs index 4ff0995f9..4d9e64444 100644 --- a/pumpkin-protocol/src/server/mod.rs +++ b/pumpkin-protocol/src/server/mod.rs @@ -3,4 +3,5 @@ pub mod config; pub mod handshake; pub mod login; +pub mod play; pub mod status; diff --git a/pumpkin-protocol/src/server/play/mod.rs b/pumpkin-protocol/src/server/play/mod.rs index e69de29bb..7126b9ee0 100644 --- a/pumpkin-protocol/src/server/play/mod.rs +++ b/pumpkin-protocol/src/server/play/mod.rs @@ -0,0 +1,15 @@ +use crate::{ServerPacket, VarInt}; + +pub struct SConfirmTeleport { + teleport_id: VarInt, +} + +impl ServerPacket for SConfirmTeleport { + const PACKET_ID: VarInt = 0x00; + + fn read(bytebuf: &mut crate::bytebuf::ByteBuffer) -> Self { + Self { + teleport_id: bytebuf.get_var_int(), + } + } +} diff --git a/pumpkin-registry/src/damage_type.rs b/pumpkin-registry/src/damage_type.rs index a936430c1..d2c7e75ae 100644 --- a/pumpkin-registry/src/damage_type.rs +++ b/pumpkin-registry/src/damage_type.rs @@ -64,19 +64,23 @@ const NAMES: &[&str] = &[ ]; pub(super) fn entires() -> Vec { - let items: Vec<_> = NAMES - .iter() - .map(|name| RegistryEntry { - entry_id: (*name).into(), - data: fastnbt::to_bytes_with_opts(&DamageType { - exhaustion: 0.1, - message_id: "inFire".into(), - scaling: "when_caused_by_living_non_player".into(), - death_message_type: None, - effects: None, - }, SerOpts::network_nbt()).unwrap(), - }) - .collect(); + let items: Vec<_> = NAMES + .iter() + .map(|name| RegistryEntry { + entry_id: (*name).into(), + data: fastnbt::to_bytes_with_opts( + &DamageType { + exhaustion: 0.1, + message_id: "inFire".into(), + scaling: "when_caused_by_living_non_player".into(), + death_message_type: None, + effects: None, + }, + SerOpts::network_nbt(), + ) + .unwrap(), + }) + .collect(); - items -} \ No newline at end of file + items +} diff --git a/pumpkin-registry/src/lib.rs b/pumpkin-registry/src/lib.rs index 2b5e433dc..93fbc3b0c 100644 --- a/pumpkin-registry/src/lib.rs +++ b/pumpkin-registry/src/lib.rs @@ -30,15 +30,18 @@ impl Registry { }; let biomes = Registry { registry_id: "minecraft:worldgen/biome".to_string(), - registry_entries: vec![RegistryEntry { - entry_id: "minecraft:snowy_taiga".to_string(), - data: fastnbt::to_bytes_with_opts(&Biome::default(), SerOpts::network_nbt()) - .unwrap(), - }, RegistryEntry { - entry_id: "minecraft:plains".to_string(), - data: fastnbt::to_bytes_with_opts(&Biome::default(), SerOpts::network_nbt()) - .unwrap(), - }] + registry_entries: vec![ + RegistryEntry { + entry_id: "minecraft:snowy_taiga".to_string(), + data: fastnbt::to_bytes_with_opts(&Biome::default(), SerOpts::network_nbt()) + .unwrap(), + }, + RegistryEntry { + entry_id: "minecraft:plains".to_string(), + data: fastnbt::to_bytes_with_opts(&Biome::default(), SerOpts::network_nbt()) + .unwrap(), + }, + ], }; let wolf_variants = Registry { registry_id: "minecraft:wolf_variant".to_string(), diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index bbed57b99..90af185b3 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -28,7 +28,7 @@ use std::io::Read; use thiserror::Error; mod client_packet; -mod player_packet; +pub mod player_packet; use client_packet::ClientPacketProcessor; @@ -185,6 +185,14 @@ impl Client { packet.id ), }, + pumpkin_protocol::ConnectionState::Play => { + if let Some(player) = &mut self.player { + player.handle_packet(server, packet); + } else { + // should be impossible + self.kick("no player in play state?") + } + } _ => log::error!("Invalid Connection state {:?}", self.connection_state), } } diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 9d7e372a5..3cc8ed1f6 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -1,2 +1,13 @@ +use pumpkin_protocol::server::play::SConfirmTeleport; + +use crate::{entity::player::Player, server::Server}; + // implement player packets -pub trait PlayerPacketProcessor {} +pub trait PlayerPacketProcessor { + fn handle_confirm_teleport(&mut self, server: &mut Server, confirm_teleport: SConfirmTeleport); +} + +impl PlayerPacketProcessor for Player { + fn handle_confirm_teleport(&mut self, server: &mut Server, confirm_teleport: SConfirmTeleport) { + } +} diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 28ac1f474..7ddae761f 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -1,4 +1,6 @@ -use pumpkin_protocol::VarInt; +use pumpkin_protocol::{server::play::SConfirmTeleport, RawPacket, ServerPacket, VarInt}; + +use crate::{client::player_packet::PlayerPacketProcessor, server::Server}; use super::{Entity, EntityId}; @@ -14,6 +16,16 @@ impl Player { pub fn entity_id(&self) -> EntityId { self.entity.entity_id } + + pub fn handle_packet(&mut self, server: &mut Server, packet: &mut RawPacket) { + let bytebuf = &mut packet.bytebuf; + match packet.id { + SConfirmTeleport::PACKET_ID => { + self.handle_confirm_teleport(server, SConfirmTeleport::read(bytebuf)) + } + _ => log::error!("Failed to handle Player packet, id {}", packet.id), + } + } } pub enum Hand {