From eff339661fc8ecfaa78cef3a6866eafec3bd75ae Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 22 Dec 2022 20:09:03 -0600 Subject: [PATCH] ok well it compiles but it definitely doesn't work --- Cargo.lock | 1 + azalea-world/Cargo.toml | 1 + azalea-world/src/entity/metadata.rs | 1009 ++++++++++---------- azalea-world/src/entity/mod.rs | 111 +-- azalea-world/src/entity_storage.rs | 196 ++-- azalea-world/src/world.rs | 137 ++- azalea/examples/craft_dig_straight_down.rs | 6 +- azalea/examples/pvp.rs | 8 +- codegen/lib/code/entity.py | 17 +- 9 files changed, 708 insertions(+), 778 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1cbd6a34..7af3a0e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,6 +424,7 @@ dependencies = [ "enum-as-inner", "log", "nohash-hasher", + "once_cell", "parking_lot", "thiserror", "uuid", diff --git a/azalea-world/Cargo.toml b/azalea-world/Cargo.toml index 9dd228c7..f5100105 100644 --- a/azalea-world/Cargo.toml +++ b/azalea-world/Cargo.toml @@ -20,6 +20,7 @@ derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]} enum-as-inner = "0.5.1" log = "0.4.17" nohash-hasher = "0.2.0" +once_cell = "1.16.0" parking_lot = "^0.12.1" thiserror = "1.0.34" uuid = "1.1.2" diff --git a/azalea-world/src/entity/metadata.rs b/azalea-world/src/entity/metadata.rs index 77fe75ec..3ec424ed 100644 --- a/azalea-world/src/entity/metadata.rs +++ b/azalea-world/src/entity/metadata.rs @@ -77,18 +77,18 @@ pub struct CanDuplicate(pub bool); pub struct Allay; impl Allay { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(Dancing(d.value.into_boolean()?)); } 17 => { entity.insert(CanDuplicate(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -152,12 +152,11 @@ pub struct Waiting(pub bool); pub struct AreaEffectCloud; impl AreaEffectCloud { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(Radius(d.value.into_float()?)); } @@ -170,6 +169,7 @@ impl AreaEffectCloud { 11 => { entity.insert(d.value.into_particle()?); } + _ => {} } Ok(()) } @@ -234,12 +234,11 @@ pub struct RightLegPose(pub Rotations); pub struct ArmorStand; impl ArmorStand { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=14 => AbstractLiving::update_metadata(ecs, entity, d)?, + 0..=14 => AbstractLiving::update_metadata(entity, d)?, 15 => { let bitfield = d.value.into_byte()?; entity.insert(Small(bitfield & 0x1 != 0)); @@ -265,6 +264,7 @@ impl ArmorStand { 21 => { entity.insert(RightLegPose(d.value.into_rotations()?)); } + _ => {} } Ok(()) } @@ -341,12 +341,11 @@ pub struct ArrowEffectColor(pub i32); pub struct Arrow; impl Arrow { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { let bitfield = d.value.into_byte()?; entity.insert(ArrowCritArrow(bitfield & 0x1 != 0)); @@ -359,6 +358,7 @@ impl Arrow { 10 => { entity.insert(ArrowEffectColor(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -413,12 +413,11 @@ pub struct AxolotlFromBucket(pub bool); pub struct Axolotl; impl Axolotl { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(AxolotlVariant(d.value.into_int()?)); } @@ -428,6 +427,7 @@ impl Axolotl { 19 => { entity.insert(AxolotlFromBucket(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -494,16 +494,16 @@ pub struct Resting(pub bool); pub struct Bat; impl Bat { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractInsentient::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractInsentient::update_metadata(entity, d)?, 16 => { let bitfield = d.value.into_byte()?; entity.insert(Resting(bitfield & 0x1 != 0)); } + _ => {} } Ok(()) } @@ -565,12 +565,11 @@ pub struct BeeRemainingAngerTime(pub i32); pub struct Bee; impl Bee { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(HasNectar(bitfield & 0x8 != 0)); @@ -580,6 +579,7 @@ impl Bee { 18 => { entity.insert(BeeRemainingAngerTime(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -648,16 +648,16 @@ pub struct Charged(pub bool); pub struct Blaze; impl Blaze { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { let bitfield = d.value.into_byte()?; entity.insert(Charged(bitfield & 0x1 != 0)); } + _ => {} } Ok(()) } @@ -729,12 +729,11 @@ pub struct BubbleTime(pub i32); pub struct Boat; impl Boat { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(BoatHurt(d.value.into_int()?)); } @@ -756,6 +755,7 @@ impl Boat { 14 => { entity.insert(BubbleTime(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -822,12 +822,11 @@ pub struct LastPoseChangeTick(pub i64); pub struct Camel; impl Camel { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(CamelTamed(bitfield & 0x2 != 0)); @@ -845,6 +844,7 @@ impl Camel { 20 => { entity.insert(LastPoseChangeTick(d.value.into_long()?)); } + _ => {} } Ok(()) } @@ -933,12 +933,11 @@ pub struct CatCollarColor(pub i32); pub struct Cat; impl Cat { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=18 => AbstractTameable::update_metadata(ecs, entity, d)?, + 0..=18 => AbstractTameable::update_metadata(entity, d)?, 19 => { entity.insert(CatVariant(d.value.into_cat_variant()?)); } @@ -951,6 +950,7 @@ impl Cat { 22 => { entity.insert(CatCollarColor(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -1024,12 +1024,12 @@ pub struct Climbing(pub bool); pub struct CaveSpider; impl CaveSpider { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => Spider::update_metadata(ecs, entity, d)?, + 0..=16 => Spider::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1088,12 +1088,12 @@ impl Default for CaveSpiderBundle { pub struct ChestBoat; impl ChestBoat { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=14 => Boat::update_metadata(ecs, entity, d)?, + 0..=14 => Boat::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1151,12 +1151,12 @@ pub struct CustomDisplay(pub bool); pub struct ChestMinecart; impl ChestMinecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=13 => AbstractMinecart::update_metadata(ecs, entity, d)?, + 0..=13 => AbstractMinecart::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1201,12 +1201,12 @@ impl Default for ChestMinecartBundle { pub struct Chicken; impl Chicken { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1267,15 +1267,15 @@ pub struct CodFromBucket(pub bool); pub struct Cod; impl Cod { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(CodFromBucket(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -1335,18 +1335,18 @@ pub struct LastOutput(pub FormattedText); pub struct CommandBlockMinecart; impl CommandBlockMinecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=13 => AbstractMinecart::update_metadata(ecs, entity, d)?, + 0..=13 => AbstractMinecart::update_metadata(entity, d)?, 14 => { entity.insert(CommandName(d.value.into_string()?)); } 15 => { entity.insert(LastOutput(d.value.into_formatted_text()?)); } + _ => {} } Ok(()) } @@ -1395,12 +1395,12 @@ impl Default for CommandBlockMinecartBundle { pub struct Cow; impl Cow { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1465,12 +1465,11 @@ pub struct IsIgnited(pub bool); pub struct Creeper; impl Creeper { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(SwellDir(d.value.into_int()?)); } @@ -1480,6 +1479,7 @@ impl Creeper { 18 => { entity.insert(IsIgnited(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -1547,12 +1547,11 @@ pub struct MoistnessLevel(pub i32); pub struct Dolphin; impl Dolphin { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(TreasurePos(d.value.into_block_pos()?)); } @@ -1562,6 +1561,7 @@ impl Dolphin { 18 => { entity.insert(MoistnessLevel(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -1635,12 +1635,11 @@ pub struct DonkeyChest(pub bool); pub struct Donkey; impl Donkey { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(DonkeyTamed(bitfield & 0x2 != 0)); @@ -1655,6 +1654,7 @@ impl Donkey { 19 => { entity.insert(DonkeyChest(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -1727,12 +1727,12 @@ impl Default for DonkeyBundle { pub struct DragonFireball; impl DragonFireball { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1775,12 +1775,12 @@ pub struct DrownedConversion(pub bool); pub struct Drowned; impl Drowned { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=18 => Zombie::update_metadata(ecs, entity, d)?, + 0..=18 => Zombie::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1843,15 +1843,15 @@ pub struct EggItemStack(pub Slot); pub struct Egg; impl Egg { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(EggItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -1894,12 +1894,12 @@ pub struct AttackTarget(pub i32); pub struct ElderGuardian; impl ElderGuardian { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=17 => Guardian::update_metadata(ecs, entity, d)?, + 0..=17 => Guardian::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -1963,18 +1963,18 @@ pub struct ShowBottom(pub bool); pub struct EndCrystal; impl EndCrystal { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(BeamTarget(d.value.into_optional_block_pos()?)); } 9 => { entity.insert(ShowBottom(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -2017,15 +2017,15 @@ pub struct Phase(pub i32); pub struct EnderDragon; impl EnderDragon { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractInsentient::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractInsentient::update_metadata(entity, d)?, 16 => { entity.insert(Phase(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -2081,15 +2081,15 @@ pub struct EnderPearlItemStack(pub Slot); pub struct EnderPearl; impl EnderPearl { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(EnderPearlItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -2134,12 +2134,11 @@ pub struct StaredAt(pub bool); pub struct Enderman; impl Enderman { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(CarryState(d.value.into_block_state()?)); } @@ -2149,6 +2148,7 @@ impl Enderman { 18 => { entity.insert(StaredAt(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -2210,12 +2210,12 @@ impl Default for EndermanBundle { pub struct Endermite; impl Endermite { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -2275,18 +2275,18 @@ pub struct EvokerSpellCasting(pub u8); pub struct Evoker; impl Evoker { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(EvokerIsCelebrating(d.value.into_boolean()?)); } 17 => { entity.insert(EvokerSpellCasting(d.value.into_byte()?)); } + _ => {} } Ok(()) } @@ -2346,12 +2346,12 @@ impl Default for EvokerBundle { pub struct EvokerFangs; impl EvokerFangs { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -2390,15 +2390,15 @@ pub struct ExperienceBottleItemStack(pub Slot); pub struct ExperienceBottle; impl ExperienceBottle { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(ExperienceBottleItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -2437,12 +2437,12 @@ impl Default for ExperienceBottleBundle { pub struct ExperienceOrb; impl ExperienceOrb { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -2481,15 +2481,15 @@ pub struct EyeOfEnderItemStack(pub Slot); pub struct EyeOfEnder; impl EyeOfEnder { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(EyeOfEnderItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -2530,15 +2530,15 @@ pub struct StartPos(pub BlockPos); pub struct FallingBlock; impl FallingBlock { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(StartPos(d.value.into_block_pos()?)); } + _ => {} } Ok(()) } @@ -2579,15 +2579,15 @@ pub struct FireballItemStack(pub Slot); pub struct Fireball; impl Fireball { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(FireballItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -2632,12 +2632,11 @@ pub struct ShotAtAngle(pub bool); pub struct FireworkRocket; impl FireworkRocket { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(FireworksItem(d.value.into_item_stack()?)); } @@ -2647,6 +2646,7 @@ impl FireworkRocket { 10 => { entity.insert(ShotAtAngle(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -2693,18 +2693,18 @@ pub struct Biting(pub bool); pub struct FishingBobber; impl FishingBobber { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(HookedEntity(d.value.into_int()?)); } 9 => { entity.insert(Biting(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -2763,12 +2763,11 @@ pub struct TrustedId1(pub Option); pub struct Fox; impl Fox { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(FoxKind(d.value.into_int()?)); } @@ -2787,6 +2786,7 @@ impl Fox { 20 => { entity.insert(TrustedId1(d.value.into_optional_uuid()?)); } + _ => {} } Ok(()) } @@ -2867,18 +2867,18 @@ pub struct TongueTarget(pub OptionalUnsignedInt); pub struct Frog; impl Frog { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(FrogVariant(d.value.into_frog_variant()?)); } 18 => { entity.insert(TongueTarget(d.value.into_optional_unsigned_int()?)); } + _ => {} } Ok(()) } @@ -2943,15 +2943,15 @@ pub struct Fuel(pub bool); pub struct FurnaceMinecart; impl FurnaceMinecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=13 => AbstractMinecart::update_metadata(ecs, entity, d)?, + 0..=13 => AbstractMinecart::update_metadata(entity, d)?, 14 => { entity.insert(Fuel(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -3000,15 +3000,15 @@ pub struct IsCharging(pub bool); pub struct Ghast; impl Ghast { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractInsentient::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractInsentient::update_metadata(entity, d)?, 16 => { entity.insert(IsCharging(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -3062,12 +3062,12 @@ impl Default for GhastBundle { pub struct Giant; impl Giant { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -3127,12 +3127,12 @@ pub struct Rotation(pub i32); pub struct GlowItemFrame; impl GlowItemFrame { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=9 => ItemFrame::update_metadata(ecs, entity, d)?, + 0..=9 => ItemFrame::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -3175,15 +3175,15 @@ pub struct DarkTicksRemaining(pub i32); pub struct GlowSquid; impl GlowSquid { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => Squid::update_metadata(ecs, entity, d)?, + 0..=15 => Squid::update_metadata(entity, d)?, 16 => { entity.insert(DarkTicksRemaining(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -3247,12 +3247,11 @@ pub struct HasRightHorn(pub bool); pub struct Goat; impl Goat { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(IsScreamingGoat(d.value.into_boolean()?)); } @@ -3262,6 +3261,7 @@ impl Goat { 19 => { entity.insert(HasRightHorn(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -3326,18 +3326,18 @@ impl Default for GoatBundle { pub struct Guardian; impl Guardian { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(Moving(d.value.into_boolean()?)); } 17 => { entity.insert(AttackTarget(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -3399,15 +3399,15 @@ pub struct HoglinImmuneToZombification(pub bool); pub struct Hoglin; impl Hoglin { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(HoglinImmuneToZombification(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -3468,12 +3468,12 @@ impl Default for HoglinBundle { pub struct HopperMinecart; impl HopperMinecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=13 => AbstractMinecart::update_metadata(ecs, entity, d)?, + 0..=13 => AbstractMinecart::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -3532,12 +3532,11 @@ pub struct HorseTypeVariant(pub i32); pub struct Horse; impl Horse { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(HorseTamed(bitfield & 0x2 != 0)); @@ -3552,6 +3551,7 @@ impl Horse { 19 => { entity.insert(HorseTypeVariant(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -3624,12 +3624,12 @@ impl Default for HorseBundle { pub struct Husk; impl Husk { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=18 => Zombie::update_metadata(ecs, entity, d)?, + 0..=18 => Zombie::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -3694,18 +3694,18 @@ pub struct IllusionerSpellCasting(pub u8); pub struct Illusioner; impl Illusioner { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(IllusionerIsCelebrating(d.value.into_boolean()?)); } 17 => { entity.insert(IllusionerSpellCasting(d.value.into_byte()?)); } + _ => {} } Ok(()) } @@ -3767,16 +3767,16 @@ pub struct PlayerCreated(pub bool); pub struct IronGolem; impl IronGolem { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { let bitfield = d.value.into_byte()?; entity.insert(PlayerCreated(bitfield & 0x1 != 0)); } + _ => {} } Ok(()) } @@ -3834,15 +3834,15 @@ pub struct ItemItem(pub Slot); pub struct Item; impl Item { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(ItemItem(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -3881,18 +3881,18 @@ impl Default for ItemBundle { pub struct ItemFrame; impl ItemFrame { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(ItemFrameItem(d.value.into_item_stack()?)); } 9 => { entity.insert(Rotation(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -3933,12 +3933,12 @@ impl Default for ItemFrameBundle { pub struct LeashKnot; impl LeashKnot { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -3975,12 +3975,12 @@ impl Default for LeashKnotBundle { pub struct LightningBolt; impl LightningBolt { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -4037,12 +4037,11 @@ pub struct LlamaVariant(pub i32); pub struct Llama; impl Llama { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(LlamaTamed(bitfield & 0x2 != 0)); @@ -4066,6 +4065,7 @@ impl Llama { 22 => { entity.insert(LlamaVariant(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -4144,12 +4144,12 @@ impl Default for LlamaBundle { pub struct LlamaSpit; impl LlamaSpit { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -4188,12 +4188,12 @@ pub struct SlimeSize(pub i32); pub struct MagmaCube; impl MagmaCube { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => Slime::update_metadata(ecs, entity, d)?, + 0..=16 => Slime::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -4248,12 +4248,12 @@ impl Default for MagmaCubeBundle { pub struct Marker; impl Marker { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -4290,12 +4290,12 @@ impl Default for MarkerBundle { pub struct Minecart; impl Minecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=13 => AbstractMinecart::update_metadata(ecs, entity, d)?, + 0..=13 => AbstractMinecart::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -4342,15 +4342,15 @@ pub struct MooshroomKind(pub String); pub struct Mooshroom; impl Mooshroom { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => Cow::update_metadata(ecs, entity, d)?, + 0..=16 => Cow::update_metadata(entity, d)?, 17 => { entity.insert(MooshroomKind(d.value.into_string()?)); } + _ => {} } Ok(()) } @@ -4427,12 +4427,11 @@ pub struct MuleChest(pub bool); pub struct Mule; impl Mule { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(MuleTamed(bitfield & 0x2 != 0)); @@ -4447,6 +4446,7 @@ impl Mule { 19 => { entity.insert(MuleChest(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -4521,15 +4521,15 @@ pub struct Trusting(pub bool); pub struct Ocelot; impl Ocelot { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(Trusting(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -4592,15 +4592,15 @@ pub struct PaintingVariant(pub azalea_registry::PaintingVariant); pub struct Painting; impl Painting { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(PaintingVariant(d.value.into_painting_variant()?)); } + _ => {} } Ok(()) } @@ -4657,12 +4657,11 @@ pub struct PandaFlags(pub u8); pub struct Panda; impl Panda { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(PandaUnhappyCounter(d.value.into_int()?)); } @@ -4685,6 +4684,7 @@ impl Panda { 22 => { entity.insert(PandaFlags(d.value.into_byte()?)); } + _ => {} } Ok(()) } @@ -4763,15 +4763,15 @@ pub struct ParrotVariant(pub i32); pub struct Parrot; impl Parrot { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=18 => AbstractTameable::update_metadata(ecs, entity, d)?, + 0..=18 => AbstractTameable::update_metadata(entity, d)?, 19 => { entity.insert(ParrotVariant(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -4839,15 +4839,15 @@ pub struct PhantomSize(pub i32); pub struct Phantom; impl Phantom { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractInsentient::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractInsentient::update_metadata(entity, d)?, 16 => { entity.insert(PhantomSize(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -4905,18 +4905,18 @@ pub struct PigBoostTime(pub i32); pub struct Pig; impl Pig { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(PigSaddle(d.value.into_boolean()?)); } 18 => { entity.insert(PigBoostTime(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -4987,12 +4987,11 @@ pub struct IsDancing(pub bool); pub struct Piglin; impl Piglin { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(PiglinImmuneToZombification(d.value.into_boolean()?)); } @@ -5005,6 +5004,7 @@ impl Piglin { 19 => { entity.insert(IsDancing(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -5070,15 +5070,15 @@ pub struct PiglinBruteImmuneToZombification(pub bool); pub struct PiglinBrute; impl PiglinBrute { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(PiglinBruteImmuneToZombification(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -5140,18 +5140,18 @@ pub struct PillagerIsChargingCrossbow(pub bool); pub struct Pillager; impl Pillager { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(PillagerIsCelebrating(d.value.into_boolean()?)); } 17 => { entity.insert(PillagerIsChargingCrossbow(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -5223,12 +5223,11 @@ pub struct ShoulderRight(pub azalea_nbt::Tag); pub struct Player; impl Player { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=14 => AbstractLiving::update_metadata(ecs, entity, d)?, + 0..=14 => AbstractLiving::update_metadata(entity, d)?, 15 => { entity.insert(PlayerAbsorption(d.value.into_float()?)); } @@ -5247,6 +5246,7 @@ impl Player { 20 => { entity.insert(ShoulderRight(d.value.into_compound_tag()?)); } + _ => {} } Ok(()) } @@ -5307,15 +5307,15 @@ pub struct PolarBearStanding(pub bool); pub struct PolarBear; impl PolarBear { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(PolarBearStanding(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -5378,15 +5378,15 @@ pub struct PotionItemStack(pub Slot); pub struct Potion; impl Potion { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(PotionItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -5429,18 +5429,18 @@ pub struct PuffState(pub i32); pub struct Pufferfish; impl Pufferfish { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(PufferfishFromBucket(d.value.into_boolean()?)); } 17 => { entity.insert(PuffState(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -5500,15 +5500,15 @@ pub struct RabbitKind(pub i32); pub struct Rabbit; impl Rabbit { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(RabbitKind(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -5571,15 +5571,15 @@ pub struct RavagerIsCelebrating(pub bool); pub struct Ravager; impl Ravager { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(RavagerIsCelebrating(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -5639,15 +5639,15 @@ pub struct SalmonFromBucket(pub bool); pub struct Salmon; impl Salmon { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(SalmonFromBucket(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -5705,16 +5705,16 @@ pub struct Sheared(pub bool); pub struct Sheep; impl Sheep { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(Sheared(bitfield & 0x10 != 0)); } + _ => {} } Ok(()) } @@ -5781,12 +5781,11 @@ pub struct ShulkerColor(pub u8); pub struct Shulker; impl Shulker { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(AttachFace(d.value.into_direction()?)); } @@ -5796,6 +5795,7 @@ impl Shulker { 18 => { entity.insert(ShulkerColor(d.value.into_byte()?)); } + _ => {} } Ok(()) } @@ -5855,12 +5855,12 @@ impl Default for ShulkerBundle { pub struct ShulkerBullet; impl ShulkerBullet { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -5897,12 +5897,12 @@ impl Default for ShulkerBulletBundle { pub struct Silverfish; impl Silverfish { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -5960,15 +5960,15 @@ pub struct StrayConversion(pub bool); pub struct Skeleton; impl Skeleton { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(StrayConversion(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -6038,12 +6038,11 @@ pub struct SkeletonHorseOwnerUuid(pub Option); pub struct SkeletonHorse; impl SkeletonHorse { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(SkeletonHorseTamed(bitfield & 0x2 != 0)); @@ -6055,6 +6054,7 @@ impl SkeletonHorse { 18 => { entity.insert(SkeletonHorseOwnerUuid(d.value.into_optional_uuid()?)); } + _ => {} } Ok(()) } @@ -6125,15 +6125,15 @@ impl Default for SkeletonHorseBundle { pub struct Slime; impl Slime { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractInsentient::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractInsentient::update_metadata(entity, d)?, 16 => { entity.insert(SlimeSize(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -6189,15 +6189,15 @@ pub struct SmallFireballItemStack(pub Slot); pub struct SmallFireball; impl SmallFireball { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(SmallFireballItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -6238,16 +6238,16 @@ pub struct HasPumpkin(pub bool); pub struct SnowGolem; impl SnowGolem { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { let bitfield = d.value.into_byte()?; entity.insert(HasPumpkin(bitfield & 0x10 != 0)); } + _ => {} } Ok(()) } @@ -6305,15 +6305,15 @@ pub struct SnowballItemStack(pub Slot); pub struct Snowball; impl Snowball { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(SnowballItemStack(d.value.into_item_stack()?)); } + _ => {} } Ok(()) } @@ -6352,12 +6352,12 @@ impl Default for SnowballBundle { pub struct SpawnerMinecart; impl SpawnerMinecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=13 => AbstractMinecart::update_metadata(ecs, entity, d)?, + 0..=13 => AbstractMinecart::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -6410,12 +6410,11 @@ pub struct SpectralArrowPierceLevel(pub u8); pub struct SpectralArrow; impl SpectralArrow { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { let bitfield = d.value.into_byte()?; entity.insert(SpectralArrowCritArrow(bitfield & 0x1 != 0)); @@ -6425,6 +6424,7 @@ impl SpectralArrow { 9 => { entity.insert(SpectralArrowPierceLevel(d.value.into_byte()?)); } + _ => {} } Ok(()) } @@ -6469,16 +6469,16 @@ impl Default for SpectralArrowBundle { pub struct Spider; impl Spider { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { let bitfield = d.value.into_byte()?; entity.insert(Climbing(bitfield & 0x1 != 0)); } + _ => {} } Ok(()) } @@ -6536,12 +6536,12 @@ impl Default for SpiderBundle { pub struct Squid; impl Squid { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -6595,12 +6595,12 @@ impl Default for SquidBundle { pub struct Stray; impl Stray { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -6662,12 +6662,11 @@ pub struct StriderSaddle(pub bool); pub struct Strider; impl Strider { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(StriderBoostTime(d.value.into_int()?)); } @@ -6677,6 +6676,7 @@ impl Strider { 19 => { entity.insert(StriderSaddle(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -6743,15 +6743,15 @@ pub struct TadpoleFromBucket(pub bool); pub struct Tadpole; impl Tadpole { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(TadpoleFromBucket(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -6809,15 +6809,15 @@ pub struct Fuse(pub i32); pub struct Tnt; impl Tnt { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(Fuse(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -6856,12 +6856,12 @@ impl Default for TntBundle { pub struct TntMinecart; impl TntMinecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=13 => AbstractMinecart::update_metadata(ecs, entity, d)?, + 0..=13 => AbstractMinecart::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -6906,12 +6906,12 @@ impl Default for TntMinecartBundle { pub struct TraderLlama; impl TraderLlama { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=22 => Llama::update_metadata(ecs, entity, d)?, + 0..=22 => Llama::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -6994,12 +6994,11 @@ pub struct Foil(pub bool); pub struct Trident; impl Trident { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { let bitfield = d.value.into_byte()?; entity.insert(TridentCritArrow(bitfield & 0x1 != 0)); @@ -7015,6 +7014,7 @@ impl Trident { 11 => { entity.insert(Foil(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -7067,18 +7067,18 @@ pub struct TropicalFishTypeVariant(pub i32); pub struct TropicalFish; impl TropicalFish { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(TropicalFishFromBucket(d.value.into_boolean()?)); } 17 => { entity.insert(TropicalFishTypeVariant(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -7148,12 +7148,11 @@ pub struct Travelling(pub bool); pub struct Turtle; impl Turtle { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { entity.insert(HomePos(d.value.into_block_pos()?)); } @@ -7172,6 +7171,7 @@ impl Turtle { 22 => { entity.insert(Travelling(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -7244,15 +7244,15 @@ pub struct VexFlags(pub u8); pub struct Vex; impl Vex { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(VexFlags(d.value.into_byte()?)); } + _ => {} } Ok(()) } @@ -7314,18 +7314,18 @@ pub struct VillagerVillagerData(pub VillagerData); pub struct Villager; impl Villager { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAgeable::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAgeable::update_metadata(entity, d)?, 17 => { entity.insert(VillagerUnhappyCounter(d.value.into_int()?)); } 18 => { entity.insert(VillagerVillagerData(d.value.into_villager_data()?)); } + _ => {} } Ok(()) } @@ -7392,15 +7392,15 @@ pub struct VindicatorIsCelebrating(pub bool); pub struct Vindicator; impl Vindicator { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(VindicatorIsCelebrating(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -7460,15 +7460,15 @@ pub struct WanderingTraderUnhappyCounter(pub i32); pub struct WanderingTrader; impl WanderingTrader { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAgeable::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAgeable::update_metadata(entity, d)?, 17 => { entity.insert(WanderingTraderUnhappyCounter(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -7529,15 +7529,15 @@ pub struct ClientAngerLevel(pub i32); pub struct Warden; impl Warden { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(ClientAngerLevel(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -7599,18 +7599,18 @@ pub struct WitchUsingItem(pub bool); pub struct Witch; impl Witch { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(WitchIsCelebrating(d.value.into_boolean()?)); } 17 => { entity.insert(WitchUsingItem(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -7678,12 +7678,11 @@ pub struct Inv(pub i32); pub struct Wither; impl Wither { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(TargetA(d.value.into_int()?)); } @@ -7696,6 +7695,7 @@ impl Wither { 19 => { entity.insert(Inv(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -7759,12 +7759,12 @@ impl Default for WitherBundle { pub struct WitherSkeleton; impl WitherSkeleton { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -7822,15 +7822,15 @@ pub struct Dangerous(pub bool); pub struct WitherSkull; impl WitherSkull { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(Dangerous(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -7875,12 +7875,11 @@ pub struct WolfRemainingAngerTime(pub i32); pub struct Wolf; impl Wolf { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=18 => AbstractTameable::update_metadata(ecs, entity, d)?, + 0..=18 => AbstractTameable::update_metadata(entity, d)?, 19 => { entity.insert(WolfInterested(d.value.into_boolean()?)); } @@ -7890,6 +7889,7 @@ impl Wolf { 21 => { entity.insert(WolfRemainingAngerTime(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -7961,15 +7961,15 @@ pub struct ZoglinBaby(pub bool); pub struct Zoglin; impl Zoglin { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(ZoglinBaby(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -8027,12 +8027,11 @@ impl Default for ZoglinBundle { pub struct Zombie; impl Zombie { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractMonster::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractMonster::update_metadata(entity, d)?, 16 => { entity.insert(ZombieBaby(d.value.into_boolean()?)); } @@ -8042,6 +8041,7 @@ impl Zombie { 18 => { entity.insert(DrownedConversion(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -8115,12 +8115,11 @@ pub struct ZombieHorseOwnerUuid(pub Option); pub struct ZombieHorse; impl ZombieHorse { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(ZombieHorseTamed(bitfield & 0x2 != 0)); @@ -8132,6 +8131,7 @@ impl ZombieHorse { 18 => { entity.insert(ZombieHorseOwnerUuid(d.value.into_optional_uuid()?)); } + _ => {} } Ok(()) } @@ -8206,18 +8206,18 @@ pub struct ZombieVillagerVillagerData(pub VillagerData); pub struct ZombieVillager; impl ZombieVillager { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=18 => Zombie::update_metadata(ecs, entity, d)?, + 0..=18 => Zombie::update_metadata(entity, d)?, 19 => { entity.insert(Converting(d.value.into_boolean()?)); } 20 => { entity.insert(ZombieVillagerVillagerData(d.value.into_villager_data()?)); } + _ => {} } Ok(()) } @@ -8286,12 +8286,12 @@ impl Default for ZombieVillagerBundle { pub struct ZombifiedPiglin; impl ZombifiedPiglin { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=18 => Zombie::update_metadata(ecs, entity, d)?, + 0..=18 => Zombie::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -8352,15 +8352,15 @@ impl Default for ZombifiedPiglinBundle { pub struct AbstractAgeable; impl AbstractAgeable { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, 16 => { entity.insert(AbstractAgeableBaby(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -8416,12 +8416,12 @@ impl Default for AbstractAgeableBundle { pub struct AbstractAnimal; impl AbstractAnimal { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAgeable::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAgeable::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -8478,12 +8478,12 @@ impl Default for AbstractAnimalBundle { pub struct AbstractCreature; impl AbstractCreature { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractInsentient::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractInsentient::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -8535,9 +8535,8 @@ impl Default for AbstractCreatureBundle { pub struct AbstractEntity; impl AbstractEntity { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { 0 => { @@ -8571,6 +8570,7 @@ impl AbstractEntity { 7 => { entity.insert(TicksFrozen(d.value.into_int()?)); } + _ => {} } Ok(()) } @@ -8618,18 +8618,18 @@ impl Default for AbstractEntityBundle { pub struct AbstractInsentient; impl AbstractInsentient { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=14 => AbstractLiving::update_metadata(ecs, entity, d)?, + 0..=14 => AbstractLiving::update_metadata(entity, d)?, 15 => { let bitfield = d.value.into_byte()?; entity.insert(NoAi(bitfield & 0x1 != 0)); entity.insert(LeftHanded(bitfield & 0x2 != 0)); entity.insert(Aggressive(bitfield & 0x4 != 0)); } + _ => {} } Ok(()) } @@ -8682,12 +8682,11 @@ impl Default for AbstractInsentientBundle { pub struct AbstractLiving; impl AbstractLiving { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { let bitfield = d.value.into_byte()?; entity.insert(AutoSpinAttack(bitfield & 0x4 != 0)); @@ -8711,6 +8710,7 @@ impl AbstractLiving { 14 => { entity.insert(SleepingPos(d.value.into_optional_block_pos()?)); } + _ => {} } Ok(()) } @@ -8763,12 +8763,11 @@ impl Default for AbstractLivingBundle { pub struct AbstractMinecart; impl AbstractMinecart { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=7 => AbstractEntity::update_metadata(ecs, entity, d)?, + 0..=7 => AbstractEntity::update_metadata(entity, d)?, 8 => { entity.insert(AbstractMinecartHurt(d.value.into_int()?)); } @@ -8787,6 +8786,7 @@ impl AbstractMinecart { 13 => { entity.insert(CustomDisplay(d.value.into_boolean()?)); } + _ => {} } Ok(()) } @@ -8835,12 +8835,12 @@ impl Default for AbstractMinecartBundle { pub struct AbstractMonster; impl AbstractMonster { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=15 => AbstractCreature::update_metadata(ecs, entity, d)?, + 0..=15 => AbstractCreature::update_metadata(entity, d)?, + _ => {} } Ok(()) } @@ -8894,12 +8894,11 @@ impl Default for AbstractMonsterBundle { pub struct AbstractTameable; impl AbstractTameable { pub fn update_metadata( - ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, - d: &EntityDataItem, + d: EntityDataItem, ) -> Result<(), UpdateMetadataError> { match d.index { - 0..=16 => AbstractAnimal::update_metadata(ecs, entity, d)?, + 0..=16 => AbstractAnimal::update_metadata(entity, d)?, 17 => { let bitfield = d.value.into_byte()?; entity.insert(Tame(bitfield & 0x4 != 0)); @@ -8908,6 +8907,7 @@ impl AbstractTameable { 18 => { entity.insert(Owneruuid(d.value.into_optional_uuid()?)); } + _ => {} } Ok(()) } @@ -8969,721 +8969,720 @@ impl Default for AbstractTameableBundle { } pub fn update_metadatas( - ecs: bevy_ecs::world::World, - entity: bevy_ecs::world::EntityMut, - items: &Vec, + mut entity: bevy_ecs::world::EntityMut, + items: Vec, ) -> Result<(), UpdateMetadataError> { if entity.contains::() { for d in items { - Allay::update_metadata(ecs, &mut entity, d)?; + Allay::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - AreaEffectCloud::update_metadata(ecs, &mut entity, d)?; + AreaEffectCloud::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ArmorStand::update_metadata(ecs, &mut entity, d)?; + ArmorStand::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Arrow::update_metadata(ecs, &mut entity, d)?; + Arrow::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Axolotl::update_metadata(ecs, &mut entity, d)?; + Axolotl::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Bat::update_metadata(ecs, &mut entity, d)?; + Bat::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Bee::update_metadata(ecs, &mut entity, d)?; + Bee::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Blaze::update_metadata(ecs, &mut entity, d)?; + Blaze::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Boat::update_metadata(ecs, &mut entity, d)?; + Boat::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Camel::update_metadata(ecs, &mut entity, d)?; + Camel::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Cat::update_metadata(ecs, &mut entity, d)?; + Cat::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - CaveSpider::update_metadata(ecs, &mut entity, d)?; + CaveSpider::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ChestBoat::update_metadata(ecs, &mut entity, d)?; + ChestBoat::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ChestMinecart::update_metadata(ecs, &mut entity, d)?; + ChestMinecart::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Chicken::update_metadata(ecs, &mut entity, d)?; + Chicken::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Cod::update_metadata(ecs, &mut entity, d)?; + Cod::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - CommandBlockMinecart::update_metadata(ecs, &mut entity, d)?; + CommandBlockMinecart::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Cow::update_metadata(ecs, &mut entity, d)?; + Cow::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Creeper::update_metadata(ecs, &mut entity, d)?; + Creeper::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Dolphin::update_metadata(ecs, &mut entity, d)?; + Dolphin::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Donkey::update_metadata(ecs, &mut entity, d)?; + Donkey::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - DragonFireball::update_metadata(ecs, &mut entity, d)?; + DragonFireball::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Drowned::update_metadata(ecs, &mut entity, d)?; + Drowned::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Egg::update_metadata(ecs, &mut entity, d)?; + Egg::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ElderGuardian::update_metadata(ecs, &mut entity, d)?; + ElderGuardian::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - EndCrystal::update_metadata(ecs, &mut entity, d)?; + EndCrystal::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - EnderDragon::update_metadata(ecs, &mut entity, d)?; + EnderDragon::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - EnderPearl::update_metadata(ecs, &mut entity, d)?; + EnderPearl::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Enderman::update_metadata(ecs, &mut entity, d)?; + Enderman::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Endermite::update_metadata(ecs, &mut entity, d)?; + Endermite::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Evoker::update_metadata(ecs, &mut entity, d)?; + Evoker::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - EvokerFangs::update_metadata(ecs, &mut entity, d)?; + EvokerFangs::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ExperienceBottle::update_metadata(ecs, &mut entity, d)?; + ExperienceBottle::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ExperienceOrb::update_metadata(ecs, &mut entity, d)?; + ExperienceOrb::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - EyeOfEnder::update_metadata(ecs, &mut entity, d)?; + EyeOfEnder::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - FallingBlock::update_metadata(ecs, &mut entity, d)?; + FallingBlock::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Fireball::update_metadata(ecs, &mut entity, d)?; + Fireball::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - FireworkRocket::update_metadata(ecs, &mut entity, d)?; + FireworkRocket::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - FishingBobber::update_metadata(ecs, &mut entity, d)?; + FishingBobber::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Fox::update_metadata(ecs, &mut entity, d)?; + Fox::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Frog::update_metadata(ecs, &mut entity, d)?; + Frog::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - FurnaceMinecart::update_metadata(ecs, &mut entity, d)?; + FurnaceMinecart::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Ghast::update_metadata(ecs, &mut entity, d)?; + Ghast::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Giant::update_metadata(ecs, &mut entity, d)?; + Giant::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - GlowItemFrame::update_metadata(ecs, &mut entity, d)?; + GlowItemFrame::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - GlowSquid::update_metadata(ecs, &mut entity, d)?; + GlowSquid::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Goat::update_metadata(ecs, &mut entity, d)?; + Goat::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Guardian::update_metadata(ecs, &mut entity, d)?; + Guardian::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Hoglin::update_metadata(ecs, &mut entity, d)?; + Hoglin::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - HopperMinecart::update_metadata(ecs, &mut entity, d)?; + HopperMinecart::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Horse::update_metadata(ecs, &mut entity, d)?; + Horse::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Husk::update_metadata(ecs, &mut entity, d)?; + Husk::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Illusioner::update_metadata(ecs, &mut entity, d)?; + Illusioner::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - IronGolem::update_metadata(ecs, &mut entity, d)?; + IronGolem::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Item::update_metadata(ecs, &mut entity, d)?; + Item::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ItemFrame::update_metadata(ecs, &mut entity, d)?; + ItemFrame::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - LeashKnot::update_metadata(ecs, &mut entity, d)?; + LeashKnot::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - LightningBolt::update_metadata(ecs, &mut entity, d)?; + LightningBolt::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Llama::update_metadata(ecs, &mut entity, d)?; + Llama::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - LlamaSpit::update_metadata(ecs, &mut entity, d)?; + LlamaSpit::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - MagmaCube::update_metadata(ecs, &mut entity, d)?; + MagmaCube::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Marker::update_metadata(ecs, &mut entity, d)?; + Marker::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Minecart::update_metadata(ecs, &mut entity, d)?; + Minecart::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Mooshroom::update_metadata(ecs, &mut entity, d)?; + Mooshroom::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Mule::update_metadata(ecs, &mut entity, d)?; + Mule::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Ocelot::update_metadata(ecs, &mut entity, d)?; + Ocelot::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Painting::update_metadata(ecs, &mut entity, d)?; + Painting::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Panda::update_metadata(ecs, &mut entity, d)?; + Panda::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Parrot::update_metadata(ecs, &mut entity, d)?; + Parrot::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Phantom::update_metadata(ecs, &mut entity, d)?; + Phantom::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Pig::update_metadata(ecs, &mut entity, d)?; + Pig::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Piglin::update_metadata(ecs, &mut entity, d)?; + Piglin::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - PiglinBrute::update_metadata(ecs, &mut entity, d)?; + PiglinBrute::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Pillager::update_metadata(ecs, &mut entity, d)?; + Pillager::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Player::update_metadata(ecs, &mut entity, d)?; + Player::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - PolarBear::update_metadata(ecs, &mut entity, d)?; + PolarBear::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Potion::update_metadata(ecs, &mut entity, d)?; + Potion::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Pufferfish::update_metadata(ecs, &mut entity, d)?; + Pufferfish::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Rabbit::update_metadata(ecs, &mut entity, d)?; + Rabbit::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Ravager::update_metadata(ecs, &mut entity, d)?; + Ravager::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Salmon::update_metadata(ecs, &mut entity, d)?; + Salmon::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Sheep::update_metadata(ecs, &mut entity, d)?; + Sheep::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Shulker::update_metadata(ecs, &mut entity, d)?; + Shulker::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ShulkerBullet::update_metadata(ecs, &mut entity, d)?; + ShulkerBullet::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Silverfish::update_metadata(ecs, &mut entity, d)?; + Silverfish::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Skeleton::update_metadata(ecs, &mut entity, d)?; + Skeleton::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - SkeletonHorse::update_metadata(ecs, &mut entity, d)?; + SkeletonHorse::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Slime::update_metadata(ecs, &mut entity, d)?; + Slime::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - SmallFireball::update_metadata(ecs, &mut entity, d)?; + SmallFireball::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - SnowGolem::update_metadata(ecs, &mut entity, d)?; + SnowGolem::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Snowball::update_metadata(ecs, &mut entity, d)?; + Snowball::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - SpawnerMinecart::update_metadata(ecs, &mut entity, d)?; + SpawnerMinecart::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - SpectralArrow::update_metadata(ecs, &mut entity, d)?; + SpectralArrow::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Spider::update_metadata(ecs, &mut entity, d)?; + Spider::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Squid::update_metadata(ecs, &mut entity, d)?; + Squid::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Stray::update_metadata(ecs, &mut entity, d)?; + Stray::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Strider::update_metadata(ecs, &mut entity, d)?; + Strider::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Tadpole::update_metadata(ecs, &mut entity, d)?; + Tadpole::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Tnt::update_metadata(ecs, &mut entity, d)?; + Tnt::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - TntMinecart::update_metadata(ecs, &mut entity, d)?; + TntMinecart::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - TraderLlama::update_metadata(ecs, &mut entity, d)?; + TraderLlama::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Trident::update_metadata(ecs, &mut entity, d)?; + Trident::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - TropicalFish::update_metadata(ecs, &mut entity, d)?; + TropicalFish::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Turtle::update_metadata(ecs, &mut entity, d)?; + Turtle::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Vex::update_metadata(ecs, &mut entity, d)?; + Vex::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Villager::update_metadata(ecs, &mut entity, d)?; + Villager::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Vindicator::update_metadata(ecs, &mut entity, d)?; + Vindicator::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - WanderingTrader::update_metadata(ecs, &mut entity, d)?; + WanderingTrader::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Warden::update_metadata(ecs, &mut entity, d)?; + Warden::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Witch::update_metadata(ecs, &mut entity, d)?; + Witch::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Wither::update_metadata(ecs, &mut entity, d)?; + Wither::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - WitherSkeleton::update_metadata(ecs, &mut entity, d)?; + WitherSkeleton::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - WitherSkull::update_metadata(ecs, &mut entity, d)?; + WitherSkull::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Wolf::update_metadata(ecs, &mut entity, d)?; + Wolf::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Zoglin::update_metadata(ecs, &mut entity, d)?; + Zoglin::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - Zombie::update_metadata(ecs, &mut entity, d)?; + Zombie::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ZombieHorse::update_metadata(ecs, &mut entity, d)?; + ZombieHorse::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ZombieVillager::update_metadata(ecs, &mut entity, d)?; + ZombieVillager::update_metadata(&mut entity, d)?; } return Ok(()); } if entity.contains::() { for d in items { - ZombifiedPiglin::update_metadata(ecs, &mut entity, d)?; + ZombifiedPiglin::update_metadata(&mut entity, d)?; } return Ok(()); } diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index ce7525e9..5be72866 100644 --- a/azalea-world/src/entity/mod.rs +++ b/azalea-world/src/entity/mod.rs @@ -3,30 +3,30 @@ mod data; mod dimensions; pub mod metadata; -use self::{ - attributes::{AttributeInstance, AttributeModifiers}, - metadata::UpdateMetadataError, -}; +use self::metadata::UpdateMetadataError; use crate::WeakWorld; use azalea_block::BlockState; use azalea_core::{BlockPos, ChunkPos, Vec3, AABB}; -use azalea_registry::EntityKind; -use bevy_ecs::{component::Component, world::EntityMut}; +use bevy_ecs::{ + component::Component, + world::{EntityMut, Mut}, +}; pub use data::*; use derive_more::{Deref, DerefMut}; pub use dimensions::*; use std::{ fmt::{Debug, Display, Formatter}, - marker::PhantomData, - ops::{Deref, DerefMut}, - ptr::NonNull, + ops::Deref, }; use uuid::Uuid; +/// An entity ID that's used by ECS library. +pub type EcsEntityId = bevy_ecs::entity::Entity; + /// The unique 32-bit unsigned id of an entity. -#[derive(Deref, Eq, PartialEq, DerefMut)] +#[derive(Deref, Eq, PartialEq, DerefMut, Copy, Clone)] pub struct EntityId(pub u32); -impl From for bevy_ecs::entity::Entity { +impl From for EcsEntityId { // bevy_ecs `Entity`s also store the "generation" which adds another 32 bits, // but we don't care about the generation fn from(id: EntityId) -> Self { @@ -50,53 +50,56 @@ impl std::hash::Hash for EntityId { } impl nohash_hasher::IsEnabled for EntityId {} -/// A mutable reference to an entity in a world. -pub struct Entity<'w, W = &'w WeakWorld> { - /// The [`WeakWorld`] this entity is in. - pub world: W, - /// The container for the incrementing numerical id of the entity. - pub id: EntityId, - /// The ECS data for the entity. - pub data: bevy_ecs::world::EntityMut<'w>, -} +// /// A mutable reference to an entity in a world. +// pub struct Entity<'w, W = &'w WeakWorld> { +// /// The [`WeakWorld`] this entity is in. +// pub world: W, +// /// The incrementing numerical id of the entity. +// pub id: u32, +// /// The ECS data for the entity. +// pub data: bevy_ecs::world::EntityMut<'w>, +// } /// Create an entity if you only have a [`bevy_ecs::world::World`]. /// /// If you do have access to a [`PartialEntityStorage`] though then just call /// [`PartialEntityStorage::insert`]. +/// +/// This doesn't return anything since you should be using the [`EntityId`] to +/// get the entity data. pub(crate) fn new_entity<'w>( - ecs: &mut bevy_ecs::world::World, + ecs: &'w mut bevy_ecs::world::World, id: EntityId, bundle: impl bevy_ecs::bundle::Bundle, -) -> EntityMut<'w> { +) { // bevy_ecs only returns None if the entity only exists with a different // generation, which shouldn't be possible here - ecs.get_or_spawn(id.into()) - .expect("Entities should always be generation 0 if we're manually spawning from ids") + let mut entity = ecs + .get_or_spawn(id.into()) + .expect("Entities should always be generation 0 if we're manually spawning from ids"); } -impl<'d, D: Deref> Entity<'d, D> { - /// Create an Entity when we already know its id and data. - pub(crate) fn new(world: D, id: u32, bundle: impl bevy_ecs::bundle::Bundle) -> Self { - let ecs = world.entity_storage.write().ecs; - let id = EntityId(id); - let data = new_entity(&mut ecs, id, bundle); - Self { world, id, data } - } -} +// impl<'d, D: Deref> Entity<'d, D> { +// /// Create an Entity when we already know its id and data. +// pub(crate) fn new(world: D, id: u32, bundle: impl +// bevy_ecs::bundle::Bundle) -> Self { let ecs = +// world.entity_storage.write().ecs; let data = new_entity(&mut ecs, id, +// bundle); Self { world, id, data } +// } +// } -impl<'d, D: Deref> Entity<'d, D> { - // todo: write more here and add an example too - /// Get data from the entity. - pub fn get(&self) -> Option<&T> { - self.data.get() - } - pub fn get_mut( - &mut self, - ) -> Option> { - self.data.get_mut() - } -} +// impl<'d, D: Deref> Entity<'d, D> { +// // todo: write more here and add an example too +// /// Get data from the entity. +// pub fn get(&self) -> Option<&T> { +// self.data.get() +// } +// pub fn get_mut( +// &mut self, +// ) -> Option> { +// self.data.get_mut() +// } +// } /// Sets the position of the entity. This doesn't update the cache in /// azalea-world, and should only be used within azalea-world! @@ -105,7 +108,7 @@ impl<'d, D: Deref> Entity<'d, D> { /// Cached position in the world must be updated. pub unsafe fn move_unchecked(pos: &mut Position, physics: &mut Physics, new_pos: Vec3) { *pos = Position(new_pos); - let bounding_box = make_bounding_box(pos, physics); + let bounding_box = make_bounding_box(&pos, &physics); physics.bounding_box = bounding_box; } @@ -146,9 +149,9 @@ pub fn input_vector(physics: &mut Physics, speed: f32, acceleration: &Vec3) -> V pub fn update_metadatas( ecs: bevy_ecs::world::World, entity: bevy_ecs::world::EntityMut, - items: &Vec, + items: Vec, ) -> Result<(), UpdateMetadataError> { - metadata::update_metadatas(ecs, entity, items) + metadata::update_metadatas(entity, items) } pub fn make_bounding_box(pos: &Position, physics: &Physics) -> AABB { @@ -206,7 +209,7 @@ pub fn on_pos>( pos } -#[derive(Component, Deref, DerefMut)] +#[derive(Component, Deref, DerefMut, Clone, Copy)] pub struct EntityUuid(Uuid); /// The position of the entity right now. @@ -331,11 +334,11 @@ pub struct Physics { // } // } -impl> Debug for Entity<'_, W> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Entity").field("id", &self.id).finish() - } -} +// impl> Debug for Entity<'_, W> { +// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +// f.debug_struct("Entity").field("id", &self.id).finish() +// } +// } #[cfg(test)] mod tests { diff --git a/azalea-world/src/entity_storage.rs b/azalea-world/src/entity_storage.rs index 585faf20..e49d99ed 100755 --- a/azalea-world/src/entity_storage.rs +++ b/azalea-world/src/entity_storage.rs @@ -1,8 +1,12 @@ -use crate::entity::{new_entity, Entity, EntityId, EntityUuid, Position}; +use crate::entity::{new_entity, EcsEntityId, EntityId, EntityUuid, Position}; use azalea_core::ChunkPos; -use bevy_ecs::world::{EntityMut, EntityRef}; +use bevy_ecs::{ + query::{QueryEntityError, QueryState, ReadOnlyWorldQuery, WorldQuery}, + world::{EntityMut, EntityRef}, +}; use log::warn; use nohash_hasher::{IntMap, IntSet}; +use once_cell::sync::Lazy; use parking_lot::RwLock; use std::{ collections::HashMap, @@ -88,31 +92,26 @@ impl PartialEntityStorage { /// Add an entity to the storage. #[inline] - pub fn insert(&mut self, id: u32, bundle: impl bevy_ecs::bundle::Bundle) { - // if you're trying to optimize this, see if checking if the id is in - // self.loaded_entity_ids would help with performance - // i didn't put the check here just in case it doesn't actually help - + pub fn insert(&mut self, id: EntityId, bundle: impl bevy_ecs::bundle::Bundle) { + let mut shared = self.shared.write(); // if the entity is already in the shared world, we don't need to do // anything - let id = EntityId(id); - - if self.shared.read().contains_id(id) { + if shared.contains_id(id) { return; } - let entity = new_entity(&mut self.shared.read().ecs, id, bundle); + new_entity(&mut shared.ecs, id, bundle); + + let mut query = shared.ecs.query::<(&EntityUuid, &Position)>(); + let (&uuid, &pos) = query.get(&mut shared.ecs, id.into()).unwrap(); // add the entity to the indexes - let mut shared = self.shared.write(); shared .ids_by_chunk - .entry(ChunkPos::from(entity.get::().unwrap())) + .entry(ChunkPos::from(&pos)) .or_default() .insert(id); - shared - .id_by_uuid - .insert(**entity.get::().unwrap(), id); + shared.id_by_uuid.insert(*uuid, id); self.loaded_entity_ids.insert(id); // set our updates_received to the shared updates_received, unless it's // not there in which case set both to 1 @@ -132,15 +131,22 @@ impl PartialEntityStorage { #[inline] pub fn remove_by_id(&mut self, id: EntityId) { if self.loaded_entity_ids.remove(&id) { - let entity = self.shared.read().get_by_id(id).expect( - "If the entity was being loaded by this storage, it must be in the shared storage.", + let mut shared = self.shared.write(); + + let mut query = shared.query::<(&Position, &EntityUuid)>(); + let (pos, uuid) = query.get(&mut shared.ecs, id.into()).expect( + "If the entity was being loaded by this storage, it must be in the shared + storage.", ); - let pos = entity.get::().unwrap(); let chunk = ChunkPos::from(pos); - let uuid = **entity.get::().unwrap(); + let uuid = **uuid; + + // TODO: is this line actually necessary? test if it doesn't immediately + // panic/deadlock without this line + drop(query); + self.updates_received.remove(&id); - drop(entity); - self.shared.write().remove_entity_if_unused(id, uuid, chunk); + shared.remove_entity_if_unused(id, uuid, chunk); } else { warn!("Tried to remove entity with id {id} but it was not found.") } @@ -154,12 +160,15 @@ impl PartialEntityStorage { self.loaded_entity_ids.contains(id) } - /// Get a reference to an entity by its id, if it's being loaded by this - /// storage. + /// Get an [`EntityId`] from this u32 entity ID if the entity is being + /// loaded by this storage. + /// + /// Note that you can just create an `EntityId` directly if you want, and + /// it'll work if the entity is being loaded by any storage. #[inline] - pub fn limited_get_by_id(&self, id: EntityId) -> Option { - if self.limited_contains_id(&id) { - self.shared.read().get_by_id(id) + pub fn limited_get_by_id(&self, id: u32) -> Option { + if self.limited_contains_id(&EntityId(id)) { + Some(EntityId(id)) } else { None } @@ -191,23 +200,24 @@ impl PartialEntityStorage { /// Get a reference to an entity by its UUID, if it's being loaded by this /// storage. #[inline] - pub fn limited_get_by_uuid(&self, uuid: &Uuid) -> Option { - let entity_id = self.shared.read().id_by_uuid.get(uuid)?; - self.limited_get_by_id(*entity_id) + pub fn limited_get_by_uuid(&self, uuid: &Uuid) -> Option { + let shared = self.shared.read(); + let entity_id = shared.id_by_uuid.get(uuid)?; + self.limited_get_by_id(entity_id.0) } /// Clear all entities in a chunk. This will not clear them from the /// shared storage, unless there are no other references to them. pub fn clear_chunk(&mut self, chunk: &ChunkPos) { - let shared = self.shared.write(); - if let Some(entities) = shared.ids_by_chunk.get(chunk) { - for id in entities.iter() { - if self.loaded_entity_ids.remove(id) { - let mut entity = shared.get_by_id(*id).unwrap(); - let uuid = **entity.get::().unwrap(); - drop(entity); + let mut shared = self.shared.write(); + let mut query = shared.query::<&EntityUuid>(); + + if let Some(entities) = shared.ids_by_chunk.get(chunk).cloned() { + for &id in entities.iter() { + if self.loaded_entity_ids.remove(&id) { + let uuid = **query.get(&shared.ecs, id.into()).unwrap(); // maybe remove it from the storage - shared.remove_entity_if_unused(*id, uuid, *chunk); + shared.remove_entity_if_unused(id, uuid, *chunk); } } } @@ -217,7 +227,7 @@ impl PartialEntityStorage { #[inline] pub fn update_entity_chunk( &mut self, - entity_id: u32, + entity_id: EntityId, old_chunk: &ChunkPos, new_chunk: &ChunkPos, ) { @@ -227,6 +237,10 @@ impl PartialEntityStorage { } } +/// This is useful so functions that return an IntSet of entity ids can return a +/// reference to nothing. +static EMPTY_ENTITY_ID_INTSET: Lazy> = Lazy::new(|| IntSet::default()); + impl WeakEntityStorage { pub fn new() -> Self { Self { @@ -246,9 +260,9 @@ impl WeakEntityStorage { /// /// Returns whether the entity was removed. pub fn remove_entity_if_unused(&mut self, id: EntityId, uuid: Uuid, chunk: ChunkPos) -> bool { - if let Some(&mut count) = self.entity_reference_count.get_mut(&id) { - count -= 1; - if count == 0 { + if let Some(count) = self.entity_reference_count.get_mut(&id) { + *count -= 1; + if *count == 0 { self.entity_reference_count.remove(&id); return true; } @@ -282,106 +296,32 @@ impl WeakEntityStorage { } } - /// Get an iterator over all entities in the shared storage. The iterator - /// is over `Weak`s, so you'll have to manually try to upgrade. - /// - /// # Examples - /// - /// ```rust - /// # use std::sync::Arc; - /// # use azalea_world::{PartialEntityStorage, entity::{EntityData, EntityMetadata, metadata}}; - /// # use azalea_core::Vec3; - /// # use uuid::Uuid; - /// # - /// let mut storage = PartialEntityStorage::default(); - /// storage.insert( - /// 0, - /// EntityData::new( - /// Uuid::nil(), - /// Vec3::default(), - /// EntityMetadata::Player(metadata::Player::default()), - /// ), - /// ); - /// for entity in storage.shared.read().entities() { - /// if let Some(entity) = entity.upgrade() { - /// println!("Entity: {:?}", entity); - /// } - /// } - /// ``` - pub fn entities(&self) -> std::collections::hash_map::Values<'_, u32, Weak> { - self.data_by_id.values() + pub fn query(&mut self) -> QueryState { + self.ecs.query::() } /// Whether the entity with the given id is in the shared storage. #[inline] pub fn contains_id(&self, id: EntityId) -> bool { - self.ecs.get_entity(*id).is_some() + self.ecs.get_entity(id.into()).is_some() } - /// Get an entity by its id, if it exists. - #[inline] - pub fn get_by_id(&self, id: EntityId) -> Option { - self.ecs.get_entity_mut(*id) + /// Returns a set of entities in the given chunk. + pub fn entities_in_chunk(&self, chunk: &ChunkPos) -> &IntSet { + self.ids_by_chunk + .get(chunk) + .unwrap_or(&EMPTY_ENTITY_ID_INTSET) } - /// Get an entity in the shared storage by its UUID, if it exists. - #[inline] - pub fn get_by_uuid(&self, uuid: &Uuid) -> Option> { - self.id_by_uuid - .get(uuid) - .and_then(|id| self.data_by_id.get(id).and_then(|e| e.upgrade())) - } - - pub fn get_by(&self, mut f: F) -> Option> - where - F: FnMut(&Arc) -> bool, - { - for entity in self.entities() { - if let Some(entity) = entity.upgrade() { - if f(&entity) { - return Some(entity); - } - } - } - None - } - - pub fn entities_by(&self, mut f: F) -> Vec> - where - F: FnMut(&Arc) -> bool, - { - let mut entities = Vec::new(); - for entity in self.entities() { - if let Some(entity) = entity.upgrade() { - if f(&entity) { - entities.push(entity); - } - } - } - entities - } - - pub fn entity_by_in_chunk(&self, chunk: &ChunkPos, mut f: F) -> Option> - where - F: FnMut(&EntityData) -> bool, - { - if let Some(entities) = self.ids_by_chunk.get(chunk) { - for entity_id in entities { - if let Some(entity) = self.data_by_id.get(entity_id).and_then(|e| e.upgrade()) { - if f(&entity) { - return Some(entity); - } - } - } - } - None + pub fn id_by_uuid(&self, uuid: &Uuid) -> Option<&EntityId> { + self.id_by_uuid.get(uuid) } /// Move an entity from its old chunk to a new chunk. #[inline] pub fn update_entity_chunk( &mut self, - entity_id: u32, + entity_id: EntityId, old_chunk: &ChunkPos, new_chunk: &ChunkPos, ) { @@ -409,7 +349,7 @@ impl Debug for WeakEntityStorage { #[cfg(test)] mod tests { - use crate::entity::{metadata, EntityMetadata}; + use crate::entity::metadata; use super::*; use azalea_core::Vec3; diff --git a/azalea-world/src/world.rs b/azalea-world/src/world.rs index 23244380..6b55136d 100644 --- a/azalea-world/src/world.rs +++ b/azalea-world/src/world.rs @@ -1,11 +1,16 @@ use crate::{ - entity::{move_unchecked, Entity, Physics, Position}, + entity::{move_unchecked, EcsEntityId, EntityId, Physics, Position}, Chunk, MoveEntityError, PartialChunkStorage, PartialEntityStorage, WeakChunkStorage, WeakEntityStorage, }; use azalea_block::BlockState; use azalea_buf::BufReadError; use azalea_core::{BlockPos, ChunkPos, PositionDelta8, Vec3}; +use bevy_ecs::{ + query::{QueryEntityError, QueryState, ReadOnlyWorldQuery, WorldQuery}, + system::Query, + world::EntityMut, +}; use parking_lot::RwLock; use std::{backtrace::Backtrace, fmt::Debug}; use std::{fmt::Formatter, io::Cursor, sync::Arc}; @@ -37,7 +42,11 @@ pub struct WeakWorld { } impl PartialWorld { - pub fn new(chunk_radius: u32, shared: Arc, owner_entity_id: Option) -> Self { + pub fn new( + chunk_radius: u32, + shared: Arc, + owner_entity_id: Option, + ) -> Self { PartialWorld { shared: shared.clone(), chunk_storage: PartialChunkStorage::new(chunk_radius, shared.chunk_storage.clone()), @@ -74,65 +83,61 @@ impl PartialWorld { self.chunk_storage.set_block_state(pos, state) } - /// Returns a mutable reference to the entity with the given ID. - pub fn entity_mut(&mut self, id: u32) -> Option> { + /// Whether we're allowed to update the entity with the given ID. + /// + /// Only call this if you're actually updating the entity, otherwise it'll + /// cause the update tracker to get out of sync. + fn maybe_update_entity(&mut self, id: EntityId) -> bool { // no entity for you (we're processing this entity somewhere else) if Some(id) != self.entity_storage.owner_entity_id && !self.entity_storage.maybe_update(id) { - return None; + false + } else { + true } - - self.shared.entity(id) } - pub fn add_entity(&mut self, id: u32, bundle: impl bevy_ecs::prelude::Bundle) { + /// Makes sure we can modify this EntityId, and returns it if we can. + /// + /// Only call this if you're actually updating the entity, otherwise it'll + /// cause the update tracker to get out of sync. + pub fn entity_mut(&mut self, id: EntityId) -> Option { + if self.maybe_update_entity(id) { + Some(id) + } else { + None + } + } + + pub fn add_entity(&mut self, id: EntityId, bundle: impl bevy_ecs::prelude::Bundle) { self.entity_storage.insert(id, bundle); } - pub fn set_entity_pos(&mut self, entity_id: u32, new_pos: Vec3) -> Result<(), MoveEntityError> { - let mut entity = self - .entity_mut(entity_id) - .ok_or_else(|| MoveEntityError::EntityDoesNotExist(Backtrace::capture()))?; - - let pos = entity.get_mut::().unwrap(); - let physics = entity.get_mut::().unwrap(); - - let old_chunk = ChunkPos::from(pos.as_ref()); - let new_chunk = ChunkPos::from(&new_pos); - // this is fine because we update the chunk below - unsafe { move_unchecked(&mut pos, &mut physics, new_pos) }; - - if old_chunk != new_chunk { - self.entity_storage - .update_entity_chunk(entity_id, &old_chunk, &new_chunk); + pub fn set_entity_pos( + &mut self, + entity_id: EntityId, + new_pos: Vec3, + ) -> Result<(), MoveEntityError> { + if self.maybe_update_entity(entity_id) { + self.shared.set_entity_pos(entity_id, new_pos) + } else { + Err(MoveEntityError::EntityDoesNotExist(Backtrace::capture())) } - Ok(()) } pub fn move_entity_with_delta( &mut self, - entity_id: u32, + entity_id: EntityId, delta: &PositionDelta8, ) -> Result<(), MoveEntityError> { - let mut entity = self - .entity_mut(entity_id) - .ok_or_else(|| MoveEntityError::EntityDoesNotExist(Backtrace::capture()))?; - - let pos = entity.get_mut::().unwrap(); - let physics = entity.get_mut::().unwrap(); + let mut query = self.shared.query_entities::<&Position>(); + let pos = **query + .get(&self.shared.entity_storage.read().ecs, entity_id.into()) + .map_err(|_| MoveEntityError::EntityDoesNotExist(Backtrace::capture()))?; let new_pos = pos.with_delta(delta); - let old_chunk = ChunkPos::from(pos.as_ref()); - let new_chunk = ChunkPos::from(&new_pos); - // this is fine because we update the chunk below - - unsafe { move_unchecked(&mut pos, &mut physics, new_pos) }; - if old_chunk != new_chunk { - self.entity_storage - .update_entity_chunk(entity_id, &old_chunk, &new_chunk); - } - Ok(()) + self.set_entity_pos(entity_id, new_pos) } } @@ -155,47 +160,29 @@ impl WeakWorld { self.chunk_storage.read().min_y } - /// Returns a entity with the given ID. - /// - /// The returned Entity can technically be mutated, but you should avoid - /// doing any relative mutations (i.e. getting the current position and then - /// setting the new position relative to that position). - pub fn entity(&self, id: u32) -> Option> { - let entity_data = self.entity_storage.read().get_by_id(id)?; - let entity_ptr = unsafe { entity_data.as_ptr() }; - Some(Entity::new(self, id, entity_ptr)) + pub fn id_by_uuid(&self, uuid: &Uuid) -> Option { + self.entity_storage.read().id_by_uuid(uuid).copied() } - pub fn entity_by_uuid(&self, uuid: &Uuid) -> Option> { - self.entity_storage.read().get_by_uuid(uuid) + pub fn query_entities(&self) -> QueryState { + self.entity_storage.write().query::() } - pub fn entity_by(&self, mut f: F) -> Option> - where - F: FnMut(&EntityData) -> bool, - { - self.entity_storage.read().get_by(|e| f(e)) - } - - pub fn entities_by(&self, mut f: F) -> Vec> - where - F: FnMut(&EntityData) -> bool, - { - self.entity_storage.read().entities_by(|e| f(e)) - } - - pub fn set_entity_pos(&self, entity_id: u32, new_pos: Vec3) -> Result<(), MoveEntityError> { - let mut entity = self - .entity(entity_id) - .ok_or_else(|| MoveEntityError::EntityDoesNotExist(Backtrace::capture()))?; - - let pos = entity.get_mut::().unwrap(); - let physics = entity.get_mut::().unwrap(); + pub fn set_entity_pos( + &self, + entity_id: EntityId, + new_pos: Vec3, + ) -> Result<(), MoveEntityError> { + let mut entity_storage = self.entity_storage.write(); + let mut query = entity_storage.query::<(&mut Position, &mut Physics)>(); + let (pos, physics) = query + .get_mut(&mut entity_storage.ecs, entity_id.into()) + .unwrap(); let old_chunk = ChunkPos::from(pos.as_ref()); let new_chunk = ChunkPos::from(&new_pos); // this is fine because we update the chunk below - unsafe { move_unchecked(&mut pos, &mut physics, new_pos) }; + unsafe { move_unchecked(pos.into_inner(), physics.into_inner(), new_pos) }; if old_chunk != new_chunk { self.entity_storage .write() diff --git a/azalea/examples/craft_dig_straight_down.rs b/azalea/examples/craft_dig_straight_down.rs index 864b9809..76979406 100755 --- a/azalea/examples/craft_dig_straight_down.rs +++ b/azalea/examples/craft_dig_straight_down.rs @@ -64,8 +64,12 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { crafting_table.close().await; bot.hold(&pickaxe); + loop { - if let Err(e) = bot.dig(bot.entity().feet_pos().down(1)).await { + if let Err(e) = bot + .dig(azalea::entity::feet_pos(bot.entity()).down(1)) + .await + { println!("{:?}", e); break; } diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs index 9d2fdc35..7dfd2b7a 100755 --- a/azalea/examples/pvp.rs +++ b/azalea/examples/pvp.rs @@ -47,15 +47,11 @@ async fn swarm_handle( match event { SwarmEvent::Tick => { // choose an arbitrary player within render distance to target - if let Some(target) = swarm - .worlds - .read() - .entity_by(|e| e.id == "minecraft:player") - { + if let Some(target) = swarm.worlds.read().entity_by(|_: &Player| true) { for (bot, bot_state) in swarm { bot.tick_goto_goal(pathfinder::Goals::Reach(target.bounding_box)); // if target.bounding_box.distance(bot.eyes) < bot.reach_distance() { - if bot.entity().can_reach(target.bounding_box) { + if azalea::entities::can_reach(bot.entity(), target.bounding_box) { bot.swing(); } if !bot.using_held_item() && bot.hunger() <= 17 { diff --git a/codegen/lib/code/entity.py b/codegen/lib/code/entity.py index d4987880..f459f844 100644 --- a/codegen/lib/code/entity.py +++ b/codegen/lib/code/entity.py @@ -183,12 +183,11 @@ impl From for UpdateMetadataError { # impl Allay { # pub fn update_metadata( - # ecs: bevy_ecs::world::World, # entity: &mut bevy_ecs::world::EntityMut, # d: EntityDataItem, # ) -> Result<(), UpdateMetadataError> { # match d.index { - # 0..=15 => AbstractCreatureBundle::update_metadata(ecs, entity, d)?, + # 0..=15 => AbstractCreatureBundle::update_metadata(entity, d)?, # 16 => entity.insert(Dancing(d.value.into_boolean()?)), # 17 => entity.insert(CanDuplicate(d.value.into_boolean()?)), # } @@ -197,7 +196,7 @@ impl From for UpdateMetadataError { # } code.append(f'impl {struct_name} {{') code.append( - f' pub fn update_metadata(ecs: bevy_ecs::world::World, entity: &mut bevy_ecs::world::EntityMut, d: &EntityDataItem) -> Result<(), UpdateMetadataError> {{') + f' pub fn update_metadata(entity: &mut bevy_ecs::world::EntityMut, d: EntityDataItem) -> Result<(), UpdateMetadataError> {{') code.append(f' match d.index {{') parent_last_index = -1 @@ -207,7 +206,7 @@ impl From for UpdateMetadataError { parent_last_index = index if parent_last_index != -1: code.append( - f' 0..={parent_last_index} => {parent_struct_name}::update_metadata(ecs, entity, d)?,') + f' 0..={parent_last_index} => {parent_struct_name}::update_metadata(entity, d)?,') for index, name_or_bitfield in enumerate(all_field_names_or_bitfields): if index <= parent_last_index: @@ -242,6 +241,7 @@ impl From for UpdateMetadataError { code.append( f'entity.insert({field_struct_name}(bitfield & {mask} != 0));') code.append(' },') + code.append(' _ => {}') code.append(' }') code.append(' Ok(())') code.append(' }') @@ -390,13 +390,12 @@ impl From for UpdateMetadataError { # and now make the main update_metadatas # pub fn update_metadatas( - # ecs: bevy_ecs::world::World, # entity: bevy_ecs::world::EntityMut, - # items: &Vec, + # items: Vec, # ) -> Result<(), UpdateMetadataError> { # if entity.contains::() { # for d in items { - # Allay::update_metadata(ecs, entity, d)?; + # Allay::update_metadata(entity, d)?; # } # return Ok(()); # } @@ -404,7 +403,7 @@ impl From for UpdateMetadataError { # Ok(()) # } code.append( - f'pub fn update_metadatas(ecs: bevy_ecs::world::World, entity: bevy_ecs::world::EntityMut, items: &Vec) -> Result<(), UpdateMetadataError> {{') + f'pub fn update_metadatas(mut entity: bevy_ecs::world::EntityMut, items: Vec) -> Result<(), UpdateMetadataError> {{') for entity_id in burger_entity_data: if entity_id.startswith('~'): # not actually an entity @@ -414,7 +413,7 @@ impl From for UpdateMetadataError { f' if entity.contains::<{struct_name}>() {{') code.append(' for d in items {') code.append( - f' {struct_name}::update_metadata(ecs, &mut entity, d)?;') + f' {struct_name}::update_metadata(&mut entity, d)?;') code.append(' }') code.append(f' return Ok(());') code.append(' }')