Skip to content

Commit

Permalink
Components (ish) [Wont Compile]
Browse files Browse the repository at this point in the history
  • Loading branch information
Outspending committed Jan 5, 2025
1 parent 20ceb40 commit 2db4348
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/lib/net/src/slot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::io::Read;

use ferrumc_macros::{NetDecode, NetEncode};
use ferrumc_net_codec::{
decode::{NetDecode, NetDecodeOpts, NetDecodeResult},
net_types::{length_prefixed_vec::LengthPrefixedVec, var_int::VarInt},
};

#[derive(NetEncode, Debug, Clone, Copy)]
pub enum SlotComponent {
MaxStackSize { max_stack_size: VarInt },
}

#[derive(Debug, Clone, Copy)]
pub struct NetworkSlot {
pub item_count: VarInt,
pub item_id: Option<VarInt>,
pub components_to_add: Option<LengthPrefixedVec<SlotComponent>>,
pub components_to_remove: Option<LengthPrefixedVec<VarInt>>,
}

impl NetworkSlot {
pub fn new(item_count: i32, item_id: i32) -> Self {
Self::with_components(item_count, item_id, vec![])
}

pub fn with_components(item_count: i32, item_id: i32, components: Vec<SlotComponent>) -> Self {
Self {
item_count: VarInt::new(item_count),
item_id: if item_count == 0 {
None
} else {
Some(VarInt::new(item_id))
},
components_to_add: if item_count == 0 {
None
} else {
Some(LengthPrefixedVec::new(components))
},
components_to_remove: if item_count == 0 {
None
} else {
Some(LengthPrefixedVec::default())
},
}
}

pub fn empty() -> Self {
Self::new(0, 0)
}

pub fn item_id(&mut self, item_id: VarInt) -> &mut Self {
self.item_id = Some(item_id);
self
}
}

0 comments on commit 2db4348

Please sign in to comment.