Skip to content

Commit

Permalink
Move mclib-protocol to main crate
Browse files Browse the repository at this point in the history
  • Loading branch information
ya7on committed Feb 24, 2024
1 parent 4324be1 commit ad889c9
Show file tree
Hide file tree
Showing 72 changed files with 136 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea/
.vscode/

/target
target
12 changes: 2 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = ["macros", "protocol"]

[workspace.dependencies]
[dependencies]
mclib-macros = { path = "macros", version = "0.0.1" }
mclib-protocol = { path = "protocol", version = "0.0.1" }

darling = { version = "0.20.3" }
flate2 = { version = "1.0.28" }
syn = { version = "2.0.39" }
uuid = { version = "1.5.0", features = ["v4", "fast-rng", "macro-diagnostics"] }

[dependencies]
mclib-macros = { workspace = true }
mclib-protocol = { workspace = true }
4 changes: 2 additions & 2 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ edition = "2021"
proc-macro = true

[dependencies]
darling = { workspace = true }
syn = { workspace = true }
darling = { version = "0.20.3" }
syn = { version = "2.0.39" }
12 changes: 0 additions & 12 deletions protocol/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions protocol/src/lib.rs

This file was deleted.

3 changes: 0 additions & 3 deletions protocol/src/packets.rs

This file was deleted.

9 changes: 0 additions & 9 deletions protocol/src/packets/client.rs

This file was deleted.

8 changes: 0 additions & 8 deletions protocol/src/packets/server.rs

This file was deleted.

19 changes: 0 additions & 19 deletions protocol/src/types.rs

This file was deleted.

11 changes: 7 additions & 4 deletions protocol/src/chunk_format.rs → src/chunk_format.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::chunk_format::section::ChunkSection;
use crate::types::base::MCType;
use crate::utils::TcpUtils;
use std::io::Read;

pub mod data_array;
pub mod palleted_container;
pub mod section;
pub(crate) mod data_array;
pub(crate) mod palleted_container;
pub(crate) mod section;

pub use data_array::DataArray;
pub use palleted_container::PalletedContainer;
pub use section::ChunkSection;

#[derive(Debug, Clone)]
pub struct ChunkData(pub Vec<ChunkSection>);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
94 changes: 8 additions & 86 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,91 +71,13 @@
//! ```
//! For more information about NBT tags [their pages](nbt)

pub mod chunk_format;
pub mod nbt;
pub mod packets;
pub mod types;
pub mod utils;

pub use crate::packets::base::MCPacket;
pub use crate::types::base::MCType;
pub use mclib_macros::MCPacket;
pub use mclib_macros::MCType;
pub use mclib_protocol::packets::base::MCPacket;
pub use mclib_protocol::types::base::MCType;

