Add Serverbound Confirm Teleportation

This commit is contained in:
Snowiiii
2024-08-03 13:25:28 +02:00
parent f111c7881c
commit a45a43397c
7 changed files with 81 additions and 27 deletions

View File

@@ -3,4 +3,5 @@
pub mod config;
pub mod handshake;
pub mod login;
pub mod play;
pub mod status;

View File

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

View File

@@ -64,19 +64,23 @@ const NAMES: &[&str] = &[
];
pub(super) fn entires() -> Vec<RegistryEntry> {
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
}
items
}

View File

@@ -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(),

View File

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

View File

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

View File

@@ -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 {