aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src
diff options
context:
space:
mode:
authorEightFactorial <murphkev000@gmail.com>2022-12-06 18:48:48 -0800
committerGitHub <noreply@github.com>2022-12-06 20:48:48 -0600
commit9f5e5c092be9167e4d5222fdee4a1d2c419e5052 (patch)
tree1d0a8b57434e0afd14b4a02cbbc579a3ad70da61 /azalea-core/src
parente99a822995c80e1f95c5f7a69e0d8c5d131af20f (diff)
downloadazalea-drasl-9f5e5c092be9167e4d5222fdee4a1d2c419e5052.tar.xz
Complete ClientboundCommand{Suggestion}sPacket, Serde support for NBT Tags (#49)
* Serializing ClientboundStatusResponsePacket Enable serialization of ClientboundStatusResponsePacket * Update clientbound_status_response_packet.rs Add options previewsChat and enforcesSecureChat * Serialize Style and TextColor * Serialize BaseComponent * Serialize TextComponent * Fix Style * Serialize Component * Fix multiple formats per message, fix reset tag * Fix Style, again * Use FlatMapSerializer * Forgot italics * Count struct fields, reorganize logic * Serialize TranslatableComponent * Rewrite TextComponent Serializer * Fix using TextColor::Parse * Code Cleanup * Add default attribute, just in case * Clippy * use serde derive feature + preferred formatting choices * McBufWritable for BrigadierNodeStub * Thanks Clippy... * Implement suggestions in azalea-brigadier * Serde support for NBT Tags * Serde options * Forgot Options * Oops, that's McBufWritable for BrigadierParser * Fix McBufWritable for SlotData * Complete ClientboundUpdateRecipesPacket * fix some issues * better impl McBufReadable for Suggestions Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: mat <github@matdoes.dev>
Diffstat (limited to 'azalea-core/src')
-rwxr-xr-xazalea-core/src/slot.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/azalea-core/src/slot.rs b/azalea-core/src/slot.rs
index f1cd4f0b..4406e08d 100755
--- a/azalea-core/src/slot.rs
+++ b/azalea-core/src/slot.rs
@@ -1,6 +1,7 @@
// TODO: have an azalea-inventory or azalea-container crate and put this there
use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable};
+use azalea_nbt::Tag;
use std::io::{Cursor, Write};
#[derive(Debug, Clone, Default)]
@@ -13,29 +14,27 @@ pub enum Slot {
#[derive(Debug, Clone, McBuf)]
pub struct SlotData {
#[var]
- pub id: i32,
+ pub id: u32,
pub count: u8,
- pub nbt: azalea_nbt::Tag,
+ pub nbt: Tag,
}
impl McBufReadable for Slot {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
- let present = bool::read_from(buf)?;
- if !present {
- return Ok(Slot::Empty);
- }
- let slot = SlotData::read_from(buf)?;
- Ok(Slot::Present(slot))
+ let slot = Option::<SlotData>::read_from(buf)?;
+ Ok(slot.map_or(Slot::Empty, Slot::Present))
}
}
impl McBufWritable for Slot {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
match self {
- Slot::Empty => 0u8.write_into(buf)?,
- Slot::Present(i) => i.write_into(buf)?,
- }
-
+ Slot::Empty => false.write_into(buf)?,
+ Slot::Present(i) => {
+ true.write_into(buf)?;
+ i.write_into(buf)?;
+ }
+ };
Ok(())
}
}