Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.5 #127

Merged
merged 16 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
item components are "implemented" meowmeowmeowmeowmeowmeowmeowmeowmeo…
…wmeowmeowmeowmeowmeowmeowmeowmeowmeow
  • Loading branch information
mat-1 committed Apr 17, 2024
commit 561f226b30f96806973d871e17d045ba9c155f65
16 changes: 13 additions & 3 deletions Cargo.lock

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

38 changes: 24 additions & 14 deletions azalea-buf/azalea-buf-macros/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,34 @@ fn read_named_fields(

pub fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream {
match data {
syn::Data::Struct(syn::DataStruct { fields, .. }) => {
let syn::Fields::Named(FieldsNamed { named, .. }) = fields else {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
};

let (read_fields, read_field_names) = read_named_fields(named);
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
syn::Fields::Named(FieldsNamed { named, .. }) => {
let (read_fields, read_field_names) = read_named_fields(named);

quote! {
impl azalea_buf::McBufReadable for #ident {
fn read_from(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
#(#read_fields)*
Ok(#ident {
#(#read_field_names: #read_field_names),*
})
quote! {
impl azalea_buf::McBufReadable for #ident {
fn read_from(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
#(#read_fields)*
Ok(Self {
#(#read_field_names: #read_field_names),*
})
}
}
}
}
syn::Fields::Unit => {
quote! {
impl azalea_buf::McBufReadable for #ident {
fn read_from(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
Ok(Self)
}
}
}
}
}
_ => {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
}
},
syn::Data::Enum(syn::DataEnum { variants, .. }) => {
let mut match_contents = quote!();
let mut variant_discrim: u32 = 0;
Expand Down
36 changes: 23 additions & 13 deletions azalea-buf/azalea-buf-macros/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,33 @@ fn write_named_fields(

pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream {
match data {
syn::Data::Struct(syn::DataStruct { fields, .. }) => {
let syn::Fields::Named(FieldsNamed { named, .. }) = fields else {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
};

let write_fields =
write_named_fields(named, Some(&Ident::new("self", Span::call_site())));
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
syn::Fields::Named(FieldsNamed { named, .. }) => {
let write_fields =
write_named_fields(named, Some(&Ident::new("self", Span::call_site())));

quote! {
impl azalea_buf::McBufWritable for #ident {
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
#write_fields
Ok(())
quote! {
impl azalea_buf::McBufWritable for #ident {
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
#write_fields
Ok(())
}
}
}
}
}
syn::Fields::Unit => {
quote! {
impl azalea_buf::McBufWritable for #ident {
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
Ok(())
}
}
}
}
_ => {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
}
},
syn::Data::Enum(syn::DataEnum { variants, .. }) => {
// remember whether it's a data variant so we can do an optimization later
let mut is_data_enum = false;
Expand Down
20 changes: 9 additions & 11 deletions azalea-buf/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ fn read_utf_with_len(buf: &mut Cursor<&[u8]>, max_length: u32) -> Result<String,
Ok(string)
}

// fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L67
/// Read a single varint from the reader and return the value, along with the
/// number of bytes read
// pub async fn read_varint_async(
// reader: &mut (dyn AsyncRead + Unpin + Send),
// ) -> Result<i32, BufReadError> { let mut buffer = [0]; let mut ans = 0; for i
// in 0..5 { reader.read_exact(&mut buffer).await?; ans |= ((buffer[0] &
// 0b0111_1111) as i32) << (7 * i); if buffer[0] & 0b1000_0000 == 0 { break; }
// } Ok(ans)
// }

pub trait McBufReadable
where
Self: Sized,
Expand Down Expand Up @@ -373,3 +362,12 @@ impl McBufReadable for simdnbt::owned::Nbt {
Ok(simdnbt::owned::Nbt::read_unnamed(buf)?)
}
}

