pub mod bvh;
pub mod chunk;
pub mod entity;
pub mod message;
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
pub use chunk::ChunkLayer;
pub use entity::EntityLayer;
use valence_entity::{InitEntitiesSet, UpdateTrackedDataSet};
use valence_protocol::encode::WritePacket;
use valence_protocol::{BlockPos, ChunkPos, Ident};
use valence_registry::{BiomeRegistry, DimensionTypeRegistry};
use valence_server_common::Server;
pub struct LayerPlugin;
#[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct UpdateLayersPreClientSet;
#[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct UpdateLayersPostClientSet;
impl Plugin for LayerPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
PostUpdate,
(
UpdateLayersPreClientSet
.after(InitEntitiesSet)
.after(UpdateTrackedDataSet),
UpdateLayersPostClientSet.after(UpdateLayersPreClientSet),
),
);
chunk::build(app);
entity::build(app);
}
}
pub trait Layer: WritePacket {
type ExceptWriter<'a>: WritePacket
where
Self: 'a;
type ViewWriter<'a>: WritePacket
where
Self: 'a;
type ViewExceptWriter<'a>: WritePacket
where
Self: 'a;
type RadiusWriter<'a>: WritePacket
where
Self: 'a;
type RadiusExceptWriter<'a>: WritePacket
where
Self: 'a;
fn except_writer(&mut self, except: Entity) -> Self::ExceptWriter<'_>;
fn view_writer(&mut self, pos: impl Into<ChunkPos>) -> Self::ViewWriter<'_>;
fn view_except_writer(
&mut self,
pos: impl Into<ChunkPos>,
except: Entity,
) -> Self::ViewExceptWriter<'_>;
fn radius_writer(&mut self, pos: impl Into<BlockPos>, radius: u32) -> Self::RadiusWriter<'_>;
fn radius_except_writer(
&mut self,
pos: impl Into<BlockPos>,
radius: u32,
except: Entity,
) -> Self::RadiusExceptWriter<'_>;
}
#[derive(Bundle)]
pub struct LayerBundle {
pub chunk: ChunkLayer,
pub entity: EntityLayer,
}
impl LayerBundle {
pub fn new(
dimension_type_name: impl Into<Ident<String>>,
dimensions: &DimensionTypeRegistry,
biomes: &BiomeRegistry,
server: &Server,
) -> Self {
Self {
chunk: ChunkLayer::new(dimension_type_name, dimensions, biomes, server),
entity: EntityLayer::new(server),
}
}
}