You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.0 KiB

mod chat;
mod chests;
mod combat;
mod commands;
mod loot_tables;
mod player;
mod special;
mod utils;
mod world;
use std::net::SocketAddr;
use std::sync::atomic::{AtomicI32, Ordering};
use commands::{handle_command_execution, CommandExecution};
use valence::{
ecs as bevy_ecs,
network::{async_trait, ServerListPing},
prelude::*,
};
pub static PLAYER_COUNT: AtomicI32 = AtomicI32::new(0);
struct MyCallbacks;
#[async_trait]
impl NetworkCallbacks for MyCallbacks {
async fn server_list_ping(
&self,
_shared: &SharedNetworkState,
_remote_addr: SocketAddr,
_protocol_version: i32,
) -> ServerListPing {
ServerListPing::Respond {
online_players: PLAYER_COUNT.load(Ordering::Relaxed),
max_players: 69420,
player_sample: vec![],
description: "Crazy! Insane! Et cetera!".into(),
favicon_png: include_bytes!("../assets/icon.png"),
}
}
}
#[derive(Resource, Debug)]
pub struct MessageQueue(pub Vec<Text>);
fn main() {
tracing_subscriber::fmt::init();
App::new()
.insert_resource(NetworkSettings {
//connection_mode: valence::network::ConnectionMode::Offline,
callbacks: MyCallbacks.into(),
..Default::default()
})
.insert_resource(MessageQueue(vec![]))
.add_plugins(DefaultPlugins)
.add_startup_system(world::setup)
.add_event::<CommandExecution>()
.add_system(player::update_username_cache)
.add_system(handle_command_execution)
.add_systems((
chat::player_message_handler,
chests::open_chests,
commands::command_executor,
player::fall_damage,
combat::handle_combat_events,
player::death,
player::respawn,
chat::flush_message_queue,
))
.add_system(player::init_clients)
.add_system(player::despawn_disconnected_clients)
.run();
}