Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e5bd06e
packet accept_teleportation
hayanesuru May 1, 2026
696199f
packet block_entity_tag_query
hayanesuru May 1, 2026
a0ec286
packet bundle_item_selected
hayanesuru May 1, 2026
9875f91
packet change_difficulty
hayanesuru May 2, 2026
807acf7
packet change_game_mode
hayanesuru May 2, 2026
27080d0
packet chat_ack
hayanesuru May 2, 2026
a41923a
packet chat_command
hayanesuru May 2, 2026
7148391
packet chat_command_signed
hayanesuru May 2, 2026
8762881
packet chat
hayanesuru May 3, 2026
654fe7e
packet chat_session_update
hayanesuru May 3, 2026
e035163
packet chunk_batch_received
hayanesuru May 3, 2026
a860465
packet client_command
hayanesuru May 3, 2026
6bc072b
packet client_tick_end
hayanesuru May 3, 2026
508846f
packet client_information
hayanesuru May 3, 2026
2cdcdd6
packet command_suggestion
hayanesuru May 3, 2026
e8d40c8
packet configuration_acknowledged
hayanesuru May 3, 2026
bccf711
packet container_button_click
hayanesuru May 3, 2026
0901a89
packet container_click
hayanesuru May 3, 2026
e37d6fd
packet container_close
hayanesuru May 3, 2026
baa0ec0
packet container_slot_state_changed
hayanesuru May 3, 2026
5a10b74
packet cookie_response
hayanesuru May 3, 2026
ed704bc
packet custom_payload
hayanesuru May 3, 2026
fc0ae5b
packet debug_subscription_request
hayanesuru May 3, 2026
274e820
packet edit_book
hayanesuru May 3, 2026
9026254
packet entity_tag_query
hayanesuru May 3, 2026
b73c12c
packet interact
hayanesuru May 3, 2026
282307b
packet jigsaw_generate
hayanesuru May 3, 2026
4a56da7
packet keep_alive
hayanesuru May 3, 2026
6c5b416
packet lock_difficulty
hayanesuru May 3, 2026
0ed48b8
packet move_player_pos
hayanesuru May 3, 2026
4ca1de5
packet move_player_pos_rot
hayanesuru May 3, 2026
1fe1b99
packet move_player_rot
hayanesuru May 3, 2026
b44df34
packet move_player_status_only
hayanesuru May 3, 2026
244b404
packet move_vehicle
hayanesuru May 3, 2026
49efbc1
packet paddle_boat
hayanesuru May 3, 2026
1311061
packet pick_item_from_block
hayanesuru May 3, 2026
3b09355
packet pick_item_from_entity
hayanesuru May 3, 2026
e3bf882
packet ping_request
hayanesuru May 3, 2026
ea227e8
packet place_recipe
hayanesuru May 3, 2026
51c2ddd
packet player_abilities
hayanesuru May 3, 2026
c592d5c
packet player_action
hayanesuru May 3, 2026
d0f7cd2
packet player_command
hayanesuru May 3, 2026
310460a
packet player_input
hayanesuru May 3, 2026
8743b8c
packet player_loaded
hayanesuru May 3, 2026
aad3ed8
packet pong
hayanesuru May 3, 2026
d94a58b
packet recipe_book_change_settings
hayanesuru May 3, 2026
a5071b4
packet recipe_book_seen_recipe
hayanesuru May 3, 2026
7291943
packet rename_item
hayanesuru May 3, 2026
18ae840
packet resource_pack
hayanesuru May 3, 2026
42363e3
packet seen_advancements
hayanesuru May 3, 2026
831521b
packet select_trade
hayanesuru May 3, 2026
7a02ff4
packet set_beacon
hayanesuru May 3, 2026
d632166
packet set_carried_item
hayanesuru May 3, 2026
8001838
packet set_command_block
hayanesuru May 3, 2026
d55b944
packet set_command_minecart
hayanesuru May 3, 2026
eb67cf1
packet set_creative_mode_slot
hayanesuru May 3, 2026
d178acc
packet set_jigsaw_block
hayanesuru May 3, 2026
ec02907
packet set_structure_block
hayanesuru May 3, 2026
856c85f
packet set_test_block
hayanesuru May 3, 2026
78c4f0d
packet sign_update
hayanesuru May 3, 2026
db8d535
packet swing
hayanesuru May 3, 2026
655e6a9
packet teleport_to_entity
hayanesuru May 3, 2026
2a2a8d9
add hashbrown
hayanesuru May 4, 2026
54ed1fb
packet test_instance_block_action
hayanesuru May 5, 2026
fbf7095
packet use_item_on
hayanesuru May 5, 2026
8d18093
packet use_item
hayanesuru May 5, 2026
ec6d2ad
packet custom_click_action
hayanesuru May 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 3 additions & 31 deletions haya_collection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate alloc;

