1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

azalea-ecs stuff compiles

This commit is contained in:
Ubuntu 2023-01-30 16:24:37 +00:00
parent 57d91b5220
commit 284a5b645e
33 changed files with 327 additions and 290 deletions

9
Cargo.lock generated
View file

@ -170,12 +170,11 @@ dependencies = [
"azalea-chat", "azalea-chat",
"azalea-client", "azalea-client",
"azalea-core", "azalea-core",
"azalea-ecs",
"azalea-physics", "azalea-physics",
"azalea-protocol", "azalea-protocol",
"azalea-registry", "azalea-registry",
"azalea-world", "azalea-world",
"bevy_app",
"bevy_ecs",
"derive_more", "derive_more",
"env_logger 0.10.0", "env_logger 0.10.0",
"futures", "futures",
@ -377,10 +376,9 @@ version = "0.5.0"
dependencies = [ dependencies = [
"azalea-block", "azalea-block",
"azalea-core", "azalea-core",
"azalea-ecs",
"azalea-registry", "azalea-registry",
"azalea-world", "azalea-world",
"bevy_app",
"bevy_ecs",
"iyes_loopless", "iyes_loopless",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
@ -459,10 +457,9 @@ dependencies = [
"azalea-buf", "azalea-buf",
"azalea-chat", "azalea-chat",
"azalea-core", "azalea-core",
"azalea-ecs",
"azalea-nbt", "azalea-nbt",
"azalea-registry", "azalea-registry",
"bevy_app",
"bevy_ecs",
"derive_more", "derive_more",
"enum-as-inner", "enum-as-inner",
"iyes_loopless", "iyes_loopless",

View file

@ -11,12 +11,13 @@ use crate::{
use azalea_auth::{game_profile::GameProfile, sessionserver::ClientSessionServerError}; use azalea_auth::{game_profile::GameProfile, sessionserver::ClientSessionServerError};
use azalea_chat::FormattedText; use azalea_chat::FormattedText;
use azalea_ecs::{ecs::Ecs, TickPlugin};
use azalea_ecs::{ use azalea_ecs::{
app::{App, Plugin},
component::Component, component::Component,
entity::Entity,
schedule::{IntoSystemDescriptor, Schedule, Stage, SystemSet}, schedule::{IntoSystemDescriptor, Schedule, Stage, SystemSet},
App, Plugin,
}; };
use azalea_ecs::{ecs::Ecs, TickPlugin};
use azalea_physics::PhysicsPlugin; use azalea_physics::PhysicsPlugin;
use azalea_protocol::{ use azalea_protocol::{
connect::{Connection, ConnectionError}, connect::{Connection, ConnectionError},
@ -38,7 +39,7 @@ use azalea_protocol::{
}, },
resolver, ServerAddress, resolver, ServerAddress,
}; };
use azalea_world::{entity::Entity, EntityPlugin, Local, PartialWorld, World, WorldContainer}; use azalea_world::{EntityPlugin, Local, PartialWorld, World, WorldContainer};
use bevy_time::TimePlugin; use bevy_time::TimePlugin;
use iyes_loopless::prelude::*; use iyes_loopless::prelude::*;
use log::{debug, error}; use log::{debug, error};

View file

@ -1,9 +1,11 @@
use std::sync::Arc; use std::sync::Arc;
use azalea_ecs::component::Component; use azalea_ecs::{
use azalea_ecs::ecs::Ecs; component::Component,
use azalea_ecs::query::{ROQueryItem, ReadOnlyWorldQuery, WorldQuery}; ecs::Ecs,
use azalea_world::entity::Entity; entity::Entity,
query::{ROQueryItem, ReadOnlyWorldQuery, WorldQuery},
};
use parking_lot::Mutex; use parking_lot::Mutex;
use crate::Client; use crate::Client;

View file

@ -4,11 +4,11 @@
use std::sync::Arc; use std::sync::Arc;
use azalea_ecs::{ use azalea_ecs::{
app::{App, Plugin},
component::Component, component::Component,
event::EventReader, event::EventReader,
query::{Added, Changed}, query::{Added, Changed},
system::Query, system::Query,
Plugin,
}; };
use azalea_protocol::packets::game::{ use azalea_protocol::packets::game::{
clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket, clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket,
@ -85,7 +85,7 @@ pub struct LocalPlayerEvents(pub mpsc::UnboundedSender<Event>);
pub struct EventPlugin; pub struct EventPlugin;
impl Plugin for EventPlugin { impl Plugin for EventPlugin {
fn build(&self, app: &mut azalea_ecs::App) { fn build(&self, app: &mut App) {
app.add_system(chat_listener) app.add_system(chat_listener)
.add_system(login_listener) .add_system(login_listener)
.add_system(init_listener) .add_system(init_listener)

View file

@ -3,12 +3,13 @@ use std::{collections::HashMap, io, sync::Arc};
use azalea_auth::game_profile::GameProfile; use azalea_auth::game_profile::GameProfile;
use azalea_core::{ChunkPos, ResourceLocation}; use azalea_core::{ChunkPos, ResourceLocation};
use azalea_ecs::component::Component; use azalea_ecs::component::Component;
use azalea_ecs::entity::Entity;
use azalea_ecs::{query::Added, system::Query};
use azalea_protocol::packets::game::ServerboundGamePacket; use azalea_protocol::packets::game::ServerboundGamePacket;
use azalea_world::{ use azalea_world::{
entity::{self, Dead, Entity}, entity::{self, Dead},
PartialWorld, World, PartialWorld, World,
}; };
use bevy_ecs::{component::Component, query::Added, system::Query};
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use parking_lot::RwLock; use parking_lot::RwLock;
use thiserror::Error; use thiserror::Error;

View file

@ -1,5 +1,7 @@
use crate::client::Client; use crate::client::Client;
use crate::local_player::{LocalPlayer, LocalPlayerInLoadedChunk, PhysicsState}; use crate::local_player::{LocalPlayer, LocalPlayerInLoadedChunk, PhysicsState};
use azalea_ecs::entity::Entity;
use azalea_ecs::{event::EventReader, query::With, system::Query};
use azalea_protocol::packets::game::serverbound_player_command_packet::ServerboundPlayerCommandPacket; use azalea_protocol::packets::game::serverbound_player_command_packet::ServerboundPlayerCommandPacket;
use azalea_protocol::packets::game::{ use azalea_protocol::packets::game::{
serverbound_move_player_pos_packet::ServerboundMovePlayerPosPacket, serverbound_move_player_pos_packet::ServerboundMovePlayerPosPacket,
@ -7,12 +9,10 @@ use azalea_protocol::packets::game::{
serverbound_move_player_rot_packet::ServerboundMovePlayerRotPacket, serverbound_move_player_rot_packet::ServerboundMovePlayerRotPacket,
serverbound_move_player_status_only_packet::ServerboundMovePlayerStatusOnlyPacket, serverbound_move_player_status_only_packet::ServerboundMovePlayerStatusOnlyPacket,
}; };
use azalea_world::entity::metadata::Sprinting; use azalea_world::{
use azalea_world::entity::{Attributes, Entity, Jumping, MinecraftEntityId}; entity::{self, metadata::Sprinting, Attributes, Jumping, MinecraftEntityId},
use azalea_world::{entity, MoveEntityError}; MoveEntityError,
use bevy_ecs::event::EventReader; };
use bevy_ecs::prelude::With;
use bevy_ecs::system::Query;
use std::backtrace::Backtrace; use std::backtrace::Backtrace;
use thiserror::Error; use thiserror::Error;

View file

@ -1,14 +1,13 @@
use std::{collections::HashSet, io::Cursor, sync::Arc}; use std::{collections::HashSet, io::Cursor, sync::Arc};
use azalea_core::{ChunkPos, ResourceLocation, Vec3}; use azalea_core::{ChunkPos, ResourceLocation, Vec3};
use azalea_ecs::{component::Component, ecs::Ecs};
use azalea_ecs::{ use azalea_ecs::{
component::Component, component::Component,
prelude::{Entity, EventWriter}, ecs::Ecs,
query::Changed, query::Changed,
schedule::{IntoSystemDescriptor, SystemSet}, schedule::{IntoSystemDescriptor, SystemSet},
system::{Commands, Query, ResMut, SystemState}, system::{Commands, Query, ResMut, SystemState},
App, Plugin, app::{App, Plugin}, event::EventWriter, entity::Entity,
}; };
use azalea_protocol::{ use azalea_protocol::{
connect::{ReadConnection, WriteConnection}, connect::{ReadConnection, WriteConnection},

View file

@ -19,7 +19,7 @@ pub fn derive_resource(input: TokenStream) -> TokenStream {
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl(); let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
TokenStream::from(quote! { TokenStream::from(quote! {
impl #impl_generics #azalea_ecs_path::system::Resource for #struct_name #type_generics #where_clause { impl #impl_generics #azalea_ecs_path::system::BevyResource for #struct_name #type_generics #where_clause {
} }
}) })
} }
@ -44,7 +44,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream {
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl(); let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
TokenStream::from(quote! { TokenStream::from(quote! {
impl #impl_generics #azalea_ecs_path::component::Component for #struct_name #type_generics #where_clause { impl #impl_generics #azalea_ecs_path::component::BevyComponent for #struct_name #type_generics #where_clause {
type Storage = #storage; type Storage = #storage;
} }
}) })

View file

@ -151,13 +151,13 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
match field_kind { match field_kind {
BundleFieldKind::Component => { BundleFieldKind::Component => {
field_component_ids.push(quote! { field_component_ids.push(quote! {
<#field_type as #ecs_path::bundle::Bundle>::component_ids(components, storages, &mut *ids); <#field_type as #ecs_path::bundle::BevyBundle>::component_ids(components, storages, &mut *ids);
}); });
field_get_components.push(quote! { field_get_components.push(quote! {
self.#field.get_components(&mut *func); self.#field.get_components(&mut *func);
}); });
field_from_components.push(quote! { field_from_components.push(quote! {
#field: <#field_type as #ecs_path::bundle::Bundle>::from_components(ctx, &mut *func), #field: <#field_type as #ecs_path::bundle::BevyBundle>::from_components(ctx, &mut *func),
}); });
} }
@ -174,7 +174,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
TokenStream::from(quote! { TokenStream::from(quote! {
/// SAFETY: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order /// SAFETY: ComponentId is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
unsafe impl #impl_generics #ecs_path::bundle::Bundle for #struct_name #ty_generics #where_clause { unsafe impl #impl_generics #ecs_path::bundle::BevyBundle for #struct_name #ty_generics #where_clause {
fn component_ids( fn component_ids(
components: &mut #ecs_path::component::Components, components: &mut #ecs_path::component::Components,
storages: &mut #ecs_path::storage::Storages, storages: &mut #ecs_path::storage::Storages,

View file

@ -1,3 +1,5 @@
#![allow(dead_code)]
use syn::DeriveInput; use syn::DeriveInput;
use super::symbol::Symbol; use super::symbol::Symbol;

View file

@ -1,3 +1,5 @@
#![allow(dead_code)]
extern crate proc_macro; extern crate proc_macro;
mod attrs; mod attrs;
@ -35,8 +37,9 @@ impl Default for BevyManifest {
impl BevyManifest { impl BevyManifest {
pub fn maybe_get_path(&self, name: &str) -> Option<syn::Path> { pub fn maybe_get_path(&self, name: &str) -> Option<syn::Path> {
const AZALEA: &str = "azalea";
const BEVY_ECS: &str = "bevy_ecs";
const BEVY: &str = "bevy"; const BEVY: &str = "bevy";
const BEVY_INTERNAL: &str = "bevy_internal";
fn dep_package(dep: &Value) -> Option<&str> { fn dep_package(dep: &Value) -> Option<&str> {
if dep.as_str().is_some() { if dep.as_str().is_some() {
@ -52,16 +55,18 @@ impl BevyManifest {
let find_in_deps = |deps: &Map<String, Value>| -> Option<syn::Path> { let find_in_deps = |deps: &Map<String, Value>| -> Option<syn::Path> {
let package = if let Some(dep) = deps.get(name) { let package = if let Some(dep) = deps.get(name) {
return Some(Self::parse_str(dep_package(dep).unwrap_or(name))); return Some(Self::parse_str(dep_package(dep).unwrap_or(name)));
} else if let Some(dep) = deps.get(AZALEA) {
dep_package(dep).unwrap_or(AZALEA)
} else if let Some(dep) = deps.get(BEVY_ECS) {
dep_package(dep).unwrap_or(BEVY_ECS)
} else if let Some(dep) = deps.get(BEVY) { } else if let Some(dep) = deps.get(BEVY) {
dep_package(dep).unwrap_or(BEVY) dep_package(dep).unwrap_or(BEVY)
} else if let Some(dep) = deps.get(BEVY_INTERNAL) {
dep_package(dep).unwrap_or(BEVY_INTERNAL)
} else { } else {
return None; return None;
}; };
let mut path = Self::parse_str::<syn::Path>(package); let mut path = Self::parse_str::<syn::Path>(package);
if let Some(module) = name.strip_prefix("bevy_") { if let Some(module) = name.strip_prefix("azalea_") {
path.segments.push(Self::parse_str(module)); path.segments.push(Self::parse_str(module));
} }
Some(path) Some(path)
@ -109,7 +114,8 @@ impl BevyManifest {
/// ///
/// # Args /// # Args
/// ///
/// - `input`: The [`syn::DeriveInput`] for struct that is deriving the label trait /// - `input`: The [`syn::DeriveInput`] for struct that is deriving the label
/// trait
/// - `trait_path`: The path [`syn::Path`] to the label trait /// - `trait_path`: The path [`syn::Path`] to the label trait
pub fn derive_label( pub fn derive_label(
input: syn::DeriveInput, input: syn::DeriveInput,

View file

@ -1,18 +1,29 @@
#![feature(trait_alias)] #![feature(trait_alias)]
//! Re-export the necessary parts of `bevy_ecs` and `bevy_app`. //! Re-export important parts of `bevy_ecs` and `bevy_app` and make them more
//! compatible with Azalea.
//! //!
//! This is completely compatible with `bevy_ecs`, so it won't cause issues if //! This is completely compatible with `bevy_ecs`, so it won't cause issues if
//! you use plugins meant for Bevy. //! you use plugins meant for Bevy.
//!
//! Changes:
//! - Add [`TickPlugin`], [`TickStage`] and [`AppTickExt`]
//! - Change the macros to use azalea_ecs instead of bevy_ecs
//! - Rename bevy_ecs::world::World to azalea_ecs::ecs::Ecs
//! - Re-export `bevy_app` in the `app` module.
use std::{ use std::{
task::{Context, Poll}, task::{Context, Poll},
time::Duration, time::Duration,
}; };
pub mod ecs {
pub use bevy_ecs::world::World as Ecs;
pub use bevy_ecs::world::{EntityMut, EntityRef, Mut};
}
pub mod component { pub mod component {
pub use azalea_ecs_macros::Component; pub use azalea_ecs_macros::Component;
pub use bevy_ecs::component::{ComponentStorage, TableStorage}; pub use bevy_ecs::component::{ComponentId, ComponentStorage, Components, TableStorage};
// we do this because re-exporting Component would re-export the macro as well, // we do this because re-exporting Component would re-export the macro as well,
// which is bad (since we have our own Component macro) // which is bad (since we have our own Component macro)
@ -21,14 +32,24 @@ pub mod component {
pub trait Component = bevy_ecs::component::Component; pub trait Component = bevy_ecs::component::Component;
pub use bevy_ecs::component::Component as BevyComponent; pub use bevy_ecs::component::Component as BevyComponent;
} }
pub mod ecs { pub mod bundle {
pub use bevy_ecs::world::World as Ecs; pub use azalea_ecs_macros::Bundle;
pub use bevy_ecs::world::{EntityMut, EntityRef, Mut}; pub trait Bundle = bevy_ecs::bundle::Bundle;
pub use bevy_ecs::bundle::Bundle as BevyBundle;
} }
pub use bevy_app::*; pub mod system {
pub use azalea_ecs_macros::Resource;
pub use bevy_ecs::system::{
Command, Commands, EntityCommands, Query, Res, ResMut, SystemState,
};
pub trait Resource = bevy_ecs::system::Resource;
pub use bevy_ecs::system::Resource as BevyResource;
}
pub use bevy_app as app;
pub use bevy_ecs::{entity, event, ptr, query, schedule, storage};
use app::{App, CoreStage, Plugin};
use bevy_ecs::schedule::*; use bevy_ecs::schedule::*;
pub use bevy_ecs::system;
pub use bevy_ecs::{event, query, schedule};
use ecs::Ecs; use ecs::Ecs;
use futures::task::noop_waker_ref; use futures::task::noop_waker_ref;
use tokio::time::Interval; use tokio::time::Interval;
@ -68,7 +89,7 @@ impl TickStage {
impl Stage for TickStage { impl Stage for TickStage {
fn run(&mut self, ecs: &mut Ecs) { fn run(&mut self, ecs: &mut Ecs) {
// keep calling run until it's caught up // keep calling run until it's caught up
while let Poll::Ready(r) = self while let Poll::Ready(_) = self
.interval .interval
.poll_tick(&mut Context::from_waker(&noop_waker_ref())) .poll_tick(&mut Context::from_waker(&noop_waker_ref()))
{ {

View file

@ -13,11 +13,10 @@ azalea-block = { path = "../azalea-block", version = "^0.5.0" }
azalea-core = { path = "../azalea-core", version = "^0.5.0" } azalea-core = { path = "../azalea-core", version = "^0.5.0" }
azalea-world = { path = "../azalea-world", version = "^0.5.0" } azalea-world = { path = "../azalea-world", version = "^0.5.0" }
azalea-registry = { path = "../azalea-registry", version = "^0.5.0" } azalea-registry = { path = "../azalea-registry", version = "^0.5.0" }
bevy_app = { version = "0.9.1", default-features = false }
bevy_ecs = { version = "0.9.1", default-features = false }
iyes_loopless = "0.9.1" iyes_loopless = "0.9.1"
once_cell = "1.16.0" once_cell = "1.16.0"
parking_lot = "^0.12.1" parking_lot = "^0.12.1"
azalea-ecs = { version = "0.5.0", path = "../azalea-ecs" }
[dev-dependencies] [dev-dependencies]
uuid = "^1.1.2" uuid = "^1.1.2"

View file

@ -4,44 +4,41 @@ pub mod collision;
use azalea_block::{Block, BlockState}; use azalea_block::{Block, BlockState};
use azalea_core::{BlockPos, Vec3}; use azalea_core::{BlockPos, Vec3};
use azalea_ecs::{
app::{App, Plugin},
entity::Entity,
event::{EventReader, EventWriter},
query::With,
schedule::{IntoSystemDescriptor, SystemSet},
system::{Query, Res},
AppTickExt,
};
use azalea_world::{ use azalea_world::{
entity::{ entity::{
metadata::Sprinting, move_relative, Attributes, Entity, Jumping, Physics, Position, metadata::Sprinting, move_relative, Attributes, Jumping, Physics, Position, WorldName,
WorldName,
}, },
Local, World, WorldContainer, Local, World, WorldContainer,
}; };
use bevy_app::Plugin;
use bevy_ecs::{
event::{EventReader, EventWriter},
query::With,
schedule::{IntoSystemDescriptor, SystemStage},
system::Res,
};
use bevy_ecs::{schedule::SystemSet, system::Query};
use collision::{move_colliding, MoverType}; use collision::{move_colliding, MoverType};
pub struct PhysicsPlugin; pub struct PhysicsPlugin;
impl Plugin for PhysicsPlugin { impl Plugin for PhysicsPlugin {
fn build(&self, app: &mut bevy_app::App) { fn build(&self, app: &mut App) {
app.add_event::<ForceJumpEvent>() app.add_event::<ForceJumpEvent>().add_tick_system_set(
.stage("tick", |stage: &mut SystemStage| { SystemSet::new()
stage.add_system_set( .with_system(ai_step.label("ai_step"))
SystemSet::new() .with_system(
.with_system(ai_step.label("ai_step")) force_jump_listener
.with_system( .label("force_jump_listener")
force_jump_listener .after("ai_step"),
.label("force_jump_listener")
.after("ai_step"),
)
.with_system(
travel
.label("travel")
.after("ai_step")
.after("force_jump_listener"),
),
) )
}); .with_system(
travel
.label("travel")
.after("ai_step")
.after("force_jump_listener"),
),
);
} }
} }
@ -310,11 +307,11 @@ mod tests {
use super::*; use super::*;
use azalea_core::{ChunkPos, ResourceLocation}; use azalea_core::{ChunkPos, ResourceLocation};
use azalea_ecs::app::App;
use azalea_world::{ use azalea_world::{
entity::{EntityBundle, MinecraftEntityId}, entity::{EntityBundle, MinecraftEntityId},
Chunk, EntityPlugin, PartialWorld, Chunk, EntityPlugin, PartialWorld,
}; };
use bevy_app::App;
use iyes_loopless::fixedtimestep::FixedTimestepStageLabel; use iyes_loopless::fixedtimestep::FixedTimestepStageLabel;
use parking_lot::RwLock; use parking_lot::RwLock;
use uuid::Uuid; use uuid::Uuid;

View file

@ -13,10 +13,9 @@ azalea-block = {path = "../azalea-block", default-features = false, version = "^
azalea-buf = {path = "../azalea-buf", version = "^0.5.0"} azalea-buf = {path = "../azalea-buf", version = "^0.5.0"}
azalea-chat = {path = "../azalea-chat", version = "^0.5.0"} azalea-chat = {path = "../azalea-chat", version = "^0.5.0"}
azalea-core = {path = "../azalea-core", version = "^0.5.0", features = ["bevy_ecs"]} azalea-core = {path = "../azalea-core", version = "^0.5.0", features = ["bevy_ecs"]}
azalea-ecs = { version = "0.5.0", path = "../azalea-ecs" }
azalea-nbt = {path = "../azalea-nbt", version = "^0.5.0"} azalea-nbt = {path = "../azalea-nbt", version = "^0.5.0"}
azalea-registry = {path = "../azalea-registry", version = "^0.5.0"} azalea-registry = {path = "../azalea-registry", version = "^0.5.0"}
bevy_app = {version = "0.9.1", default-features = false}
bevy_ecs = {version = "0.9.1", default-features = false}
derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]} derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]}
enum-as-inner = "0.5.1" enum-as-inner = "0.5.1"
iyes_loopless = "0.9.1" iyes_loopless = "0.9.1"

View file

@ -1,5 +1,5 @@
use azalea_core::ResourceLocation; use azalea_core::ResourceLocation;
use bevy_ecs::system::Resource; use azalea_ecs::system::Resource;
use log::error; use log::error;
use nohash_hasher::IntMap; use nohash_hasher::IntMap;
use parking_lot::RwLock; use parking_lot::RwLock;

View file

@ -6,7 +6,7 @@ use std::{
}; };
use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable};
use bevy_ecs::component::Component; use azalea_ecs::component::Component;
use thiserror::Error; use thiserror::Error;
use uuid::{uuid, Uuid}; use uuid::{uuid, Uuid};

View file

@ -1,11 +1,12 @@
//! Define some types needed for entity metadata. //! Define some types needed for entity metadata.
use azalea_block::BlockState; use azalea_block::BlockState;
use azalea_buf::{BufReadError, McBufVarReadable, McBufVarWritable}; use azalea_buf::{
use azalea_buf::{McBuf, McBufReadable, McBufWritable}; BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
};
use azalea_chat::FormattedText; use azalea_chat::FormattedText;
use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Slot}; use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Slot};
use bevy_ecs::component::Component; use azalea_ecs::component::Component;
use derive_more::Deref; use derive_more::Deref;
use enum_as_inner::EnumAsInner; use enum_as_inner::EnumAsInner;
use nohash_hasher::IntSet; use nohash_hasher::IntSet;

View file

@ -1,5 +1,5 @@
use azalea_core::{Vec3, AABB}; use azalea_core::{Vec3, AABB};
use bevy_ecs::{query::Changed, system::Query}; use azalea_ecs::{query::Changed, system::Query};
use super::{Physics, Position}; use super::{Physics, Position};

File diff suppressed because it is too large Load diff

View file

@ -11,9 +11,10 @@ use self::{attributes::AttributeInstance, metadata::Health};
pub use attributes::Attributes; pub use attributes::Attributes;
use azalea_block::BlockState; use azalea_block::BlockState;
use azalea_core::{BlockPos, ChunkPos, ResourceLocation, Vec3, AABB}; use azalea_core::{BlockPos, ChunkPos, ResourceLocation, Vec3, AABB};
use bevy_ecs::{ use azalea_ecs::{
bundle::Bundle, bundle::Bundle,
component::Component, component::Component,
entity::Entity,
query::Changed, query::Changed,
system::{Commands, Query}, system::{Commands, Query},
}; };
@ -23,15 +24,6 @@ pub use dimensions::{update_bounding_box, EntityDimensions};
use std::fmt::Debug; use std::fmt::Debug;
use uuid::Uuid; use uuid::Uuid;
/// A lightweight identifier of an entity.
///
/// Don't rely on the index of this being the same as a Minecraft entity id!
/// (unless you're implementin a server, in which case you can decide your
/// entity ids however you want)
///
/// If you want to refer to a Minecraft entity id, use [`MinecraftEntityId`].
pub type Entity = bevy_ecs::entity::Entity;
/// An entity ID used by Minecraft. These are not guaranteed to be unique in /// An entity ID used by Minecraft. These are not guaranteed to be unique in
/// shared worlds, that's what [`Entity`] is for. /// shared worlds, that's what [`Entity`] is for.
#[derive(Component, Copy, Clone, Debug, PartialEq, Eq, Deref, DerefMut)] #[derive(Component, Copy, Clone, Debug, PartialEq, Eq, Deref, DerefMut)]

View file

@ -1,19 +1,20 @@
use crate::{ use crate::{
deduplicate_entities, deduplicate_entities,
entity::{ entity::{
self, add_dead, update_bounding_box, Entity, EntityUuid, MinecraftEntityId, Position, self, add_dead, update_bounding_box, EntityUuid, MinecraftEntityId, Position, WorldName,
WorldName,
}, },
update_entity_by_id_index, update_uuid_index, PartialWorld, WorldContainer, update_entity_by_id_index, update_uuid_index, PartialWorld, WorldContainer,
}; };
use azalea_core::ChunkPos; use azalea_core::ChunkPos;
use bevy_app::{App, Plugin}; use azalea_ecs::{
use bevy_ecs::{ app::{App, Plugin},
prelude::Component, component::Component,
ecs::Ecs,
ecs::EntityMut,
entity::Entity,
query::{Added, Changed, With, Without}, query::{Added, Changed, With, Without},
schedule::{IntoSystemDescriptor, SystemSet}, schedule::{IntoSystemDescriptor, SystemSet},
system::{Command, Commands, Query, Res, ResMut, Resource}, system::{Command, Commands, Query, Res, ResMut, Resource},
world::EntityMut,
}; };
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use log::{debug, warn}; use log::{debug, warn};
@ -121,7 +122,7 @@ pub struct RelativeEntityUpdate {
pub update: Box<dyn FnOnce(&mut EntityMut) + Send + Sync>, pub update: Box<dyn FnOnce(&mut EntityMut) + Send + Sync>,
} }
impl Command for RelativeEntityUpdate { impl Command for RelativeEntityUpdate {
fn write(self, world: &mut bevy_ecs::world::World) { fn write(self, world: &mut Ecs) {
let partial_entity_infos = &mut self.partial_world.write().entity_infos; let partial_entity_infos = &mut self.partial_world.write().entity_infos;
let mut entity = world.entity_mut(self.entity); let mut entity = world.entity_mut(self.entity);

View file

@ -1,10 +1,11 @@
use crate::{ use crate::{
entity::{Entity, EntityUuid, MinecraftEntityId, Position, WorldName}, entity::{EntityUuid, MinecraftEntityId, Position, WorldName},
entity_info::LoadedBy, entity_info::LoadedBy,
ChunkStorage, EntityInfos, PartialChunkStorage, PartialEntityInfos, WorldContainer, ChunkStorage, EntityInfos, PartialChunkStorage, PartialEntityInfos, WorldContainer,
}; };
use azalea_core::ChunkPos; use azalea_core::ChunkPos;
use bevy_ecs::{ use azalea_ecs::{
entity::Entity,
query::Changed, query::Changed,
system::{Commands, Query, Res, ResMut}, system::{Commands, Query, Res, ResMut},
}; };

View file

@ -18,12 +18,11 @@ azalea-block = {version = "0.5.0", path = "../azalea-block"}
azalea-chat = {version = "0.5.0", path = "../azalea-chat"} azalea-chat = {version = "0.5.0", path = "../azalea-chat"}
azalea-client = {version = "0.5.0", path = "../azalea-client"} azalea-client = {version = "0.5.0", path = "../azalea-client"}
azalea-core = {version = "0.5.0", path = "../azalea-core"} azalea-core = {version = "0.5.0", path = "../azalea-core"}
azalea-ecs = { version = "0.5.0", path = "../azalea-ecs" }
azalea-physics = {version = "0.5.0", path = "../azalea-physics"} azalea-physics = {version = "0.5.0", path = "../azalea-physics"}
azalea-protocol = {version = "0.5.0", path = "../azalea-protocol"} azalea-protocol = {version = "0.5.0", path = "../azalea-protocol"}
azalea-registry = {version = "0.5.0", path = "../azalea-registry"} azalea-registry = {version = "0.5.0", path = "../azalea-registry"}
azalea-world = {version = "0.5.0", path = "../azalea-world"} azalea-world = {version = "0.5.0", path = "../azalea-world"}
bevy_app = {version = "0.9.1", default-features = false}
bevy_ecs = {version = "0.9.1", default-features = false}
derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]} derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]}
futures = "0.3.25" futures = "0.3.25"
iyes_loopless = "0.9.1" iyes_loopless = "0.9.1"

View file

@ -1,14 +1,19 @@
use azalea_core::Vec3; use azalea_core::Vec3;
use azalea_world::entity::{set_rotation, Entity, Jumping, Physics, Position}; use azalea_ecs::{
use bevy_app::App; app::{App, Plugin},
use bevy_ecs::schedule::IntoSystemDescriptor; component::Component,
use bevy_ecs::{event::EventReader, prelude::Component, schedule::SystemSet, system::Query}; event::EventReader,
schedule::IntoSystemDescriptor,
schedule::SystemSet,
system::Query, entity::Entity,
};
use azalea_world::entity::{set_rotation, Jumping, Physics, Position};
use iyes_loopless::prelude::*; use iyes_loopless::prelude::*;
use std::f64::consts::PI; use std::f64::consts::PI;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct Plugin; pub struct BotPlugin;
impl bevy_app::Plugin for Plugin { impl Plugin for BotPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<LookAtEvent>() app.add_event::<LookAtEvent>()
.add_event::<JumpEvent>() .add_event::<JumpEvent>()

View file

@ -11,11 +11,13 @@ mod swarm;
pub use azalea_block as blocks; pub use azalea_block as blocks;
pub use azalea_client::*; pub use azalea_client::*;
pub use azalea_core::{BlockPos, Vec3}; pub use azalea_core::{BlockPos, Vec3};
use azalea_ecs::{
app::{App, Plugin},
component::Component,
};
pub use azalea_protocol as protocol; pub use azalea_protocol as protocol;
pub use azalea_registry::EntityKind; pub use azalea_registry::EntityKind;
pub use azalea_world::{entity, World}; pub use azalea_world::{entity, World};
use bevy_app::Plugin;
use bevy_ecs::prelude::Component;
use futures::Future; use futures::Future;
use protocol::ServerAddress; use protocol::ServerAddress;
pub use swarm::*; pub use swarm::*;
@ -36,7 +38,7 @@ where
S: Default + Send + Sync + Clone + 'static, S: Default + Send + Sync + Clone + 'static,
Fut: Future<Output = Result<(), anyhow::Error>>, Fut: Future<Output = Result<(), anyhow::Error>>,
{ {
app: bevy_app::App, app: App,
/// The function that's called every time a bot receives an [`Event`]. /// The function that's called every time a bot receives an [`Event`].
handler: Option<HandleFn<Fut, S>>, handler: Option<HandleFn<Fut, S>>,
state: S, state: S,

View file

@ -6,28 +6,31 @@ use crate::{SprintDirection, WalkDirection};
use azalea_client::{StartSprintEvent, StartWalkEvent}; use azalea_client::{StartSprintEvent, StartWalkEvent};
use azalea_core::{BlockPos, CardinalDirection}; use azalea_core::{BlockPos, CardinalDirection};
use azalea_world::entity::{Entity, Physics, Position, WorldName}; use azalea_ecs::app::{App, Plugin};
use azalea_world::WorldContainer; use azalea_ecs::AppTickExt;
use bevy_ecs::event::EventReader; use azalea_ecs::{
use bevy_ecs::schedule::SystemSet; component::Component,
use bevy_ecs::system::{Query, Res}; entity::Entity,
use bevy_ecs::{component::Component, event::EventWriter}; event::EventReader,
use iyes_loopless::prelude::*; event::EventWriter,
schedule::SystemSet,
system::{Query, Res},
};
use azalea_world::{
entity::{Physics, Position, WorldName},
WorldContainer,
};
use log::{debug, error}; use log::{debug, error};
use mtdstarlite::Edge; use mtdstarlite::Edge;
pub use mtdstarlite::MTDStarLite; pub use mtdstarlite::MTDStarLite;
use std::collections::VecDeque; use std::collections::VecDeque;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct Plugin; pub struct PathfinderPlugin;
impl bevy_app::Plugin for Plugin { impl Plugin for PathfinderPlugin {
fn build(&self, app: &mut bevy_app::App) { fn build(&self, app: &mut App) {
app.add_fixed_timestep_system_set( app.add_tick_system_set(SystemSet::new().with_system(tick_execute_path))
"tick", .add_system(goto_listener);
0,
SystemSet::new().with_system(tick_execute_path),
)
.add_system(goto_listener);
} }
} }

View file

@ -4,5 +4,4 @@
pub use crate::bot::BotClientExt; pub use crate::bot::BotClientExt;
pub use crate::pathfinder::PathfinderClientExt; pub use crate::pathfinder::PathfinderClientExt;
pub use azalea_client::{Account, Client, Event}; pub use azalea_client::{Account, Client, Event};
pub use bevy_ecs; pub use azalea_ecs::component::Component;
pub use bevy_ecs::component::Component;

View file

@ -14,8 +14,11 @@
// messages from the queue that are before that index. // messages from the queue that are before that index.
use azalea_client::{packet_handling::ChatReceivedEvent, ChatPacket, LocalPlayer}; use azalea_client::{packet_handling::ChatReceivedEvent, ChatPacket, LocalPlayer};
use bevy_ecs::{ use azalea_ecs::app::{Plugin, App};
prelude::{Component, Entity, EventReader, EventWriter}, use azalea_ecs::{
component::Component,
entity::Entity,
event::{EventReader, EventWriter},
query::{Added, Without}, query::{Added, Without},
system::{Commands, Query, Res, ResMut, Resource}, system::{Commands, Query, Res, ResMut, Resource},
}; };
@ -24,9 +27,9 @@ use std::collections::VecDeque;
use crate::{Swarm, SwarmEvent}; use crate::{Swarm, SwarmEvent};
#[derive(Clone)] #[derive(Clone)]
pub struct Plugin; pub struct SwarmChatPlugin;
impl bevy_app::Plugin for Plugin { impl Plugin for SwarmChatPlugin {
fn build(&self, app: &mut bevy_app::App) { fn build(&self, app: &mut App) {
app.add_event::<NewChatMessageEvent>() app.add_event::<NewChatMessageEvent>()
.add_system(chat_listener) .add_system(chat_listener)
.add_system(add_default_client_state) .add_system(add_default_client_state)

View file

@ -1,14 +1,16 @@
use azalea_client::LocalPlayer; use azalea_client::LocalPlayer;
use azalea_world::entity::MinecraftEntityId; use azalea_ecs::{
use bevy_ecs::{ app::{App, Plugin},
prelude::{EventWriter, With}, event::EventWriter,
query::With,
system::{Query, ResMut, Resource}, system::{Query, ResMut, Resource},
}; };
use azalea_world::entity::MinecraftEntityId;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
pub struct Plugin; pub struct SwarmPlugin;
impl bevy_app::Plugin for Plugin { impl Plugin for SwarmPlugin {
fn build(&self, app: &mut bevy_app::App) { fn build(&self, app: &mut App) {
app.add_event::<SwarmReadyEvent>() app.add_event::<SwarmReadyEvent>()
.add_system(check_ready) .add_system(check_ready)
.init_resource::<IsSwarmReady>(); .init_resource::<IsSwarmReady>();

View file

@ -5,14 +5,19 @@ mod events;
use crate::{bot, HandleFn}; use crate::{bot, HandleFn};
use azalea_client::{init_ecs_app, start_ecs, Account, ChatPacket, Client, Event, JoinError}; use azalea_client::{init_ecs_app, start_ecs, Account, ChatPacket, Client, Event, JoinError};
use azalea_ecs::{
app::{App, Plugin},
component::Component,
ecs::Ecs,
entity::Entity,
system::Resource,
};
use azalea_protocol::{ use azalea_protocol::{
connect::ConnectionError, connect::ConnectionError,
resolver::{self, ResolverError}, resolver::{self, ResolverError},
ServerAddress, ServerAddress,
}; };
use azalea_world::{entity::Entity, WorldContainer}; use azalea_world::WorldContainer;
use bevy_app::Plugin;
use bevy_ecs::{prelude::Component, system::Resource};
use futures::future::join_all; use futures::future::join_all;
use log::error; use log::error;
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
@ -31,7 +36,7 @@ use tokio::sync::mpsc;
/// [`azalea::start_swarm`]: fn.start_swarm.html /// [`azalea::start_swarm`]: fn.start_swarm.html
#[derive(Clone, Resource)] #[derive(Clone, Resource)]
pub struct Swarm { pub struct Swarm {
pub ecs_lock: Arc<Mutex<bevy_ecs::world::World>>, pub ecs_lock: Arc<Mutex<Ecs>>,
bots: Arc<Mutex<HashMap<Entity, Client>>>, bots: Arc<Mutex<HashMap<Entity, Client>>>,
@ -54,7 +59,7 @@ where
Fut: Future<Output = Result<(), anyhow::Error>>, Fut: Future<Output = Result<(), anyhow::Error>>,
SwarmFut: Future<Output = Result<(), anyhow::Error>>, SwarmFut: Future<Output = Result<(), anyhow::Error>>,
{ {
app: bevy_app::App, app: App,
/// The accounts that are going to join the server. /// The accounts that are going to join the server.
accounts: Vec<Account>, accounts: Vec<Account>,
/// The individual bot states. This must be the same length as `accounts`, /// The individual bot states. This must be the same length as `accounts`,
@ -163,9 +168,9 @@ where
} }
fn add_default_swarm_plugins(self) -> Self { fn add_default_swarm_plugins(self) -> Self {
self.add_plugin(chat::Plugin) self.add_plugin(chat::SwarmChatPlugin)
.add_plugin(events::Plugin) .add_plugin(events::SwarmPlugin)
.add_plugin(bot::Plugin) .add_plugin(bot::BotPlugin)
} }
/// Build this `SwarmBuilder` into an actual [`Swarm`] and join the given /// Build this `SwarmBuilder` into an actual [`Swarm`] and join the given

View file

@ -1,6 +1,6 @@
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
use azalea::bevy_ecs::query::With; use azalea::ecs::query::With;
use azalea::entity::metadata::Player; use azalea::entity::metadata::Player;
use azalea::entity::Position; use azalea::entity::Position;
use azalea::pathfinder::BlockPosGoal; use azalea::pathfinder::BlockPosGoal;

View file

@ -46,7 +46,7 @@ use super::{EntityDataItem, EntityDataValue, OptionalUnsignedInt, Pose, Rotation
use azalea_block::BlockState; use azalea_block::BlockState;
use azalea_chat::FormattedText; use azalea_chat::FormattedText;
use azalea_core::{BlockPos, Direction, Particle, Slot}; use azalea_core::{BlockPos, Direction, Particle, Slot};
use bevy_ecs::{bundle::Bundle, component::Component}; use azalea_ecs::{bundle::Bundle, component::Component};
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use thiserror::Error; use thiserror::Error;
use uuid::Uuid; use uuid::Uuid;
@ -183,7 +183,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
# impl Allay { # impl Allay {
# pub fn apply_metadata( # pub fn apply_metadata(
# entity: &mut bevy_ecs::system::EntityCommands, # entity: &mut azalea_ecs::system::EntityCommands,
# d: EntityDataItem, # d: EntityDataItem,
# ) -> Result<(), UpdateMetadataError> { # ) -> Result<(), UpdateMetadataError> {
# match d.index { # match d.index {
@ -196,7 +196,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
# } # }
code.append(f'impl {struct_name} {{') code.append(f'impl {struct_name} {{')
code.append( code.append(
f' pub fn apply_metadata(entity: &mut bevy_ecs::system::EntityCommands, d: EntityDataItem) -> Result<(), UpdateMetadataError> {{') f' pub fn apply_metadata(entity: &mut azalea_ecs::system::EntityCommands, d: EntityDataItem) -> Result<(), UpdateMetadataError> {{')
code.append(f' match d.index {{') code.append(f' match d.index {{')
parent_last_index = -1 parent_last_index = -1
@ -400,7 +400,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
# and now make the main apply_metadata # and now make the main apply_metadata
# pub fn apply_metadata( # pub fn apply_metadata(
# entity: &mut bevy_ecs::system::EntityCommands, # entity: &mut azalea_ecs::system::EntityCommands,
# items: Vec<EntityDataItem>, # items: Vec<EntityDataItem>,
# ) -> Result<(), UpdateMetadataError> { # ) -> Result<(), UpdateMetadataError> {
# if entity.contains::<Allay>() { # if entity.contains::<Allay>() {
@ -414,7 +414,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
# } # }
code.append( code.append(
f'''pub fn apply_metadata( f'''pub fn apply_metadata(
entity: &mut bevy_ecs::system::EntityCommands, entity: &mut azalea_ecs::system::EntityCommands,
entity_kind: azalea_registry::EntityKind, entity_kind: azalea_registry::EntityKind,
items: Vec<EntityDataItem>, items: Vec<EntityDataItem>,
) -> Result<(), UpdateMetadataError> {{ ) -> Result<(), UpdateMetadataError> {{
@ -436,7 +436,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
code.append('}') code.append('}')
code.append('') code.append('')
# pub fn apply_default_metadata(entity: &mut bevy_ecs::system::EntityCommands, kind: azalea_registry::EntityKind) { # pub fn apply_default_metadata(entity: &mut azalea_ecs::system::EntityCommands, kind: azalea_registry::EntityKind) {
# match kind { # match kind {
# azalea_registry::EntityKind::AreaEffectCloud => { # azalea_registry::EntityKind::AreaEffectCloud => {
# entity.insert(AreaEffectCloudMetadataBundle::default()); # entity.insert(AreaEffectCloudMetadataBundle::default());
@ -444,7 +444,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
# } # }
# } # }
code.append( code.append(
'pub fn apply_default_metadata(entity: &mut bevy_ecs::system::EntityCommands, kind: azalea_registry::EntityKind) {') 'pub fn apply_default_metadata(entity: &mut azalea_ecs::system::EntityCommands, kind: azalea_registry::EntityKind) {')
code.append(' match kind {') code.append(' match kind {')
for entity_id in burger_entity_data: for entity_id in burger_entity_data:
if entity_id.startswith('~'): if entity_id.startswith('~'):