impl<T> McBufReadable for Box<T>
where
T: McBufReadable,
{
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
Ok(Box::new(T::read_from(buf)?))
}
}
9 changes: 9 additions & 0 deletions azalea-buf/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
while value != 0 {
buffer[0] = (value & 0b0111_1111) as u8;
value = (value >> 7) & (i32::max_value() >> 6);

Check warning on line 44 in azalea-buf/src/write.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> azalea-buf/src/write.rs:44:42 | 44 | value = (value >> 7) & (i32::max_value() >> 6); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default help: use the associated constant instead | 44 | value = (value >> 7) & (i32::MAX >> 6); | ~~~
if value != 0 {
buffer[0] |= 0b1000_0000;
}
Expand Down Expand Up @@ -137,7 +137,7 @@
}
while value != 0 {
buffer[0] = (value & 0b0111_1111) as u8;
value = (value >> 7) & (i64::max_value() >> 6);

Check warning on line 140 in azalea-buf/src/write.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> azalea-buf/src/write.rs:140:42 | 140 | value = (value >> 7) & (i64::max_value() >> 6); | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants help: use the associated constant instead | 140 | value = (value >> 7) & (i64::MAX >> 6); | ~~~
if value != 0 {
buffer[0] |= 0b1000_0000;
}
Expand Down Expand Up @@ -281,3 +281,12 @@
buf.write_all(&data)
}
}

impl<T> McBufWritable for Box<T>
where
T: McBufWritable,
{
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
T::write_into(&**self, buf)
}
}
2 changes: 2 additions & 0 deletions azalea-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ uuid = "^1.7.0"
serde_json = "1.0.113"
serde = "1.0.196"
minecraft_folder_path = "0.1.2"
azalea-entity = { version = "0.9.0", path = "../azalea-entity" }
azalea-inventory = { version = "0.9.0", path = "../azalea-inventory" }

