diff --git a/cosmos_client/assets/lang/blocks/en_us.lang b/cosmos_client/assets/lang/blocks/en_us.lang index 5d7ba5fad..68fd97c0a 100644 --- a/cosmos_client/assets/lang/blocks/en_us.lang +++ b/cosmos_client/assets/lang/blocks/en_us.lang @@ -18,3 +18,4 @@ cosmos:molten_stone=Molten Stone cosmos:cheese=Cheese (Lava) cosmos:ice=Ice cosmos:water=Water +cosmos:build_block=Build Block diff --git a/cosmos_client/src/netty/gameplay/receiver.rs b/cosmos_client/src/netty/gameplay/receiver.rs index a44cc8758..111b4f730 100644 --- a/cosmos_client/src/netty/gameplay/receiver.rs +++ b/cosmos_client/src/netty/gameplay/receiver.rs @@ -349,6 +349,7 @@ pub(crate) fn client_sync_players( BloomSettings { ..Default::default() }, CameraHelper::default(), Skybox(Handle::default()), + Name::new("Main Camera"), MainCamera, // No double UI rendering UiCameraConfig { show_ui: false }, @@ -358,6 +359,7 @@ pub(crate) fn client_sync_players( commands.spawn(( PlayerWorld { player: client_entity }, + Name::new("Player World"), loc, PhysicsWorld { world_id: DEFAULT_WORLD_ID, diff --git a/cosmos_client/src/structure/ship/build_mode.rs b/cosmos_client/src/structure/ship/build_mode.rs index 6777e8134..88a386de5 100644 --- a/cosmos_client/src/structure/ship/build_mode.rs +++ b/cosmos_client/src/structure/ship/build_mode.rs @@ -1,9 +1,10 @@ //! Handles the build mode logic on the client-side use bevy::{ + pbr::{NotShadowCaster, NotShadowReceiver}, prelude::{ in_state, shape, App, AssetServer, Assets, BuildChildren, Changed, Color, Commands, Component, DespawnRecursiveExt, Entity, - EventReader, IntoSystemConfigs, MaterialMeshBundle, Mesh, Parent, Query, Res, ResMut, Transform, Update, Vec3, With, Without, + EventReader, IntoSystemConfigs, MaterialMeshBundle, Mesh, Name, Parent, Query, Res, ResMut, Transform, Update, Vec3, With, Without, }, time::Time, }; @@ -14,7 +15,10 @@ use cosmos_core::{ structure::{ chunk::CHUNK_DIMENSIONSF, coordinates::BlockCoordinate, - ship::build_mode::{BuildAxis, BuildMode, ExitBuildModeEvent}, + ship::{ + build_mode::{BuildAxis, BuildMode, ExitBuildModeEvent}, + core::DieWithStructure, + }, Structure, }, }; @@ -233,20 +237,26 @@ fn change_visuals( commands.entity(structure_entity).with_children(|ecmds| { visuals.0 = Some( ecmds - .spawn(MaterialMeshBundle { - mesh: meshes.add(shape::Box::new(0.001, size as f32, size as f32).into()), - material: materials.add(UnlitRepeatedMaterial { - repeats: Repeats { - horizontal: size as u32, - vertical: size as u32, - ..Default::default() - }, - texture: texture_handle.clone(), - color: Color::rgb(1.0, 0.0, 0.0).into(), - }), - transform: Transform::from_xyz(coords.x, 0.5, 0.5), - ..Default::default() - }) + .spawn(( + DieWithStructure, + NotShadowCaster, + NotShadowReceiver, + Name::new("X Axis - build mode"), + MaterialMeshBundle { + mesh: meshes.add(shape::Box::new(0.001, size as f32, size as f32).into()), + material: materials.add(UnlitRepeatedMaterial { + repeats: Repeats { + horizontal: size as u32, + vertical: size as u32, + ..Default::default() + }, + texture: texture_handle.clone(), + color: Color::rgb(1.0, 0.0, 0.0).into(), + }), + transform: Transform::from_xyz(coords.x, 0.5, 0.5), + ..Default::default() + }, + )) .id(), ); }); @@ -258,20 +268,26 @@ fn change_visuals( commands.entity(structure_entity).with_children(|ecmds| { visuals.1 = Some( ecmds - .spawn(MaterialMeshBundle { - mesh: meshes.add(shape::Box::new(size as f32, 0.001, size as f32).into()), - material: materials.add(UnlitRepeatedMaterial { - repeats: Repeats { - horizontal: size as u32, - vertical: size as u32, - ..Default::default() - }, - texture: texture_handle.clone(), - color: Color::rgb(0.0, 1.0, 0.0).into(), - }), - transform: Transform::from_xyz(0.5, coords.y, 0.5), - ..Default::default() - }) + .spawn(( + DieWithStructure, + NotShadowCaster, + NotShadowReceiver, + Name::new("Y Axis - build mode"), + MaterialMeshBundle { + mesh: meshes.add(shape::Box::new(size as f32, 0.001, size as f32).into()), + material: materials.add(UnlitRepeatedMaterial { + repeats: Repeats { + horizontal: size as u32, + vertical: size as u32, + ..Default::default() + }, + texture: texture_handle.clone(), + color: Color::rgb(0.0, 1.0, 0.0).into(), + }), + transform: Transform::from_xyz(0.5, coords.y, 0.5), + ..Default::default() + }, + )) .id(), ); }); @@ -283,20 +299,26 @@ fn change_visuals( commands.entity(structure_entity).with_children(|ecmds| { visuals.2 = Some( ecmds - .spawn(MaterialMeshBundle { - mesh: meshes.add(shape::Box::new(size as f32, size as f32, 0.001).into()), - material: materials.add(UnlitRepeatedMaterial { - repeats: Repeats { - horizontal: size as u32 / 4, - vertical: size as u32 / 4, - ..Default::default() - }, - texture: texture_handle.clone(), - color: Color::rgb(0.0, 0.0, 1.0).into(), - }), - transform: Transform::from_xyz(0.5, 0.5, coords.z), - ..Default::default() - }) + .spawn(( + DieWithStructure, + NotShadowCaster, + NotShadowReceiver, + Name::new("Z Axis - build mode"), + MaterialMeshBundle { + mesh: meshes.add(shape::Box::new(size as f32, size as f32, 0.001).into()), + material: materials.add(UnlitRepeatedMaterial { + repeats: Repeats { + horizontal: size as u32 / 4, + vertical: size as u32 / 4, + ..Default::default() + }, + texture: texture_handle.clone(), + color: Color::rgb(0.0, 0.0, 1.0).into(), + }), + transform: Transform::from_xyz(0.5, 0.5, coords.z), + ..Default::default() + }, + )) .id(), ); }); diff --git a/cosmos_client/src/universe/star.rs b/cosmos_client/src/universe/star.rs index bb02c9fb0..7453c851c 100644 --- a/cosmos_client/src/universe/star.rs +++ b/cosmos_client/src/universe/star.rs @@ -5,8 +5,8 @@ use std::f32::consts::PI; use bevy::{ pbr::NotShadowCaster, prelude::{ - shape, Added, App, Assets, Commands, DirectionalLight, DirectionalLightBundle, Entity, EulerRot, Mesh, OnEnter, PbrBundle, Quat, - Query, ResMut, StandardMaterial, Transform, Update, Vec3, With, Without, + shape, Added, App, Assets, Commands, DirectionalLight, DirectionalLightBundle, Entity, EulerRot, Mesh, Name, OnEnter, PbrBundle, + Quat, Query, ResMut, StandardMaterial, Transform, Update, Vec3, With, Without, }, }; use cosmos_core::{physics::location::SECTOR_DIMENSIONS, universe::star::Star}; @@ -62,19 +62,22 @@ fn create_added_star( /// There is only ever one light source for stars, it is just moved around as needed fn create_star_light_source(mut commands: Commands) { - commands.spawn(DirectionalLightBundle { - directional_light: DirectionalLight { - illuminance: 30000.0, - shadows_enabled: true, - ..Default::default() - }, - transform: Transform { - translation: Vec3::ZERO, - rotation: Quat::from_euler(EulerRot::XYZ, -PI / 4.0, 0.1, 0.1), + commands.spawn(( + Name::new("Star Light Emitter"), + DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: 30000.0, + shadows_enabled: true, + ..Default::default() + }, + transform: Transform { + translation: Vec3::ZERO, + rotation: Quat::from_euler(EulerRot::XYZ, -PI / 4.0, 0.1, 0.1), + ..Default::default() + }, ..Default::default() }, - ..Default::default() - }); + )); } pub(super) fn register(app: &mut App) { diff --git a/cosmos_core/src/structure/asteroid/asteroid_builder.rs b/cosmos_core/src/structure/asteroid/asteroid_builder.rs index b82e758ba..18744e4a0 100644 --- a/cosmos_core/src/structure/asteroid/asteroid_builder.rs +++ b/cosmos_core/src/structure/asteroid/asteroid_builder.rs @@ -1,6 +1,6 @@ //! Used to build an asteroid -use bevy::ecs::system::EntityCommands; +use bevy::{ecs::system::EntityCommands, prelude::Name}; use bevy_rapier3d::prelude::{RigidBody, Velocity}; use crate::{ @@ -36,6 +36,7 @@ impl TAsteroidBuilder for AsteroidBuilder { entity.insert(( Asteroid, + Name::new("Asteroid"), RigidBody::Fixed, LoadingDistance::new(ASTEROID_LOAD_RADIUS, ASTEROID_UNLOAD_RADIUS), )); diff --git a/cosmos_core/src/structure/ship/core.rs b/cosmos_core/src/structure/ship/core.rs index 7e53c8a8c..245066fc5 100644 --- a/cosmos_core/src/structure/ship/core.rs +++ b/cosmos_core/src/structure/ship/core.rs @@ -32,11 +32,17 @@ fn monitor_block_events(mut commands: Commands, blocks: Res>, mu } } +#[derive(Component)] +/// Marks a child of a structure as needing to be despawned when the structure itself is despawned. +/// +/// If something does not have this component and its parent ship is despawned, it will have its parent removed instead of being despawned. +pub struct DieWithStructure; + /// Makes sure that when the ship is despawned, only that ship is despawned and not /// any of the things docked to it (like the player walking on it) fn save_the_kids( query: Query<&Children, (With, With)>, - is_this_structure: Query<(), Or<(With, With)>>, + is_this_structure: Query<(), Or<(With, With, With)>>, mut commands: Commands, ) { for children in query.iter() { diff --git a/cosmos_server/src/physics/mod.rs b/cosmos_server/src/physics/mod.rs index 8773028c1..5925d50e1 100644 --- a/cosmos_server/src/physics/mod.rs +++ b/cosmos_server/src/physics/mod.rs @@ -47,7 +47,12 @@ pub fn assign_player_world( let world_id = rapier_context.add_world(RapierWorld::default()); let world_entity = commands - .spawn((PlayerWorld { player: player_entity }, *location, PhysicsWorld { world_id })) + .spawn(( + Name::new("Player World"), + PlayerWorld { player: player_entity }, + *location, + PhysicsWorld { world_id }, + )) .id(); commands @@ -108,7 +113,12 @@ fn move_players_between_worlds( let world_id = rapier_context.add_world(RapierWorld::default()); let world_entity = commands - .spawn((PlayerWorld { player: entity }, *location, PhysicsWorld { world_id })) + .spawn(( + Name::new("Player World"), + PlayerWorld { player: entity }, + *location, + PhysicsWorld { world_id }, + )) .id(); let (mut world_within, mut body_world) = world_within_query.get_mut(entity).unwrap();