use alloc::boxed::Box;
use alloc::vec::Vec;
use mser::{Error, Read, Reader, V21, Write, Writer};
use mser::{Error, Read, Reader, V21, Write, Writer, read_v21_len};

pub enum List<'a, T: 'a, const MAX: usize = { usize::MAX }> {
Borrowed(&'a [T]),
Expand Down Expand Up @@ -95,10 +95,7 @@ pub fn capacity_fix(len: usize) -> usize {

impl<'a, T: Read<'a>, const MAX: usize> Read<'a> for List<'a, T, MAX> {
fn read(buf: &mut Reader<'a>) -> Result<Self, Error> {
let len = V21::read(buf)?.0 as usize;
if len > MAX {
return Err(Error);
}
let len = read_v21_len(buf, MAX)?;
let mut vec = Vec::with_capacity(capacity_fix(len));
for _ in 0..len {
vec.push(T::read(buf)?);
Expand Down Expand Up @@ -135,10 +132,7 @@ impl<'a, K: Write + 'a, V: Write + 'a, const MAX: usize> Write for Map<'a, K, V,

impl<'a, K: Read<'a>, V: Read<'a>, const MAX: usize> Read<'a> for Map<'a, K, V, MAX> {
fn read(buf: &mut Reader<'a>) -> Result<Self, Error> {
let len = V21::read(buf)?.0 as usize;
if len > MAX {
return Err(Error);
}
let len = read_v21_len(buf, MAX)?;
let mut vec = Vec::with_capacity(capacity_fix(len));
for _ in 0..len {
let k = K::read(buf)?;
Expand Down Expand Up @@ -179,25 +173,3 @@ impl<'a, T: Read<'a>> Read<'a> for Cow<'a, T> {
Ok(Self::Owned(Box::new(T::read(buf)?)))
}
}

#[derive(Debug, Clone, Copy)]
pub struct FixedByteArray<'a, const L: usize>(pub &'a [u8; L]);

impl<'a, const L: usize> Read<'a> for FixedByteArray<'a, L> {
fn read(buf: &mut Reader<'a>) -> Result<Self, Error> {
match buf.read_array() {
Ok(x) => Ok(Self(x)),
Err(e) => Err(e),
}
}
}

impl<'a, const L: usize> Write for FixedByteArray<'a, L> {
unsafe fn write(&self, w: &mut Writer) {
unsafe { w.write(self.0) }
}

fn len_s(&self) -> usize {
self.0.len()
}
}
30 changes: 28 additions & 2 deletions haya_math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ impl From<Vec3> for LpVec3 {
pub struct ByteAngle(pub u8);

impl ByteAngle {
pub fn new(f: f32) -> ByteAngle {
ByteAngle(libm::floorf(f * 256.0 / 360.0) as u8)
pub fn new(f: f32) -> Self {
Self(libm::floorf(f * 256.0 / 360.0) as u8)
}

pub fn to_degrees(self) -> f32 {
Expand Down Expand Up @@ -562,6 +562,32 @@ pub enum Direction {
East,
}

#[derive(Clone, Copy, Eq, PartialEq)]
pub struct ByteDirection(pub Direction);

impl<'a> Read<'a> for ByteDirection {
fn read(buf: &mut Reader<'a>) -> Result<Self, Error> {
Ok(Self(match buf.read_byte()? {
1 => Direction::Up,
2 => Direction::North,
3 => Direction::South,
4 => Direction::West,
5 => Direction::East,
_ => Direction::Down,
}))
}
}

impl Write for ByteDirection {
unsafe fn write(&self, w: &mut Writer) {
unsafe { w.write_byte(self.0 as u8) }
}

fn len_s(&self) -> usize {
1
}
}

impl<'a> Read<'a> for Direction {
fn read(buf: &mut Reader<'a>) -> Result<Self, Error> {
Ok(match V21::read(buf)?.0 {
Expand Down
47 changes: 13 additions & 34 deletions haya_nbt/src/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,31 @@ use haya_mutf8::{as_mutf8_ascii, decode_mutf8_len};
use haya_str::HayaStr;
use mser::{Error, Read, Reader, Write, Writer};

enum CowVec {
Thin(HayaStr),
Heap(Vec<u8>),
}

impl<'a> Read<'a> for Name {
fn read(buf: &mut Reader<'a>) -> Result<Self, Error> {
let len = u16::read(buf)? as usize;
let data = buf.read_slice(len)?;
if let Some(x) = as_mutf8_ascii(data) {
Ok(Self::new(x))
unsafe { Ok(Self::new(x)) }
} else {
let len = decode_mutf8_len(data)?;
let mut ptr = if len <= haya_str::MAX {
CowVec::Thin(HayaStr::new())
} else {
CowVec::Heap(Vec::with_capacity(len))
};
let mut vec = Vec::with_capacity(len);
unsafe {
mser::write_unchecked(
match &mut ptr {
CowVec::Thin(s) => s.as_mut_ptr(),
CowVec::Heap(x) => x.as_mut_ptr(),
},
&(DecodeMutf8(data, len)),
);
match ptr {
CowVec::Thin(mut s) => {
s.set_len(len);
Ok(Self::Thin(s))
}
CowVec::Heap(mut x) => {
x.set_len(len);
Ok(Self::Heap(String::from_utf8_unchecked(x).into_boxed_str()))
}
}
mser::write_unchecked(vec.as_mut_ptr(), &(DecodeMutf8(data, len)));
vec.set_len(len);
Ok(Self(crate::Inner::Heap(
String::from_utf8_unchecked(vec).into_boxed_str(),
)))
}
}
}
}

impl AsRef<str> for Name {
fn as_ref(&self) -> &str {
match self {
Self::Thin(x) => x,
Self::Heap(x) => x,
match &self.0 {
crate::Inner::Thin(x) => x,
crate::Inner::Heap(x) => x,
}
}
}
Expand All @@ -66,10 +45,10 @@ impl core::ops::Deref for Name {
}

impl Name {
pub fn new(s: &str) -> Self {
pub(crate) unsafe fn new(s: &str) -> Self {
match HayaStr::copy_from(s) {
Ok(x) => Self::Thin(x),
Err(_) => Self::Heap(s.to_owned().into_boxed_str()),
Ok(x) => Self(crate::Inner::Thin(x)),
Err(_) => Self(crate::Inner::Heap(s.to_owned().into_boxed_str())),
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion haya_nbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pub struct Compound(Vec<(Name, Tag)>);
pub struct CompoundStringify(pub Compound);

#[derive(Clone, Debug)]
pub enum Name {
pub struct Name(Inner);

#[derive(Clone, Debug)]
enum Inner {
Thin(HayaStr),
Heap(Box<str>),
}
Expand Down
26 changes: 16 additions & 10 deletions haya_nbt/src/string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Error, Name, RawStringTag, Read, RefStringTag, StringTag, Write, Writer};
use crate::{Error, Inner, Name, RawStringTag, Read, RefStringTag, StringTag, Write, Writer};
use alloc::borrow::ToOwned;
use alloc::vec::Vec;
use haya_mutf8::{as_mutf8_ascii, decode_mutf8, decode_mutf8_len, encode_mutf8, encode_mutf8_len};
Expand Down Expand Up @@ -129,21 +129,27 @@ impl Write for Name {
#[inline]
unsafe fn write(&self, w: &mut Writer) {
unsafe {
if let Some(x) = RawStringTag::new(self.as_bytes()) {
x.write(w);
} else {
(encode_mutf8_len(self) as u16).write(w);
encode_mutf8(self, w);
match &self.0 {
Inner::Thin(direct) => RawStringTag::new_unchecked(direct).write(w),
Inner::Heap(x) => match RawStringTag::new(x.as_bytes()) {
Some(x) => x.write(w),
None => {
(encode_mutf8_len(self) as u16).write(w);
encode_mutf8(self, w);
}
},
}
}
}

#[inline]
fn len_s(&self) -> usize {
if let Some(x) = RawStringTag::new(self.as_bytes()) {
x.len_s()
} else {
encode_mutf8_len(self) + 2
match &self.0 {
Inner::Thin(direct) => RawStringTag::new_unchecked(direct).len_s(),
Inner::Heap(x) => match RawStringTag::new(x.as_bytes()) {
Some(x) => x.len_s(),
None => encode_mutf8_len(self) + 2,
},
}
}
}
2 changes: 2 additions & 0 deletions haya_palette/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ edition.workspace = true
[dependencies]
mser = { workspace = true }
minecraft_data = { workspace = true }

hashbrown = { version = "0", default-features = false }
Loading