[features]
default = ["log"]
Expand Down
13 changes: 2 additions & 11 deletions azalea-client/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use azalea_protocol::packets::game::{
serverbound_swing_packet::ServerboundSwingPacket,
serverbound_use_item_on_packet::{BlockHit, ServerboundUseItemOnPacket},
};
use azalea_registry::DataComponentKind;
use azalea_world::{Instance, InstanceContainer, InstanceName};
use bevy_app::{App, Plugin, Update};
use bevy_ecs::{
Expand All @@ -28,7 +29,6 @@ use bevy_ecs::{
system::{Commands, Query, Res},
};
use derive_more::{Deref, DerefMut};
use simdnbt::owned::NbtList;
use tracing::warn;

use crate::{
Expand Down Expand Up @@ -269,20 +269,11 @@ pub fn check_block_can_be_broken_by_item_in_adventure_mode(
// minecraft caches the last checked block but that's kind of an unnecessary
// optimization and makes the code too complicated

let Some(can_destroy) = item
.nbt
.compound("tag")
.and_then(|nbt| nbt.list("CanDestroy"))
else {
let Some(_can_destroy) = item.components.get(DataComponentKind::CanBreak) else {
// no CanDestroy tag
return false;
};

let NbtList::String(_can_destroy) = can_destroy else {
// CanDestroy tag must be a list of strings
return false;
};

false

// for block_predicate in can_destroy {
Expand Down
3 changes: 0 additions & 3 deletions azalea-client/src/packet_handling/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io::Cursor;
use std::sync::Arc;

use azalea_entity::indexing::EntityIdIndex;
use azalea_protocol::packets::configuration::serverbound_finish_configuration_packet::ServerboundFinishConfigurationPacket;
Expand All @@ -12,10 +11,8 @@ use azalea_protocol::packets::configuration::{
};
use azalea_protocol::packets::ConnectionProtocol;
use azalea_protocol::read::deserialize_packet;
use azalea_world::Instance;
use bevy_ecs::prelude::*;
use bevy_ecs::system::SystemState;
use parking_lot::RwLock;
use tracing::{debug, error, warn};

use crate::client::InConfigurationState;
Expand Down
1 change: 0 additions & 1 deletion azalea-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ version = "0.9.0"
[dependencies]
simdnbt = { version = "0.4", git = "https://github.com/azalea-rs/simdnbt" }
azalea-buf = { path = "../azalea-buf", version = "0.9.0" }
azalea-inventory = { version = "0.9.0", path = "../azalea-inventory" }
azalea-registry = { path = "../azalea-registry", version = "0.9.0" }
bevy_ecs = { version = "0.13.0", default-features = false, optional = true }
nohash-hasher = "0.2.0"
Expand Down
2 changes: 0 additions & 2 deletions azalea-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ pub mod cursor3d;
pub mod delta;
pub mod difficulty;
pub mod direction;
pub mod entity;
pub mod game_type;
pub mod inventory;
pub mod math;
pub mod objectives;
pub mod position;
Expand Down
4 changes: 2 additions & 2 deletions azalea-core/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ impl From<ChunkSectionBlockPos> for u16 {
impl nohash_hasher::IsEnabled for ChunkSectionBlockPos {}

/// A block pos with an attached world
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct GlobalPos {
pub pos: BlockPos,
// this is actually a ResourceKey in Minecraft, but i don't think it matters?
pub world: ResourceLocation,
pub pos: BlockPos,
}

impl From<&BlockPos> for ChunkPos {
Expand Down
1 change: 0 additions & 1 deletion azalea-core/src/registry_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! the game, including the types of chat messages, dimensions, and
//! biomes.

use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufWritable};
use simdnbt::{
owned::{NbtCompound, NbtTag},
Deserialize, FromNbtTag, Serialize, ToNbtTag,
Expand All @@ -29,7 +28,7 @@
id: ResourceLocation,
entries: HashMap<ResourceLocation, Option<NbtCompound>>,
) {
let map = self.map.entry(id).or_insert_with(HashMap::new);

Check warning on line 31 in azalea-core/src/registry_holder.rs

View workflow job for this annotation

GitHub Actions / clippy

use of `or_insert_with` to construct default value

warning: use of `or_insert_with` to construct default value --> azalea-core/src/registry_holder.rs:31:38 | 31 | let map = self.map.entry(id).or_insert_with(HashMap::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default = note: `#[warn(clippy::unwrap_or_default)]` on by default
for (key, value) in entries {
if let Some(value) = value {
map.insert(key, value);
Expand Down
3 changes: 2 additions & 1 deletion azalea-entity/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use azalea_buf::{
use azalea_chat::FormattedText;
use azalea_core::{
direction::Direction,
particle::Particle,
position::{BlockPos, GlobalPos, Vec3},
};
use azalea_inventory::ItemSlot;
Expand All @@ -17,6 +16,8 @@ use nohash_hasher::IntSet;
use std::io::{Cursor, Write};
use uuid::Uuid;

use crate::particle::Particle;

#[derive(Clone, Debug, Deref)]
pub struct EntityMetadataItems(Vec<EntityDataItem>);

Expand Down
7 changes: 4 additions & 3 deletions azalea-entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ mod effects;
mod enchantments;
pub mod metadata;
pub mod mining;
pub mod particle;
mod plugin;

use self::attributes::AttributeInstance;
use crate::{
pub use attributes::Attributes;
use azalea_block::BlockState;
use azalea_core::{
aabb::AABB,
math,
position::{BlockPos, ChunkPos, Vec3},
resource_location::ResourceLocation,
};
pub use attributes::Attributes;
use azalea_block::BlockState;
use azalea_world::{ChunkStorage, InstanceName};
use bevy_ecs::{bundle::Bundle, component::Component};
pub use data::*;
Expand Down
3 changes: 2 additions & 1 deletion azalea-entity/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// This file is generated from codegen/lib/code/entity.py.
// Don't change it manually!

use crate::particle::Particle;

use super::{
ArmadilloStateKind, EntityDataItem, EntityDataValue, OptionalUnsignedInt, Pose, Quaternion,
Rotations, SnifferState, VillagerData,
};
use azalea_chat::FormattedText;
use azalea_core::{
direction::Direction,
particle::Particle,
position::{BlockPos, Vec3},
};
use azalea_inventory::ItemSlot;
Expand Down
6 changes: 3 additions & 3 deletions azalea-core/src/particle.rs → azalea-entity/src/particle.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::position::BlockPos;
use azalea_buf::McBuf;
use azalea_core::position::BlockPos;
use azalea_inventory::ItemSlot;
use azalea_registry::ParticleKind;
use bevy_ecs::component::Component;

#[cfg_attr(feature = "bevy_ecs", derive(bevy_ecs::component::Component))]
#[derive(Debug, Clone, McBuf, Default)]
#[derive(Component, Debug, Clone, McBuf, Default)]
pub struct Particle {
#[var]
pub id: i32,
Expand Down
3 changes: 3 additions & 0 deletions azalea-inventory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ simdnbt = { version = "0.4", git = "https://github.com/azalea-rs/simdnbt" }
azalea-buf = { version = "0.9.0", path = "../azalea-buf" }
azalea-inventory-macros = { version = "0.9.0", path = "./azalea-inventory-macros" }
azalea-registry = { version = "0.9.0", path = "../azalea-registry" }
azalea-chat = { version = "0.9.0", path = "../azalea-chat" }
azalea-core = { version = "0.9.0", path = "../azalea-core" }
uuid = "1.8.0"
Loading
Loading