Skip to content

Commit 26d619c

Browse files
authored
Enchantments (#286)
* start implementing enchants * store parsed registries * more work on enchants * implement deserializer for some entity effects * mostly working definitions for enchants * fix tests * detect equipment changes * fix errors * update changelog * fix some imports * remove outdated todo * add basic test for enchants applying attributes * use git simdnbt
1 parent 84cd261 commit 26d619c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2550
-843
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ is breaking anyways, semantic versioning is not followed.
1212

1313
- Add `Client::query_entity` and `try_query_entity` to complement `query_self`.
1414
- Add `Client::entity_interact` and `EntityInteractEvent` to interact with entities without checking that they're in the crosshair.
15-
- Implement initial support for mob effects, including jump boost, haste, conduit power, and mining fatigue. (@ShayBox)
1615
- Allow disabling dependencies related to Microsoft auth with the `online-mode` cargo feature.
16+
- Implement mob effects, including jump boost, haste, conduit power, and mining fatigue. (@ShayBox)
17+
- Support for the efficiency enchantment.
18+
- Support for items with attribute modifiers.
1719

1820
### Changed
1921

@@ -22,9 +24,11 @@ is breaking anyways, semantic versioning is not followed.
2224
- `Client::query`, `map_component`, and `map_get_component` were replaced by `Client::query_self`.
2325
- Rename `SendPacketEvent` to `SendGamePacketEvent` and `PingEvent` to `GamePingEvent`.
2426
- Swap the order of the type parameters in entity filtering functions so query is first, then filter.
27+
- Moved `azalea_client::inventory::Inventory` to `azalea_entity::inventory::Inventory`.
2528
- Add `Client::open_container_at_with_timeout_ticks`, and `Client::open_container_at` now times out after 5 seconds.
2629
- Rename `ResourceLocation` to `Identifier` to match Minecraft's new internal naming.
2730
- Rename `azalea_protocol::resolver` to `resolve` and `ResolverError` to `ResolveError`.
31+
- Refactor `RegistryHolder` to pre-deserialize some registries.
2832

2933
### Fixed
3034

Cargo.lock

Lines changed: 41 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ sha1 = "0.11.0-rc.3"
7878
sha2 = "0.11.0-rc.3"
7979
# TODO: Remove when rsa is fixed.
8080
signature = "=3.0.0-rc.5"
81+
# TODO
8182
simdnbt = { version = "0.8.0", git = "https://github.com/azalea-rs/simdnbt" }
8283
socks5-impl = "0.7.2"
8384
syn = "2.0.110"

azalea-chat/src/component.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ use std::{
55
sync::LazyLock,
66
};
77

8-
#[cfg(feature = "azalea-buf")]
8+
#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
99
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
1010
use serde::{Deserialize, Deserializer, Serialize, de};
11-
#[cfg(feature = "simdnbt")]
12-
use simdnbt::{Deserialize as _, FromNbtTag as _, Serialize as _};
13-
#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
14-
use tracing::{debug, trace, warn};
1511

1612
use crate::{
1713
base_component::BaseComponent,
@@ -66,6 +62,8 @@ impl FormattedText {
6662

6763
#[cfg(feature = "simdnbt")]
6864
fn parse_separator_nbt(nbt: &simdnbt::borrow::NbtCompound) -> Option<FormattedText> {
65+
use simdnbt::FromNbtTag;
66+
6967
if let Some(separator) = nbt.get("separator") {
7068
FormattedText::from_nbt_tag(separator)
7169
} else {
@@ -461,6 +459,8 @@ impl FormattedText {
461459
FormattedText::from(s)
462460
}
463461
fn from_nbt_list(list: simdnbt::borrow::NbtList) -> Option<FormattedText> {
462+
use tracing::debug;
463+
464464
let mut component;
465465
if let Some(compounds) = list.compounds() {
466466
component = FormattedText::from_nbt_compound(compounds.first()?)?;
@@ -480,6 +480,9 @@ impl FormattedText {
480480
}
481481

482482
pub fn from_nbt_compound(compound: simdnbt::borrow::NbtCompound) -> Option<Self> {
483+
use simdnbt::{Deserialize, FromNbtTag};
484+
use tracing::{trace, warn};
485+
483486
let mut component: FormattedText;
484487

485488
if let Some(text) = compound.get("text") {
@@ -631,6 +634,9 @@ impl From<&simdnbt::Mutf8Str> for FormattedText {
631634
#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
632635
impl AzaleaRead for FormattedText {
633636
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
637+
use simdnbt::FromNbtTag;
638+
use tracing::trace;
639+
634640
let nbt = simdnbt::borrow::read_optional_tag(buf)?;
635641
trace!(
636642
"Reading NBT for FormattedText: {:?}",
@@ -648,6 +654,8 @@ impl AzaleaRead for FormattedText {
648654
#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
649655
impl AzaleaWrite for FormattedText {
650656
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
657+
use simdnbt::Serialize;
658+
651659
let mut out = Vec::new();
652660
simdnbt::owned::BaseNbt::write_unnamed(&(self.clone().to_compound().into()), &mut out);
653661
buf.write_all(&out)

azalea-client/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Azalea Client
22

3-
A library that can mimic everything a normal Minecraft client can do. If you want to make a bot with higher-level functions, you should use the `azalea` crate instead.
3+
A library that can mimic everything a normal Minecraft client can do.
4+
5+
If you want to make a bot with higher-level functions, consider using the `azalea` crate instead.

0 commit comments

Comments
 (0)