Skip to content

Commit

Permalink
update to bevy 0.14 (#634)
Browse files Browse the repository at this point in the history
update to bevy 0.14. works towards #620  task 3.
  • Loading branch information
JackCrumpLeys authored Jul 28, 2024
1 parent f0e26ed commit 80c570f
Show file tree
Hide file tree
Showing 33 changed files with 297 additions and 261 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 7 additions & 7 deletions benches/many_players.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<DimensionTypeRegistry>(),
app.world.resource::<BiomeRegistry>(),
app.world.resource::<Server>(),
app.world().resource::<DimensionTypeRegistry>(),
app.world().resource::<BiomeRegistry>(),
app.world().resource::<Server>(),
);

for z in -world_size..world_size {
Expand All @@ -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![];

Expand All @@ -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();

Expand All @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion crates/valence_advancement/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) fn handle_advancement_tab_change(
AdvancementTabC2s::ClosedScreen => None,
AdvancementTabC2s::OpenedTab { tab_id } => Some(tab_id.into()),
},
})
});
}
}
}
6 changes: 3 additions & 3 deletions crates/valence_entity/src/query.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl EntityInitQueryItem<'_> {
}
}

#[derive(WorldQuery)]
#[derive(QueryData)]
pub struct UpdateEntityQuery {
pub id: &'static EntityId,
pub pos: &'static Position,
Expand Down
2 changes: 1 addition & 1 deletion crates/valence_inventory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ fn handle_player_actions(
client: packet.client,
from_slot: Some(held.slot()),
stack,
})
});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/valence_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ impl Plugin for NetworkPlugin {

fn build_plugin(app: &mut App) -> anyhow::Result<()> {
let threshold = app
.world
.world()
.get_resource::<Server>()
.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);
Expand Down
42 changes: 24 additions & 18 deletions crates/valence_server/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
Expand Down
8 changes: 4 additions & 4 deletions crates/valence_server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
18 changes: 10 additions & 8 deletions crates/valence_server/src/client_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -117,21 +119,21 @@ fn handle_client_command(
sprinting_events.send(SprintEvent {
client: packet.client,
state: SprintState::Stop,
})
});
}
ClientCommand::StartJumpWithHorse => {
jump_with_horse_events.send(JumpWithHorseEvent {
client: packet.client,
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 => {
Expand Down
2 changes: 1 addition & 1 deletion crates/valence_server/src/custom_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn handle_custom_payload(
client: packet.client,
channel: pkt.channel.into(),
data: pkt.data.0 .0.into(),
})
});
}
}
}
2 changes: 1 addition & 1 deletion crates/valence_server/src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MainScheduleOrder>()
.insert_after(PreUpdate, RunEventLoop);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/valence_server/src/interact_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn handle_interact_entity(
entity,
sneaking: pkt.sneaking,
interact: pkt.interact,
})
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/valence_server/src/resource_pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn handle_resource_pack_status(
events.send(ResourcePackStatusEvent {
client: packet.client,
status: pkt,
})
});
}
}
}
8 changes: 4 additions & 4 deletions crates/valence_server/src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions crates/valence_server/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ fn handle_status(
for packet in packets.read() {
if let Some(pkt) = packet.decode::<ClientStatusC2s>() {
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,
});
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/valence_server/src/status_effect.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/valence_server_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples/combat.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 80c570f

Please sign in to comment.