diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-12-07 21:09:58 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-07 21:09:58 -0600 |
| commit | 7d901e39bc10a855b545d7b6c167f45148a1fb0a (patch) | |
| tree | 88fe0a8f2f04f49f4df90e2f5462aa35a4278c68 /azalea-core | |
| parent | 9f5e5c092be9167e4d5222fdee4a1d2c419e5052 (diff) | |
| download | azalea-drasl-7d901e39bc10a855b545d7b6c167f45148a1fb0a.tar.xz | |
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
Diffstat (limited to 'azalea-core')
| -rwxr-xr-x | azalea-core/src/bitset.rs | 87 | ||||
| -rw-r--r--[-rwxr-xr-x] | azalea-core/src/game_type.rs | 3 | ||||
| -rwxr-xr-x | azalea-core/src/lib.rs | 2 |
3 files changed, 90 insertions, 2 deletions
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<Self, BufReadError> { + let mut data = vec![0; length.div_ceil(8)]; + buf.read_exact(&mut data)?; + Ok(BitSet::from(data)) + } +} + +impl From<Vec<u64>> for BitSet { + fn from(data: Vec<u64>) -> Self { + BitSet { data } + } +} + +impl From<Vec<u8>> for BitSet { + fn from(data: Vec<u8>) -> 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<const N: usize> +where + [(); N.div_ceil(8)]: Sized, +{ + data: [u8; N.div_ceil(8)], +} + +impl<const N: usize> FixedBitSet<N> +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<const N: usize> McBufReadable for FixedBitSet<N> +where + [u8; N.div_ceil(8)]: Sized, +{ + fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + 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<const N: usize> McBufWritable for FixedBitSet<N> +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<const N: usize> Default for FixedBitSet<N> +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 index 75ee0674..c4b4cf76 100755..100644 --- 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::*; |
