Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Outspending committed Jan 5, 2025
1 parent 8d90ee5 commit 2ff5a83
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/lib/derive_macros/src/inventory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ pub fn create(input: TokenStream) -> TokenStream {
}
}

pub fn inventory_type(args: TokenStream, input: TokenStream) -> TokenStream {
pub fn inventory_type(_args: TokenStream, input: TokenStream) -> TokenStream {
input
}

pub fn slot(args: TokenStream, input: TokenStream) -> TokenStream {
pub fn slot(_args: TokenStream, input: TokenStream) -> TokenStream {
input
}
39 changes: 39 additions & 0 deletions src/lib/derive_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use proc_macro::TokenStream;

mod events;
mod helpers;
mod inventory;
mod nbt;
mod net;
mod profiling;
mod static_loading;

#[proc_macro_attribute]
pub fn profile(attr: TokenStream, item: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -44,6 +46,11 @@ pub fn net_decode(input: TokenStream) -> TokenStream {
}

// #=================== PACKETS ===================#
/// You can get the packet_id from:
/// https://protocol.ferrumc.com,
/// In incoming packets (serverbound),
/// You should use the 'resource' value referenced in the packet,
/// e.g. "finish_configuration", which would result in the packet_id being automatically fetched.
#[proc_macro_attribute]
pub fn packet(args: TokenStream, input: TokenStream) -> TokenStream {
net::packets::attribute(args, input)
Expand All @@ -53,4 +60,36 @@ pub fn packet(args: TokenStream, input: TokenStream) -> TokenStream {
pub fn bake_packet_registry(input: TokenStream) -> TokenStream {
net::packets::bake_registry(input)
}

/// Get a packet entry from the packets.json file.
/// returns protocol_id (as 0x??) of the specified packet.
/// e.g. get_packet_entry!("play", "clientbound", "add_entity") -> 0x01
#[proc_macro]
pub fn get_packet_entry(input: TokenStream) -> TokenStream {
static_loading::packets::get(input)
}
// #=================== PACKETS ===================#

/// Get a registry entry from the registries.json file.
/// returns protocol_id (as u64) of the specified entry.
#[proc_macro]
pub fn get_registry_entry(input: TokenStream) -> TokenStream {
static_loading::registry::get(input)
}

// #=================== INVENTORY ===================#
#[proc_macro_derive(Inventory, attributes(slot))]
pub fn create_inventory(input: TokenStream) -> TokenStream {
inventory::create(input)
}

#[proc_macro_attribute]
pub fn slot(args: TokenStream, input: TokenStream) -> TokenStream {
inventory::slot(args, input)
}

#[proc_macro_attribute]
pub fn inventory_type(args: TokenStream, input: TokenStream) -> TokenStream {
inventory::inventory_type(args, input)
}
// #=================== INVENTORY ===================#
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/incoming/click_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl ChangedSlots {
}

#[derive(Debug)]
#[packet(packet_id = 0x0E, state = "play")]
#[packet(packet_id = "container_click", state = "play")]
pub struct ClickContainerPacket {
pub window_id: u8,
pub state_id: VarInt,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/incoming/close_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ferrumc_state::ServerState;
use std::sync::Arc;

#[derive(NetDecode, Debug)]
#[packet(packet_id = 0x0F, state = "play")]
#[packet(packet_id = "container_close", state = "play")]
pub struct IncomingCloseContainerPacket {
pub window_id: u8,
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/incoming/set_creative_mode_slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};

#[derive(NetDecode, Debug)]
#[packet(packet_id = 0x32, state = "play")]
#[packet(packet_id = "set_creative_mode_slot", state = "play")]
pub struct SetCreativeModeSlotPacket {
pub slot: i16,
pub clicked_item: NetworkSlot,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/incoming/set_held_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ferrumc_state::ServerState;
use crate::{packets::IncomingPacket, NetResult};

#[derive(NetDecode, Debug)]
#[packet(packet_id = 0x2F, state = "play")]
#[packet(packet_id = "set_carried_item", state = "play")]
pub struct IncomingSetHeldItemPacket {
pub slot: u16,
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/incoming/use_item_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ferrumc_state::ServerState;
use std::sync::Arc;

#[derive(NetDecode, Debug)]
#[packet(packet_id = 0x38, state = "play")]
#[packet(packet_id = "use_item_on", state = "play")]
pub struct UseItemOnPacket {
pub hand: VarInt,
pub location: NetworkPosition,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/outgoing/close_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ferrumc_macros::{packet, NetEncode};
use std::io::Write;

#[derive(NetEncode)]
#[packet(packet_id = 0x12)]
#[packet(packet_id = "container_close", state_id = "play")]
pub struct CloseContainerPacket {
pub window_id: u8,
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/outgoing/open_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ferrumc_text::{TextComponent, TextComponentBuilder};
use std::io::Write;

#[derive(NetEncode)]
#[packet(packet_id = 0x33)]
#[packet(packet_id = "open_screen", state_id = "play")]
pub struct OpenScreenPacket {
pub window_id: VarInt,
pub window_type: VarInt,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/outgoing/set_container_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ferrumc_net_codec::net_types::{length_prefixed_vec::LengthPrefixedVec, var_i
use std::io::Write;

#[derive(NetEncode, Debug)]
#[packet(packet_id = 0x13)]
#[packet(packet_id = "container_set_content", state_id = "play")]
pub struct SetContainerContentPacket {
pub window_id: u8,
pub state_id: VarInt,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/outgoing/set_container_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ferrumc_macros::{packet, NetEncode};
use std::io::Write;

#[derive(NetEncode)]
#[packet(packet_id = 0x14)]
#[packet(packet_id = "container_set_data", state_id = "play")]
pub struct SetContainerPropertyPacket {
pub window_id: u8,
pub property: u16,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/outgoing/set_container_slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl NetworkSlot {
}

#[derive(NetEncode)]
#[packet(packet_id = 0x15)]
#[packet(packet_id = "container_set_slot", state_id = "play")]
pub struct SetContainerSlotPacket {
pub window_id: VarInt,
pub state_id: VarInt,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/outgoing/set_equipment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Equipment {
}

#[derive(NetEncode)]
#[packet(packet_id = 0x5B)]
#[packet(packet_id = "set_equipment", state_id = "play")]
pub struct SetEquipmentPacket {
pub conn_id: VarInt,
pub equipment: Vec<Equipment>,
Expand Down

0 comments on commit 2ff5a83

Please sign in to comment.