Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Workspace #386

Merged
merged 4 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ where appropriate.
Unit tests help your contributions last! They ensure that your code works as expected and that it continues to work in
the future.

whole-server unit tests can be found in [`crates/valence/src/tests/`](crates/valence/src/tests).
whole-server unit tests can be found in [`/src/tests/`](/src/tests).

## Naming Quantities

Expand Down
85 changes: 76 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,80 @@
[package]
name = "valence"
version.workspace = true
edition.workspace = true
description = "A framework for building Minecraft servers in Rust."
documentation.workspace = true
repository.workspace = true
readme = "README.md"
license.workspace = true
keywords = ["minecraft", "gamedev", "server", "ecs"]
categories = ["game-engines"]

[features]
default = [
"network",
"player_list",
"inventory",
"anvil",
"advancement",
"world_border",
]
network = ["dep:valence_network"]
player_list = ["dep:valence_player_list"]
inventory = ["dep:valence_inventory"]
anvil = ["dep:valence_anvil"]
advancement = ["dep:valence_advancement"]
world_border = ["dep:valence_world_border"]

[dependencies]
bevy_app.workspace = true
bevy_ecs.workspace = true
glam.workspace = true
uuid.workspace = true
valence_nbt.workspace = true
valence_core.workspace = true
valence_registry.workspace = true
valence_block.workspace = true
valence_biome.workspace = true
valence_dimension.workspace = true
valence_entity.workspace = true
valence_instance.workspace = true
valence_client.workspace = true
valence_network = { workspace = true, optional = true }
valence_player_list = { workspace = true, optional = true }
valence_inventory = { workspace = true, optional = true }
valence_anvil = { workspace = true, optional = true }
valence_advancement = { workspace = true, optional = true }
valence_world_border = { workspace = true, optional = true }

[dev-dependencies]
anyhow.workspace = true
bytes.workspace = true
clap.workspace = true
criterion.workspace = true
flume.workspace = true
noise.workspace = true # For the terrain example.
rand.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true

[dev-dependencies.reqwest]
workspace = true
default-features = false
features = ["rustls-tls", "blocking", "stream"]

[[bench]]
name = "main"
harness = false

[profile.dev.package."*"]
opt-level = 3

[profile.dev]
opt-level = 1

[workspace]
members = ["crates/*", "tools/*"]
exclude = ["rust-mc-bot"]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -96,12 +170,5 @@ valence_network.path = "crates/valence_network"
valence_player_list.path = "crates/valence_player_list"
valence_registry.path = "crates/valence_registry"
valence_world_border.path = "crates/valence_world_border"
valence.path = "crates/valence"

valence.path = "."
zip = "0.6.3"

[profile.dev.package."*"]
opt-level = 3

[profile.dev]
opt-level = 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 0 additions & 66 deletions crates/valence/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions crates/valence/README.md

This file was deleted.

58 changes: 31 additions & 27 deletions crates/valence_client/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use valence_entity::{entity, Pose};
use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent};

