diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-08-10 18:55:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-10 18:55:23 -0500 |
| commit | 7120842f9d2c659a2f12d8922299c2a761bc5582 (patch) | |
| tree | 0d7976ceec82d914e4c75f23adcdd5839f9960a4 /azalea-inventory/tests | |
| parent | 3b659833c1ad4cca89b4cd553193edcb6d223163 (diff) | |
| download | azalea-drasl-7120842f9d2c659a2f12d8922299c2a761bc5582.tar.xz | |
Send correct data component checksums (#234)
* start implementing data component crc32 hashes
* start doing serde impls for checksums
* make more components hashable
* make all data components serializable
* support recursive components
* fix simdnbt dep
* update changelog
* clippy
Diffstat (limited to 'azalea-inventory/tests')
| -rw-r--r-- | azalea-inventory/tests/components.rs | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/azalea-inventory/tests/components.rs b/azalea-inventory/tests/components.rs new file mode 100644 index 00000000..6c20436c --- /dev/null +++ b/azalea-inventory/tests/components.rs @@ -0,0 +1,201 @@ +use std::collections::HashMap; + +use azalea_chat::{ + FormattedText, + style::{Style, TextColor}, + text_component::TextComponent, +}; +use azalea_core::{ + checksum::get_checksum, + position::{BlockPos, GlobalPos}, + registry_holder::RegistryHolder, +}; +use azalea_inventory::{ + ItemStack, + components::{ + AdventureModePredicate, AttributeModifier, AttributeModifierDisplay, + AttributeModifierOperation, AttributeModifiers, AttributeModifiersEntry, BlockPredicate, + CanPlaceOn, ChargedProjectiles, CustomData, CustomName, Enchantments, EquipmentSlotGroup, + Glider, JukeboxPlayable, LodestoneTracker, Lore, MapColor, PotDecorations, Rarity, + }, +}; +use azalea_registry::{Attribute, Block, DataRegistry, Enchantment, Item}; +use simdnbt::owned::{BaseNbt, Nbt, NbtCompound, NbtList, NbtTag}; + +#[test] +fn test_custom_name_checksum() { + let c = CustomName { + name: FormattedText::from("meow"), + }; + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 2222287064); +} +#[test] +fn test_custom_name_checksum_2() { + let c = CustomName { + name: TextComponent::new("meow") + .with_style( + Style::new() + .color(Some(TextColor::parse("red").unwrap())) + .underlined(true), + ) + .into(), + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 187682122); +} +#[test] +fn test_map_color_checksum() { + let c = MapColor { color: 1 }; + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 1565579036); +} +#[test] +fn test_lore_checksum() { + let c = Lore { + lines: vec!["first".into(), "second".into()], + }; + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 1545409323); +} +#[test] +fn test_rarity_checksum() { + let c = Rarity::Rare; + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 2874400570); +} +#[test] +fn test_enchantments_checksum() { + let mut registry_holder = RegistryHolder::default(); + registry_holder.append( + "enchantment".into(), + vec![ + ("sharpness".into(), Some(NbtCompound::default())), + ("knockback".into(), Some(NbtCompound::default())), + ], + ); + let c = Enchantments { + levels: HashMap::from_iter([(Enchantment::new_raw(0), 5), (Enchantment::new_raw(1), 1)]), + }; + assert_eq!(get_checksum(&c, ®istry_holder).unwrap().0, 3717391112); +} +#[test] +fn test_can_place_on_checksum() { + let c = CanPlaceOn { + predicate: AdventureModePredicate { + predicates: vec![BlockPredicate { + blocks: Some(vec![Block::GrassBlock].into()), + properties: None, + nbt: None, + }], + }, + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 227436005); +} + +#[test] +fn test_custom_data_nbt() { + let c = CustomData { + nbt: Nbt::Some(BaseNbt::new( + "", + NbtCompound::from_values(vec![ + ("meow".into(), "mrrp".into()), + ( + "nya".into(), + NbtList::Compound(vec![ + NbtTag::Int(1).into(), + NbtTag::Int(2).into(), + NbtCompound::new(), + NbtCompound::from_values(vec![("data".into(), NbtTag::Byte(1))]), + ]) + .into(), + ), + ]), + )), + }; + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 1035780974); +} +#[test] +fn test_attribute_modifiers_checksum() { + let c = AttributeModifiers { + modifiers: vec![AttributeModifiersEntry { + kind: Attribute::Scale, + modifier: AttributeModifier { + id: "example:grow".into(), + amount: 4.0, + operation: AttributeModifierOperation::AddMultipliedBase, + }, + slot: EquipmentSlotGroup::Hand, + display: AttributeModifierDisplay::Default, + }], + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 2501379836); +} + +#[test] +fn test_firework_explosion_checksum() { + let c = AttributeModifiers { + modifiers: vec![AttributeModifiersEntry { + kind: Attribute::Scale, + modifier: AttributeModifier { + id: "example:grow".into(), + amount: 4.0, + operation: AttributeModifierOperation::AddMultipliedBase, + }, + slot: EquipmentSlotGroup::Hand, + display: AttributeModifierDisplay::Default, + }], + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 2501379836); +} + +#[test] +fn test_charged_projectile_checksum() { + let c = ChargedProjectiles { + items: vec![ItemStack::from(Item::MusicDiscCat)], + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 3435761017); +} + +#[test] +fn test_charged_projectile_with_components_checksum() { + let c = ChargedProjectiles { + items: vec![ + ItemStack::from(Item::MusicDiscCat) + .with_component::<JukeboxPlayable>(None) + .with_component(ChargedProjectiles { + items: vec![ItemStack::from(Item::MusicDiscCat)], + }), + ], + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 170375255); +} + +#[test] +fn test_lodestone_tracker_checksum() { + let c = LodestoneTracker { + target: Some(GlobalPos { + dimension: "meow".into(), + pos: BlockPos::new(1, 2, 3), + }), + tracked: true, + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 4138292505); +} + +#[test] +fn test_pot_decorations_checksum() { + let c = PotDecorations { + items: [Item::Stick, Item::Brick, Item::Brick, Item::Brick], + }; + + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 1951715383); +} + +#[test] +fn test_glider_checksum() { + let c = Glider; + assert_eq!(get_checksum(&c, &Default::default()).unwrap().0, 3312760008); +} |
