diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2024-11-27 19:31:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-27 19:31:40 -0600 |
| commit | 08958c2278b15ebeac8a964f392ebb792e479b61 (patch) | |
| tree | 4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /azalea-inventory/src | |
| parent | 139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff) | |
| download | azalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz | |
Refactor azalea-protocol (#190)
* start updating to 1.21.4
* fix block codegen and stop using block data from burger
* rename packet related modules and structs to be simpler
* ItemSlot -> ItemStack for more consistency with mojmap
* .get() -> .into_packet()
* simplify declare_state_packets by removing packet ids
* rename read_from and write_into to azalea_read and azalea_write
* rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite
* McBuf -> AzBuf
* remove most uses of into_variant
* update codegen and use resourcelocation names for packets
* implement #[limit(i)] attribute for AzBuf derive macro
* fixes for 1.21.4
* fix examples
* update some physics code and fix ChatType
* remove unused imports in codegen
* re-add some things to migrate.py and update +mc version numbers automatically
* downgrade to 1.21.3 lol
Diffstat (limited to 'azalea-inventory/src')
| -rw-r--r-- | azalea-inventory/src/components.rs | 326 | ||||
| -rw-r--r-- | azalea-inventory/src/item/mod.rs | 4 | ||||
| -rw-r--r-- | azalea-inventory/src/lib.rs | 10 | ||||
| -rw-r--r-- | azalea-inventory/src/operations.rs | 28 | ||||
| -rw-r--r-- | azalea-inventory/src/slot.rs | 122 |
5 files changed, 246 insertions, 244 deletions
diff --git a/azalea-inventory/src/components.rs b/azalea-inventory/src/components.rs index d7adf2c9..10b00b36 100644 --- a/azalea-inventory/src/components.rs +++ b/azalea-inventory/src/components.rs @@ -1,7 +1,7 @@ use core::f64; use std::{any::Any, collections::HashMap, io::Cursor}; -use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; use azalea_chat::FormattedText; use azalea_core::{position::GlobalPos, resource_location::ResourceLocation}; use azalea_registry::{ @@ -11,7 +11,7 @@ use azalea_registry::{ use simdnbt::owned::{Nbt, NbtCompound}; use uuid::Uuid; -use crate::ItemSlot; +use crate::ItemStack; pub trait DataComponent: Send + Sync + Any {} @@ -26,10 +26,10 @@ pub trait EncodableDataComponent: Send + Sync + Any { impl<T> EncodableDataComponent for T where - T: DataComponent + Clone + McBufWritable + McBufReadable + PartialEq, + T: DataComponent + Clone + AzaleaWrite + AzaleaRead + PartialEq, { fn encode(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { - self.write_into(buf) + self.azalea_write(buf) } fn clone(&self) -> Box<dyn EncodableDataComponent> { let cloned = self.clone(); @@ -54,105 +54,107 @@ pub fn from_kind( // note that this match statement is updated by genitemcomponents.py Ok(match kind { - DataComponentKind::CustomData => Box::new(CustomData::read_from(buf)?), - DataComponentKind::MaxStackSize => Box::new(MaxStackSize::read_from(buf)?), - DataComponentKind::MaxDamage => Box::new(MaxDamage::read_from(buf)?), - DataComponentKind::Damage => Box::new(Damage::read_from(buf)?), - DataComponentKind::Unbreakable => Box::new(Unbreakable::read_from(buf)?), - DataComponentKind::CustomName => Box::new(CustomName::read_from(buf)?), - DataComponentKind::ItemName => Box::new(ItemName::read_from(buf)?), - DataComponentKind::Lore => Box::new(Lore::read_from(buf)?), - DataComponentKind::Rarity => Box::new(Rarity::read_from(buf)?), - DataComponentKind::Enchantments => Box::new(Enchantments::read_from(buf)?), - DataComponentKind::CanPlaceOn => Box::new(CanPlaceOn::read_from(buf)?), - DataComponentKind::CanBreak => Box::new(CanBreak::read_from(buf)?), - DataComponentKind::AttributeModifiers => Box::new(AttributeModifiers::read_from(buf)?), - DataComponentKind::CustomModelData => Box::new(CustomModelData::read_from(buf)?), + DataComponentKind::CustomData => Box::new(CustomData::azalea_read(buf)?), + DataComponentKind::MaxStackSize => Box::new(MaxStackSize::azalea_read(buf)?), + DataComponentKind::MaxDamage => Box::new(MaxDamage::azalea_read(buf)?), + DataComponentKind::Damage => Box::new(Damage::azalea_read(buf)?), + DataComponentKind::Unbreakable => Box::new(Unbreakable::azalea_read(buf)?), + DataComponentKind::CustomName => Box::new(CustomName::azalea_read(buf)?), + DataComponentKind::ItemName => Box::new(ItemName::azalea_read(buf)?), + DataComponentKind::Lore => Box::new(Lore::azalea_read(buf)?), + DataComponentKind::Rarity => Box::new(Rarity::azalea_read(buf)?), + DataComponentKind::Enchantments => Box::new(Enchantments::azalea_read(buf)?), + DataComponentKind::CanPlaceOn => Box::new(CanPlaceOn::azalea_read(buf)?), + DataComponentKind::CanBreak => Box::new(CanBreak::azalea_read(buf)?), + DataComponentKind::AttributeModifiers => Box::new(AttributeModifiers::azalea_read(buf)?), + DataComponentKind::CustomModelData => Box::new(CustomModelData::azalea_read(buf)?), DataComponentKind::HideAdditionalTooltip => { - Box::new(HideAdditionalTooltip::read_from(buf)?) + Box::new(HideAdditionalTooltip::azalea_read(buf)?) } - DataComponentKind::HideTooltip => Box::new(HideTooltip::read_from(buf)?), - DataComponentKind::RepairCost => Box::new(RepairCost::read_from(buf)?), - DataComponentKind::CreativeSlotLock => Box::new(CreativeSlotLock::read_from(buf)?), + DataComponentKind::HideTooltip => Box::new(HideTooltip::azalea_read(buf)?), + DataComponentKind::RepairCost => Box::new(RepairCost::azalea_read(buf)?), + DataComponentKind::CreativeSlotLock => Box::new(CreativeSlotLock::azalea_read(buf)?), DataComponentKind::EnchantmentGlintOverride => { - Box::new(EnchantmentGlintOverride::read_from(buf)?) + Box::new(EnchantmentGlintOverride::azalea_read(buf)?) } - DataComponentKind::IntangibleProjectile => Box::new(IntangibleProjectile::read_from(buf)?), - DataComponentKind::Food => Box::new(Food::read_from(buf)?), - DataComponentKind::Tool => Box::new(Tool::read_from(buf)?), - DataComponentKind::StoredEnchantments => Box::new(StoredEnchantments::read_from(buf)?), - DataComponentKind::DyedColor => Box::new(DyedColor::read_from(buf)?), - DataComponentKind::MapColor => Box::new(MapColor::read_from(buf)?), - DataComponentKind::MapId => Box::new(MapId::read_from(buf)?), - DataComponentKind::MapDecorations => Box::new(MapDecorations::read_from(buf)?), - DataComponentKind::MapPostProcessing => Box::new(MapPostProcessing::read_from(buf)?), - DataComponentKind::ChargedProjectiles => Box::new(ChargedProjectiles::read_from(buf)?), - DataComponentKind::BundleContents => Box::new(BundleContents::read_from(buf)?), - DataComponentKind::PotionContents => Box::new(PotionContents::read_from(buf)?), + DataComponentKind::IntangibleProjectile => { + Box::new(IntangibleProjectile::azalea_read(buf)?) + } + DataComponentKind::Food => Box::new(Food::azalea_read(buf)?), + DataComponentKind::Tool => Box::new(Tool::azalea_read(buf)?), + DataComponentKind::StoredEnchantments => Box::new(StoredEnchantments::azalea_read(buf)?), + DataComponentKind::DyedColor => Box::new(DyedColor::azalea_read(buf)?), + DataComponentKind::MapColor => Box::new(MapColor::azalea_read(buf)?), + DataComponentKind::MapId => Box::new(MapId::azalea_read(buf)?), + DataComponentKind::MapDecorations => Box::new(MapDecorations::azalea_read(buf)?), + DataComponentKind::MapPostProcessing => Box::new(MapPostProcessing::azalea_read(buf)?), + DataComponentKind::ChargedProjectiles => Box::new(ChargedProjectiles::azalea_read(buf)?), + DataComponentKind::BundleContents => Box::new(BundleContents::azalea_read(buf)?), + DataComponentKind::PotionContents => Box::new(PotionContents::azalea_read(buf)?), DataComponentKind::SuspiciousStewEffects => { - Box::new(SuspiciousStewEffects::read_from(buf)?) + Box::new(SuspiciousStewEffects::azalea_read(buf)?) } - DataComponentKind::WritableBookContent => Box::new(WritableBookContent::read_from(buf)?), - DataComponentKind::WrittenBookContent => Box::new(WrittenBookContent::read_from(buf)?), - DataComponentKind::Trim => Box::new(Trim::read_from(buf)?), - DataComponentKind::DebugStickState => Box::new(DebugStickState::read_from(buf)?), - DataComponentKind::EntityData => Box::new(EntityData::read_from(buf)?), - DataComponentKind::BucketEntityData => Box::new(BucketEntityData::read_from(buf)?), - DataComponentKind::BlockEntityData => Box::new(BlockEntityData::read_from(buf)?), - DataComponentKind::Instrument => Box::new(Instrument::read_from(buf)?), + DataComponentKind::WritableBookContent => Box::new(WritableBookContent::azalea_read(buf)?), + DataComponentKind::WrittenBookContent => Box::new(WrittenBookContent::azalea_read(buf)?), + DataComponentKind::Trim => Box::new(Trim::azalea_read(buf)?), + DataComponentKind::DebugStickState => Box::new(DebugStickState::azalea_read(buf)?), + DataComponentKind::EntityData => Box::new(EntityData::azalea_read(buf)?), + DataComponentKind::BucketEntityData => Box::new(BucketEntityData::azalea_read(buf)?), + DataComponentKind::BlockEntityData => Box::new(BlockEntityData::azalea_read(buf)?), + DataComponentKind::Instrument => Box::new(Instrument::azalea_read(buf)?), DataComponentKind::OminousBottleAmplifier => { - Box::new(OminousBottleAmplifier::read_from(buf)?) + Box::new(OminousBottleAmplifier::azalea_read(buf)?) } - DataComponentKind::Recipes => Box::new(Recipes::read_from(buf)?), - DataComponentKind::LodestoneTracker => Box::new(LodestoneTracker::read_from(buf)?), - DataComponentKind::FireworkExplosion => Box::new(FireworkExplosion::read_from(buf)?), - DataComponentKind::Fireworks => Box::new(Fireworks::read_from(buf)?), - DataComponentKind::Profile => Box::new(Profile::read_from(buf)?), - DataComponentKind::NoteBlockSound => Box::new(NoteBlockSound::read_from(buf)?), - DataComponentKind::BannerPatterns => Box::new(BannerPatterns::read_from(buf)?), - DataComponentKind::BaseColor => Box::new(BaseColor::read_from(buf)?), - DataComponentKind::PotDecorations => Box::new(PotDecorations::read_from(buf)?), - DataComponentKind::Container => Box::new(Container::read_from(buf)?), - DataComponentKind::BlockState => Box::new(BlockState::read_from(buf)?), - DataComponentKind::Bees => Box::new(Bees::read_from(buf)?), - DataComponentKind::Lock => Box::new(Lock::read_from(buf)?), - DataComponentKind::ContainerLoot => Box::new(ContainerLoot::read_from(buf)?), - DataComponentKind::JukeboxPlayable => Box::new(JukeboxPlayable::read_from(buf)?), - DataComponentKind::Consumable => Box::new(Consumable::read_from(buf)?), - DataComponentKind::UseRemainder => Box::new(UseRemainder::read_from(buf)?), - DataComponentKind::UseCooldown => Box::new(UseCooldown::read_from(buf)?), - DataComponentKind::Enchantable => Box::new(Enchantable::read_from(buf)?), - DataComponentKind::Repairable => Box::new(Repairable::read_from(buf)?), - DataComponentKind::ItemModel => Box::new(ItemModel::read_from(buf)?), - DataComponentKind::DamageResistant => Box::new(DamageResistant::read_from(buf)?), - DataComponentKind::Equippable => Box::new(Equippable::read_from(buf)?), - DataComponentKind::Glider => Box::new(Glider::read_from(buf)?), - DataComponentKind::TooltipStyle => Box::new(TooltipStyle::read_from(buf)?), - DataComponentKind::DeathProtection => Box::new(DeathProtection::read_from(buf)?), + DataComponentKind::Recipes => Box::new(Recipes::azalea_read(buf)?), + DataComponentKind::LodestoneTracker => Box::new(LodestoneTracker::azalea_read(buf)?), + DataComponentKind::FireworkExplosion => Box::new(FireworkExplosion::azalea_read(buf)?), + DataComponentKind::Fireworks => Box::new(Fireworks::azalea_read(buf)?), + DataComponentKind::Profile => Box::new(Profile::azalea_read(buf)?), + DataComponentKind::NoteBlockSound => Box::new(NoteBlockSound::azalea_read(buf)?), + DataComponentKind::BannerPatterns => Box::new(BannerPatterns::azalea_read(buf)?), + DataComponentKind::BaseColor => Box::new(BaseColor::azalea_read(buf)?), + DataComponentKind::PotDecorations => Box::new(PotDecorations::azalea_read(buf)?), + DataComponentKind::Container => Box::new(Container::azalea_read(buf)?), + DataComponentKind::BlockState => Box::new(BlockState::azalea_read(buf)?), + DataComponentKind::Bees => Box::new(Bees::azalea_read(buf)?), + DataComponentKind::Lock => Box::new(Lock::azalea_read(buf)?), + DataComponentKind::ContainerLoot => Box::new(ContainerLoot::azalea_read(buf)?), + DataComponentKind::JukeboxPlayable => Box::new(JukeboxPlayable::azalea_read(buf)?), + DataComponentKind::Consumable => Box::new(Consumable::azalea_read(buf)?), + DataComponentKind::UseRemainder => Box::new(UseRemainder::azalea_read(buf)?), + DataComponentKind::UseCooldown => Box::new(UseCooldown::azalea_read(buf)?), + DataComponentKind::Enchantable => Box::new(Enchantable::azalea_read(buf)?), + DataComponentKind::Repairable => Box::new(Repairable::azalea_read(buf)?), + DataComponentKind::ItemModel => Box::new(ItemModel::azalea_read(buf)?), + DataComponentKind::DamageResistant => Box::new(DamageResistant::azalea_read(buf)?), + DataComponentKind::Equippable => Box::new(Equippable::azalea_read(buf)?), + DataComponentKind::Glider => Box::new(Glider::azalea_read(buf)?), + DataComponentKind::TooltipStyle => Box::new(TooltipStyle::azalea_read(buf)?), + DataComponentKind::DeathProtection => Box::new(DeathProtection::azalea_read(buf)?), }) } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct CustomData { pub nbt: Nbt, } impl DataComponent for CustomData {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct MaxStackSize { #[var] pub count: i32, } impl DataComponent for MaxStackSize {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct MaxDamage { #[var] pub amount: i32, } impl DataComponent for MaxDamage {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Damage { #[var] pub amount: i32, @@ -160,7 +162,7 @@ pub struct Damage { impl DataComponent for Damage {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Unbreakable { pub show_in_tooltip: bool, } @@ -173,26 +175,26 @@ impl Default for Unbreakable { } } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct CustomName { pub name: FormattedText, } impl DataComponent for CustomName {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct ItemName { pub name: FormattedText, } impl DataComponent for ItemName {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Lore { pub lines: Vec<FormattedText>, // vanilla also has styled_lines here but it doesn't appear to be used for the protocol } impl DataComponent for Lore {} -#[derive(Clone, PartialEq, Copy, McBuf)] +#[derive(Clone, PartialEq, Copy, AzBuf)] pub enum Rarity { Common, Uncommon, @@ -201,7 +203,7 @@ pub enum Rarity { } impl DataComponent for Rarity {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Enchantments { #[var] pub levels: HashMap<Enchantment, u32>, @@ -209,7 +211,7 @@ pub struct Enchantments { } impl DataComponent for Enchantments {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub enum BlockStateValueMatcher { Exact { value: String, @@ -220,38 +222,38 @@ pub enum BlockStateValueMatcher { }, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BlockStatePropertyMatcher { pub name: String, pub value_matcher: BlockStateValueMatcher, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BlockPredicate { pub blocks: Option<HolderSet<Block, ResourceLocation>>, pub properties: Option<Vec<BlockStatePropertyMatcher>>, pub nbt: Option<NbtCompound>, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct AdventureModePredicate { pub predicates: Vec<BlockPredicate>, pub show_in_tooltip: bool, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct CanPlaceOn { pub predicate: AdventureModePredicate, } impl DataComponent for CanPlaceOn {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct CanBreak { pub predicate: AdventureModePredicate, } impl DataComponent for CanBreak {} -#[derive(Clone, Copy, PartialEq, McBuf)] +#[derive(Clone, Copy, PartialEq, AzBuf)] pub enum EquipmentSlotGroup { Any, Mainhand, @@ -265,7 +267,7 @@ pub enum EquipmentSlotGroup { Body, } -#[derive(Clone, Copy, PartialEq, McBuf)] +#[derive(Clone, Copy, PartialEq, AzBuf)] pub enum AttributeModifierOperation { Addition, MultiplyBase, @@ -275,7 +277,7 @@ pub enum AttributeModifierOperation { // this is duplicated in azalea-entity, BUT the one there has a different // protocol format (and we can't use it anyways because it would cause a // circular dependency) -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct AttributeModifier { pub uuid: Uuid, pub name: String, @@ -283,57 +285,57 @@ pub struct AttributeModifier { pub operation: AttributeModifierOperation, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct AttributeModifiersEntry { pub attribute: Attribute, pub modifier: AttributeModifier, pub slot: EquipmentSlotGroup, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct AttributeModifiers { pub modifiers: Vec<AttributeModifiersEntry>, pub show_in_tooltip: bool, } impl DataComponent for AttributeModifiers {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct CustomModelData { #[var] pub value: i32, } impl DataComponent for CustomModelData {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct HideAdditionalTooltip; impl DataComponent for HideAdditionalTooltip {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct HideTooltip; impl DataComponent for HideTooltip {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct RepairCost { #[var] pub cost: u32, } impl DataComponent for RepairCost {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct CreativeSlotLock; impl DataComponent for CreativeSlotLock {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct EnchantmentGlintOverride { pub show_glint: bool, } impl DataComponent for EnchantmentGlintOverride {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct IntangibleProjectile; impl DataComponent for IntangibleProjectile {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct MobEffectDetails { #[var] pub amplifier: i32, @@ -345,19 +347,19 @@ pub struct MobEffectDetails { pub hidden_effect: Option<Box<MobEffectDetails>>, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct MobEffectInstance { pub effect: MobEffect, pub details: MobEffectDetails, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct PossibleEffect { pub effect: MobEffectInstance, pub probability: f32, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Food { #[var] pub nutrition: i32, @@ -368,14 +370,14 @@ pub struct Food { } impl DataComponent for Food {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct ToolRule { pub blocks: HolderSet<Block, ResourceLocation>, pub speed: Option<f32>, pub correct_for_drops: Option<bool>, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Tool { pub rules: Vec<ToolRule>, pub default_mining_speed: f32, @@ -384,7 +386,7 @@ pub struct Tool { } impl DataComponent for Tool {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct StoredEnchantments { #[var] pub enchantments: HashMap<Enchantment, i32>, @@ -392,52 +394,52 @@ pub struct StoredEnchantments { } impl DataComponent for StoredEnchantments {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct DyedColor { pub rgb: i32, pub show_in_tooltip: bool, } impl DataComponent for DyedColor {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct MapColor { pub color: i32, } impl DataComponent for MapColor {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct MapId { #[var] pub id: i32, } impl DataComponent for MapId {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct MapDecorations { pub decorations: NbtCompound, } impl DataComponent for MapDecorations {} -#[derive(Clone, Copy, PartialEq, McBuf)] +#[derive(Clone, Copy, PartialEq, AzBuf)] pub enum MapPostProcessing { Lock, Scale, } impl DataComponent for MapPostProcessing {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct ChargedProjectiles { - pub items: Vec<ItemSlot>, + pub items: Vec<ItemStack>, } impl DataComponent for ChargedProjectiles {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BundleContents { - pub items: Vec<ItemSlot>, + pub items: Vec<ItemStack>, } impl DataComponent for BundleContents {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct PotionContents { pub potion: Option<Potion>, pub custom_color: Option<i32>, @@ -445,26 +447,26 @@ pub struct PotionContents { } impl DataComponent for PotionContents {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct SuspiciousStewEffect { pub effect: MobEffect, #[var] pub duration: i32, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct SuspiciousStewEffects { pub effects: Vec<SuspiciousStewEffect>, } impl DataComponent for SuspiciousStewEffects {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct WritableBookContent { pub pages: Vec<String>, } impl DataComponent for WritableBookContent {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct WrittenBookContent { pub title: String, pub author: String, @@ -475,7 +477,7 @@ pub struct WrittenBookContent { } impl DataComponent for WrittenBookContent {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Trim { pub material: TrimMaterial, pub pattern: TrimPattern, @@ -483,57 +485,57 @@ pub struct Trim { } impl DataComponent for Trim {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct DebugStickState { pub properties: NbtCompound, } impl DataComponent for DebugStickState {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct EntityData { pub entity: NbtCompound, } impl DataComponent for EntityData {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BucketEntityData { pub entity: NbtCompound, } impl DataComponent for BucketEntityData {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BlockEntityData { pub entity: NbtCompound, } impl DataComponent for BlockEntityData {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Instrument { pub instrument: azalea_registry::Instrument, } impl DataComponent for Instrument {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct OminousBottleAmplifier { #[var] pub amplifier: i32, } impl DataComponent for OminousBottleAmplifier {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Recipes { pub recipes: Vec<ResourceLocation>, } impl DataComponent for Recipes {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct LodestoneTracker { pub target: Option<GlobalPos>, pub tracked: bool, } impl DataComponent for LodestoneTracker {} -#[derive(Clone, Copy, PartialEq, McBuf)] +#[derive(Clone, Copy, PartialEq, AzBuf)] pub enum FireworkExplosionShape { SmallBall, LargeBall, @@ -542,7 +544,7 @@ pub enum FireworkExplosionShape { Burst, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct FireworkExplosion { pub shape: FireworkExplosionShape, pub colors: Vec<i32>, @@ -552,7 +554,7 @@ pub struct FireworkExplosion { } impl DataComponent for FireworkExplosion {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Fireworks { #[var] pub flight_duration: i32, @@ -560,14 +562,14 @@ pub struct Fireworks { } impl DataComponent for Fireworks {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct GameProfileProperty { pub name: String, pub value: String, pub signature: Option<String>, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Profile { pub name: String, pub id: Option<Uuid>, @@ -575,13 +577,13 @@ pub struct Profile { } impl DataComponent for Profile {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct NoteBlockSound { pub sound: ResourceLocation, } impl DataComponent for NoteBlockSound {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BannerPattern { #[var] pub pattern: i32, @@ -589,13 +591,13 @@ pub struct BannerPattern { pub color: i32, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BannerPatterns { pub patterns: Vec<BannerPattern>, } impl DataComponent for BannerPatterns {} -#[derive(Clone, Copy, PartialEq, McBuf)] +#[derive(Clone, Copy, PartialEq, AzBuf)] pub enum DyeColor { White, Orange, @@ -615,31 +617,31 @@ pub enum DyeColor { Black, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BaseColor { pub color: DyeColor, } impl DataComponent for BaseColor {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct PotDecorations { pub items: Vec<Item>, } impl DataComponent for PotDecorations {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Container { - pub items: Vec<ItemSlot>, + pub items: Vec<ItemStack>, } impl DataComponent for Container {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BlockState { pub properties: HashMap<String, String>, } impl DataComponent for BlockState {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct BeehiveOccupant { pub entity_data: NbtCompound, #[var] @@ -648,32 +650,32 @@ pub struct BeehiveOccupant { pub min_ticks_in_hive: i32, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Bees { pub occupants: Vec<BeehiveOccupant>, } impl DataComponent for Bees {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Lock { pub key: String, } impl DataComponent for Lock {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct ContainerLoot { pub loot: NbtCompound, } impl DataComponent for ContainerLoot {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct JukeboxPlayable { pub song: azalea_registry::JukeboxSong, pub show_in_tooltip: bool, } impl DataComponent for JukeboxPlayable {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Consumable { pub consume_seconds: f32, pub animation: ItemUseAnimation, @@ -683,7 +685,7 @@ pub struct Consumable { } impl DataComponent for Consumable {} -#[derive(Clone, Copy, PartialEq, McBuf)] +#[derive(Clone, Copy, PartialEq, AzBuf)] pub enum ItemUseAnimation { None, Eat, @@ -697,39 +699,39 @@ pub enum ItemUseAnimation { Brush, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct UseRemainder { - pub convert_into: ItemSlot, + pub convert_into: ItemStack, } impl DataComponent for UseRemainder {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct UseCooldown { pub seconds: f32, pub cooldown_group: Option<ResourceLocation>, } impl DataComponent for UseCooldown {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Enchantable { #[var] pub value: u32, } impl DataComponent for Enchantable {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Repairable { pub items: HolderSet<Item, ResourceLocation>, } impl DataComponent for Repairable {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct ItemModel { pub resource_location: ResourceLocation, } impl DataComponent for ItemModel {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct DamageResistant { // in the vanilla code this is // ``` @@ -743,7 +745,7 @@ pub struct DamageResistant { } impl DataComponent for DamageResistant {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Equippable { pub slot: EquipmentSlot, pub equip_sound: SoundEvent, @@ -752,7 +754,7 @@ pub struct Equippable { } impl DataComponent for Equippable {} -#[derive(Clone, Copy, Debug, PartialEq, McBuf)] +#[derive(Clone, Copy, Debug, PartialEq, AzBuf)] pub enum EquipmentSlot { Mainhand, Offhand, @@ -765,17 +767,17 @@ pub enum EquipmentSlot { Body, } -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct Glider; impl DataComponent for Glider {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct TooltipStyle { pub resource_location: ResourceLocation, } impl DataComponent for TooltipStyle {} -#[derive(Clone, PartialEq, McBuf)] +#[derive(Clone, PartialEq, AzBuf)] pub struct DeathProtection { pub death_effects: Vec<ConsumeEffectKind>, } diff --git a/azalea-inventory/src/item/mod.rs b/azalea-inventory/src/item/mod.rs index 862cd20e..7f077c6a 100644 --- a/azalea-inventory/src/item/mod.rs +++ b/azalea-inventory/src/item/mod.rs @@ -2,9 +2,9 @@ pub trait MaxStackSizeExt { /// Get the maximum stack size for this item. /// /// This is a signed integer to be consistent with the `count` field of - /// [`ItemSlotData`]. + /// [`ItemStackData`]. /// - /// [`ItemSlotData`]: crate::ItemSlotData + /// [`ItemStackData`]: crate::ItemStackData fn max_stack_size(&self) -> i32; /// Whether this item can be stacked with other items. diff --git a/azalea-inventory/src/lib.rs b/azalea-inventory/src/lib.rs index 930c1a5d..3f9ba237 100644 --- a/azalea-inventory/src/lib.rs +++ b/azalea-inventory/src/lib.rs @@ -9,17 +9,17 @@ mod slot; use std::ops::{Deref, DerefMut, RangeInclusive}; use azalea_inventory_macros::declare_menus; -pub use slot::{DataComponentPatch, ItemSlot, ItemSlotData}; +pub use slot::{DataComponentPatch, ItemStack, ItemStackData}; // TODO: remove this here and in azalea-inventory-macros when rust makes // Default be implemented for all array sizes // https://github.com/rust-lang/rust/issues/61415 -/// A fixed-size list of [`ItemSlot`]s. +/// A fixed-size list of [`ItemStack`]s. #[derive(Debug, Clone)] -pub struct SlotList<const N: usize>([ItemSlot; N]); +pub struct SlotList<const N: usize>([ItemStack; N]); impl<const N: usize> Deref for SlotList<N> { - type Target = [ItemSlot; N]; + type Target = [ItemStack; N]; fn deref(&self) -> &Self::Target { &self.0 } @@ -31,7 +31,7 @@ impl<const N: usize> DerefMut for SlotList<N> { } impl<const N: usize> Default for SlotList<N> { fn default() -> Self { - SlotList([(); N].map(|_| ItemSlot::Empty)) + SlotList([(); N].map(|_| ItemStack::Empty)) } } diff --git a/azalea-inventory/src/operations.rs b/azalea-inventory/src/operations.rs index 652d1900..0df7c794 100644 --- a/azalea-inventory/src/operations.rs +++ b/azalea-inventory/src/operations.rs @@ -1,6 +1,6 @@ use std::ops::RangeInclusive; -use azalea_buf::McBuf; +use azalea_buf::AzBuf; use crate::{ item::MaxStackSizeExt, AnvilMenuLocation, BeaconMenuLocation, BlastFurnaceMenuLocation, @@ -8,7 +8,7 @@ use crate::{ CraftingMenuLocation, EnchantmentMenuLocation, FurnaceMenuLocation, Generic3x3MenuLocation, Generic9x1MenuLocation, Generic9x2MenuLocation, Generic9x3MenuLocation, Generic9x4MenuLocation, Generic9x5MenuLocation, Generic9x6MenuLocation, GrindstoneMenuLocation, HopperMenuLocation, - ItemSlot, ItemSlotData, LecternMenuLocation, LoomMenuLocation, Menu, MenuLocation, + ItemStack, ItemStackData, LecternMenuLocation, LoomMenuLocation, Menu, MenuLocation, MerchantMenuLocation, Player, PlayerMenuLocation, ShulkerBoxMenuLocation, SmithingMenuLocation, SmokerMenuLocation, StonecutterMenuLocation, }; @@ -250,7 +250,7 @@ impl ClickOperation { } } -#[derive(McBuf, Clone, Copy, Debug)] +#[derive(AzBuf, Clone, Copy, Debug)] pub enum ClickType { Pickup = 0, QuickMove = 1, @@ -266,10 +266,10 @@ impl Menu { /// /// Keep in mind that this doesn't send any packets to the server, it just /// mutates this specific `Menu`. - pub fn quick_move_stack(&mut self, slot_index: usize) -> ItemSlot { + pub fn quick_move_stack(&mut self, slot_index: usize) -> ItemStack { let slot = self.slot(slot_index); if slot.is_none() { - return ItemSlot::Empty; + return ItemStack::Empty; }; let slot_location = self @@ -587,7 +587,7 @@ impl Menu { }, } - ItemSlot::Empty + ItemStack::Empty } fn try_move_item_to_slots_or_toggle_hotbar( @@ -610,7 +610,7 @@ impl Menu { /// Whether the given item could be placed in this menu. /// /// TODO: right now this always returns true - pub fn may_place(&self, _target_slot_index: usize, _item: &ItemSlotData) -> bool { + pub fn may_place(&self, _target_slot_index: usize, _item: &ItemStackData) -> bool { true } @@ -662,14 +662,14 @@ impl Menu { /// slot is present and the same item. fn move_item_to_slot_if_stackable( &mut self, - item_slot: &mut ItemSlot, + item_slot: &mut ItemStack, target_slot_index: usize, ) { - let ItemSlot::Present(item) = item_slot else { + let ItemStack::Present(item) = item_slot else { return; }; let target_slot = self.slot(target_slot_index).unwrap(); - if let ItemSlot::Present(target_item) = target_slot { + if let ItemStack::Present(target_item) = target_slot { // the target slot is empty, so we can just move the item there if self.may_place(target_slot_index, item) && target_item.is_same_item_and_components(item) @@ -679,15 +679,15 @@ impl Menu { // get the target slot again but mut this time so we can update it let target_slot = self.slot_mut(target_slot_index).unwrap(); - *target_slot = ItemSlot::Present(new_target_slot_data); + *target_slot = ItemStack::Present(new_target_slot_data); item_slot.update_empty(); } } } - fn move_item_to_slot_if_empty(&mut self, item_slot: &mut ItemSlot, target_slot_index: usize) { - let ItemSlot::Present(item) = item_slot else { + fn move_item_to_slot_if_empty(&mut self, item_slot: &mut ItemStack, target_slot_index: usize) { + let ItemStack::Present(item) = item_slot else { return; }; let target_slot = self.slot(target_slot_index).unwrap(); @@ -696,7 +696,7 @@ impl Menu { let new_target_slot_data = item.split(u32::min(slot_item_limit, item.count as u32)); let target_slot = self.slot_mut(target_slot_index).unwrap(); - *target_slot = ItemSlot::Present(new_target_slot_data); + *target_slot = ItemStack::Present(new_target_slot_data); item_slot.update_empty(); } } diff --git a/azalea-inventory/src/slot.rs b/azalea-inventory/src/slot.rs index 601c28e2..7d62bf69 100644 --- a/azalea-inventory/src/slot.rs +++ b/azalea-inventory/src/slot.rs @@ -4,34 +4,34 @@ use std::{ io::{Cursor, Write}, }; -use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_registry::DataComponentKind; use crate::components::{self}; /// Either an item in an inventory or nothing. #[derive(Debug, Clone, Default, PartialEq)] -pub enum ItemSlot { +pub enum ItemStack { #[default] Empty, - Present(ItemSlotData), + Present(ItemStackData), } -impl ItemSlot { - /// Check if the slot is ItemSlot::Empty, if the count is <= 0, or if the +impl ItemStack { + /// Check if the slot is ItemStack::Empty, if the count is <= 0, or if the /// item is air. /// - /// This is the opposite of [`ItemSlot::is_present`]. + /// This is the opposite of [`ItemStack::is_present`]. pub fn is_empty(&self) -> bool { match self { - ItemSlot::Empty => true, - ItemSlot::Present(item) => item.is_empty(), + ItemStack::Empty => true, + ItemStack::Present(item) => item.is_empty(), } } - /// Check if the slot is not ItemSlot::Empty, if the count is > 0, and if + /// Check if the slot is not ItemStack::Empty, if the count is > 0, and if /// the item is not air. /// - /// This is the opposite of [`ItemSlot::is_empty`]. + /// This is the opposite of [`ItemStack::is_empty`]. pub fn is_present(&self) -> bool { !self.is_empty() } @@ -42,21 +42,21 @@ impl ItemSlot { /// slot is present. pub fn count(&self) -> i32 { match self { - ItemSlot::Empty => 0, - ItemSlot::Present(i) => i.count, + ItemStack::Empty => 0, + ItemStack::Present(i) => i.count, } } /// Remove `count` items from this slot, returning the removed items. - pub fn split(&mut self, count: u32) -> ItemSlot { + pub fn split(&mut self, count: u32) -> ItemStack { match self { - ItemSlot::Empty => ItemSlot::Empty, - ItemSlot::Present(i) => { + ItemStack::Empty => ItemStack::Empty, + ItemStack::Present(i) => { let returning = i.split(count); if i.is_empty() { - *self = ItemSlot::Empty; + *self = ItemStack::Empty; } - ItemSlot::Present(returning) + ItemStack::Present(returning) } } } @@ -65,33 +65,33 @@ impl ItemSlot { /// [`azalea_registry::Item::Air`] pub fn kind(&self) -> azalea_registry::Item { match self { - ItemSlot::Empty => azalea_registry::Item::Air, - ItemSlot::Present(i) => i.kind, + ItemStack::Empty => azalea_registry::Item::Air, + ItemStack::Present(i) => i.kind, } } /// Update whether this slot is empty, based on the count. pub fn update_empty(&mut self) { - if let ItemSlot::Present(i) = self { + if let ItemStack::Present(i) = self { if i.is_empty() { - *self = ItemSlot::Empty; + *self = ItemStack::Empty; } } } - /// Convert this slot into an [`ItemSlotData`], if it's present. - pub fn as_present(&self) -> Option<&ItemSlotData> { + /// Convert this slot into an [`ItemStackData`], if it's present. + pub fn as_present(&self) -> Option<&ItemStackData> { match self { - ItemSlot::Empty => None, - ItemSlot::Present(i) => Some(i), + ItemStack::Empty => None, + ItemStack::Present(i) => Some(i), } } } -/// An item in an inventory, with a count and NBT. Usually you want [`ItemSlot`] -/// or [`azalea_registry::Item`] instead. +/// An item in an inventory, with a count and NBT. Usually you want +/// [`ItemStack`] or [`azalea_registry::Item`] instead. #[derive(Debug, Clone, PartialEq)] -pub struct ItemSlotData { +pub struct ItemStackData { /// The amount of the item in this slot. /// /// The count can be zero or negative, but this is rare. @@ -100,9 +100,9 @@ pub struct ItemSlotData { pub components: DataComponentPatch, } -impl ItemSlotData { +impl ItemStackData { /// Remove `count` items from this slot, returning the removed items. - pub fn split(&mut self, count: u32) -> ItemSlotData { + pub fn split(&mut self, count: u32) -> ItemStackData { let returning_count = i32::min(count as i32, self.count); let mut returning = self.clone(); returning.count = returning_count; @@ -118,14 +118,14 @@ impl ItemSlotData { /// Whether this item is the same as another item, ignoring the count. /// /// ``` - /// # use azalea_inventory::ItemSlotData; + /// # use azalea_inventory::ItemStackData; /// # use azalea_registry::Item; - /// let mut a = ItemSlotData { + /// let mut a = ItemStackData { /// kind: Item::Stone, /// count: 1, /// components: Default::default(), /// }; - /// let mut b = ItemSlotData { + /// let mut b = ItemStackData { /// kind: Item::Stone, /// count: 2, /// components: Default::default(), @@ -135,20 +135,20 @@ impl ItemSlotData { /// b.kind = Item::Dirt; /// assert!(!a.is_same_item_and_components(&b)); /// ``` - pub fn is_same_item_and_components(&self, other: &ItemSlotData) -> bool { + pub fn is_same_item_and_components(&self, other: &ItemStackData) -> bool { self.kind == other.kind && self.components == other.components } } -impl McBufReadable for ItemSlot { - fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let count = i32::var_read_from(buf)?; +impl AzaleaRead for ItemStack { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let count = i32::azalea_read_var(buf)?; if count <= 0 { - Ok(ItemSlot::Empty) + Ok(ItemStack::Empty) } else { - let kind = azalea_registry::Item::read_from(buf)?; - let components = DataComponentPatch::read_from(buf)?; - Ok(ItemSlot::Present(ItemSlotData { + let kind = azalea_registry::Item::azalea_read(buf)?; + let components = DataComponentPatch::azalea_read(buf)?; + Ok(ItemStack::Present(ItemStackData { count, kind, components, @@ -157,14 +157,14 @@ impl McBufReadable for ItemSlot { } } -impl McBufWritable for ItemSlot { - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { +impl AzaleaWrite for ItemStack { + fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { - ItemSlot::Empty => 0.var_write_into(buf)?, - ItemSlot::Present(i) => { - i.count.var_write_into(buf)?; - i.kind.write_into(buf)?; - i.components.write_into(buf)?; + ItemStack::Empty => 0.azalea_write_var(buf)?, + ItemStack::Present(i) => { + i.count.azalea_write_var(buf)?; + i.kind.azalea_write(buf)?; + i.components.azalea_write(buf)?; } }; Ok(()) @@ -182,10 +182,10 @@ impl DataComponentPatch { } } -impl McBufReadable for DataComponentPatch { - fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { - let components_with_data_count = u32::var_read_from(buf)?; - let components_without_data_count = u32::var_read_from(buf)?; +impl AzaleaRead for DataComponentPatch { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let components_with_data_count = u32::azalea_read_var(buf)?; + let components_without_data_count = u32::azalea_read_var(buf)?; if components_without_data_count == 0 && components_with_data_count == 0 { return Ok(DataComponentPatch::default()); @@ -193,13 +193,13 @@ impl McBufReadable for DataComponentPatch { let mut components = HashMap::new(); for _ in 0..components_with_data_count { - let component_kind = DataComponentKind::read_from(buf)?; + let component_kind = DataComponentKind::azalea_read(buf)?; let component_data = components::from_kind(component_kind, buf)?; components.insert(component_kind, Some(component_data)); } for _ in 0..components_without_data_count { - let component_kind = DataComponentKind::read_from(buf)?; + let component_kind = DataComponentKind::azalea_read(buf)?; components.insert(component_kind, None); } @@ -207,8 +207,8 @@ impl McBufReadable for DataComponentPatch { } } -impl McBufWritable for DataComponentPatch { - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { +impl AzaleaWrite for DataComponentPatch { + fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut components_with_data_count = 0; let mut components_without_data_count = 0; for component in self.components.values() { @@ -219,21 +219,21 @@ impl McBufWritable for DataComponentPatch { } } - components_with_data_count.write_into(buf)?; - components_without_data_count.write_into(buf)?; + components_with_data_count.azalea_write(buf)?; + components_without_data_count.azalea_write(buf)?; for (kind, component) in &self.components { if let Some(component) = component { - kind.write_into(buf)?; + kind.azalea_write(buf)?; let mut component_buf = Vec::new(); component.encode(&mut component_buf).unwrap(); - component_buf.write_into(buf)?; + component_buf.azalea_write(buf)?; } } for (kind, component) in &self.components { if component.is_none() { - kind.write_into(buf)?; + kind.azalea_write(buf)?; } } |