pub mod packets {
//! Minecraft protocol packets
pub mod server {
//! Packets that bound to server (from client to server)
pub use mclib_protocol::packets::server::finish_configuration::FinishConfigurationServerbound;
pub use mclib_protocol::packets::server::handshake::{Handshake, HandshakeNextState};
pub use mclib_protocol::packets::server::keepalive::ServerboundKeelAlivePlay;
pub use mclib_protocol::packets::server::login_acknowledged::LoginAcknowledged;
pub use mclib_protocol::packets::server::login_start::LoginStart;
pub use mclib_protocol::packets::server::ping::PingRequest;
pub use mclib_protocol::packets::server::set_player_position::SetPlayerPosition;
pub use mclib_protocol::packets::server::status_request::StatusRequest;
}
pub mod client {
//! Packets that bound to client (from server to client)
pub use mclib_protocol::packets::client::chunk_data_and_update_light::ChunkDataAndUpdateLight;
pub use mclib_protocol::packets::client::finish_configuration::FinishConfigurationClientbound;
pub use mclib_protocol::packets::client::keepalive::ClientboundKeelAlivePlay;
pub use mclib_protocol::packets::client::login_success::{
LoginSuccess, LoginSuccessProperty,
};
pub use mclib_protocol::packets::client::play::{DeathInfo, Play};
pub use mclib_protocol::packets::client::registry_data::RegistryData;
pub use mclib_protocol::packets::client::set_default_spawn_position::SetDefaultSpawnPosition;
pub use mclib_protocol::packets::client::status_response::StatusResponse;
pub use mclib_protocol::packets::client::synchronize_player_position::SynchronizePlayerPosition;
}
}
pub mod types {
//! Minecraft data types
pub use mclib_protocol::types::bitset::MCBitSet;
pub use mclib_protocol::types::boolean::MCBoolean;
pub use mclib_protocol::types::byte::MCByte;
pub use mclib_protocol::types::byte_array::MCByteArray;
pub use mclib_protocol::types::double::MCDouble;
pub use mclib_protocol::types::float::MCFloat;
pub use mclib_protocol::types::int::MCInt;
pub use mclib_protocol::types::long::MCLong;
pub use mclib_protocol::types::nbt::MCNBT;
pub use mclib_protocol::types::position::MCPosition;
pub use mclib_protocol::types::short::MCShort;
pub use mclib_protocol::types::string::MCString;
pub use mclib_protocol::types::ubyte::MCUByte;
pub use mclib_protocol::types::ushort::MCUShort;
pub use mclib_protocol::types::uuid::MCUuid;
pub use mclib_protocol::types::varint::MCVarInt;
}
pub mod nbt {
//! Named Binary Tag (NBT) protocol
//!
//! [More information](https://wiki.vg/NBT)
pub use mclib_protocol::nbt::tags::base::{IntoNBTTag, NBTTag};
/// TAG_Byte
pub use mclib_protocol::nbt::tags::byte::TagByte;
/// TAG_Byte_Array
pub use mclib_protocol::nbt::tags::byte_array::TagByteArray;
/// TAG_Compound (any non root)
pub use mclib_protocol::nbt::tags::compound::TagCompound;
/// TAG_Double
pub use mclib_protocol::nbt::tags::double::TagDouble;
/// TAG_Float
pub use mclib_protocol::nbt::tags::float::TagFloat;
/// TAG_Int
pub use mclib_protocol::nbt::tags::int::TagInt;
/// TAG_List
pub use mclib_protocol::nbt::tags::list::TagList;
/// TAG_Long
pub use mclib_protocol::nbt::tags::long::TagLong;
/// TAG_Long_Array
pub use mclib_protocol::nbt::tags::long_array::TagLongArray;
/// TAG_Short
pub use mclib_protocol::nbt::tags::short::TagShort;
/// TAG_String
pub use mclib_protocol::nbt::tags::string::TagString;
/// Parent NBT tag (Root TAG_Compound)
pub use mclib_protocol::nbt::NBT;
}
pub mod chunk_format {
pub use mclib_protocol::chunk_format::{
data_array::DataArray, palleted_container::PalletedContainer, section::ChunkSection,
ChunkData,
};
}
33 changes: 31 additions & 2 deletions protocol/src/nbt.rs → src/nbt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
use crate::nbt::tags::base::{unpack_by_ty_id, NBTTag};
//! Named Binary Tag (NBT) protocol
//!
//! [More information](https://wiki.vg/NBT)

use crate::nbt::tags::base::unpack_by_ty_id;
use crate::utils::TcpUtils;
use std::io::Read;

pub mod tags;
pub(crate) mod tags;

pub use tags::base::{IntoNBTTag, NBTTag};
/// TAG_Byte
pub use tags::byte::TagByte;
/// TAG_Byte_Array
pub use tags::byte_array::TagByteArray;
/// TAG_Compound (any non root)
pub use tags::compound::TagCompound;
/// TAG_Double
pub use tags::double::TagDouble;
/// TAG_Float
pub use tags::float::TagFloat;
/// TAG_Int
pub use tags::int::TagInt;
/// TAG_List
pub use tags::list::TagList;
/// TAG_Long
pub use tags::long::TagLong;
/// TAG_Long_Array
pub use tags::long_array::TagLongArray;
/// TAG_Short
pub use tags::short::TagShort;
/// TAG_String
pub use tags::string::TagString;

