diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-09 13:29:59 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-09 13:29:59 -0600 |
| commit | 26d619c9a329087a23d6577ee74bd764f50cd773 (patch) | |
| tree | 8020fe902257764a23a445c6ed9987ea4848189d /azalea-client/tests | |
| parent | 84cd261118c9d1e3145d4d1751c0d22098cd8cd8 (diff) | |
| download | azalea-drasl-26d619c9a329087a23d6577ee74bd764f50cd773.tar.xz | |
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
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/close_open_container.rs | 3 | ||||
| -rw-r--r-- | azalea-client/tests/enchantments.rs | 125 | ||||
| -rw-r--r-- | azalea-client/tests/mine_block_timing_hand.rs (renamed from azalea-client/tests/mine_block_timing.rs) | 2 |
3 files changed, 128 insertions, 2 deletions
diff --git a/azalea-client/tests/close_open_container.rs b/azalea-client/tests/close_open_container.rs index f0457b5b..96978c59 100644 --- a/azalea-client/tests/close_open_container.rs +++ b/azalea-client/tests/close_open_container.rs @@ -1,6 +1,7 @@ use azalea_chat::FormattedText; -use azalea_client::{inventory::Inventory, test_utils::prelude::*}; +use azalea_client::test_utils::prelude::*; use azalea_core::position::ChunkPos; +use azalea_entity::inventory::Inventory; use azalea_protocol::packets::{ ConnectionProtocol, game::{ClientboundContainerClose, ClientboundOpenScreen, ClientboundSetChunkCacheCenter}, diff --git a/azalea-client/tests/enchantments.rs b/azalea-client/tests/enchantments.rs new file mode 100644 index 00000000..55b7c452 --- /dev/null +++ b/azalea-client/tests/enchantments.rs @@ -0,0 +1,125 @@ +use azalea_client::test_utils::prelude::*; +use azalea_core::identifier::Identifier; +use azalea_entity::Attributes; +use azalea_inventory::{ItemStack, components::Enchantments}; +use azalea_protocol::packets::{ + ConnectionProtocol, + config::{ClientboundFinishConfiguration, ClientboundRegistryData}, + game::ClientboundContainerSetSlot, +}; +use azalea_registry::{Enchantment, Item, Registry}; +use simdnbt::owned::{NbtCompound, NbtTag}; + +#[test] +fn test_enchantments() { + init_tracing(); + + let mut s = Simulation::new(ConnectionProtocol::Configuration); + s.receive_packet(ClientboundRegistryData { + registry_id: Identifier::new("minecraft:dimension_type"), + entries: vec![( + Identifier::new("minecraft:overworld"), + Some(NbtCompound::from_values(vec![ + ("height".into(), NbtTag::Int(384)), + ("min_y".into(), NbtTag::Int(-64)), + ])), + )] + .into_iter() + .collect(), + }); + // actual registry data copied from vanillaw + s.receive_packet(ClientboundRegistryData { + registry_id: Identifier::new("minecraft:enchantment"), + entries: vec![( + Identifier::new("minecraft:efficiency"), + Some(NbtCompound::from([ + ( + "description", + [("translate", "enchantment.minecraft.efficiency".into())].into(), + ), + ("anvil_cost", 1.into()), + ( + "max_cost", + [("base", 51.into()), ("per_level_above_first", 10.into())].into(), + ), + ( + "min_cost", + [("base", 1.into()), ("per_level_above_first", 10.into())].into(), + ), + ( + "effects", + [( + "minecraft:attributes", + [ + ("operation", "add_value".into()), + ("attribute", "minecraft:mining_efficiency".into()), + ( + "amount", + [ + ("type", "minecraft:levels_squared".into()), + ("added", 1.0f32.into()), + ] + .into(), + ), + ("id", "minecraft:enchantment.efficiency".into()), + ] + .into(), + )] + .into(), + ), + ("max_level", 5.into()), + ("weight", 10.into()), + ("slots", ["mainhand"].into()), + ("supported_items", "#minecraft:enchantable/mining".into()), + ])), + )] + .into_iter() + .collect(), + }); + s.tick(); + s.receive_packet(ClientboundFinishConfiguration); + s.tick(); + s.receive_packet(default_login_packet()); + s.tick(); + + fn efficiency(simulation: &mut Simulation) -> f64 { + simulation.query_self::<&Attributes, _>(|c| c.mining_efficiency.calculate()) + } + + assert_eq!(efficiency(&mut s), 0.); + + s.receive_packet(ClientboundContainerSetSlot { + container_id: 0, + state_id: 1, + slot: *azalea_inventory::Player::HOTBAR_SLOTS.start() as u16, + item_stack: Item::DiamondPickaxe.into(), + }); + s.tick(); + + // still 0 efficiency + assert_eq!(efficiency(&mut s), 0.); + + s.receive_packet(ClientboundContainerSetSlot { + container_id: 0, + state_id: 2, + slot: *azalea_inventory::Player::HOTBAR_SLOTS.start() as u16, + item_stack: ItemStack::from(Item::DiamondPickaxe).with_component(Enchantments { + levels: [(Enchantment::from_u32(0).unwrap(), 1)].into(), + }), + }); + s.tick(); + + // level 1 gives us value 2 + assert_eq!(efficiency(&mut s), 2.); + + s.receive_packet(ClientboundContainerSetSlot { + container_id: 0, + state_id: 1, + slot: *azalea_inventory::Player::HOTBAR_SLOTS.start() as u16, + item_stack: Item::DiamondPickaxe.into(), + }); + s.tick(); + + // enchantment is cleared, so back to 0 + assert_eq!(efficiency(&mut s), 0.); +} diff --git a/azalea-client/tests/mine_block_timing.rs b/azalea-client/tests/mine_block_timing_hand.rs index 6548b28a..650e630e 100644 --- a/azalea-client/tests/mine_block_timing.rs +++ b/azalea-client/tests/mine_block_timing_hand.rs @@ -18,7 +18,7 @@ use azalea_protocol::{ use azalea_registry::Block; #[test] -fn test_mine_block_timing() { +fn test_mine_block_timing_hand() { init_tracing(); let mut simulation = Simulation::new(ConnectionProtocol::Game); |