pub(super) fn build(app: &mut App) {
app.add_event::<Sprinting>()
.add_event::<Sneaking>()
.add_event::<JumpWithHorse>()
.add_event::<LeaveBed>()
app.add_event::<SprintEvent>()
.add_event::<SneakEvent>()
.add_event::<JumpWithHorseEvent>()
.add_event::<LeaveBedEvent>()
.add_system(
handle_client_command
.in_schedule(EventLoopSchedule)
Expand All @@ -20,7 +20,7 @@ pub(super) fn build(app: &mut App) {
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Sprinting {
pub struct SprintEvent {
pub client: Entity,
pub state: SprintState,
}
Expand All @@ -32,7 +32,7 @@ pub enum SprintState {
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Sneaking {
pub struct SneakEvent {
pub client: Entity,
pub state: SneakState,
}
Expand All @@ -44,7 +44,7 @@ pub enum SneakState {
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct JumpWithHorse {
pub struct JumpWithHorseEvent {
pub client: Entity,
pub state: JumpWithHorseState,
}
Expand All @@ -59,17 +59,17 @@ pub enum JumpWithHorseState {
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct LeaveBed {
pub struct LeaveBedEvent {
pub client: Entity,
}

fn handle_client_command(
mut packets: EventReader<PacketEvent>,
mut clients: Query<(&mut entity::Pose, &mut Flags)>,
mut sprinting_events: EventWriter<Sprinting>,
mut sneaking_events: EventWriter<Sneaking>,
mut jump_with_horse_events: EventWriter<JumpWithHorse>,
mut leave_bed_events: EventWriter<LeaveBed>,
mut sprinting_events: EventWriter<SprintEvent>,
mut sneaking_events: EventWriter<SneakEvent>,
mut jump_with_horse_events: EventWriter<JumpWithHorseEvent>,
mut leave_bed_events: EventWriter<LeaveBedEvent>,
) {
for packet in packets.iter() {
if let Some(pkt) = packet.decode::<ClientCommandC2s>() {
Expand All @@ -80,7 +80,7 @@ fn handle_client_command(
flags.set_sneaking(true);
}

sneaking_events.send(Sneaking {
sneaking_events.send(SneakEvent {
client: packet.client,
state: SneakState::Start,
})
Expand All @@ -91,20 +91,20 @@ fn handle_client_command(
flags.set_sneaking(false);
}

sneaking_events.send(Sneaking {
sneaking_events.send(SneakEvent {
client: packet.client,
state: SneakState::Stop,
})
}
ClientCommand::LeaveBed => leave_bed_events.send(LeaveBed {
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);
}

sprinting_events.send(Sprinting {
sprinting_events.send(SprintEvent {
client: packet.client,
state: SprintState::Start,
});
Expand All @@ -114,21 +114,25 @@ fn handle_client_command(
flags.set_sprinting(false);
}

sprinting_events.send(Sprinting {
sprinting_events.send(SprintEvent {
client: packet.client,
state: SprintState::Stop,
})
}
ClientCommand::StartJumpWithHorse => jump_with_horse_events.send(JumpWithHorse {
client: packet.client,
state: JumpWithHorseState::Start {
power: pkt.jump_boost.0 as u8,
},
}),
ClientCommand::StopJumpWithHorse => jump_with_horse_events.send(JumpWithHorse {
client: packet.client,
state: JumpWithHorseState::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 => {
if let Ok((mut pose, _)) = clients.get_mut(packet.client) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::collections::HashMap;

use valence::advancement::bevy_hierarchy::{BuildChildren, Children, Parent};
use valence::advancement::ForceTabUpdate;
use valence::prelude::*;
use valence_advancement::bevy_hierarchy::{BuildChildren, Children, Parent};
use valence_advancement::ForceTabUpdate;
use valence_client::SpawnClientsSet;

#[derive(Component)]
struct RootCriteria;
Expand All @@ -29,13 +28,14 @@ fn main() {
.init_resource::<ClientSave>()
.add_startup_system(setup)
.add_systems((
load_clients,
apply_system_buffers
.after(load_clients)
.before(init_advancements),
init_clients,
init_advancements,
sneak,
tab_change,
load_clients
.after(SpawnClientsSet)
.in_base_set(CoreSet::PreUpdate),
))
.run();
}
Expand Down Expand Up @@ -225,7 +225,7 @@ fn init_advancements(
}

fn sneak(
mut sneaking: EventReader<Sneaking>,
mut sneaking: EventReader<SneakEvent>,
mut client: Query<(&mut AdvancementClientUpdate, &mut RootCriteriaDone)>,
root_criteria: Query<Entity, With<RootCriteria>>,
client_uuid: Query<&UniqueId>,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

use std::time::Instant;

use valence::instance::{Chunk, Instance};
use valence::prelude::*;
use valence_network::ConnectionMode;

const SPAWN_Y: i32 = 64;

Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion crates/valence/examples/building.rs → examples/building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ fn init_clients(
}
}

fn toggle_gamemode_on_sneak(mut clients: Query<&mut GameMode>, mut events: EventReader<Sneaking>) {
fn toggle_gamemode_on_sneak(
mut clients: Query<&mut GameMode>,
mut events: EventReader<SneakEvent>,
) {
for event in events.iter() {
let Ok(mut mode) = clients.get_mut(event.client) else {
continue;
Expand Down
5 changes: 4 additions & 1 deletion crates/valence/examples/chest.rs → examples/chest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ fn init_clients(
}
}

fn toggle_gamemode_on_sneak(mut clients: Query<&mut GameMode>, mut events: EventReader<Sneaking>) {
fn toggle_gamemode_on_sneak(
mut clients: Query<&mut GameMode>,
mut events: EventReader<SneakEvent>,
) {
for event in events.iter() {
let Ok(mut mode) = clients.get_mut(event.client) else {
continue;
Expand Down
4 changes: 2 additions & 2 deletions crates/valence/examples/combat.rs → examples/combat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ struct CombatQuery {
fn handle_combat_events(
server: Res<Server>,
mut clients: Query<CombatQuery>,
mut sprinting: EventReader<Sprinting>,
mut sprinting: EventReader<SprintEvent>,
mut interact_entity: EventReader<InteractEntityEvent>,
) {
for &Sprinting { client, state } in sprinting.iter() {
for &SprintEvent { client, state } in sprinting.iter() {
if let Ok(mut client) = clients.get_mut(client) {
client.state.has_bonus_knockback = state == SprintState::Start;
}
Expand Down
File renamed without changes.
Loading