/// Parent NBT tag (Root TAG_Compound)
#[derive(Debug)]
pub struct NBT(pub Option<String>, pub Box<dyn NBTTag>);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/packets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Minecraft protocol packets

pub(crate) mod base;
pub mod client;
pub mod server;
File renamed without changes.
20 changes: 20 additions & 0 deletions src/packets/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Packets that bound to client (from server to client)

mod chunk_data_and_update_light;
pub use chunk_data_and_update_light::{BlockEntity, ChunkDataAndUpdateLight};
mod finish_configuration;
pub use finish_configuration::FinishConfigurationClientbound;
mod keepalive;
pub use keepalive::ClientboundKeelAlivePlay;
mod login_success;
pub use login_success::{LoginSuccess, LoginSuccessProperty};
mod play;
pub use play::{DeathInfo, Play};
mod registry_data;
pub use registry_data::RegistryData;
mod set_default_spawn_position;
pub use set_default_spawn_position::SetDefaultSpawnPosition;
mod status_response;
pub use status_response::StatusResponse;
mod synchronize_player_position;
pub use synchronize_player_position::SynchronizePlayerPosition;
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ pub struct ChunkDataAndUpdateLight {

#[cfg(test)]
mod tests {
use crate::chunk_format::ChunkData;
use crate::chunk_format::data_array::DataArray;
use crate::chunk_format::palleted_container::PalletedContainer;
use crate::chunk_format::section::ChunkSection;
use crate::chunk_format::ChunkData;
use crate::nbt::IntoNBTTag;
use crate::nbt::NBT;
use crate::nbt::tags::base::IntoNBTTag;
use crate::packets::base::MCPacket;
use crate::packets::client::chunk_data_and_update_light::ChunkDataAndUpdateLight;
use crate::types::bitset::MCBitSet;
Expand All @@ -54,7 +54,7 @@ mod tests {
#[test]
fn test_chunk_data() {
let reference =
include_bytes!("../../../../tests/references/chunk_data_and_update_light.packet");
include_bytes!("../../../tests/references/chunk_data_and_update_light.packet");

let heightmap = NBT(
None,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions src/packets/server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Packets that bound to server (from client to server)

mod finish_configuration;
pub use finish_configuration::FinishConfigurationServerbound;
mod handshake;
pub use handshake::{Handshake, HandshakeNextState};
mod keepalive;
pub use keepalive::ServerboundKeelAlivePlay;
mod login_acknowledged;
pub use login_acknowledged::LoginAcknowledged;
mod login_start;
pub use login_start::LoginStart;
mod ping;
pub use ping::PingRequest;
mod set_player_position;
pub use set_player_position::SetPlayerPosition;
mod status_request;
pub use status_request::StatusRequest;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Minecraft data types

pub(crate) mod base;
pub(crate) mod bitset;
pub(crate) mod boolean;
pub(crate) mod byte;
pub(crate) mod byte_array;
pub(crate) mod double;
pub(crate) mod float;
pub(crate) mod int;
pub(crate) mod long;
pub(crate) mod nbt;
pub(crate) mod option;
pub(crate) mod position;
pub(crate) mod short;
pub(crate) mod string;
pub(crate) mod ubyte;
pub(crate) mod ushort;
pub(crate) mod uuid;
pub(crate) mod varint;
pub(crate) mod vec;

pub use bitset::MCBitSet;
pub use boolean::MCBoolean;
pub use byte::MCByte;
pub use byte_array::MCByteArray;
pub use double::MCDouble;
pub use float::MCFloat;
pub use int::MCInt;
pub use long::MCLong;
pub use nbt::MCNBT;
pub use position::MCPosition;
pub use short::MCShort;
pub use string::MCString;
pub use ubyte::MCUByte;
pub use ushort::MCUShort;
pub use uuid::MCUuid;
pub use varint::MCVarInt;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ad889c9

Please sign in to comment.