From 80c570f25b39373bca0ef425f335cb4447daea5e Mon Sep 17 00:00:00 2001 From: Jack Crump-Leys <51773589+JackCrumpLeys@users.noreply.github.com> Date: Mon, 29 Jul 2024 02:19:19 +1200 Subject: [PATCH] update to bevy 0.14 (#634) update to bevy 0.14. works towards #620 task 3. --- Cargo.toml | 16 +-- benches/many_players.rs | 14 +- crates/valence_advancement/src/event.rs | 2 +- crates/valence_entity/src/query.rs | 6 +- crates/valence_inventory/src/lib.rs | 2 +- crates/valence_network/src/lib.rs | 4 +- crates/valence_server/src/action.rs | 42 +++--- crates/valence_server/src/client.rs | 8 +- crates/valence_server/src/client_command.rs | 18 +-- crates/valence_server/src/custom_payload.rs | 2 +- crates/valence_server/src/event_loop.rs | 2 +- crates/valence_server/src/interact_entity.rs | 2 +- crates/valence_server/src/resource_pack.rs | 2 +- crates/valence_server/src/spawn.rs | 8 +- crates/valence_server/src/status.rs | 16 ++- crates/valence_server/src/status_effect.rs | 6 +- crates/valence_server_common/src/lib.rs | 4 +- examples/combat.rs | 6 +- examples/ctf.rs | 10 +- src/lib.rs | 5 +- src/testing.rs | 12 +- src/tests/boss_bar.rs | 24 ++-- src/tests/client.rs | 12 +- src/tests/example.rs | 14 +- src/tests/hunger.rs | 6 +- src/tests/inventory.rs | 138 ++++++++++--------- src/tests/layer.rs | 72 +++++----- src/tests/player_list.rs | 4 +- src/tests/potions.rs | 4 +- src/tests/scoreboard.rs | 37 ++--- src/tests/weather.rs | 21 +-- src/tests/world_border.rs | 35 +++-- tools/dump_schedule/src/main.rs | 4 +- 33 files changed, 297 insertions(+), 261 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 17522db43..4c798bd5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,15 +113,15 @@ arrayvec = "0.7.4" async-trait = "0.1.80" atty = "0.2.14" base64 = "0.22.1" -bevy_app = { version = "0.12", default-features = false } -bevy_derive = "0.12" -bevy_ecs = { version = "0.12", default-features = false, features = [ - "multi-threaded", +bevy_app = { version = "0.14.0", default-features = false } +bevy_derive = "0.14.0" +bevy_ecs = { version = "0.14.0", default-features = false, features = [ + "multi_threaded", ] } -bevy_hierarchy = { version = "0.12", default-features = false } -bevy_log = { version = "0.12" } -bevy_mod_debugdump = { version = "0.9.0", default-features = false } -bevy_utils = { version = "0.12" } +bevy_hierarchy = { version = "0.14.0", default-features = false, features = ["bevy_app"] } +bevy_log = { version = "0.14.0" } +bevy_mod_debugdump = { version = "0.11.0" } +bevy_utils = { version = "0.14.0" } bitfield-struct = "0.8.0" bitvec = "1.0.1" byteorder = "1.5.0" diff --git a/benches/many_players.rs b/benches/many_players.rs index 54d100af7..76eadc400 100644 --- a/benches/many_players.rs +++ b/benches/many_players.rs @@ -43,9 +43,9 @@ fn run_many_players(bencher: Bencher, client_count: usize, view_dist: u8, world_ let mut layer = LayerBundle::new( ident!("overworld"), - app.world.resource::(), - app.world.resource::(), - app.world.resource::(), + app.world().resource::(), + app.world().resource::(), + app.world().resource::(), ); for z in -world_size..world_size { @@ -56,7 +56,7 @@ fn run_many_players(bencher: Bencher, client_count: usize, view_dist: u8, world_ } } - let layer = app.world.spawn(layer).id(); + let layer = app.world_mut().spawn(layer).id(); let mut clients = vec![]; @@ -75,12 +75,12 @@ fn run_many_players(bencher: Bencher, client_count: usize, view_dist: u8, world_ bundle.player.position.set(DVec3::new(x, 64.0, z)); - let id = app.world.spawn(bundle).id(); + let id = app.world_mut().spawn(bundle).id(); clients.push((id, helper)); } - let mut query = app.world.query::<&mut Position>(); + let mut query = app.world_mut().query::<&mut Position>(); app.update(); @@ -96,7 +96,7 @@ fn run_many_players(bencher: Bencher, client_count: usize, view_dist: u8, world_ // Move the clients around randomly. They'll cross chunk borders and cause // interesting things to happen. for (id, helper) in &mut clients { - let pos = query.get(&app.world, *id).unwrap().get(); + let pos = query.get(app.world_mut(), *id).unwrap().get(); let offset = DVec3::new(rng.gen_range(-1.0..=1.0), 0.0, rng.gen_range(-1.0..=1.0)); diff --git a/crates/valence_advancement/src/event.rs b/crates/valence_advancement/src/event.rs index 905025a79..8df00673d 100644 --- a/crates/valence_advancement/src/event.rs +++ b/crates/valence_advancement/src/event.rs @@ -23,7 +23,7 @@ pub(crate) fn handle_advancement_tab_change( AdvancementTabC2s::ClosedScreen => None, AdvancementTabC2s::OpenedTab { tab_id } => Some(tab_id.into()), }, - }) + }); } } } diff --git a/crates/valence_entity/src/query.rs b/crates/valence_entity/src/query.rs index dad5eaed9..73f18bb45 100644 --- a/crates/valence_entity/src/query.rs +++ b/crates/valence_entity/src/query.rs @@ -1,7 +1,7 @@ use std::mem; use bevy_ecs::prelude::DetectChanges; -use bevy_ecs::query::WorldQuery; +use bevy_ecs::query::QueryData; use bevy_ecs::world::Ref; use valence_math::DVec3; use valence_protocol::encode::WritePacket; @@ -21,7 +21,7 @@ use crate::{ ObjectData, OldEntityLayerId, OldPosition, OnGround, Position, Velocity, }; -#[derive(WorldQuery)] +#[derive(QueryData)] pub struct EntityInitQuery { pub entity_id: &'static EntityId, pub uuid: &'static UniqueId, @@ -85,7 +85,7 @@ impl EntityInitQueryItem<'_> { } } -#[derive(WorldQuery)] +#[derive(QueryData)] pub struct UpdateEntityQuery { pub id: &'static EntityId, pub pos: &'static Position, diff --git a/crates/valence_inventory/src/lib.rs b/crates/valence_inventory/src/lib.rs index 7e615a9b3..2fdf5e06e 100644 --- a/crates/valence_inventory/src/lib.rs +++ b/crates/valence_inventory/src/lib.rs @@ -1128,7 +1128,7 @@ fn handle_player_actions( client: packet.client, from_slot: Some(held.slot()), stack, - }) + }); } } } diff --git a/crates/valence_network/src/lib.rs b/crates/valence_network/src/lib.rs index 1b37b7e27..43442152a 100644 --- a/crates/valence_network/src/lib.rs +++ b/crates/valence_network/src/lib.rs @@ -45,13 +45,13 @@ impl Plugin for NetworkPlugin { fn build_plugin(app: &mut App) -> anyhow::Result<()> { let threshold = app - .world + .world() .get_resource::() .context("missing server resource")? .compression_threshold(); let settings = app - .world + .world_mut() .get_resource_or_insert_with(NetworkSettings::default); let (new_clients_send, new_clients_recv) = flume::bounded(64); diff --git a/crates/valence_server/src/action.rs b/crates/valence_server/src/action.rs index b0f462c65..767516aa0 100644 --- a/crates/valence_server/src/action.rs +++ b/crates/valence_server/src/action.rs @@ -64,24 +64,30 @@ fn handle_player_action( // TODO: check that blocks are being broken at the appropriate speeds. match pkt.action { - PlayerAction::StartDestroyBlock => digging_events.send(DiggingEvent { - client: packet.client, - position: pkt.position, - direction: pkt.direction, - state: DiggingState::Start, - }), - PlayerAction::AbortDestroyBlock => digging_events.send(DiggingEvent { - client: packet.client, - position: pkt.position, - direction: pkt.direction, - state: DiggingState::Abort, - }), - PlayerAction::StopDestroyBlock => digging_events.send(DiggingEvent { - client: packet.client, - position: pkt.position, - direction: pkt.direction, - state: DiggingState::Stop, - }), + PlayerAction::StartDestroyBlock => { + digging_events.send(DiggingEvent { + client: packet.client, + position: pkt.position, + direction: pkt.direction, + state: DiggingState::Stop, + }); + } + PlayerAction::AbortDestroyBlock => { + digging_events.send(DiggingEvent { + client: packet.client, + position: pkt.position, + direction: pkt.direction, + state: DiggingState::Abort, + }); + } + PlayerAction::StopDestroyBlock => { + digging_events.send(DiggingEvent { + client: packet.client, + position: pkt.position, + direction: pkt.direction, + state: DiggingState::Stop, + }); + } PlayerAction::DropAllItems => {} PlayerAction::DropItem => {} PlayerAction::ReleaseUseItem => {} diff --git a/crates/valence_server/src/client.rs b/crates/valence_server/src/client.rs index 3a01bb964..e4dbf41e7 100644 --- a/crates/valence_server/src/client.rs +++ b/crates/valence_server/src/client.rs @@ -6,8 +6,8 @@ use std::time::Instant; use bevy_app::prelude::*; use bevy_ecs::prelude::*; -use bevy_ecs::query::WorldQuery; -use bevy_ecs::system::Command; +use bevy_ecs::query::QueryData; +use bevy_ecs::world::Command; use byteorder::{NativeEndian, ReadBytesExt}; use bytes::{Bytes, BytesMut}; use derive_more::{Deref, DerefMut, From, Into}; @@ -529,7 +529,7 @@ impl OldViewDistance { } } -#[derive(WorldQuery, Copy, Clone, Debug)] +#[derive(QueryData, Copy, Clone, Debug)] pub struct View { pub pos: &'static Position, pub view_dist: &'static ViewDistance, @@ -541,7 +541,7 @@ impl ViewItem<'_> { } } -#[derive(WorldQuery, Copy, Clone, Debug)] +#[derive(QueryData, Copy, Clone, Debug)] pub struct OldView { pub old_pos: &'static OldPosition, pub old_view_dist: &'static OldViewDistance, diff --git a/crates/valence_server/src/client_command.rs b/crates/valence_server/src/client_command.rs index 05f084333..d3e747d52 100644 --- a/crates/valence_server/src/client_command.rs +++ b/crates/valence_server/src/client_command.rs @@ -83,7 +83,7 @@ fn handle_client_command( sneaking_events.send(SneakEvent { client: packet.client, state: SneakState::Start, - }) + }); } ClientCommand::StopSneaking => { if let Ok((mut pose, mut flags)) = clients.get_mut(packet.client) { @@ -94,11 +94,13 @@ fn handle_client_command( sneaking_events.send(SneakEvent { client: packet.client, state: SneakState::Stop, - }) + }); + } + ClientCommand::LeaveBed => { + leave_bed_events.send(LeaveBedEvent { + client: packet.client, + }); } - ClientCommand::LeaveBed => leave_bed_events.send(LeaveBedEvent { - client: packet.client, - }), ClientCommand::StartSprinting => { if let Ok((_, mut flags)) = clients.get_mut(packet.client) { flags.set_sprinting(true); @@ -117,7 +119,7 @@ fn handle_client_command( sprinting_events.send(SprintEvent { client: packet.client, state: SprintState::Stop, - }) + }); } ClientCommand::StartJumpWithHorse => { jump_with_horse_events.send(JumpWithHorseEvent { @@ -125,13 +127,13 @@ fn handle_client_command( state: JumpWithHorseState::Start { power: pkt.jump_boost.0 as u8, }, - }) + }); } ClientCommand::StopJumpWithHorse => { jump_with_horse_events.send(JumpWithHorseEvent { client: packet.client, state: JumpWithHorseState::Stop, - }) + }); } ClientCommand::OpenHorseInventory => {} // TODO ClientCommand::StartFlyingWithElytra => { diff --git a/crates/valence_server/src/custom_payload.rs b/crates/valence_server/src/custom_payload.rs index bbf661e0c..4b7f3193a 100644 --- a/crates/valence_server/src/custom_payload.rs +++ b/crates/valence_server/src/custom_payload.rs @@ -41,7 +41,7 @@ fn handle_custom_payload( client: packet.client, channel: pkt.channel.into(), data: pkt.data.0 .0.into(), - }) + }); } } } diff --git a/crates/valence_server/src/event_loop.rs b/crates/valence_server/src/event_loop.rs index 0d4b0d8b7..49f71c227 100644 --- a/crates/valence_server/src/event_loop.rs +++ b/crates/valence_server/src/event_loop.rs @@ -22,7 +22,7 @@ impl Plugin for EventLoopPlugin { .add_schedule(Schedule::new(EventLoopPostUpdate)) .add_systems(RunEventLoop, run_event_loop); - app.world + app.world_mut() .resource_mut::() .insert_after(PreUpdate, RunEventLoop); } diff --git a/crates/valence_server/src/interact_entity.rs b/crates/valence_server/src/interact_entity.rs index 98e0d84f5..7915c8680 100644 --- a/crates/valence_server/src/interact_entity.rs +++ b/crates/valence_server/src/interact_entity.rs @@ -43,7 +43,7 @@ fn handle_interact_entity( entity, sneaking: pkt.sneaking, interact: pkt.interact, - }) + }); } } } diff --git a/crates/valence_server/src/resource_pack.rs b/crates/valence_server/src/resource_pack.rs index ddd590e30..08d866b97 100644 --- a/crates/valence_server/src/resource_pack.rs +++ b/crates/valence_server/src/resource_pack.rs @@ -58,7 +58,7 @@ fn handle_resource_pack_status( events.send(ResourcePackStatusEvent { client: packet.client, status: pkt, - }) + }); } } } diff --git a/crates/valence_server/src/spawn.rs b/crates/valence_server/src/spawn.rs index 9e005398e..19f299555 100644 --- a/crates/valence_server/src/spawn.rs +++ b/crates/valence_server/src/spawn.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use std::collections::BTreeSet; use bevy_ecs::prelude::*; -use bevy_ecs::query::WorldQuery; +use bevy_ecs::query::QueryData; use derive_more::{Deref, DerefMut}; use valence_entity::EntityLayerId; use valence_protocol::packets::play::{GameJoinS2c, PlayerRespawnS2c, PlayerSpawnPositionS2c}; @@ -65,10 +65,10 @@ pub struct RespawnPosition { pub yaw: f32, } -/// A convenient [`WorldQuery`] for obtaining client spawn components. Also see +/// A convenient [`QueryData`] for obtaining client spawn components. Also see /// [`ClientSpawnQueryReadOnly`]. -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] pub struct ClientSpawnQuery { pub is_hardcore: &'static mut IsHardcore, pub game_mode: &'static mut GameMode, diff --git a/crates/valence_server/src/status.rs b/crates/valence_server/src/status.rs index 1e0c66bd5..89d25ded3 100644 --- a/crates/valence_server/src/status.rs +++ b/crates/valence_server/src/status.rs @@ -32,12 +32,16 @@ fn handle_status( for packet in packets.read() { if let Some(pkt) = packet.decode::() { match pkt { - ClientStatusC2s::PerformRespawn => respawn_events.send(RequestRespawnEvent { - client: packet.client, - }), - ClientStatusC2s::RequestStats => request_stats_events.send(RequestStatsEvent { - client: packet.client, - }), + ClientStatusC2s::PerformRespawn => { + respawn_events.send(RequestRespawnEvent { + client: packet.client, + }); + } + ClientStatusC2s::RequestStats => { + request_stats_events.send(RequestStatsEvent { + client: packet.client, + }); + } } } } diff --git a/crates/valence_server/src/status_effect.rs b/crates/valence_server/src/status_effect.rs index a4766f00b..8f7829ab8 100644 --- a/crates/valence_server/src/status_effect.rs +++ b/crates/valence_server/src/status_effect.rs @@ -1,6 +1,6 @@ use bevy_app::prelude::*; use bevy_ecs::prelude::*; -use bevy_ecs::query::WorldQuery; +use bevy_ecs::query::QueryData; use bevy_ecs::system::SystemState; use valence_entity::active_status_effects::{ActiveStatusEffect, ActiveStatusEffects}; use valence_entity::entity::Flags; @@ -70,8 +70,8 @@ fn create_packet(effect: &ActiveStatusEffect) -> EntityStatusEffectS2c { } } -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] struct StatusEffectQuery { entity: Entity, active_effects: &'static mut ActiveStatusEffects, diff --git a/crates/valence_server_common/src/lib.rs b/crates/valence_server_common/src/lib.rs index 29359cbf5..6bae10fae 100644 --- a/crates/valence_server_common/src/lib.rs +++ b/crates/valence_server_common/src/lib.rs @@ -65,7 +65,7 @@ pub struct ServerPlugin; impl Plugin for ServerPlugin { fn build(&self, app: &mut App) { let settings = app - .world + .world_mut() .get_resource_or_insert_with(ServerSettings::default) .clone(); @@ -89,7 +89,7 @@ impl Plugin for ServerPlugin { } /// Contains global server state accessible as a [`Resource`]. -#[derive(Resource)] +#[derive(Resource, Clone)] pub struct Server { /// Incremented on every tick. current_tick: i64, diff --git a/examples/combat.rs b/examples/combat.rs index fabc265a7..870f662ad 100644 --- a/examples/combat.rs +++ b/examples/combat.rs @@ -1,6 +1,6 @@ #![allow(clippy::type_complexity)] -use bevy_ecs::query::WorldQuery; +use bevy_ecs::query::QueryData; use rand::Rng; use valence::entity::EntityStatuses; use valence::math::Vec3Swizzles; @@ -104,8 +104,8 @@ fn init_clients( } } -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] struct CombatQuery { client: &'static mut Client, pos: &'static Position, diff --git a/examples/ctf.rs b/examples/ctf.rs index 8339bd644..83e38ccac 100644 --- a/examples/ctf.rs +++ b/examples/ctf.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; -use bevy_ecs::query::WorldQuery; +use bevy_ecs::query::QueryData; use valence::entity::cow::CowEntityBundle; use valence::entity::entity::Flags; use valence::entity::living::Health; @@ -870,8 +870,8 @@ impl CtfLayers { #[derive(Debug, Component)] struct ClonedEntity(Entity); -#[derive(Debug, WorldQuery)] -#[world_query(mutable)] +#[derive(Debug, QueryData)] +#[query_data(mutable)] struct CloneQuery { position: &'static mut Position, head_yaw: &'static mut HeadYaw, @@ -912,8 +912,8 @@ struct CombatState { has_bonus_knockback: bool, } -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] struct CombatQuery { client: &'static mut Client, pos: &'static Position, diff --git a/src/lib.rs b/src/lib.rs index c1df475a4..d8049a5cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,11 +90,12 @@ pub use valence_world_border as world_border; /// /// This is usually glob imported like so: /// -/// ``` +/// ```no_run /// use valence::prelude::*; // Glob import. /// -/// let mut app = App::new(); +/// let mut app = App::empty(); /// app.add_systems(Update, || println!("yippee!")); +/// app.update() /// // ... /// ``` pub mod prelude { diff --git a/src/testing.rs b/src/testing.rs index 885e02e02..fb3ac64c2 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -50,18 +50,18 @@ impl ScenarioSingleClient { let chunk_layer = ChunkLayer::new( ident!("overworld"), - app.world.resource::(), - app.world.resource::(), - app.world.resource::(), + app.world().resource::(), + app.world().resource::(), + app.world().resource::(), ); - let entity_layer = EntityLayer::new(app.world.resource::()); - let layer = app.world.spawn((chunk_layer, entity_layer)).id(); + let entity_layer = EntityLayer::new(app.world().resource::()); + let layer = app.world_mut().spawn((chunk_layer, entity_layer)).id(); let (mut client, helper) = create_mock_client("test"); client.player.layer.0 = layer; client.visible_chunk_layer.0 = layer; client.visible_entity_layers.0.insert(layer); - let client = app.world.spawn(client).id(); + let client = app.world_mut().spawn(client).id(); ScenarioSingleClient { app, diff --git a/src/tests/boss_bar.rs b/src/tests/boss_bar.rs index 0d525368d..bbb1fd149 100644 --- a/src/tests/boss_bar.rs +++ b/src/tests/boss_bar.rs @@ -18,7 +18,7 @@ fn test_initialize_on_join() { // Insert a boss bar into the world scenario .app - .world + .world_mut() .entity_mut(scenario.layer) .insert(BossBarBundle { title: BossBarTitle("Boss Bar".into_text()), @@ -44,7 +44,7 @@ fn test_despawn() { } = prepare(); // Despawn the boss bar - app.world.entity_mut(layer).insert(Despawned); + app.world_mut().entity_mut(layer).insert(Despawned); app.update(); @@ -63,7 +63,7 @@ fn test_title_update() { } = prepare(); // Update the title - app.world + app.world_mut() .entity_mut(layer) .insert(BossBarTitle(Text::text("Test 2"))); @@ -84,7 +84,7 @@ fn test_health_update() { } = prepare(); // Update the health - app.world.entity_mut(layer).insert(BossBarHealth(0.5)); + app.world_mut().entity_mut(layer).insert(BossBarHealth(0.5)); app.update(); @@ -103,7 +103,7 @@ fn test_style_update() { } = prepare(); // Update the style - app.world.entity_mut(layer).insert(BossBarStyle { + app.world_mut().entity_mut(layer).insert(BossBarStyle { color: BossBarColor::Red, division: BossBarDivision::TenNotches, }); @@ -127,7 +127,7 @@ fn test_flags_update() { // Update the flags let mut new_flags = BossBarFlags::new(); new_flags.set_create_fog(true); - app.world.entity_mut(layer).insert(new_flags); + app.world_mut().entity_mut(layer).insert(new_flags); app.update(); @@ -147,7 +147,10 @@ fn test_client_layer_change() { // Remove the layer from the client { - let mut visible_entity_layers = app.world.get_mut::(client).unwrap(); + let mut visible_entity_layers = app + .world_mut() + .get_mut::(client) + .unwrap(); visible_entity_layers.0.clear() }; @@ -159,7 +162,10 @@ fn test_client_layer_change() { // Add the layer back to the client { - let mut visible_entity_layers = app.world.get_mut::(client).unwrap(); + let mut visible_entity_layers = app + .world_mut() + .get_mut::(client) + .unwrap(); visible_entity_layers.0.insert(layer) }; @@ -180,7 +186,7 @@ fn prepare() -> ScenarioSingleClient { // Insert a boss bar into the world // Attach the new boss bar to the layer for convenience. - s.app.world.entity_mut(s.layer).insert(BossBarBundle { + s.app.world_mut().entity_mut(s.layer).insert(BossBarBundle { title: BossBarTitle("Boss Bar".into_text()), health: BossBarHealth(0.5), layer: EntityLayerId(s.layer), diff --git a/src/tests/client.rs b/src/tests/client.rs index a9abce3f4..c660d7ef3 100644 --- a/src/tests/client.rs +++ b/src/tests/client.rs @@ -17,7 +17,7 @@ fn client_teleport_and_move() { .. } = ScenarioSingleClient::new(); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); for z in -10..10 { for x in -10..10 { @@ -31,7 +31,7 @@ fn client_teleport_and_move() { bundle.visible_chunk_layer.0 = layer_ent; bundle.visible_entity_layers.0.insert(layer_ent); - app.world.spawn(bundle); + app.world_mut().spawn(bundle); app.update(); @@ -67,7 +67,7 @@ fn client_gamemode_changed_ability() { *scenario .app - .world + .world_mut() .get_mut::(scenario.client) .unwrap() = GameMode::Creative; @@ -75,7 +75,7 @@ fn client_gamemode_changed_ability() { let abilities = scenario .app - .world + .world_mut() .get::(scenario.client) .unwrap(); @@ -85,7 +85,7 @@ fn client_gamemode_changed_ability() { *scenario .app - .world + .world_mut() .get_mut::(scenario.client) .unwrap() = GameMode::Adventure; @@ -93,7 +93,7 @@ fn client_gamemode_changed_ability() { let abilities = scenario .app - .world + .world_mut() .get::(scenario.client) .unwrap(); diff --git a/src/tests/example.rs b/src/tests/example.rs index 624c72389..7560cf56f 100644 --- a/src/tests/example.rs +++ b/src/tests/example.rs @@ -22,11 +22,11 @@ fn example_test_server_tick_increment() { app.add_plugins(DefaultPlugins); - let tick = app.world.resource::().current_tick(); + let tick = app.world_mut().resource::().current_tick(); app.update(); - let server = app.world.resource::(); + let server = app.world_mut().resource::(); assert_eq!(server.current_tick(), tick + 1); } @@ -52,7 +52,7 @@ fn example_test_client_position() { app.update(); // Make assertions - let pos = app.world.get::(client).unwrap(); + let pos = app.world_mut().get::(client).unwrap(); assert_eq!(pos.0, DVec3::new(12.0, 64.0, 0.0)); } @@ -67,7 +67,7 @@ fn example_test_open_inventory() { } = ScenarioSingleClient::new(); let inventory = Inventory::new(InventoryKind::Generic3x3); - let inventory_ent = app.world.spawn(inventory).id(); + let inventory_ent = app.world_mut().spawn(inventory).id(); // Process a tick to get past the "on join" logic. app.update(); @@ -75,7 +75,7 @@ fn example_test_open_inventory() { // Open the inventory. let open_inventory = OpenInventory::new(inventory_ent); - app.world + app.world_mut() .get_entity_mut(client) .expect("could not find client") .insert(open_inventory); @@ -84,7 +84,9 @@ fn example_test_open_inventory() { app.update(); // Make assertions - app.world.get::(client).expect("client not found"); + app.world_mut() + .get::(client) + .expect("client not found"); let sent_packets = helper.collect_received(); diff --git a/src/tests/hunger.rs b/src/tests/hunger.rs index ea998b9e8..1cbe03a72 100644 --- a/src/tests/hunger.rs +++ b/src/tests/hunger.rs @@ -17,11 +17,11 @@ fn test_hunger() { app.update(); helper.clear_received(); - let og_saturation = app.world.get::(client).unwrap().0; - let og_health = app.world.get::(client).unwrap().0; + let og_saturation = app.world_mut().get::(client).unwrap().0; + let og_health = app.world_mut().get::(client).unwrap().0; // set food level to 5 - app.world.get_mut::(client).unwrap().0 = 5; + app.world_mut().get_mut::(client).unwrap().0 = 5; app.update(); diff --git a/src/tests/inventory.rs b/src/tests/inventory.rs index 65b7873f2..d1d6d900f 100644 --- a/src/tests/inventory.rs +++ b/src/tests/inventory.rs @@ -23,7 +23,7 @@ fn test_should_open_inventory() { } = ScenarioSingleClient::new(); let inventory = Inventory::new(InventoryKind::Generic3x3); - let inventory_ent = app.world.spawn(inventory).id(); + let inventory_ent = app.world_mut().spawn(inventory).id(); // Process a tick to get past the "on join" logic. app.update(); @@ -31,7 +31,7 @@ fn test_should_open_inventory() { // Open the inventory. let open_inventory = OpenInventory::new(inventory_ent); - app.world + app.world_mut() .get_entity_mut(client) .expect("could not find client") .insert(open_inventory); @@ -56,7 +56,7 @@ fn test_should_close_inventory() { } = ScenarioSingleClient::new(); let inventory = Inventory::new(InventoryKind::Generic3x3); - let inventory_ent = app.world.spawn(inventory).id(); + let inventory_ent = app.world_mut().spawn(inventory).id(); // Process a tick to get past the "on join" logic. app.update(); @@ -64,7 +64,7 @@ fn test_should_close_inventory() { // Open the inventory. let open_inventory = OpenInventory::new(inventory_ent); - app.world + app.world_mut() .get_entity_mut(client) .expect("could not find client") .insert(open_inventory); @@ -73,7 +73,7 @@ fn test_should_close_inventory() { helper.clear_received(); // Close the inventory. - app.world + app.world_mut() .get_entity_mut(client) .expect("could not find client") .remove::(); @@ -96,7 +96,7 @@ fn test_should_remove_invalid_open_inventory() { } = ScenarioSingleClient::new(); let inventory = Inventory::new(InventoryKind::Generic3x3); - let inventory_ent = app.world.spawn(inventory).id(); + let inventory_ent = app.world_mut().spawn(inventory).id(); // Process a tick to get past the "on join" logic. app.update(); @@ -104,7 +104,7 @@ fn test_should_remove_invalid_open_inventory() { // Open the inventory. let open_inventory = OpenInventory::new(inventory_ent); - app.world + app.world_mut() .get_entity_mut(client) .expect("could not find client") .insert(open_inventory); @@ -113,12 +113,12 @@ fn test_should_remove_invalid_open_inventory() { helper.clear_received(); // Remove the inventory. - app.world.despawn(inventory_ent); + app.world_mut().despawn(inventory_ent); app.update(); // Make assertions - assert!(app.world.get::(client).is_none()); + assert!(app.world_mut().get::(client).is_none()); let sent_packets = helper.collect_received(); sent_packets.assert_count::(1); @@ -138,14 +138,14 @@ fn test_should_modify_player_inventory_click_slot() { helper.clear_received(); let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory for client"); inventory.set_slot(20, ItemStack::new(ItemKind::Diamond, 2, None)); // Make the client click the slot and pick up the item. let state_id = app - .world + .world_mut() .get::(client) .unwrap() .state_id(); @@ -176,14 +176,14 @@ fn test_should_modify_player_inventory_click_slot() { sent_packets.assert_count::(0); let inventory = app - .world + .world_mut() .get::(client) .expect("could not find inventory for client"); assert_eq!(inventory.slot(20), &ItemStack::EMPTY); let cursor_item = app - .world + .world_mut() .get::(client) .expect("could not find client"); @@ -203,7 +203,7 @@ fn test_should_modify_player_inventory_server_side() { app.update(); let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory for client"); inventory.set_slot(20, ItemStack::new(ItemKind::Diamond, 2, None)); @@ -213,7 +213,7 @@ fn test_should_modify_player_inventory_server_side() { // Modify the inventory. let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory for client"); inventory.set_slot(21, ItemStack::new(ItemKind::IronIngot, 1, None)); @@ -241,7 +241,7 @@ fn test_should_sync_entire_player_inventory() { helper.clear_received(); let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory for client"); inventory.changed = u64::MAX; @@ -255,11 +255,11 @@ fn test_should_sync_entire_player_inventory() { fn set_up_open_inventory(app: &mut App, client_ent: Entity) -> Entity { let inventory = Inventory::new(InventoryKind::Generic9x3); - let inventory_ent = app.world.spawn(inventory).id(); + let inventory_ent = app.world_mut().spawn(inventory).id(); // Open the inventory. let open_inventory = OpenInventory::new(inventory_ent); - app.world + app.world_mut() .get_entity_mut(client_ent) .expect("could not find client") .insert(open_inventory); @@ -279,7 +279,7 @@ fn test_should_modify_open_inventory_click_slot() { let inventory_ent = set_up_open_inventory(&mut app, client); let mut inventory = app - .world + .world_mut() .get_mut::(inventory_ent) .expect("could not find inventory for client"); @@ -290,7 +290,7 @@ fn test_should_modify_open_inventory_click_slot() { helper.clear_received(); // Make the client click the slot and pick up the item. - let inv_state = app.world.get::(client).unwrap(); + let inv_state = app.world_mut().get::(client).unwrap(); let state_id = inv_state.state_id(); let window_id = inv_state.window_id(); helper.send(&ClickSlotC2s { @@ -319,12 +319,12 @@ fn test_should_modify_open_inventory_click_slot() { sent_packets.assert_count::(0); let inventory = app - .world + .world_mut() .get::(inventory_ent) .expect("could not find inventory"); assert_eq!(inventory.slot(20), &ItemStack::EMPTY); let cursor_item = app - .world + .world_mut() .get::(client) .expect("could not find client"); assert_eq!(cursor_item.0, ItemStack::new(ItemKind::Diamond, 2, None)); @@ -347,7 +347,7 @@ fn test_should_modify_open_inventory_server_side() { // Modify the inventory. let mut inventory = app - .world + .world_mut() .get_mut::(inventory_ent) .expect("could not find inventory for client"); inventory.set_slot(5, ItemStack::new(ItemKind::IronIngot, 1, None)); @@ -362,7 +362,7 @@ fn test_should_modify_open_inventory_server_side() { sent_packets.assert_count::(1); let inventory = app - .world + .world_mut() .get::(inventory_ent) .expect("could not find inventory for client"); @@ -388,7 +388,7 @@ fn test_should_sync_entire_open_inventory() { helper.clear_received(); let mut inventory = app - .world + .world_mut() .get_mut::(inventory_ent) .expect("could not find inventory"); inventory.changed = u64::MAX; @@ -410,7 +410,7 @@ fn test_set_creative_mode_slot_handling() { } = ScenarioSingleClient::new(); let mut game_mode = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); *game_mode.as_mut() = GameMode::Creative; @@ -428,7 +428,7 @@ fn test_set_creative_mode_slot_handling() { // Make assertions let inventory = app - .world + .world_mut() .get::(client) .expect("could not find inventory for client"); @@ -448,7 +448,7 @@ fn test_ignore_set_creative_mode_slot_if_not_creative() { } = ScenarioSingleClient::new(); let mut game_mode = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); *game_mode.as_mut() = GameMode::Survival; @@ -466,7 +466,7 @@ fn test_ignore_set_creative_mode_slot_if_not_creative() { // Make assertions let inventory = app - .world + .world_mut() .get::(client) .expect("could not find inventory for client"); assert_eq!(inventory.slot(36), &ItemStack::EMPTY); @@ -482,7 +482,7 @@ fn test_window_id_increments() { } = ScenarioSingleClient::new(); let inventory = Inventory::new(InventoryKind::Generic9x3); - let inventory_ent = app.world.spawn(inventory).id(); + let inventory_ent = app.world_mut().spawn(inventory).id(); // Process a tick to get past the "on join" logic. app.update(); @@ -490,14 +490,14 @@ fn test_window_id_increments() { for _ in 0..3 { let open_inventory = OpenInventory::new(inventory_ent); - app.world + app.world_mut() .get_entity_mut(client) .expect("could not find client") .insert(open_inventory); app.update(); - app.world + app.world_mut() .get_entity_mut(client) .expect("could not find client") .remove::(); @@ -507,7 +507,7 @@ fn test_window_id_increments() { // Make assertions let inv_state = app - .world + .world_mut() .get::(client) .expect("could not find client"); assert_eq!(inv_state.window_id(), 3); @@ -532,7 +532,7 @@ fn test_should_handle_set_held_item() { // Make assertions let held = app - .world + .world_mut() .get::(client) .expect("could not find client"); @@ -553,19 +553,19 @@ fn should_not_increment_state_id_on_cursor_item_change() { helper.clear_received(); let inv_state = app - .world + .world_mut() .get::(client) .expect("could not find client"); let expected_state_id = inv_state.state_id().0; - let mut cursor_item = app.world.get_mut::(client).unwrap(); + let mut cursor_item = app.world_mut().get_mut::(client).unwrap(); cursor_item.0 = ItemStack::new(ItemKind::Diamond, 2, None); app.update(); // Make assertions let inv_state = app - .world + .world_mut() .get::(client) .expect("could not find client"); assert_eq!( @@ -595,7 +595,7 @@ mod dropping_items { helper.clear_received(); let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory"); inventory.set_slot(36, ItemStack::new(ItemKind::IronIngot, 3, None)); @@ -611,7 +611,7 @@ mod dropping_items { // Make assertions let inventory = app - .world + .world_mut() .get::(client) .expect("could not find client"); @@ -621,7 +621,7 @@ mod dropping_items { ); let events = app - .world + .world_mut() .get_resource::>() .expect("expected drop item stack events"); @@ -654,7 +654,7 @@ mod dropping_items { helper.clear_received(); let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory"); inventory.set_slot(36, ItemStack::new(ItemKind::IronIngot, 32, None)); @@ -670,17 +670,17 @@ mod dropping_items { // Make assertions let held = app - .world + .world_mut() .get::(client) .expect("could not find client"); assert_eq!(held.slot(), 36); let inventory = app - .world + .world_mut() .get::(client) .expect("could not find inventory"); assert_eq!(inventory.slot(36), &ItemStack::EMPTY); let events = app - .world + .world_mut() .get_resource::>() .expect("expected drop item stack events"); let events = events.iter_current_update_events().collect::>(); @@ -706,7 +706,9 @@ mod dropping_items { app.update(); helper.clear_received(); - app.world.entity_mut(client).insert(GameMode::Creative); + app.world_mut() + .entity_mut(client) + .insert(GameMode::Creative); helper.send(&CreativeInventoryActionC2s { slot: -1, @@ -717,7 +719,7 @@ mod dropping_items { // Make assertions let events = app - .world + .world_mut() .get_resource::>() .expect("expected drop item stack events") .iter_current_update_events() @@ -746,12 +748,12 @@ mod dropping_items { helper.clear_received(); let mut cursor_item = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); cursor_item.0 = ItemStack::new(ItemKind::IronIngot, 32, None); let inv_state = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); let state_id = inv_state.state_id().0; @@ -770,14 +772,14 @@ mod dropping_items { // Make assertions let cursor_item = app - .world + .world_mut() .get::(client) .expect("could not find client"); assert_eq!(cursor_item.0, ItemStack::EMPTY); let events = app - .world + .world_mut() .get_resource::>() .expect("expected drop item stack events"); @@ -806,14 +808,14 @@ mod dropping_items { helper.clear_received(); let inv_state = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); let state_id = inv_state.state_id().0; let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory"); @@ -837,7 +839,7 @@ mod dropping_items { // Make assertions let events = app - .world + .world_mut() .get_resource::>() .expect("expected drop item stack events"); @@ -866,14 +868,14 @@ mod dropping_items { helper.clear_received(); let inv_state = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); let state_id = inv_state.state_id().0; let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory"); @@ -897,7 +899,7 @@ mod dropping_items { // Make assertions let events = app - .world + .world_mut() .get_resource::>() .expect("expected drop item stack events"); @@ -927,7 +929,7 @@ mod dropping_items { app.update(); let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory"); @@ -943,7 +945,7 @@ mod dropping_items { helper.clear_received(); let inv_state = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); @@ -968,12 +970,12 @@ mod dropping_items { // Make assertions let events = app - .world + .world() .get_resource::>() .expect("expected drop item stack events"); let player_inventory = app - .world + .world() .get::(client) .expect("could not find inventory"); @@ -1015,7 +1017,7 @@ fn should_drop_item_stack_player_open_inventory_with_dropkey() { app.update(); let mut inventory = app - .world + .world_mut() .get_mut::(client) .expect("could not find inventory"); @@ -1030,7 +1032,7 @@ fn should_drop_item_stack_player_open_inventory_with_dropkey() { helper.clear_received(); let inv_state = app - .world + .world_mut() .get_mut::(client) .expect("could not find client"); @@ -1055,12 +1057,12 @@ fn should_drop_item_stack_player_open_inventory_with_dropkey() { // Make assertions let events = app - .world + .world() .get_resource::>() .expect("expected drop item stack events"); let player_inventory = app - .world + .world() .get::(client) .expect("could not find inventory"); @@ -1098,10 +1100,10 @@ fn dragging_items() { app.update(); helper.clear_received(); - app.world.get_mut::(client).unwrap().0 = + app.world_mut().get_mut::(client).unwrap().0 = ItemStack::new(ItemKind::Diamond, 64, None); - let inv_state = app.world.get::(client).unwrap(); + let inv_state = app.world_mut().get::(client).unwrap(); let window_id = inv_state.window_id(); let state_id = inv_state.state_id().0; @@ -1135,14 +1137,14 @@ fn dragging_items() { assert_eq!(sent_packets.0.len(), 0); let cursor_item = app - .world + .world_mut() .get::(client) .expect("could not find client"); assert_eq!(cursor_item.0, ItemStack::new(ItemKind::Diamond, 1, None)); let inventory = app - .world + .world_mut() .get::(client) .expect("could not find inventory"); diff --git a/src/tests/layer.rs b/src/tests/layer.rs index 982a86a58..8d1b6f056 100644 --- a/src/tests/layer.rs +++ b/src/tests/layer.rs @@ -24,7 +24,7 @@ fn block_create_destroy() { .. } = ScenarioSingleClient::new(); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); // Insert an empty chunk at (0, 0). layer.insert_chunk([0, 0], UnloadedChunk::new()); @@ -32,7 +32,7 @@ fn block_create_destroy() { // Wait until the next tick to start sending changes. app.update(); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); // Set some blocks. layer.set_block([1, 1, 1], BlockState::CHEST); @@ -48,7 +48,7 @@ fn block_create_destroy() { recvd.assert_count::(3) }; - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); layer.set_block([1, 1, 1], BlockState::AIR); layer.set_block([1, 2, 1], BlockState::AIR); @@ -80,7 +80,7 @@ fn layer_chunk_view_change() { layer: layer_ent, } = ScenarioSingleClient::new(); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); for z in -30..30 { for x in -30..30 { @@ -88,14 +88,14 @@ fn layer_chunk_view_change() { } } - let mut client = app.world.entity_mut(client_ent); + let mut client = app.world_mut().entity_mut(client_ent); client.get_mut::().unwrap().set([8.0, 0.0, 8.0]); client.get_mut::().unwrap().set(6); // Tick app.update(); - let mut client = app.world.entity_mut(client_ent); + let mut client = app.world_mut().entity_mut(client_ent); let mut loaded_chunks = BTreeSet::new(); @@ -120,7 +120,7 @@ fn layer_chunk_view_change() { // Tick app.update(); - let client = app.world.entity_mut(client_ent); + let client = app.world_mut().entity_mut(client_ent); // For all chunks received this tick... for f in helper.collect_received().0 { @@ -154,12 +154,12 @@ fn chunk_viewer_count() { layer: layer_ent, } = ScenarioSingleClient::new(); - let mut client = app.world.entity_mut(client_ent); + let mut client = app.world_mut().entity_mut(client_ent); client.get_mut::().unwrap().set([8.0, 64.0, 8.0]); client.get_mut::().unwrap().set(2); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); // Create chunk at (0, 0). layer.insert_chunk([0, 0], UnloadedChunk::new()); @@ -168,7 +168,7 @@ fn chunk_viewer_count() { helper.collect_received().assert_count::(1); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); assert_eq!(layer.chunk_mut([0, 0]).unwrap().viewer_count(), 1); @@ -176,7 +176,7 @@ fn chunk_viewer_count() { // the same tick. layer.insert_chunk([0, 1], UnloadedChunk::new()); - let mut client = app.world.entity_mut(client_ent); + let mut client = app.world_mut().entity_mut(client_ent); client.get_mut::().unwrap().set([100.0, 0.0, 0.0]); app.update(); // Tick. @@ -188,7 +188,7 @@ fn chunk_viewer_count() { recvd.assert_count::(2) }; - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); // Viewer count of both chunks should be zero. assert_eq!(layer.chunk([0, 0]).unwrap().viewer_count(), 0); @@ -198,12 +198,12 @@ fn chunk_viewer_count() { layer.insert_chunk([1, 0], UnloadedChunk::new()); // Move the client back in view of all three chunks. - let mut client = app.world.entity_mut(client_ent); + let mut client = app.world_mut().entity_mut(client_ent); client.get_mut::().unwrap().set([8.0, 0.0, 8.0]); app.update(); // Tick. - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); // All three chunks should have viewer count of one. assert_eq!(layer.chunk_mut([0, 0]).unwrap().viewer_count(), 1); @@ -223,13 +223,13 @@ fn entity_layer_switching() { layer: l1, } = ScenarioSingleClient::new(); - let server = app.world.resource::(); + let server = app.world_mut().resource::(); let l2 = EntityLayer::new(server); let l3 = EntityLayer::new(server); - let l2 = app.world.spawn(l2).id(); - let _l3 = app.world.spawn(l3).id(); + let l2 = app.world_mut().spawn(l2).id(); + let _l3 = app.world_mut().spawn(l3).id(); // Spawn three entities and put them all on the main layer to start. @@ -248,9 +248,9 @@ fn entity_layer_switching() { ..Default::default() }; - let e1 = app.world.spawn(e1).id(); - let _e2 = app.world.spawn(e2).id(); - let _e3 = app.world.spawn(e3).id(); + let e1 = app.world_mut().spawn(e1).id(); + let _e2 = app.world_mut().spawn(e2).id(); + let _e3 = app.world_mut().spawn(e3).id(); app.update(); // Tick. @@ -258,8 +258,8 @@ fn entity_layer_switching() { helper.collect_received().assert_count::(3); // Move e1 to l2 and add l2 to the visible layers set. - app.world.get_mut::(e1).unwrap().0 = l2; - app.world + app.world_mut().get_mut::(e1).unwrap().0 = l2; + app.world_mut() .get_mut::(client_ent) .unwrap() .0 @@ -279,7 +279,7 @@ fn entity_layer_switching() { // Remove the original layer from the visible layer set. assert!(app - .world + .world_mut() .get_mut::(client_ent) .unwrap() .0 @@ -294,7 +294,7 @@ fn entity_layer_switching() { }; // Despawn l2. - app.world.entity_mut(l2).insert(Despawned); + app.world_mut().entity_mut(l2).insert(Despawned); app.update(); // Tick. @@ -304,7 +304,7 @@ fn entity_layer_switching() { .assert_count::(1); let mut visible_entity_layers = app - .world + .world_mut() .get_mut::(client_ent) .unwrap(); @@ -334,14 +334,14 @@ fn chunk_entity_spawn_despawn() { layer: layer_ent, } = ScenarioSingleClient::new(); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); // Insert an empty chunk at (0, 0). layer.insert_chunk([0, 0], UnloadedChunk::new()); // Put an entity in the new chunk. let cow_ent = app - .world + .world_mut() .spawn(CowEntityBundle { position: Position::new([8.0, 0.0, 8.0]), layer: EntityLayerId(layer_ent), @@ -363,7 +363,7 @@ fn chunk_entity_spawn_despawn() { }; // Move the entity. Client should receive entity move packet. - app.world.get_mut::(cow_ent).unwrap().0.x += 0.1; + app.world_mut().get_mut::(cow_ent).unwrap().0.x += 0.1; app.update(); @@ -371,7 +371,7 @@ fn chunk_entity_spawn_despawn() { // Despawning the chunk should delete the chunk and not the entity contained // within. - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); layer.remove_chunk([0, 0]).unwrap(); @@ -388,7 +388,7 @@ fn chunk_entity_spawn_despawn() { // Placing the chunk back should respawn the chunk and not the entity. - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); assert!(layer.insert_chunk([0, 0], UnloadedChunk::new()).is_none()); @@ -405,8 +405,8 @@ fn chunk_entity_spawn_despawn() { // Move player and entity away from the chunk on the same tick. - app.world.get_mut::(client_ent).unwrap().0.x = 1000.0; - app.world.get_mut::(cow_ent).unwrap().0.x = -1000.0; + app.world_mut().get_mut::(client_ent).unwrap().0.x = 1000.0; + app.world_mut().get_mut::(cow_ent).unwrap().0.x = -1000.0; app.update(); @@ -421,11 +421,11 @@ fn chunk_entity_spawn_despawn() { // Put the client and entity back on the same tick. - app.world + app.world_mut() .get_mut::(client_ent) .unwrap() .set([8.0, 0.0, 8.0]); - app.world + app.world_mut() .get_mut::(cow_ent) .unwrap() .set([8.0, 0.0, 8.0]); @@ -444,12 +444,12 @@ fn chunk_entity_spawn_despawn() { // Adding and removing a chunk on the same tick should have no effect on // the client. - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); layer.insert_chunk([0, 1], UnloadedChunk::new()); layer.remove_chunk([0, 1]).unwrap(); - app.world + app.world_mut() .get_mut::(cow_ent) .unwrap() .set([24.0, 0.0, 24.0]); diff --git a/src/tests/player_list.rs b/src/tests/player_list.rs index 1218923eb..4df72f9d1 100644 --- a/src/tests/player_list.rs +++ b/src/tests/player_list.rs @@ -12,7 +12,7 @@ fn player_list_arrives_before_player_spawn() { .. } = ScenarioSingleClient::new(); - let mut layer = app.world.get_mut::(layer_ent).unwrap(); + let mut layer = app.world_mut().get_mut::(layer_ent).unwrap(); for z in -5..5 { for x in -5..5 { @@ -38,7 +38,7 @@ fn player_list_arrives_before_player_spawn() { client_2.visible_chunk_layer.0 = layer_ent; client_2.visible_entity_layers.0.insert(layer_ent); - app.world.spawn(client_2); + app.world_mut().spawn(client_2); app.update(); diff --git a/src/tests/potions.rs b/src/tests/potions.rs index 29a8a3717..29e9b0702 100644 --- a/src/tests/potions.rs +++ b/src/tests/potions.rs @@ -20,7 +20,7 @@ fn test_status_effects_packets() { // Add a potion effect to the client. let mut effects = app - .world + .world_mut() .get_mut::(client) .expect("Client should have status effects"); effects.apply( @@ -54,7 +54,7 @@ fn test_status_effects_packets() { // Make assertions let effects = app - .world + .world() .get::(client) .expect("Client should have status effects"); diff --git a/src/tests/scoreboard.rs b/src/tests/scoreboard.rs index 89ab5ad59..a91abf552 100644 --- a/src/tests/scoreboard.rs +++ b/src/tests/scoreboard.rs @@ -20,9 +20,10 @@ fn show_scoreboard_when_added_to_layer() { } = ScenarioSingleClient::new(); // Add a new entity layer for the objective. - let server = app.world.get_resource::().unwrap(); - let obj_layer = app.world.spawn(EntityLayer::new(server)).id(); - app.world + let server = app.world().get_resource::().unwrap().clone(); + let obj_layer = app.world_mut().spawn(EntityLayer::new(&server)).id(); + + app.world_mut() .entity_mut(client) .get_mut::() .unwrap() @@ -34,7 +35,7 @@ fn show_scoreboard_when_added_to_layer() { helper.clear_received(); // Spawn the objective. - app.world.spawn(ObjectiveBundle { + app.world_mut().spawn(ObjectiveBundle { name: Objective::new("foo"), display: ObjectiveDisplay("Foo".into_text()), scores: ObjectiveScores::new(), @@ -64,9 +65,9 @@ fn show_scoreboard_when_client_join() { } = ScenarioSingleClient::new(); // Add a new entity layer for the objective. - let server = app.world.get_resource::().unwrap(); - let obj_layer = app.world.spawn(EntityLayer::new(server)).id(); - app.world + let server = app.world().get_resource::().unwrap().clone(); + let obj_layer = app.world_mut().spawn(EntityLayer::new(&server)).id(); + app.world_mut() .entity_mut(client) .get_mut::() .unwrap() @@ -74,7 +75,7 @@ fn show_scoreboard_when_client_join() { .insert(obj_layer); // Spawn the objective. - app.world.spawn(ObjectiveBundle { + app.world_mut().spawn(ObjectiveBundle { name: Objective::new("foo"), display: ObjectiveDisplay("Foo".into_text()), scores: ObjectiveScores::new(), @@ -105,9 +106,9 @@ fn should_update_score() { } = ScenarioSingleClient::new(); // Add a new entity layer for the objective. - let server = app.world.get_resource::().unwrap(); - let obj_layer = app.world.spawn(EntityLayer::new(server)).id(); - app.world + let server = app.world_mut().get_resource::().unwrap().clone(); + let obj_layer = app.world_mut().spawn(EntityLayer::new(&server)).id(); + app.world_mut() .entity_mut(client) .get_mut::() .unwrap() @@ -116,7 +117,7 @@ fn should_update_score() { // Spawn the objective. let obj = app - .world + .world_mut() .spawn(ObjectiveBundle { name: Objective::new("foo"), display: ObjectiveDisplay("Foo".into_text()), @@ -130,7 +131,7 @@ fn should_update_score() { app.update(); helper.clear_received(); - let mut scores = app.world.get_mut::(obj).unwrap(); + let mut scores = app.world_mut().get_mut::(obj).unwrap(); scores.insert("foo", 3); app.update(); @@ -153,9 +154,9 @@ fn should_only_update_score_diff() { } = ScenarioSingleClient::new(); // Add a new entity layer for the objective. - let server = app.world.get_resource::().unwrap(); - let obj_layer = app.world.spawn(EntityLayer::new(server)).id(); - app.world + let server = app.world().get_resource::().unwrap().clone(); + let obj_layer = app.world_mut().spawn(EntityLayer::new(&server)).id(); + app.world_mut() .entity_mut(client) .get_mut::() .unwrap() @@ -164,7 +165,7 @@ fn should_only_update_score_diff() { // Spawn the objective. let obj = app - .world + .world_mut() .spawn(ObjectiveBundle { name: Objective::new("foo"), display: ObjectiveDisplay("Foo".into_text()), @@ -178,7 +179,7 @@ fn should_only_update_score_diff() { app.update(); helper.clear_received(); - let mut scores = app.world.get_mut::(obj).unwrap(); + let mut scores = app.world_mut().get_mut::(obj).unwrap(); scores.insert("foo", 3); app.update(); diff --git a/src/tests/weather.rs b/src/tests/weather.rs index 81634dde1..f39eb34fe 100644 --- a/src/tests/weather.rs +++ b/src/tests/weather.rs @@ -48,7 +48,7 @@ fn test_client_rain_change() { helper.clear_received(); // Change the rain value - let mut rain = app.world.get_mut::(client).unwrap(); + let mut rain = app.world_mut().get_mut::(client).unwrap(); rain.0 = 1.0; app.update(); @@ -72,7 +72,7 @@ fn test_client_thunder_change() { helper.clear_received(); // Change the thunder value - let mut thunder = app.world.get_mut::(client).unwrap(); + let mut thunder = app.world_mut().get_mut::(client).unwrap(); thunder.0 = 1.0; app.update(); @@ -96,7 +96,7 @@ fn test_chunk_layer_rain_change() { helper.clear_received(); // Change the rain value - let mut rain = app.world.get_mut::(layer).unwrap(); + let mut rain = app.world_mut().get_mut::(layer).unwrap(); rain.0 = 1.0; app.update(); @@ -120,7 +120,7 @@ fn test_chunk_layer_thunder_change() { helper.clear_received(); // Change the thunder value - let mut thunder = app.world.get_mut::(layer).unwrap(); + let mut thunder = app.world_mut().get_mut::(layer).unwrap(); thunder.0 = 1.0; app.update(); @@ -148,14 +148,17 @@ fn prepare(client_weather: bool) -> ScenarioSingleClient { } fn add_weather_to_client(s: &mut ScenarioSingleClient) { - s.app.world.entity_mut(s.client).insert(WeatherBundle { - rain: Rain(0.5), - thunder: Thunder(0.5), - }); + s.app + .world_mut() + .entity_mut(s.client) + .insert(WeatherBundle { + rain: Rain(0.5), + thunder: Thunder(0.5), + }); } fn add_weather_to_chunk_layer(s: &mut ScenarioSingleClient) { - s.app.world.entity_mut(s.layer).insert(WeatherBundle { + s.app.world_mut().entity_mut(s.layer).insert(WeatherBundle { rain: Rain(0.5), thunder: Thunder(0.5), }); diff --git a/src/tests/world_border.rs b/src/tests/world_border.rs index 05658b4e8..5cd2da183 100644 --- a/src/tests/world_border.rs +++ b/src/tests/world_border.rs @@ -38,7 +38,7 @@ fn test_center_change() { helper.clear_received(); // Change the center - let mut center = app.world.get_mut::(layer).unwrap(); + let mut center = app.world_mut().get_mut::(layer).unwrap(); center.x = 10.0; app.update(); @@ -62,7 +62,7 @@ fn test_diameter_change() { helper.clear_received(); // Change the diameter - let mut lerp = app.world.get_mut::(layer).unwrap(); + let mut lerp = app.world_mut().get_mut::(layer).unwrap(); lerp.target_diameter = 20.0; app.update(); @@ -86,7 +86,7 @@ fn test_interpolation() { helper.clear_received(); // Change the diameter and start interpolation to it over 20 ticks - let mut lerp = app.world.get_mut::(layer).unwrap(); + let mut lerp = app.world_mut().get_mut::(layer).unwrap(); lerp.target_diameter = 20.0; lerp.remaining_ticks = 20; @@ -100,7 +100,7 @@ fn test_interpolation() { frames.assert_count::(1); // Check if the interpolation is finished - let lerp = app.world.get_mut::(layer).unwrap(); + let lerp = app.world_mut().get_mut::(layer).unwrap(); assert_eq!(lerp.current_diameter, 20.0); assert_eq!(lerp.remaining_ticks, 0); } @@ -119,7 +119,10 @@ fn test_warning_blocks_change() { helper.clear_received(); // Change the warning blocks - let mut warn_blocks = app.world.get_mut::(layer).unwrap(); + let mut warn_blocks = app + .world_mut() + .get_mut::(layer) + .unwrap(); warn_blocks.0 = 10; app.update(); @@ -143,7 +146,10 @@ fn test_warning_time_change() { helper.clear_received(); // Change the warning time - let mut warn_time = app.world.get_mut::(layer).unwrap(); + let mut warn_time = app + .world_mut() + .get_mut::(layer) + .unwrap(); warn_time.0 = 10; app.update(); @@ -168,7 +174,7 @@ fn test_portal_tp_boundary_change() { // Change the portal tp boundary let mut portal_tp_boundary = app - .world + .world_mut() .get_mut::(layer) .unwrap(); portal_tp_boundary.0 = 10; @@ -187,13 +193,16 @@ fn prepare() -> ScenarioSingleClient { s.app.update(); // Attach the world border bundle to the chunk layer - s.app.world.entity_mut(s.layer).insert(WorldBorderBundle { - lerp: WorldBorderLerp { - target_diameter: 10.0, + s.app + .world_mut() + .entity_mut(s.layer) + .insert(WorldBorderBundle { + lerp: WorldBorderLerp { + target_diameter: 10.0, + ..Default::default() + }, ..Default::default() - }, - ..Default::default() - }); + }); s } diff --git a/tools/dump_schedule/src/main.rs b/tools/dump_schedule/src/main.rs index 25e0a9ef0..db28b9dd2 100644 --- a/tools/dump_schedule/src/main.rs +++ b/tools/dump_schedule/src/main.rs @@ -29,7 +29,7 @@ fn main() -> io::Result<()> { app.add_plugins(DefaultPlugins); - let schedules = app.world.resource::(); + let schedules = app.world().resource::(); let Some(sched_name) = cli.schedule else { print_available_schedules(schedules); @@ -47,7 +47,7 @@ fn main() -> io::Result<()> { let dot_graph = bevy_mod_debugdump::schedule_graph::schedule_graph_dot( schedule, - &app.world, + app.world(), &bevy_mod_debugdump::schedule_graph::Settings { ambiguity_enable: false, ..Default::default()