diff --git a/src/data/mod.rs b/src/data/mod.rs index fd2366d..13e257d 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -53,7 +53,13 @@ impl ReadWritePosition for Packet { } #[derive(Clone)] -pub enum IDSet { +pub enum IdOr { + Id(i32), + Or(T), +} + +#[derive(Clone)] +pub enum IdSet { Tag(String), Ids(Vec), } diff --git a/src/data/slot.rs b/src/data/slot.rs index d01841c..9b96326 100644 --- a/src/data/slot.rs +++ b/src/data/slot.rs @@ -6,40 +6,123 @@ use uuid::Uuid; use crate::ServerError; -use super::{IDSet, Property, component::TextComponent, sound::SoundEvent}; +use super::{IdOr, IdSet, Property, component::TextComponent, sound::SoundEvent}; pub const SLOT_COMPONENT_LENGTH: u16 = 96; -#[derive(Clone)] -pub struct BlockPredicate; - -#[derive(Clone)] -pub struct ConsumeEffect; - -#[derive(Clone)] -pub struct PotionEffect; - -#[derive(Clone)] -pub struct TrimPattern; - -#[derive(Clone)] -pub struct Instrument; - -#[derive(Clone)] -pub struct TrimMaterial; - #[derive(Clone)] pub struct JukeboxSong; -#[derive(Clone)] -pub struct FireworkExplosion; - #[derive(Clone)] pub struct ChickenVariant; #[derive(Clone)] pub struct PaintingVariant; +#[derive(Clone)] +pub enum BlockPredicatePropertyMatch { + Exact(String), + Range(String, String), +} + +#[derive(Clone)] +pub struct BlockPredicateExactDataMatcher { + /// ID of the data component as listed in the table of data component types above. + pub component_index: usize, + pub value: StructuredComponent, +} + +#[derive(Clone)] +pub struct BlockPredicatePartialDataMatcher { + /// 0: damage, 1: enchantments, 2: stored_enchantments, 3: potion_contents, 4: custom_data, 5: container, 6: bundle_contents, 7: firework_explosion, 8: fireworks, 9: writable_book_content, 10: written_book_content, 11: attribute_modifiers, 12: trim, 13: jukebox_playable. + pub type_id: u8, + /// https://minecraft.wiki/w/Data_component_predicate + pub predicate: DynNBT, +} + +#[derive(Clone)] +pub struct BlockPredicateProperty { + pub name: String, + pub matches: BlockPredicatePropertyMatch, +} + +#[derive(Clone)] +pub struct BlockPredicate { + pub blocks: Option, + pub properties: Option>, + pub nbt: Option, + pub exact_matchers: Vec, + pub partial_matchers: Vec, +} + +#[derive(Clone)] +pub struct Instrument { + pub sound: IdOr, + pub sound_range: f32, + pub range: f32, + pub description: TextComponent, +} + +#[derive(Clone)] +pub enum ConsumeEffect { + /// Effects, Probability + ApplyEffects(Vec, f32), + RemoveEffects(IdSet), + ClearAllEffects, + /// Diameter + TeleportRandomly(f32), + PlaySound(SoundEvent), +} + +#[derive(Clone)] +pub struct TrimMaterial { + pub suffix: String, + /// Key - Armor Material Type Identifier + /// Value - Overriden Asset Name + pub overrides: Vec<(String, String)>, + pub description: TextComponent, +} + +#[derive(Clone)] +pub struct TrimPattern { + pub asset_name: String, + pub template_item: i32, + pub description: TextComponent, + pub decal: bool, +} + +#[derive(Clone)] +pub struct PotionEffectDetail { + pub amplifier: i32, + /// -1 for infinite. + pub duration: i32, + pub ambient: bool, + pub show_particles: bool, + pub show_icon: bool, + pub hidden_effect: Option>, +} + +#[derive(Clone)] +pub struct PotionEffect { + pub type_id: u32, + pub detail: PotionEffectDetail, +} + +#[derive(Clone)] +pub struct FireworkExplosion { + /// Can be one of the following: + /// - 0 - Small ball + /// - 1 - Large ball + /// - 2 - Star + /// - 3 - Creeper + /// - 4 - Burst + pub shape: u8, + pub colors: Vec, + pub fade_colors: Vec, + pub has_trail: bool, + pub has_twinkle: bool, +} + #[derive(Clone)] pub struct HiveBee { pub entity_data: DynNBT, @@ -99,7 +182,7 @@ pub struct AttributeModifier { #[derive(Clone)] pub struct ToolRule { - pub blocks: IDSet, + pub blocks: IdSet, pub has_speed: bool, pub speed: Option, pub has_correct_drop_for_blocks: bool, @@ -109,14 +192,14 @@ pub struct ToolRule { #[derive(Clone)] pub struct DamageReduction { pub horizontal_blocking_angle: f32, - pub damage_kind: Option, + pub damage_kind: Option, pub base: f32, pub factor: f32, } /// https://minecraft.wiki/w/Java_Edition_protocol/Slot_data#Structured_components #[derive(Clone, EnumIndex)] -pub enum SlotComponent { +pub enum StructuredComponent { CustomData(DynNBT), /// 1 - 99 MaxStackSize(i32), @@ -167,7 +250,7 @@ pub enum SlotComponent { Consumable { consume_seconds: f32, animation: u8, - sound: SoundEvent, + sound: IdOr, has_particles: bool, effects: Vec, }, @@ -192,16 +275,16 @@ pub enum SlotComponent { Enchantable(i32), Equippable { slot: u8, - equip_sound: SoundEvent, + equip_sound: IdOr, model: Option, camera_overlay: Option, - allowed_entities: Option, + allowed_entities: Option, dispensable: bool, swappable: bool, damage_on_hurt: bool, }, /// Items that can be combined with this item in an anvil to repair it. - Repairable(IDSet), + Repairable(IdSet), /// Makes the item function like elytra. Glider, TooltipStyle(String), @@ -215,8 +298,8 @@ pub enum SlotComponent { item_damage_base: f32, item_damage_factor: f32, bypassed_by: Option, - block_sound: Option, - disable_sound: Option, + block_sound: Option>, + disable_sound: Option>, }, /// The enchantments stored in this enchanted book. /// Key: The ID of the enchantment in the enchantment registry. \ @@ -318,7 +401,7 @@ pub enum SlotComponent { Bees(Vec), Lock(String), ContainerLoot(DynNBT), - BreakSound(SoundEvent), + BreakSound(IdOr), VillagerVariant(u64), WolfVariant(u64), WolfSoundVariant(u64), @@ -439,17 +522,17 @@ pub enum SlotComponent { } pub trait ReadWriteSlotComponent: DataReader + DataWriter { - fn read_slot_component(&mut self) -> Result; - fn write_slot_component(&mut self, val: &SlotComponent) -> Result<(), ServerError>; + fn read_slot_component(&mut self) -> Result; + fn write_slot_component(&mut self, val: &StructuredComponent) -> Result<(), ServerError>; } impl ReadWriteSlotComponent for Packet { - fn read_slot_component(&mut self) -> Result { + fn read_slot_component(&mut self) -> Result { let _ = self.read_u16_varint()?; // id todo!() } - fn write_slot_component(&mut self, val: &SlotComponent) -> Result<(), ServerError> { + fn write_slot_component(&mut self, val: &StructuredComponent) -> Result<(), ServerError> { self.write_usize_varint(val.enum_index())?; todo!() @@ -460,7 +543,7 @@ impl ReadWriteSlotComponent for Packet { pub struct Slot { pub id: i32, pub amount: i32, - pub components: Vec, + pub components: Vec, } pub trait ReadWriteSlot: DataReader + DataWriter {