Skip to content
16 changes: 4 additions & 12 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ pub fn derive_packet(_item: TokenStream) -> TokenStream {
fn ty(&self) -> PacketType {
PacketType::#ident
}

fn box_clone(&self) -> Box<dyn Packet> {
Box::new((*self).clone())
}
}
};

Expand Down
92 changes: 90 additions & 2 deletions core/src/network/packet/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ lazy_static! {
};
}

fn bla() {}
macro_rules! box_clone_impl {
($this:ident) => {
return Box::new((*$this).clone());
};
}

// SERVERBOUND

Expand Down Expand Up @@ -114,6 +118,10 @@ impl Packet for Handshake {
fn ty(&self) -> PacketType {
PacketType::Handshake
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -169,6 +177,10 @@ impl Packet for EncryptionResponse {
fn ty(&self) -> PacketType {
PacketType::EncryptionResponse
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -269,6 +281,10 @@ impl Packet for PluginMessageServerbound {
fn ty(&self) -> PacketType {
PacketType::PluginMessageServerbound
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -318,6 +334,10 @@ impl Packet for UseEntity {
fn ty(&self) -> PacketType {
PacketType::UseEntity
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(AsAny, new, Clone)]
Expand Down Expand Up @@ -438,6 +458,10 @@ impl Packet for PlayerDigging {
fn ty(&self) -> PacketType {
PacketType::PlayerDigging
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -481,6 +505,10 @@ impl Packet for EntityAction {
fn ty(&self) -> PacketType {
PacketType::EntityAction
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, FromPrimitive, ToPrimitive)]
Expand Down Expand Up @@ -621,6 +649,10 @@ impl Packet for AnimationServerbound {
fn ty(&self) -> PacketType {
PacketType::AnimationServerbound
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -685,6 +717,10 @@ impl Packet for PlayerBlockPlacement {
fn ty(&self) -> PacketType {
PacketType::PlayerBlockPlacement
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -723,6 +759,10 @@ impl Packet for EncryptionRequest {
fn ty(&self) -> PacketType {
PacketType::EncryptionRequest
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -842,6 +882,10 @@ impl Packet for SpawnPlayer {
fn ty(&self) -> PacketType {
PacketType::SpawnPlayer
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Clone)]
Expand All @@ -863,6 +907,10 @@ impl Packet for AnimationClientbound {
fn ty(&self) -> PacketType {
PacketType::AnimationClientbound
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Clone)]
Expand All @@ -888,6 +936,10 @@ impl Packet for Statistics {
fn ty(&self) -> PacketType {
PacketType::Statistics
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -961,6 +1013,10 @@ impl Packet for BossBar {
fn ty(&self) -> PacketType {
PacketType::BossBar
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -1078,6 +1134,10 @@ impl Packet for WindowItems {
fn ty(&self) -> PacketType {
PacketType::WindowItems
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -1119,6 +1179,10 @@ impl Packet for PluginMessageClientbound {
fn ty(&self) -> PacketType {
PacketType::PluginMessageClientbound
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -1189,6 +1253,10 @@ impl Packet for Explosion {
fn ty(&self) -> PacketType {
PacketType::Explosion
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -1285,6 +1353,10 @@ impl Packet for ChunkData {
fn ty(&self) -> PacketType {
PacketType::ChunkData
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -1406,6 +1478,10 @@ impl Packet for CombatEvent {
fn ty(&self) -> PacketType {
unimplemented!()
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(new, Clone)]
Expand Down Expand Up @@ -1469,6 +1545,10 @@ impl Packet for PlayerInfo {
fn ty(&self) -> PacketType {
PacketType::PlayerInfo
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1521,7 +1601,7 @@ pub struct UseBed {

#[derive(Default, AsAny, new, Clone)]
pub struct DestroyEntities {
entity_ids: Vec<VarInt>,
pub entity_ids: Vec<VarInt>,
}

impl Packet for DestroyEntities {
Expand All @@ -1540,6 +1620,10 @@ impl Packet for DestroyEntities {
fn ty(&self) -> PacketType {
PacketType::DestroyEntities
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down Expand Up @@ -1587,6 +1671,10 @@ impl Packet for PacketEntityMetadata {
fn ty(&self) -> PacketType {
PacketType::EntityMetadata
}

fn box_clone(&self) -> Box<dyn Packet> {
box_clone_impl!(self);
}
}

#[derive(Default, AsAny, new, Packet, Clone)]
Expand Down
3 changes: 3 additions & 0 deletions core/src/network/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub trait Packet: AsAny + Send {
fn read_from(&mut self, buf: &mut dyn PacketBuf) -> Result<(), ()>;
fn write_to(&self, buf: &mut ByteBuf);
fn ty(&self) -> PacketType;

/// Returns a clone of this packet in a dynamic box.
fn box_clone(&self) -> Box<dyn Packet>;
}

#[derive(Clone, Debug)]
Expand Down
Loading