From 7d901e39bc10a855b545d7b6c167f45148a1fb0a Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Wed, 7 Dec 2022 21:09:58 -0600 Subject: 1.19.3 (#34) * start updating to 22w42a * work a bit more on 22w42a * player chat packet * serverbound hello packet * Update mod.rs * add more stuff to clientbound player chat packet * ClientboundPlayerInfoUpdatePacket * features enabled and container closed * serverbound chat packets * make it compile * 22w43a * ServerboundChatSessionUpdatePacket * profile_public_key isn't Option anymore * Update bitset.rs * joining a server works * fix entitydatavalue * backtraces + fix clientbound chat message * fix some warnings and add more ecomments * 22w44a * generate en_us.json * add updating guide to codegen/readme * fix some markdown * update list of generated things * metadata stuff * Replace PJS generator mod with PixLyzer (#38) * pixlizer extractor * start working on shape extraction * fix generating language * fix pixlyzer shape generation * use empty_shape * generate blocks and shapes * update pixlyzer dir * Revert "update pixlyzer dir" This reverts commit ee9a0e7a49936dd8569c610ba9b6455895eeff71. * fix * fix * Revert "fix" This reverts commit ad12ddcb009ccc4eeb13ddef0871db1d9322ab7d. * fix * detect pixlyzer fail * fix pixlyzer * 22w45a * gen entities * add async-trait dep * update codegen/readme.md * explain when rust_log should be used * remove some unused code * start fixing pixlyzer issues * fix a thing in codegen * almost fixed * more progress towards 1.19.3 * 1.19.3-pre2 * fixes * revert some hardcoded property names * Delete clientbound_player_info_packet.rs * handle 1.19.3 player info packets * handle playerinforemove * start updating to 1.19.3-rc1 * optional registries work * fix some issues with 1.19.3 chat doesn't work yet * aaaaaaaaaaaaaaaaa * oh * ignore unused shapes * uncomment generate_blocks * fix migrate * 1.19.3-rc2 * fix clippy warnings * 1.19.3-rc3 * split the azalea-buf macro into separate modules * improve Recipe in protocol * 1.19.3 --- azalea-core/src/bitset.rs | 87 +++++++++++++++++++++++++++++++++++++++++++- azalea-core/src/game_type.rs | 3 +- azalea-core/src/lib.rs | 2 + 3 files changed, 90 insertions(+), 2 deletions(-) mode change 100755 => 100644 azalea-core/src/game_type.rs (limited to 'azalea-core/src') diff --git a/azalea-core/src/bitset.rs b/azalea-core/src/bitset.rs index d878bbf5..41d43165 100755 --- a/azalea-core/src/bitset.rs +++ b/azalea-core/src/bitset.rs @@ -1,4 +1,6 @@ -use azalea_buf::McBuf; +use std::io::{Cursor, Read, Write}; + +use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; /// Represents Java's BitSet, a list of bits. #[derive(Debug, Clone, PartialEq, Eq, Hash, Default, McBuf)] @@ -105,6 +107,89 @@ impl BitSet { pub fn set(&mut self, bit_index: usize) { self.data[bit_index / 64] |= 1u64 << (bit_index % 64); } + + /// Read a BitSet with a known length. + pub fn read_fixed(buf: &mut Cursor<&[u8]>, length: usize) -> Result { + let mut data = vec![0; length.div_ceil(8)]; + buf.read_exact(&mut data)?; + Ok(BitSet::from(data)) + } +} + +impl From> for BitSet { + fn from(data: Vec) -> Self { + BitSet { data } + } +} + +impl From> for BitSet { + fn from(data: Vec) -> Self { + let mut words = vec![0; data.len().div_ceil(8)]; + for (i, byte) in data.iter().enumerate() { + words[i / 8] |= (*byte as u64) << ((i % 8) * 8); + } + BitSet { data: words } + } +} + +/// A list of bits with a known fixed size. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct FixedBitSet +where + [(); N.div_ceil(8)]: Sized, +{ + data: [u8; N.div_ceil(8)], +} + +impl FixedBitSet +where + [u8; N.div_ceil(8)]: Sized, +{ + pub fn new() -> Self { + FixedBitSet { + data: [0; N.div_ceil(8)], + } + } + + pub fn index(&self, index: usize) -> bool { + (self.data[index / 8] & (1u8 << (index % 8))) != 0 + } + + pub fn set(&mut self, bit_index: usize) { + self.data[bit_index / 8] |= 1u8 << (bit_index % 8); + } +} + +impl McBufReadable for FixedBitSet +where + [u8; N.div_ceil(8)]: Sized, +{ + fn read_from(buf: &mut Cursor<&[u8]>) -> Result { + let mut data = [0; N.div_ceil(8)]; + for item in data.iter_mut().take(N.div_ceil(8)) { + *item = u8::read_from(buf)?; + } + Ok(FixedBitSet { data }) + } +} +impl McBufWritable for FixedBitSet +where + [u8; N.div_ceil(8)]: Sized, +{ + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + for i in 0..N.div_ceil(8) { + self.data[i].write_into(buf)?; + } + Ok(()) + } +} +impl Default for FixedBitSet +where + [u8; N.div_ceil(8)]: Sized, +{ + fn default() -> Self { + Self::new() + } } #[cfg(test)] diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs old mode 100755 new mode 100644 index 75ee0674..c4b4cf76 --- a/azalea-core/src/game_type.rs +++ b/azalea-core/src/game_type.rs @@ -1,8 +1,9 @@ use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; use std::io::{Cursor, Write}; -#[derive(Hash, Copy, Clone, Debug)] +#[derive(Hash, Copy, Clone, Debug, Default)] pub enum GameType { + #[default] Survival, Creative, Adventure, diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs index 7c74bdcb..30af2448 100755 --- a/azalea-core/src/lib.rs +++ b/azalea-core/src/lib.rs @@ -1,6 +1,8 @@ //! Random miscellaneous things like UUIDs that don't deserve their own crate. #![feature(int_roundings)] +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] mod difficulty; pub use difficulty::*; -- cgit v1.2.3