mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
Fix everything so azalea-buf works
This commit is contained in:
parent
1089aa7961
commit
37c6618c16
98 changed files with 424 additions and 276 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -96,6 +96,7 @@ dependencies = [
|
||||||
"buf-macros",
|
"buf-macros",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -150,8 +151,10 @@ dependencies = [
|
||||||
name = "azalea-entity"
|
name = "azalea-entity"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"azalea-buf",
|
||||||
|
"azalea-chat",
|
||||||
"azalea-core",
|
"azalea-core",
|
||||||
"azalea-protocol",
|
"azalea-nbt",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -188,6 +191,7 @@ dependencies = [
|
||||||
"azalea-chat",
|
"azalea-chat",
|
||||||
"azalea-core",
|
"azalea-core",
|
||||||
"azalea-crypto",
|
"azalea-crypto",
|
||||||
|
"azalea-entity",
|
||||||
"azalea-nbt",
|
"azalea-nbt",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
@ -209,10 +213,10 @@ name = "azalea-world"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"azalea-block",
|
"azalea-block",
|
||||||
|
"azalea-buf",
|
||||||
"azalea-core",
|
"azalea-core",
|
||||||
"azalea-entity",
|
"azalea-entity",
|
||||||
"azalea-nbt",
|
"azalea-nbt",
|
||||||
"azalea-protocol",
|
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,3 +9,4 @@ version = "0.1.0"
|
||||||
buf-macros = {path = "./buf-macros"}
|
buf-macros = {path = "./buf-macros"}
|
||||||
byteorder = "1.4.3"
|
byteorder = "1.4.3"
|
||||||
tokio = {version = "^1.19.2", features = ["io-util", "net", "macros"]}
|
tokio = {version = "^1.19.2", features = ["io-util", "net", "macros"]}
|
||||||
|
uuid = "1.1.2"
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
use buf_macros::McBuf;
|
use crate::{McBufReadable, McBufWritable};
|
||||||
use std::ops::Deref;
|
use std::{
|
||||||
|
io::{Read, Write},
|
||||||
|
ops::Deref,
|
||||||
|
};
|
||||||
|
|
||||||
/// A Vec<u8> that isn't prefixed by a VarInt with the size.
|
/// A Vec<u8> that isn't prefixed by a VarInt with the size.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -26,7 +29,7 @@ impl From<&str> for UnsizedByteArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents Java's BitSet, a list of bits.
|
/// Represents Java's BitSet, a list of bits.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, McBuf)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct BitSet {
|
pub struct BitSet {
|
||||||
data: Vec<u64>,
|
data: Vec<u64>,
|
||||||
}
|
}
|
||||||
|
@ -37,3 +40,17 @@ impl BitSet {
|
||||||
(self.data[index / 64] & (1u64 << (index % 64))) != 0
|
(self.data[index / 64] & (1u64 << (index % 64))) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl McBufReadable for BitSet {
|
||||||
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
|
Ok(Self {
|
||||||
|
data: Vec::<u64>::read_into(buf)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McBufWritable for BitSet {
|
||||||
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
self.data.write_into(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
|
|
||||||
mod definitions;
|
mod definitions;
|
||||||
mod read;
|
mod read;
|
||||||
|
mod serializable_uuid;
|
||||||
mod write;
|
mod write;
|
||||||
|
|
||||||
pub use buf_macros::*;
|
pub use buf_macros::*;
|
||||||
pub use definitions::*;
|
pub use definitions::*;
|
||||||
pub use read::{read_varint_async, McBufReadable, McBufVarReadable, Readable};
|
pub use read::{read_varint_async, McBufReadable, McBufVarReadable, Readable};
|
||||||
|
pub use serializable_uuid::*;
|
||||||
pub use write::{McBufVarWritable, McBufWritable, Writable};
|
pub use write::{McBufVarWritable, McBufWritable, Writable};
|
||||||
|
|
||||||
// const DEFAULT_NBT_QUOTA: u32 = 2097152;
|
// const DEFAULT_NBT_QUOTA: u32 = 2097152;
|
||||||
|
|
13
azalea-core/src/serializable_uuid.rs → azalea-buf/src/serializable_uuid.rs
Executable file → Normal file
13
azalea-core/src/serializable_uuid.rs → azalea-buf/src/serializable_uuid.rs
Executable file → Normal file
|
@ -1,3 +1,5 @@
|
||||||
|
use crate::{McBufReadable, McBufWritable, Readable};
|
||||||
|
use std::io::{Read, Write};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub trait SerializableUuid {
|
pub trait SerializableUuid {
|
||||||
|
@ -33,10 +35,10 @@ impl SerializableUuid for Uuid {
|
||||||
impl McBufReadable for Uuid {
|
impl McBufReadable for Uuid {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
Ok(Uuid::from_int_array([
|
Ok(Uuid::from_int_array([
|
||||||
Readable::read_int(self)? as u32,
|
Readable::read_int(buf)? as u32,
|
||||||
Readable::read_int(self)? as u32,
|
Readable::read_int(buf)? as u32,
|
||||||
Readable::read_int(self)? as u32,
|
Readable::read_int(buf)? as u32,
|
||||||
Readable::read_int(self)? as u32,
|
Readable::read_int(buf)? as u32,
|
||||||
]))
|
]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +54,8 @@ impl McBufWritable for Uuid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(tests)]
|
// TODO: add a test for Uuid in McBuf
|
||||||
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -189,7 +189,9 @@ impl McBufVarWritable for i64 {
|
||||||
if value != 0 {
|
if value != 0 {
|
||||||
buffer[0] |= 0b1000_0000;
|
buffer[0] |= 0b1000_0000;
|
||||||
}
|
}
|
||||||
buf.write(&mut buffer)?;
|
// this only writes a single byte, so write_all isn't necessary
|
||||||
|
// the let _ = is so clippy doesn't complain
|
||||||
|
let _ = buf.write(&mut buffer)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{Account, Player};
|
use crate::{Account, Player};
|
||||||
use azalea_core::{resource_location::ResourceLocation, ChunkPos, EntityPos};
|
use azalea_core::{ChunkPos, EntityPos, ResourceLocation};
|
||||||
use azalea_entity::Entity;
|
use azalea_entity::Entity;
|
||||||
use azalea_protocol::{
|
use azalea_protocol::{
|
||||||
connect::{GameConnection, HandshakeConnection},
|
connect::{GameConnection, HandshakeConnection},
|
||||||
|
@ -439,14 +439,14 @@ impl Client {
|
||||||
let mut state_lock = state.lock()?;
|
let mut state_lock = state.lock()?;
|
||||||
let world = state_lock.world.as_mut().unwrap();
|
let world = state_lock.world.as_mut().unwrap();
|
||||||
|
|
||||||
world.move_entity(
|
// world.move_entity(
|
||||||
p.entity_id,
|
// p.entity_id,
|
||||||
EntityPos {
|
// EntityPos {
|
||||||
x: p.x,
|
// x: p.x,
|
||||||
y: p.y,
|
// y: p.y,
|
||||||
z: p.z,
|
// z: p.z,
|
||||||
},
|
// },
|
||||||
)?;
|
// )?;
|
||||||
}
|
}
|
||||||
GamePacket::ClientboundMoveEntityRotPacket(p) => {
|
GamePacket::ClientboundMoveEntityRotPacket(p) => {
|
||||||
println!("Got move entity rot packet {:?}", p);
|
println!("Got move entity rot packet {:?}", p);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::EntityPos;
|
||||||
pub use azalea_buf::McBuf;
|
pub use azalea_buf::McBuf;
|
||||||
|
|
||||||
/// Only works for up to 8 blocks
|
/// Only works for up to 8 blocks
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
use std::fmt::{Debug, Error, Formatter};
|
use std::{
|
||||||
|
fmt::{Debug, Error, Formatter},
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
|
|
||||||
#[derive(Hash, Clone, Debug, PartialEq)]
|
#[derive(Hash, Clone, Debug, PartialEq)]
|
||||||
pub enum Difficulty {
|
pub enum Difficulty {
|
||||||
PEACEFUL,
|
PEACEFUL = 0,
|
||||||
EASY,
|
EASY = 1,
|
||||||
NORMAL,
|
NORMAL = 2,
|
||||||
HARD,
|
HARD = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Err {
|
pub enum Err {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, McBuf)]
|
#[derive(Clone, Copy, Debug, McBuf)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
Down = 0,
|
Down = 0,
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
#[derive(Hash, Clone, Debug)]
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
#[derive(Hash, Copy, Clone, Debug)]
|
||||||
pub enum GameType {
|
pub enum GameType {
|
||||||
SURVIVAL,
|
SURVIVAL,
|
||||||
CREATIVE,
|
CREATIVE,
|
||||||
|
@ -17,8 +20,8 @@ impl GameType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the id of the game type, but return -1 if the game type is invalid.
|
/// Get the id of the game type, but return -1 if the game type is invalid.
|
||||||
pub fn to_optional_id(game_type: &Option<GameType>) -> i8 {
|
pub fn to_optional_id<T: Into<Option<GameType>>>(game_type: T) -> i8 {
|
||||||
match game_type {
|
match game_type.into() {
|
||||||
Some(game_type) => game_type.to_id() as i8,
|
Some(game_type) => game_type.to_id() as i8,
|
||||||
None => -1,
|
None => -1,
|
||||||
}
|
}
|
||||||
|
@ -34,11 +37,12 @@ impl GameType {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_optional_id(id: i8) -> Result<Option<GameType>, String> {
|
pub fn from_optional_id(id: i8) -> Result<OptionalGameType, String> {
|
||||||
Ok(match id {
|
Ok(match id {
|
||||||
-1 => None,
|
-1 => None,
|
||||||
id => Some(GameType::from_id(id as u8)?),
|
id => Some(GameType::from_id(id as u8)?),
|
||||||
})
|
}
|
||||||
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn short_name(&self) -> &'static str {
|
pub fn short_name(&self) -> &'static str {
|
||||||
|
@ -74,13 +78,7 @@ impl GameType {
|
||||||
|
|
||||||
impl McBufReadable for GameType {
|
impl McBufReadable for GameType {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
GameType::from_id(buf.read_byte()?)
|
GameType::from_id(u8::read_into(buf)?)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl McBufReadable for Option<GameType> {
|
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
|
||||||
GameType::from_optional_id(buf.read_byte()? as i8)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +88,30 @@ impl McBufWritable for GameType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Option<GameType> {
|
/// Rust doesn't let us `impl McBufReadable for Option<GameType>` so we have to make a new type :(
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
#[derive(Hash, Copy, Clone, Debug)]
|
||||||
buf.write_byte(GameType::to_optional_id(self) as u8)
|
pub struct OptionalGameType(Option<GameType>);
|
||||||
|
|
||||||
|
impl From<Option<GameType>> for OptionalGameType {
|
||||||
|
fn from(game_type: Option<GameType>) -> Self {
|
||||||
|
OptionalGameType(game_type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<OptionalGameType> for Option<GameType> {
|
||||||
|
fn from(optional_game_type: OptionalGameType) -> Self {
|
||||||
|
optional_game_type.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McBufReadable for OptionalGameType {
|
||||||
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
|
GameType::from_optional_id(i8::read_into(buf)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McBufWritable for OptionalGameType {
|
||||||
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
GameType::to_optional_id(*self).write_into(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
|
|
||||||
#![feature(int_roundings)]
|
#![feature(int_roundings)]
|
||||||
|
|
||||||
pub mod difficulty;
|
mod difficulty;
|
||||||
pub mod game_type;
|
pub use difficulty::*;
|
||||||
pub mod resource_location;
|
|
||||||
pub mod serializable_uuid;
|
mod resource_location;
|
||||||
|
pub use resource_location::*;
|
||||||
|
|
||||||
|
mod game_type;
|
||||||
|
pub use game_type::*;
|
||||||
|
|
||||||
mod slot;
|
mod slot;
|
||||||
pub use slot::{Slot, SlotData};
|
pub use slot::{Slot, SlotData};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use azalea_buf::{McBufReadable, McBufWritable};
|
use crate::{BlockPos, Slot};
|
||||||
|
use azalea_buf::{McBuf, McBufReadable, McBufVarReadable, McBufWritable};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Debug, Clone, McBuf)]
|
#[derive(Debug, Clone, McBuf)]
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::ops::Rem;
|
use crate::ResourceLocation;
|
||||||
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
use crate::resource_location::ResourceLocation;
|
use std::{
|
||||||
|
io::{Read, Write},
|
||||||
|
ops::Rem,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
pub struct BlockPos {
|
pub struct BlockPos {
|
||||||
|
@ -202,11 +205,10 @@ impl McBufReadable for ChunkSectionPos {
|
||||||
|
|
||||||
impl McBufWritable for BlockPos {
|
impl McBufWritable for BlockPos {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_long(
|
let data = (((self.x & 0x3FFFFFF) as i64) << 38)
|
||||||
(((self.x & 0x3FFFFFF) as i64) << 38)
|
| (((self.z & 0x3FFFFFF) as i64) << 12)
|
||||||
| (((self.z & 0x3FFFFFF) as i64) << 12)
|
| ((self.y & 0xFFF) as i64);
|
||||||
| ((self.y & 0xFFF) as i64),
|
data.write_into(buf)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
//! A resource, like minecraft:stone
|
//! A resource, like minecraft:stone
|
||||||
|
|
||||||
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Hash, Clone, PartialEq, Eq)]
|
#[derive(Hash, Clone, PartialEq, Eq)]
|
||||||
pub struct ResourceLocation {
|
pub struct ResourceLocation {
|
||||||
pub namespace: String,
|
pub namespace: String,
|
||||||
|
@ -44,18 +47,20 @@ impl std::fmt::Debug for ResourceLocation {
|
||||||
|
|
||||||
impl McBufReadable for ResourceLocation {
|
impl McBufReadable for ResourceLocation {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let location_string = self.read_utf()?;
|
let location_string = String::read_into(buf)?;
|
||||||
ResourceLocation::new(&location_string)
|
ResourceLocation::new(&location_string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl McBufWritable for ResourceLocation {
|
impl McBufWritable for ResourceLocation {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_utf(&self.to_string())
|
self.to_string().write_into(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -86,13 +91,14 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn mcbuf_resource_location() {
|
fn mcbuf_resource_location() {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
buf.write_resource_location(&ResourceLocation::new("minecraft:dirt").unwrap())
|
ResourceLocation::new("minecraft:dirt")
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.write_into(&mut buf)?;
|
||||||
|
|
||||||
let mut buf = Cursor::new(buf);
|
let mut buf = Cursor::new(buf);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
buf.read_resource_location().unwrap(),
|
ResourceLocation::read_into(&mut buf).unwrap(),
|
||||||
ResourceLocation::new("minecraft:dirt").unwrap()
|
ResourceLocation::new("minecraft:dirt").unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
// TODO: have an azalea-inventory or azalea-container crate and put this there
|
// TODO: have an azalea-inventory or azalea-container crate and put this there
|
||||||
|
|
||||||
|
use azalea_buf::{McBuf, McBufReadable, McBufWritable};
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Slot {
|
pub enum Slot {
|
||||||
Present(SlotData),
|
|
||||||
Empty,
|
Empty,
|
||||||
|
Present(SlotData),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, McBuf)]
|
||||||
pub struct SlotData {
|
pub struct SlotData {
|
||||||
|
#[var]
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub count: u8,
|
pub count: u8,
|
||||||
pub nbt: azalea_nbt::Tag,
|
pub nbt: azalea_nbt::Tag,
|
||||||
|
@ -15,26 +19,20 @@ pub struct SlotData {
|
||||||
|
|
||||||
impl McBufReadable for Slot {
|
impl McBufReadable for Slot {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let present = buf.read_boolean()?;
|
let present = bool::read_into(buf)?;
|
||||||
if !present {
|
if !present {
|
||||||
return Ok(Slot::Empty);
|
return Ok(Slot::Empty);
|
||||||
}
|
}
|
||||||
let id = buf.read_varint()?;
|
let slot = SlotData::read_into(buf)?;
|
||||||
let count = buf.read_byte()?;
|
Ok(Slot::Present(slot))
|
||||||
let nbt = buf.read_nbt()?;
|
|
||||||
Ok(Slot::Present(SlotData { id, count, nbt }))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Slot {
|
impl McBufWritable for Slot {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
match self {
|
match self {
|
||||||
Slot::Empty => buf.write_byte(0)?,
|
Slot::Empty => 0u8.write_into(buf)?,
|
||||||
Slot::Present(i) => {
|
Slot::Present(i) => i.write_into(buf)?,
|
||||||
buf.write_varint(i.id)?;
|
|
||||||
buf.write_byte(i.count)?;
|
|
||||||
buf.write_nbt(&i.nbt)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -6,10 +6,8 @@ version = "0.1.0"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
azalea-buf = {path = "../azalea-buf"}
|
||||||
|
azalea-chat = {path = "../azalea-chat"}
|
||||||
azalea-core = {path = "../azalea-core"}
|
azalea-core = {path = "../azalea-core"}
|
||||||
azalea-protocol = {path = "../azalea-protocol", optional = true}
|
azalea-nbt = {path = "../azalea-nbt"}
|
||||||
uuid = "^1.1.2"
|
uuid = "^1.1.2"
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["protocol"]
|
|
||||||
protocol = ["dep:azalea-protocol"]
|
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
pub type EntityMetadata = Vec<EntityDataItem>;
|
use azalea_buf::McBufVarReadable;
|
||||||
|
use azalea_buf::{McBuf, McBufReadable, McBufWritable};
|
||||||
|
use azalea_chat::component::Component;
|
||||||
|
use azalea_core::{BlockPos, Direction, Particle, Slot};
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct EntityMetadata(Vec<EntityDataItem>);
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct EntityDataItem {
|
pub struct EntityDataItem {
|
||||||
|
@ -8,7 +16,7 @@ pub struct EntityDataItem {
|
||||||
pub value: EntityDataValue,
|
pub value: EntityDataValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufReadable for Vec<EntityDataItem> {
|
impl McBufReadable for EntityMetadata {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
|
@ -19,17 +27,17 @@ impl McBufReadable for Vec<EntityDataItem> {
|
||||||
let value = EntityDataValue::read_into(buf)?;
|
let value = EntityDataValue::read_into(buf)?;
|
||||||
metadata.push(EntityDataItem { index, value });
|
metadata.push(EntityDataItem { index, value });
|
||||||
}
|
}
|
||||||
Ok(metadata)
|
Ok(EntityMetadata(metadata))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for Vec<EntityDataItem> {
|
impl McBufWritable for EntityMetadata {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
for item in self {
|
for item in &self.0 {
|
||||||
buf.write_byte(item.index)?;
|
item.index.write_into(buf)?;
|
||||||
item.value.write_into(buf)?;
|
item.value.write_into(buf)?;
|
||||||
}
|
}
|
||||||
buf.write_byte(0xff)?;
|
0xffu8.write_into(buf)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,20 +71,20 @@ pub enum EntityDataValue {
|
||||||
|
|
||||||
impl McBufReadable for EntityDataValue {
|
impl McBufReadable for EntityDataValue {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let type_ = buf.read_varint()?;
|
let data_type = i32::var_read_into(buf)?;
|
||||||
Ok(match type_ {
|
Ok(match data_type {
|
||||||
0 => EntityDataValue::Byte(buf.read_byte()?),
|
0 => EntityDataValue::Byte(u8::read_into(buf)?),
|
||||||
1 => EntityDataValue::Int(buf.read_varint()?),
|
1 => EntityDataValue::Int(i32::read_into(buf)?),
|
||||||
2 => EntityDataValue::Float(buf.read_float()?),
|
2 => EntityDataValue::Float(f32::read_into(buf)?),
|
||||||
3 => EntityDataValue::String(buf.read_utf()?),
|
3 => EntityDataValue::String(String::read_into(buf)?),
|
||||||
4 => EntityDataValue::Component(Component::read_into(buf)?),
|
4 => EntityDataValue::Component(Component::read_into(buf)?),
|
||||||
5 => EntityDataValue::OptionalComponent(Option::<Component>::read_into(buf)?),
|
5 => EntityDataValue::OptionalComponent(Option::<Component>::read_into(buf)?),
|
||||||
6 => EntityDataValue::ItemStack(Slot::read_into(buf)?),
|
6 => EntityDataValue::ItemStack(Slot::read_into(buf)?),
|
||||||
7 => EntityDataValue::Boolean(buf.read_boolean()?),
|
7 => EntityDataValue::Boolean(bool::read_into(buf)?),
|
||||||
8 => EntityDataValue::Rotations {
|
8 => EntityDataValue::Rotations {
|
||||||
x: buf.read_float()?,
|
x: f32::read_into(buf)?,
|
||||||
y: buf.read_float()?,
|
y: f32::read_into(buf)?,
|
||||||
z: buf.read_float()?,
|
z: f32::read_into(buf)?,
|
||||||
},
|
},
|
||||||
9 => EntityDataValue::BlockPos(BlockPos::read_into(buf)?),
|
9 => EntityDataValue::BlockPos(BlockPos::read_into(buf)?),
|
||||||
10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_into(buf)?),
|
10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_into(buf)?),
|
||||||
|
@ -94,7 +102,7 @@ impl McBufReadable for EntityDataValue {
|
||||||
15 => EntityDataValue::Particle(Particle::read_into(buf)?),
|
15 => EntityDataValue::Particle(Particle::read_into(buf)?),
|
||||||
16 => EntityDataValue::VillagerData(VillagerData::read_into(buf)?),
|
16 => EntityDataValue::VillagerData(VillagerData::read_into(buf)?),
|
||||||
17 => EntityDataValue::OptionalUnsignedInt({
|
17 => EntityDataValue::OptionalUnsignedInt({
|
||||||
let val = buf.read_varint()?;
|
let val = u32::var_read_into(buf)?;
|
||||||
if val == 0 {
|
if val == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -102,7 +110,7 @@ impl McBufReadable for EntityDataValue {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
18 => EntityDataValue::Pose(Pose::read_into(buf)?),
|
18 => EntityDataValue::Pose(Pose::read_into(buf)?),
|
||||||
_ => return Err(format!("Unknown entity data type: {}", type_)),
|
_ => return Err(format!("Unknown entity data type: {}", data_type)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use azalea_protocol::packets::game::{
|
||||||
clientbound_add_entity_packet::ClientboundAddEntityPacket,
|
clientbound_add_entity_packet::ClientboundAddEntityPacket,
|
||||||
clientbound_add_player_packet::ClientboundAddPlayerPacket,
|
clientbound_add_player_packet::ClientboundAddPlayerPacket,
|
||||||
};
|
};
|
||||||
|
pub use data::*;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
@ -13,10 +14,14 @@ pub struct Entity {
|
||||||
/// The incrementing numerical id of the entity.
|
/// The incrementing numerical id of the entity.
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub uuid: Uuid,
|
pub uuid: Uuid,
|
||||||
pos: EntityPos,
|
pub pos: EntityPos,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity {
|
impl Entity {
|
||||||
|
pub fn new(id: u32, uuid: Uuid, pos: EntityPos) -> Self {
|
||||||
|
Self { id, uuid, pos }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn pos(&self) -> &EntityPos {
|
pub fn pos(&self) -> &EntityPos {
|
||||||
&self.pos
|
&self.pos
|
||||||
}
|
}
|
||||||
|
@ -28,36 +33,6 @@ impl Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "protocol")]
|
|
||||||
impl From<&ClientboundAddEntityPacket> for Entity {
|
|
||||||
fn from(p: &ClientboundAddEntityPacket) -> Self {
|
|
||||||
Self {
|
|
||||||
id: p.id,
|
|
||||||
uuid: p.uuid,
|
|
||||||
pos: EntityPos {
|
|
||||||
x: p.x,
|
|
||||||
y: p.y,
|
|
||||||
z: p.z,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "protocol")]
|
|
||||||
impl From<&ClientboundAddPlayerPacket> for Entity {
|
|
||||||
fn from(p: &ClientboundAddPlayerPacket) -> Self {
|
|
||||||
Self {
|
|
||||||
id: p.id,
|
|
||||||
uuid: p.uuid,
|
|
||||||
pos: EntityPos {
|
|
||||||
x: p.x,
|
|
||||||
y: p.y,
|
|
||||||
z: p.z,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[cfg(test)]
|
// #[cfg(test)]
|
||||||
// mod tests {
|
// mod tests {
|
||||||
// #[test]
|
// #[test]
|
||||||
|
|
|
@ -14,6 +14,7 @@ azalea-buf = {path = "../azalea-buf"}
|
||||||
azalea-chat = {path = "../azalea-chat"}
|
azalea-chat = {path = "../azalea-chat"}
|
||||||
azalea-core = {path = "../azalea-core", optional = true}
|
azalea-core = {path = "../azalea-core", optional = true}
|
||||||
azalea-crypto = {path = "../azalea-crypto"}
|
azalea-crypto = {path = "../azalea-crypto"}
|
||||||
|
azalea-entity = {path = "../azalea-entity"}
|
||||||
azalea-nbt = {path = "../azalea-nbt"}
|
azalea-nbt = {path = "../azalea-nbt"}
|
||||||
byteorder = "^1.4.3"
|
byteorder = "^1.4.3"
|
||||||
bytes = "^1.1.0"
|
bytes = "^1.1.0"
|
||||||
|
|
|
@ -25,13 +25,13 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||||
crate::mc_buf::McBufWritable::write_into(self, buf)
|
azalea_buf::McBufWritable::write_into(self, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(
|
pub fn read(
|
||||||
buf: &mut impl std::io::Read,
|
buf: &mut impl std::io::Read,
|
||||||
) -> Result<#state, String> {
|
) -> Result<#state, String> {
|
||||||
use crate::mc_buf::McBufReadable;
|
use azalea_buf::McBufReadable;
|
||||||
Ok(Self::read_into(buf)?.get())
|
Ok(Self::read_into(buf)?.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ use std::str::FromStr;
|
||||||
|
|
||||||
#[cfg(feature = "connecting")]
|
#[cfg(feature = "connecting")]
|
||||||
pub mod connect;
|
pub mod connect;
|
||||||
pub mod mc_buf;
|
|
||||||
#[cfg(feature = "packets")]
|
#[cfg(feature = "packets")]
|
||||||
pub mod packets;
|
pub mod packets;
|
||||||
pub mod read;
|
pub mod read;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use azalea_core::EntityPos;
|
||||||
|
use azalea_entity::Entity;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
@ -22,3 +25,17 @@ pub struct ClientboundAddEntityPacket {
|
||||||
pub y_vel: i16,
|
pub y_vel: i16,
|
||||||
pub z_vel: i16,
|
pub z_vel: i16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&ClientboundAddEntityPacket> for Entity {
|
||||||
|
fn from(p: &ClientboundAddEntityPacket) -> Self {
|
||||||
|
Self::new(
|
||||||
|
p.id,
|
||||||
|
p.uuid,
|
||||||
|
EntityPos {
|
||||||
|
x: p.x,
|
||||||
|
y: p.y,
|
||||||
|
z: p.z,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use azalea_core::EntityPos;
|
||||||
|
use azalea_entity::Entity;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// This packet is sent by the server when a player comes into visible range, not when a player joins.
|
/// This packet is sent by the server when a player comes into visible range, not when a player joins.
|
||||||
|
@ -13,3 +16,17 @@ pub struct ClientboundAddPlayerPacket {
|
||||||
pub x_rot: i8,
|
pub x_rot: i8,
|
||||||
pub y_rot: i8,
|
pub y_rot: i8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&ClientboundAddPlayerPacket> for Entity {
|
||||||
|
fn from(p: &ClientboundAddPlayerPacket) -> Self {
|
||||||
|
Self::new(
|
||||||
|
p.id,
|
||||||
|
p.uuid,
|
||||||
|
EntityPos {
|
||||||
|
x: p.x,
|
||||||
|
y: p.y,
|
||||||
|
z: p.z,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundAnimatePacket {
|
pub struct ClientboundAnimatePacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundBlockChangedAckPacket {
|
pub struct ClientboundBlockChangedAckPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::BlockPos;
|
use azalea_core::BlockPos;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundBlockUpdatePacket {
|
pub struct ClientboundBlockUpdatePacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use azalea_core::difficulty::Difficulty;
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::Difficulty;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundChangeDifficultyPacket {
|
pub struct ClientboundChangeDifficultyPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundChatPreviewPacket {
|
pub struct ClientboundChatPreviewPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::Slot;
|
use azalea_core::Slot;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundContainerSetContentPacket {
|
pub struct ClientboundContainerSetContentPacket {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::mc_buf::UnsizedByteArray;
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_buf::UnsizedByteArray;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::ResourceLocation;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundCustomPayloadPacket {
|
pub struct ClientboundCustomPayloadPacket {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use super::GamePacket;
|
use super::GamePacket;
|
||||||
use crate::mc_buf::McBufVarReadable;
|
use azalea_buf::McBuf;
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use azalea_buf::McBufVarReadable;
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::ResourceLocation;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
use std::{
|
use std::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
@ -182,10 +183,10 @@ impl McBufReadable for BrigadierParser {
|
||||||
41 => Ok(BrigadierParser::Dimension),
|
41 => Ok(BrigadierParser::Dimension),
|
||||||
42 => Ok(BrigadierParser::Time),
|
42 => Ok(BrigadierParser::Time),
|
||||||
43 => Ok(BrigadierParser::ResourceOrTag {
|
43 => Ok(BrigadierParser::ResourceOrTag {
|
||||||
registry_key: buf.read_resource_location()?,
|
registry_key: ResourceLocation::read_into(buf)?,
|
||||||
}),
|
}),
|
||||||
44 => Ok(BrigadierParser::Resource {
|
44 => Ok(BrigadierParser::Resource {
|
||||||
registry_key: buf.read_resource_location()?,
|
registry_key: ResourceLocation::read_into(buf)?,
|
||||||
}),
|
}),
|
||||||
45 => Ok(BrigadierParser::TemplateMirror),
|
45 => Ok(BrigadierParser::TemplateMirror),
|
||||||
46 => Ok(BrigadierParser::TemplateRotation),
|
46 => Ok(BrigadierParser::TemplateRotation),
|
||||||
|
@ -218,7 +219,7 @@ impl McBufReadable for BrigadierNodeStub {
|
||||||
let _name = buf.read_utf()?;
|
let _name = buf.read_utf()?;
|
||||||
let _parser = BrigadierParser::read_into(buf)?;
|
let _parser = BrigadierParser::read_into(buf)?;
|
||||||
let _suggestions_type = if has_suggestions_type {
|
let _suggestions_type = if has_suggestions_type {
|
||||||
Some(buf.read_resource_location()?)
|
Some(ResourceLocation::read_into(buf)?)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundDisconnectPacket {
|
pub struct ClientboundDisconnectPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
// we can't identify the status in azalea-protocol since they vary depending on the entity
|
// we can't identify the status in azalea-protocol since they vary depending on the entity
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundEntityVelocityPacket {
|
pub struct ClientboundEntityVelocityPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundGameEventPacket {
|
pub struct ClientboundGameEventPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundInitializeBorderPacket {
|
pub struct ClientboundInitializeBorderPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundKeepAlivePacket {
|
pub struct ClientboundKeepAlivePacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
use super::clientbound_light_update_packet::ClientboundLightUpdatePacketData;
|
use super::clientbound_light_update_packet::ClientboundLightUpdatePacketData;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::BlockPos;
|
use azalea_core::BlockPos;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundLevelEventPacket {
|
pub struct ClientboundLevelEventPacket {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::mc_buf::McBufVarReadable;
|
use azalea_buf::{McBufReadable, McBufVarReadable, McBufWritable};
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, ParticleData};
|
use azalea_core::ParticleData;
|
||||||
use packet_macros::GamePacket;
|
use packet_macros::GamePacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::mc_buf::BitSet;
|
use azalea_buf::BitSet;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundLightUpdatePacket {
|
pub struct ClientboundLightUpdatePacket {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use azalea_core::{game_type::GameType, resource_location::ResourceLocation, GlobalPos};
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::{GameType, GlobalPos, OptionalGameType, ResourceLocation};
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundLoginPacket {
|
pub struct ClientboundLoginPacket {
|
||||||
pub player_id: u32,
|
pub player_id: u32,
|
||||||
pub hardcore: bool,
|
pub hardcore: bool,
|
||||||
pub game_type: GameType,
|
pub game_type: GameType,
|
||||||
pub previous_game_type: Option<GameType>,
|
pub previous_game_type: OptionalGameType,
|
||||||
pub levels: Vec<ResourceLocation>,
|
pub levels: Vec<ResourceLocation>,
|
||||||
pub registry_holder: azalea_nbt::Tag,
|
pub registry_holder: azalea_nbt::Tag,
|
||||||
pub dimension_type: ResourceLocation,
|
pub dimension_type: ResourceLocation,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use azalea_core::EntityPos;
|
use azalea_core::{EntityPos, PositionDelta};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
use azalea_buf::McBuf;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundMoveEntityPosPacket {
|
pub struct ClientboundMoveEntityPosPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use super::clientbound_move_entity_pos_packet::PositionDelta;
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::PositionDelta;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
/// This packet is sent by the server when an entity moves less then 8 blocks.
|
/// This packet is sent by the server when an entity moves less then 8 blocks.
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundMoveEntityRotPacket {
|
pub struct ClientboundMoveEntityRotPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::{McBufReadable, McBufWritable, Readable};
|
||||||
|
use packet_macros::GamePacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use azalea_crypto::SaltSignaturePair;
|
use azalea_crypto::SaltSignaturePair;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundPlayerChatPacket {
|
pub struct ClientboundPlayerChatPacket {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use azalea_buf::McBuf;
|
||||||
|
use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::{McBufReadable, McBufWritable, Readable};
|
||||||
|
use packet_macros::GamePacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::ResourceLocation;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundRemoveEntitiesPacket {
|
pub struct ClientboundRemoveEntitiesPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundRotateHeadPacket {
|
pub struct ClientboundRotateHeadPacket {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
|
use azalea_buf::McBuf;
|
||||||
|
use azalea_buf::{McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
|
||||||
use azalea_core::{ChunkSectionBlockPos, ChunkSectionPos};
|
use azalea_core::{ChunkSectionBlockPos, ChunkSectionPos};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundServerDataPacket {
|
pub struct ClientboundServerDataPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
/// Sent to change the player's slot selection.
|
/// Sent to change the player's slot selection.
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetChunkCacheCenterPacket {
|
pub struct ClientboundSetChunkCacheCenterPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::BlockPos;
|
use azalea_core::BlockPos;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetDefaultSpawnPositionPacket {
|
pub struct ClientboundSetDefaultSpawnPositionPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetDisplayChatPreviewPacket {
|
pub struct ClientboundSetDisplayChatPreviewPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::mc_buf::EntityMetadata;
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_entity::EntityMetadata;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetEntityDataPacket {
|
pub struct ClientboundSetEntityDataPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetEntityLinkPacket {
|
pub struct ClientboundSetEntityLinkPacket {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::Slot;
|
use azalea_core::Slot;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable};
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetEquipmentPacket {
|
pub struct ClientboundSetEquipmentPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetExperiencePacket {
|
pub struct ClientboundSetExperiencePacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetHealthPacket {
|
pub struct ClientboundSetHealthPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSetTimePacket {
|
pub struct ClientboundSetTimePacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSoundPacket {
|
pub struct ClientboundSoundPacket {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundSystemChatPacket {
|
pub struct ClientboundSystemChatPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundTeleportEntityPacket {
|
pub struct ClientboundTeleportEntityPacket {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::packets::{McBufReadable, McBufWritable};
|
use azalea_buf::{McBuf, McBufReadable, McBufWritable};
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use azalea_core::{resource_location::ResourceLocation, Slot};
|
use azalea_core::{ResourceLocation, Slot};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use packet_macros::GamePacket;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::ResourceLocation;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use azalea_core::{resource_location::ResourceLocation, Slot};
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::{ResourceLocation, Slot};
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundUpdateRecipesPacket {
|
pub struct ClientboundUpdateRecipesPacket {
|
||||||
|
@ -129,8 +130,8 @@ impl McBufWritable for Recipe {
|
||||||
|
|
||||||
impl McBufReadable for Recipe {
|
impl McBufReadable for Recipe {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let recipe_type = buf.read_resource_location()?;
|
let recipe_type = ResourceLocation::read_into(buf)?;
|
||||||
let identifier = buf.read_resource_location()?;
|
let identifier = ResourceLocation::read_into(buf)?;
|
||||||
|
|
||||||
// rust doesn't let us match ResourceLocation so we have to do a big
|
// rust doesn't let us match ResourceLocation so we have to do a big
|
||||||
// if-else chain :(
|
// if-else chain :(
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::ResourceLocation;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
use std::ops::Deref;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
@ -8,7 +10,7 @@ use std::{
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundUpdateTagsPacket {
|
pub struct ClientboundUpdateTagsPacket {
|
||||||
pub tags: HashMap<ResourceLocation, Vec<Tags>>,
|
pub tags: TagMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -17,12 +19,15 @@ pub struct Tags {
|
||||||
pub elements: Vec<i32>,
|
pub elements: Vec<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct TagMap(HashMap<ResourceLocation, Vec<Tags>>);
|
||||||
|
|
||||||
|
impl McBufReadable for TagMap {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let length = buf.read_varint()? as usize;
|
let length = buf.read_varint()? as usize;
|
||||||
let mut data = HashMap::with_capacity(length);
|
let mut data = HashMap::with_capacity(length);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
let tag_type = buf.read_resource_location()?;
|
let tag_type = ResourceLocation::read_into(buf)?;
|
||||||
let tags_count = buf.read_varint()? as usize;
|
let tags_count = buf.read_varint()? as usize;
|
||||||
let mut tags_vec = Vec::with_capacity(tags_count);
|
let mut tags_vec = Vec::with_capacity(tags_count);
|
||||||
for _ in 0..tags_count {
|
for _ in 0..tags_count {
|
||||||
|
@ -31,14 +36,14 @@ impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
|
||||||
}
|
}
|
||||||
data.insert(tag_type, tags_vec);
|
data.insert(tag_type, tags_vec);
|
||||||
}
|
}
|
||||||
Ok(data)
|
Ok(TagMap(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> {
|
impl McBufWritable for TagMap {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_varint(self.len() as i32)?;
|
buf.write_varint(self.len() as i32)?;
|
||||||
for (k, v) in self {
|
for (k, v) in &self.0 {
|
||||||
k.write_into(buf)?;
|
k.write_into(buf)?;
|
||||||
v.write_into(buf)?;
|
v.write_into(buf)?;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +52,7 @@ impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> {
|
||||||
}
|
}
|
||||||
impl McBufReadable for Tags {
|
impl McBufReadable for Tags {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let name = buf.read_resource_location()?;
|
let name = ResourceLocation::read_into(buf)?;
|
||||||
let elements = buf.read_int_id_list()?;
|
let elements = buf.read_int_id_list()?;
|
||||||
Ok(Tags { name, elements })
|
Ok(Tags { name, elements })
|
||||||
}
|
}
|
||||||
|
@ -60,3 +65,11 @@ impl McBufWritable for Tags {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Deref for TagMap {
|
||||||
|
type Target = HashMap<ResourceLocation, Vec<Tags>>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ClientboundUpdateViewDistancePacket {
|
pub struct ClientboundUpdateViewDistancePacket {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundChatCommandPacket {
|
pub struct ServerboundChatCommandPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundChatPreviewPacket {
|
pub struct ServerboundChatPreviewPacket {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::mc_buf::UnsizedByteArray;
|
use azalea_buf::McBuf;
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_buf::UnsizedByteArray;
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_core::ResourceLocation;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundCustomPayloadPacket {
|
pub struct ServerboundCustomPayloadPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundKeepAlivePacket {
|
pub struct ServerboundKeepAlivePacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundMovePlayerPacketPos {
|
pub struct ServerboundMovePlayerPacketPos {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundMovePlayerPacketPosRot {
|
pub struct ServerboundMovePlayerPacketPosRot {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundMovePlayerPacketRot {
|
pub struct ServerboundMovePlayerPacketRot {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{GamePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::GamePacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, GamePacket)]
|
#[derive(Clone, Debug, McBuf, GamePacket)]
|
||||||
pub struct ServerboundMovePlayerPacketStatusOnly {
|
pub struct ServerboundMovePlayerPacketStatusOnly {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::packets::ConnectionProtocol;
|
use crate::packets::ConnectionProtocol;
|
||||||
use packet_macros::{HandshakePacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::HandshakePacket;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
#[derive(Hash, Clone, Debug, McBuf, HandshakePacket)]
|
#[derive(Hash, Clone, Debug, McBuf, HandshakePacket)]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::mc_buf::UnsizedByteArray;
|
use azalea_buf::{McBuf, UnsizedByteArray};
|
||||||
use azalea_core::resource_location::ResourceLocation;
|
use azalea_core::ResourceLocation;
|
||||||
use packet_macros::{LoginPacket, McBuf};
|
use packet_macros::LoginPacket;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
#[derive(Hash, Clone, Debug, McBuf, LoginPacket)]
|
#[derive(Hash, Clone, Debug, McBuf, LoginPacket)]
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use super::LoginPacket;
|
use super::LoginPacket;
|
||||||
use crate::mc_buf::McBufReadable;
|
|
||||||
use crate::mc_buf::{Readable, Writable};
|
|
||||||
use azalea_auth::game_profile::GameProfile;
|
use azalea_auth::game_profile::GameProfile;
|
||||||
use azalea_core::serializable_uuid::SerializableUuid;
|
use azalea_buf::{McBufReadable, Readable, SerializableUuid, Writable};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use packet_macros::LoginPacket;
|
use packet_macros::LoginPacket;
|
||||||
use packet_macros::McBuf;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
||||||
pub struct ClientboundHelloPacket {
|
pub struct ClientboundHelloPacket {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::mc_buf::{Readable, Writable};
|
use azalea_buf::{Readable, Writable};
|
||||||
|
|
||||||
use super::LoginPacket;
|
use super::LoginPacket;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_chat::component::Component;
|
use azalea_chat::component::Component;
|
||||||
use packet_macros::{LoginPacket, McBuf};
|
use packet_macros::LoginPacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
||||||
pub struct ClientboundLoginDisconnectPacket {
|
pub struct ClientboundLoginDisconnectPacket {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{LoginPacket, McBuf};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::LoginPacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
||||||
pub struct ServerboundHelloPacket {
|
pub struct ServerboundHelloPacket {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
use azalea_buf::McBuf;
|
||||||
use azalea_crypto::SaltSignaturePair;
|
use azalea_crypto::SaltSignaturePair;
|
||||||
use packet_macros::{LoginPacket, McBuf};
|
use packet_macros::LoginPacket;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use crate::mc_buf::{McBufReadable, McBufWritable};
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
#[derive(Clone, Debug, McBuf, LoginPacket)]
|
||||||
pub struct ServerboundKeyPacket {
|
pub struct ServerboundKeyPacket {
|
||||||
|
|
|
@ -3,14 +3,11 @@ pub mod handshake;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
|
||||||
use std::io::{Read, Write};
|
use crate::connect::PacketFlow;
|
||||||
|
use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||||
use crate::{
|
|
||||||
connect::PacketFlow,
|
|
||||||
mc_buf::{McBufReadable, McBufWritable, Readable, Writable},
|
|
||||||
};
|
|
||||||
use num_derive::FromPrimitive;
|
use num_derive::FromPrimitive;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
pub const PROTOCOL_VERSION: u32 = 759;
|
pub const PROTOCOL_VERSION: u32 = 759;
|
||||||
|
|
||||||
|
@ -43,7 +40,7 @@ where
|
||||||
fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
|
fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::mc_buf::McBufReadable for ConnectionProtocol {
|
impl azalea_buf::McBufReadable for ConnectionProtocol {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
ConnectionProtocol::from_i32(buf.read_varint()?)
|
ConnectionProtocol::from_i32(buf.read_varint()?)
|
||||||
.ok_or_else(|| "Invalid intention".to_string())
|
.ok_or_else(|| "Invalid intention".to_string())
|
||||||
|
|
|
@ -4,7 +4,7 @@ use azalea_chat::component::Component;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::mc_buf::Readable;
|
use azalea_buf::Readable;
|
||||||
|
|
||||||
use super::StatusPacket;
|
use super::StatusPacket;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use packet_macros::{McBuf, StatusPacket};
|
use azalea_buf::McBuf;
|
||||||
|
use packet_macros::StatusPacket;
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, StatusPacket)]
|
#[derive(Clone, Debug, McBuf, StatusPacket)]
|
||||||
pub struct ServerboundStatusRequestPacket {}
|
pub struct ServerboundStatusRequestPacket {}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use crate::{
|
use crate::{connect::PacketFlow, packets::ProtocolPacket};
|
||||||
connect::PacketFlow,
|
use azalea_buf::{read_varint_async, Readable};
|
||||||
mc_buf::{read_varint_async, Readable},
|
|
||||||
packets::ProtocolPacket,
|
|
||||||
};
|
|
||||||
use azalea_crypto::Aes128CfbDec;
|
use azalea_crypto::Aes128CfbDec;
|
||||||
use flate2::read::ZlibDecoder;
|
use flate2::read::ZlibDecoder;
|
||||||
use std::{
|
use std::{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH};
|
use crate::{packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH};
|
||||||
use async_compression::tokio::bufread::ZlibEncoder;
|
use async_compression::tokio::bufread::ZlibEncoder;
|
||||||
|
use azalea_buf::Writable;
|
||||||
use azalea_crypto::Aes128CfbEnc;
|
use azalea_crypto::Aes128CfbEnc;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||||
|
|
|
@ -7,10 +7,10 @@ version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
azalea-block = {path = "../azalea-block"}
|
azalea-block = {path = "../azalea-block"}
|
||||||
|
azalea-buf = {path = "../azalea-buf"}
|
||||||
azalea-core = {path = "../azalea-core"}
|
azalea-core = {path = "../azalea-core"}
|
||||||
azalea-entity = {path = "../azalea-entity"}
|
azalea-entity = {path = "../azalea-entity"}
|
||||||
azalea-nbt = {path = "../azalea-nbt"}
|
azalea-nbt = {path = "../azalea-nbt"}
|
||||||
azalea-protocol = {path = "../azalea-protocol"}
|
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
nohash-hasher = "0.2.0"
|
nohash-hasher = "0.2.0"
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ use crate::palette::PalettedContainer;
|
||||||
use crate::palette::PalettedContainerType;
|
use crate::palette::PalettedContainerType;
|
||||||
use crate::World;
|
use crate::World;
|
||||||
use azalea_block::BlockState;
|
use azalea_block::BlockState;
|
||||||
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
use azalea_core::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos};
|
use azalea_core::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos};
|
||||||
use azalea_protocol::mc_buf::{McBufReadable, McBufWritable};
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::{
|
use std::{
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
|
|
@ -72,21 +72,21 @@ impl World {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_entity_with_delta(&mut self, entity_id: u32, delta: PositionDelta) -> Result<(), String> {
|
// pub fn move_entity_with_delta(&mut self, entity_id: u32, delta: PositionDelta) -> Result<(), String> {
|
||||||
let entity = self
|
// let entity = self
|
||||||
.entity_storage
|
// .entity_storage
|
||||||
.get_mut_by_id(entity_id)
|
// .get_mut_by_id(entity_id)
|
||||||
.ok_or_else(|| "Moving entity that doesn't exist".to_string())?;
|
// .ok_or_else(|| "Moving entity that doesn't exist".to_string())?;
|
||||||
let old_chunk = ChunkPos::from(entity.pos());
|
// let old_chunk = ChunkPos::from(entity.pos());
|
||||||
let new_chunk = ChunkPos::from(&new_pos);
|
// let new_chunk = ChunkPos::from(&new_pos);
|
||||||
// this is fine because we update the chunk below
|
// // this is fine because we update the chunk below
|
||||||
entity.unsafe_move(new_pos);
|
// entity.unsafe_move(new_pos);
|
||||||
if old_chunk != new_chunk {
|
// if old_chunk != new_chunk {
|
||||||
self.entity_storage
|
// self.entity_storage
|
||||||
.update_entity_chunk(entity_id, &old_chunk, &new_chunk);
|
// .update_entity_chunk(entity_id, &old_chunk, &new_chunk);
|
||||||
}
|
// }
|
||||||
Ok(())
|
// Ok(())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn add_entity(&mut self, entity: Entity) {
|
pub fn add_entity(&mut self, entity: Entity) {
|
||||||
self.entity_storage.insert(entity);
|
self.entity_storage.insert(entity);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use azalea_protocol::mc_buf::{McBufReadable, McBufVarReadable, McBufWritable, Readable, Writable};
|
use azalea_buf::{McBufReadable, McBufVarReadable, McBufWritable, Readable, Writable};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use crate::BitStorage;
|
use crate::BitStorage;
|
||||||
|
|
Loading…
Add table
Reference in a new issue