Stuck before sending chunk data
This commit is contained in:
parent
e923e2ad3c
commit
a0cebf6d44
@ -1,5 +1,5 @@
|
|||||||
use crate::world::location::Location;
|
|
||||||
use crate::server::NetworkClient;
|
use crate::server::NetworkClient;
|
||||||
|
use crate::world::location::Location;
|
||||||
|
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
position: Location,
|
position: Location,
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/// Definitions for all the packets in the Minecraft protocol.
|
/// Definitions for all the packets in the Minecraft protocol.
|
||||||
pub mod packets;
|
pub mod packets;
|
||||||
|
|
||||||
|
use crate::entity::player::Player;
|
||||||
use crate::{mctypes::*, CONFIG, FAVICON};
|
use crate::{mctypes::*, CONFIG, FAVICON};
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use packets::*;
|
use packets::*;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::sync::mpsc::{self, Receiver, TryRecvError};
|
use std::sync::mpsc::{self, Receiver, TryRecvError};
|
||||||
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs};
|
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs};
|
||||||
use crate::entity::player::Player;
|
|
||||||
|
|
||||||
/// The struct containing all the data and running all the updates.
|
/// The struct containing all the data and running all the updates.
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
@ -202,24 +202,35 @@ impl NetworkClient {
|
|||||||
self.username = Some(loginsuccess.username.clone().into());
|
self.username = Some(loginsuccess.username.clone().into());
|
||||||
self.state = NetworkClientState::Play;
|
self.state = NetworkClientState::Play;
|
||||||
let joingame = JoinGame::new();
|
let joingame = JoinGame::new();
|
||||||
/// TODO: Fill out `joingame` with actual information.
|
// TODO: Fill out `joingame` with actual information.
|
||||||
joingame.write(&mut self.stream).await.unwrap();
|
joingame.write(&mut self.stream).await.unwrap();
|
||||||
debug!("{:?}", joingame);
|
debug!("{:?}", joingame);
|
||||||
let (packet_length, packet_id) =
|
let (_packet_length, _packet_id) =
|
||||||
read_packet_header(&mut self.stream).await.unwrap();
|
read_packet_header(&mut self.stream).await.unwrap();
|
||||||
let clientsettings = ClientSettings::read(&mut self.stream).await.unwrap();
|
let clientsettings = ClientSettings::read(&mut self.stream).await.unwrap();
|
||||||
|
// TODO: Actualy use client settings.
|
||||||
debug!("{:?}", clientsettings);
|
debug!("{:?}", clientsettings);
|
||||||
// TODO: S->C Held Item Change
|
|
||||||
// TODO: S->C Declare Recipes
|
// All good up to here.
|
||||||
// TODO: S->C Tags
|
|
||||||
// TODO: S->C Entity Status
|
let helditemchange = HeldItemChange::new();
|
||||||
// TODO: S->C Declare Commands
|
// TODO: Retrieve selected slot from storage.
|
||||||
// TODO: S->C Unlock Recipes
|
helditemchange.write(&mut self.stream).await.unwrap();
|
||||||
|
debug!("{:?}", helditemchange);
|
||||||
|
// TODO: S->C Declare Recipes (1.16?)
|
||||||
|
// TODO: S->C Tags (1.16?)
|
||||||
|
// TODO: S->C Entity Status (optional?)
|
||||||
|
// TODO: S->C Declare Commands (1.16?)
|
||||||
|
// TODO: S->C Unlock Recipes (1.16?)
|
||||||
// TODO: S->C Player Position and Look
|
// TODO: S->C Player Position and Look
|
||||||
// TODO: S->C Player Info (Add Player action)
|
let playerpositionandlook = PlayerPositionAndLook::new();
|
||||||
// TODO: S->C Player Info (Update latency action)
|
// TODO: Retrieve player position from storage.
|
||||||
// TODO: S->C Update View Position
|
// playerpositionandlook.write(&mut self.stream).await.unwrap();
|
||||||
// TODO: S->C Update Light
|
debug!("{:?}", playerpositionandlook);
|
||||||
|
// TODO: S->C Player Info (Add Player action) (1.16?)
|
||||||
|
// TODO: S->C Player Info (Update latency action) (1.16?)
|
||||||
|
// TODO: S->C Update View Position (1.16?)
|
||||||
|
// TODO: S->C Update Light (1.16?)
|
||||||
// TODO: S->C Chunk Data
|
// TODO: S->C Chunk Data
|
||||||
// TODO: S->C World Border
|
// TODO: S->C World Border
|
||||||
// TODO: S->C Spawn Position
|
// TODO: S->C Spawn Position
|
||||||
|
@ -227,3 +227,167 @@ impl JoinGame {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct HeldItemChange {
|
||||||
|
selected_slot: MCByte,
|
||||||
|
}
|
||||||
|
impl Into<Vec<u8>> for HeldItemChange {
|
||||||
|
fn into(self) -> Vec<u8> {
|
||||||
|
let mut out = vec![];
|
||||||
|
let mut temp: Vec<u8> = MCVarInt::from(0x09).into(); // 0x09 Held Item Change.
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.selected_slot));
|
||||||
|
out.extend_from_slice(&Into::<Vec<u8>>::into(MCVarInt::from(temp.len() as i32)));
|
||||||
|
out.extend_from_slice(&temp);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryFrom<Vec<u8>> for HeldItemChange {
|
||||||
|
type Error = &'static str;
|
||||||
|
fn try_from(_bytes: Vec<u8>) -> Result<Self, Self::Error> {
|
||||||
|
Err("unimplemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl HeldItemChange {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
HeldItemChange {
|
||||||
|
selected_slot: 0.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub async fn read(t: &mut TcpStream) -> tokio::io::Result<Self> {
|
||||||
|
let mut helditemchange = HeldItemChange::new();
|
||||||
|
helditemchange.selected_slot = MCByte::read(t).await?;
|
||||||
|
Ok(helditemchange)
|
||||||
|
}
|
||||||
|
pub async fn write(&self, t: &mut TcpStream) -> tokio::io::Result<()> {
|
||||||
|
for b in Into::<Vec<u8>>::into(self.clone()) {
|
||||||
|
write_byte(t, b).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct EntityStatus {
|
||||||
|
entity_id: MCInt,
|
||||||
|
entity_status: MCByte, // See table below.
|
||||||
|
// 1: Sent when resetting a mob spawn minecart's timer / Rabbit jump animation
|
||||||
|
// 2: Living Entity hurt
|
||||||
|
// 3: Living Entity dead
|
||||||
|
// 4: Iron Golem throwing up arms
|
||||||
|
// 6: Wolf/Ocelot/Horse taming — Spawn “heart” particles
|
||||||
|
// 7: Wolf/Ocelot/Horse tamed — Spawn “smoke” particles
|
||||||
|
// 8: Wolf shaking water — Trigger the shaking animation
|
||||||
|
// 9: (of self) Eating accepted by server
|
||||||
|
// 10: Sheep eating grass
|
||||||
|
// 10: Play TNT ignite sound
|
||||||
|
// 11: Iron Golem handing over a rose
|
||||||
|
// 12: Villager mating — Spawn “heart” particles
|
||||||
|
// 13: Spawn particles indicating that a villager is angry and seeking revenge
|
||||||
|
// 14: Spawn happy particles near a villager
|
||||||
|
// 15: Witch animation — Spawn “magic” particles
|
||||||
|
// 16: Play zombie converting into a villager sound
|
||||||
|
// 17: Firework exploding
|
||||||
|
// 18: Animal in love (ready to mate) — Spawn “heart” particles
|
||||||
|
// 19: Reset squid rotation
|
||||||
|
// 20: Spawn explosion particle — works for some living entities
|
||||||
|
// 21: Play guardian sound — works for only for guardians
|
||||||
|
// 22: Enables reduced debug for players
|
||||||
|
// 23: Disables reduced debug for players
|
||||||
|
}
|
||||||
|
impl Into<Vec<u8>> for EntityStatus {
|
||||||
|
fn into(self) -> Vec<u8> {
|
||||||
|
let mut out = vec![];
|
||||||
|
let mut temp: Vec<u8> = MCVarInt::from(0x1a).into(); // 0x1a Entity Status.
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.entity_id));
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.entity_status));
|
||||||
|
out.extend_from_slice(&Into::<Vec<u8>>::into(MCVarInt::from(temp.len() as i32)));
|
||||||
|
out.extend_from_slice(&temp);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryFrom<Vec<u8>> for EntityStatus {
|
||||||
|
type Error = &'static str;
|
||||||
|
fn try_from(_bytes: Vec<u8>) -> Result<Self, Self::Error> {
|
||||||
|
Err("unimplemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl EntityStatus {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
EntityStatus {
|
||||||
|
entity_id: 0.into(),
|
||||||
|
entity_status: 0.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub async fn read(t: &mut TcpStream) -> tokio::io::Result<Self> {
|
||||||
|
let mut entitystatus = EntityStatus::new();
|
||||||
|
entitystatus.entity_id = MCInt::read(t).await?;
|
||||||
|
entitystatus.entity_status = MCByte::read(t).await?;
|
||||||
|
Ok(entitystatus)
|
||||||
|
}
|
||||||
|
pub async fn write(&self, t: &mut TcpStream) -> tokio::io::Result<()> {
|
||||||
|
for b in Into::<Vec<u8>>::into(self.clone()) {
|
||||||
|
write_byte(t, b).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct PlayerPositionAndLook {
|
||||||
|
x: MCDouble,
|
||||||
|
y: MCDouble,
|
||||||
|
z: MCDouble,
|
||||||
|
yaw: MCFloat,
|
||||||
|
pitch: MCFloat,
|
||||||
|
flags: MCByte,
|
||||||
|
}
|
||||||
|
impl Into<Vec<u8>> for PlayerPositionAndLook {
|
||||||
|
fn into(self) -> Vec<u8> {
|
||||||
|
let mut out = vec![];
|
||||||
|
let mut temp: Vec<u8> = MCVarInt::from(0x08).into(); // 0x08 Player Position and Look.
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.x));
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.y));
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.z));
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.yaw));
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.pitch));
|
||||||
|
temp.extend_from_slice(&Into::<Vec<u8>>::into(self.flags));
|
||||||
|
out.extend_from_slice(&Into::<Vec<u8>>::into(MCVarInt::from(temp.len() as i32)));
|
||||||
|
out.extend_from_slice(&temp);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryFrom<Vec<u8>> for PlayerPositionAndLook {
|
||||||
|
type Error = &'static str;
|
||||||
|
fn try_from(_bytes: Vec<u8>) -> Result<Self, Self::Error> {
|
||||||
|
Err("unimplemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl PlayerPositionAndLook {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
PlayerPositionAndLook {
|
||||||
|
x: 0.0.into(),
|
||||||
|
y: 0.0.into(),
|
||||||
|
z: 0.0.into(),
|
||||||
|
yaw: 0.0.into(),
|
||||||
|
pitch: 0.0.into(),
|
||||||
|
flags: 0x00.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub async fn read(t: &mut TcpStream) -> tokio::io::Result<Self> {
|
||||||
|
let mut playerpositionandlook = PlayerPositionAndLook::new();
|
||||||
|
playerpositionandlook.x = MCDouble::read(t).await?;
|
||||||
|
playerpositionandlook.y = MCDouble::read(t).await?;
|
||||||
|
playerpositionandlook.z = MCDouble::read(t).await?;
|
||||||
|
playerpositionandlook.yaw = MCFloat::read(t).await?;
|
||||||
|
playerpositionandlook.pitch = MCFloat::read(t).await?;
|
||||||
|
playerpositionandlook.flags = MCByte::read(t).await?;
|
||||||
|
Ok(playerpositionandlook)
|
||||||
|
}
|
||||||
|
pub async fn write(&self, t: &mut TcpStream) -> tokio::io::Result<()> {
|
||||||
|
for b in Into::<Vec<u8>>::into(self.clone()) {
|
||||||
|
write_byte(t, b).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user