Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
First attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Nov 15, 2023
1 parent da6f6bb commit b1d1963
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 380 deletions.
11 changes: 10 additions & 1 deletion minecraft-entities-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
let code: TokenStream = code.into_iter().collect();
codes.push(code);

let code = quote! {
let mut code = quote! {
impl From<#this> for AnyEntity {
fn from(val: #this) -> Self {
AnyEntity::#this(val)
Expand All @@ -210,6 +210,15 @@ pub fn MinecraftEntity(attr: proc_macro::TokenStream, item: proc_macro::TokenStr
assert!(#parent_snake.is_some(), "Please add {} to {} list", stringify!(#this), stringify!(#parent));
}
};
if struct_name == "Player" {
code = quote! {
impl From<#this> for AnyEntity {
fn from(val: #this) -> Self {
AnyEntity::#this(val)
}
}
}
}
codes.push(code);
}

Expand Down
2 changes: 1 addition & 1 deletion minecraft-protocol/src/components/gamemode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::*;

#[derive(PartialEq)]
#[minecraft_enum(u8)]
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum Gamemode {
Survival,
Creative,
Expand Down
391 changes: 379 additions & 12 deletions minecraft-server/src/entities/player.rs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions minecraft-server/src/player_handler/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ pub async fn handle_connection(
let player_info = login(&mut stream, addr).await?;
let (player_info, change_receiver) = handshake(&mut stream, player_info, world).await?;
let uuid = player_info.uuid;
let r = handle_player(stream, player_info, server_msg_rcvr, world, change_receiver).await;
world.remove_loader(uuid).await;
r
let eid = Player::spawn_player(world, stream, player_info, server_msg_rcvr, change_receiver).await;
Ok(())
},
ConnectionState::Status => {
status(&mut stream).await;
Expand Down
22 changes: 11 additions & 11 deletions minecraft-server/src/player_handler/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use super::*;

pub struct PlayerInfo {
pub(super) addr: SocketAddr,
pub(super) username: String,
pub(super) uuid: u128,
pub(super) locale: String,
pub(super) render_distance: usize,
pub(super) chat_mode: ChatMode,
pub(super) chat_colors: bool,
pub(super) displayed_skin_parts: u8,
pub(super) main_hand: MainHand,
pub(super) enable_text_filtering: bool,
pub(super) allow_server_listing: bool,
pub addr: SocketAddr,
pub username: String,
pub uuid: u128,
pub locale: String,
pub render_distance: usize,
pub chat_mode: ChatMode,
pub chat_colors: bool,
pub displayed_skin_parts: u8,
pub main_hand: MainHand,
pub enable_text_filtering: bool,
pub allow_server_listing: bool,
}

pub async fn handshake(stream: &mut TcpStream, logged_in_player_info: LoggedInPlayerInfo, world: &'static World) -> Result<(PlayerInfo, MpscReceiver<WorldChange>), ()> {
Expand Down
2 changes: 0 additions & 2 deletions minecraft-server/src/player_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ mod login;
pub use login::*;
mod network;
pub use network::*;
mod play;
pub use play::*;
mod status;
pub use status::*;

Expand Down
Loading

0 comments on commit b1d1963

Please sign in to comment.