diff --git a/client/src/lib.rs b/client/src/lib.rs index 0dbc475509..6dad7944a1 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1420,8 +1420,8 @@ impl Client { } pub fn toggle_sprite_light(&mut self, pos: VolumePos, enable: bool) { - self.send_msg(ClientGeneral::ControlEvent( - ControlEvent::ToggleSpriteLight(pos, enable), + self.control_action(ControlAction::InventoryAction( + InventoryAction::ToggleSpriteLight(pos, enable), )); } diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 7c223267c4..285ca705e1 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -40,6 +40,9 @@ pub enum InventoryAction { Use(Slot), Sort, Collect(Vec3), + // TODO: Not actually inventory-related: refactor to allow sprite interaction without + // inventory manipulation! + ToggleSpriteLight(VolumePos, bool), } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -159,7 +162,6 @@ pub enum ControlEvent { new_ability: ability::AuxiliaryAbility, }, ActivatePortal(Uid), - ToggleSpriteLight(VolumePos, bool), } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/event.rs b/common/src/event.rs index 6597dad8ee..01d02d298c 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -340,7 +340,7 @@ pub enum ServerEvent { }, ToggleSpriteLight { entity: EcsEntity, - pos: VolumePos, + pos: Vec3, enable: bool, }, } diff --git a/common/src/states/sprite_interact.rs b/common/src/states/sprite_interact.rs index 004e08fa36..9acee5caec 100644 --- a/common/src/states/sprite_interact.rs +++ b/common/src/states/sprite_interact.rs @@ -117,8 +117,19 @@ impl CharacterBehavior for Data { sprite_pos: self.static_data.sprite_pos, required_item: inv_slot, }; - output_events - .emit_server(ServerEvent::InventoryManip(data.entity, inv_manip)); + + match self.static_data.sprite_kind { + SpriteInteractKind::ToggleLight(enable) => { + output_events.emit_server(ServerEvent::ToggleSpriteLight { + entity: data.entity, + pos: self.static_data.sprite_pos, + enable, + }) + }, + _ => output_events + .emit_server(ServerEvent::InventoryManip(data.entity, inv_manip)), + } + if matches!(self.static_data.sprite_kind, SpriteInteractKind::Unlock) { output_events.emit_local(LocalEvent::CreateOutcome( Outcome::SpriteUnlocked { diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 90b8b410e0..67958d22b4 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -20,6 +20,7 @@ use crate::{ }, consts::{FRIC_GROUND, GRAVITY, MAX_PICKUP_RANGE}, event::{LocalEvent, ServerEvent}, + mounting::Volume, outcome::Outcome, states::{behavior::JoinData, utils::CharacterState::Idle, *}, terrain::{Block, TerrainGrid, UnlockKind}, @@ -1140,6 +1141,29 @@ pub fn handle_manipulate_loadout( let inv_manip = InventoryManip::Use(slot); output_events.emit_server(ServerEvent::InventoryManip(data.entity, inv_manip)); }, + InventoryAction::ToggleSpriteLight(pos, enable) => { + if matches!(pos.kind, Volume::Terrain) { + let sprite_interact = sprite_interact::SpriteInteractKind::ToggleLight(enable); + + let (buildup_duration, use_duration, recover_duration) = + sprite_interact.durations(); + + update.character = CharacterState::SpriteInteract(sprite_interact::Data { + static_data: sprite_interact::StaticData { + buildup_duration, + use_duration, + recover_duration, + sprite_pos: pos.pos, + sprite_kind: sprite_interact, + was_wielded: data.character.is_wield(), + was_sneak: data.character.is_stealthy(), + required_item: None, + }, + timer: Duration::default(), + stage_section: StageSection::Buildup, + }); + } + }, } } diff --git a/common/src/terrain/sprite/magic.rs b/common/src/terrain/sprite/magic.rs index 9009cac475..113f281ca7 100644 --- a/common/src/terrain/sprite/magic.rs +++ b/common/src/terrain/sprite/magic.rs @@ -160,7 +160,7 @@ macro_rules! sprites { } #[inline] pub(super) fn to_initial_bytes(self) -> [u8; 3] { - let sprite_bytes = (*self as u32).to_be_bytes(); + let sprite_bytes = (self as u32).to_be_bytes(); let block = Block::from_raw(super::BlockKind::Air, [sprite_bytes[1], sprite_bytes[2], sprite_bytes[3]]); match self.category() { $(Category::$category_name => block$($(.with_attr($attr::default()).unwrap())*)?,)* diff --git a/common/systems/src/controller.rs b/common/systems/src/controller.rs index 81be3a3c14..9b6dec9ab2 100644 --- a/common/systems/src/controller.rs +++ b/common/systems/src/controller.rs @@ -140,13 +140,6 @@ impl<'a> System<'a> for Sys { server_emitter.emit(ServerEvent::StartTeleporting { entity, portal }); } }, - ControlEvent::ToggleSpriteLight(pos, enable) => { - server_emitter.emit(ServerEvent::ToggleSpriteLight { - entity, - pos, - enable, - }); - }, } } } diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index 9867de3322..c314c97b7c 100755 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -20,7 +20,7 @@ use common::{ }, event::EventBus, link::Is, - mounting::{Mount, Mounting, Rider, Volume, VolumeMounting, VolumePos, VolumeRider}, + mounting::{Mount, Mounting, Rider, VolumeMounting, VolumePos, VolumeRider}, outcome::Outcome, rtsim::RtSimEntity, terrain::{Block, SpriteKind}, @@ -473,23 +473,23 @@ pub fn handle_tame_pet(server: &mut Server, pet_entity: EcsEntity, owner_entity: pub fn handle_toggle_sprite_light( server: &mut Server, entity: EcsEntity, - pos: VolumePos, + pos: Vec3, enable: bool, ) { let state = server.state_mut(); // TODO: Implement toggling lights on volume entities if let Some(entity_pos) = state.ecs().read_storage::().get(entity) - && matches!(&pos.kind, Volume::Terrain) - && entity_pos.0.distance_squared(pos.pos.as_()) < MAX_INTERACT_RANGE.powi(2) - && state.can_set_block(pos.pos) + && entity_pos.0.distance_squared(pos.as_()) < MAX_INTERACT_RANGE.powi(2) + && state.can_set_block(pos) { if let Some(new_block) = state .terrain() - .get(pos.pos) + .get(pos) .ok() .and_then(|block| block.with_toggle_light(enable)) { - state.set_block(pos.pos, new_block); + state.set_block(pos, new_block); + // TODO: Emit outcome } } }