mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
Add Serverbound Confirm Teleportation
This commit is contained in:
@@ -3,4 +3,5 @@
|
||||
pub mod config;
|
||||
pub mod handshake;
|
||||
pub mod login;
|
||||
pub mod play;
|
||||
pub mod status;
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user