diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 557858aad1..515a6982f3 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -7,9 +7,7 @@ use common::{ comp, msg::ServerMsg, npc::{get_npc_name, NpcKind}, - state::{TerrainChange, TimeOfDay}, - terrain::Block, - vol::Vox, + state::TimeOfDay, }; use specs::{Builder, Entity as EcsEntity, Join}; use vek::*; @@ -106,18 +104,6 @@ lazy_static! { "/players : Show the online players list", handle_players, ), - ChatCommand::new( - "solid", - "{}", - "/solid : Make the blocks around you solid", - handle_solid, - ), - ChatCommand::new( - "empty", - "{}", - "/empty : Make the blocks around you empty", - handle_empty, - ), ChatCommand::new( "help", "", "/help: Display this message", handle_help), ChatCommand::new( @@ -365,44 +351,6 @@ fn handle_players(server: &mut Server, entity: EcsEntity, _args: String, _action } } -fn handle_solid(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) { - match server.state.read_component_cloned::(entity) { - Some(current_pos) => { - server.state.ecs().write_resource::().set( - current_pos.0.map(|e| e.floor() as i32), - Block::new(1, Rgb::broadcast(255)), - ); - } - None => server.clients.notify( - entity, - ServerMsg::Chat(String::from("You have no position!")), - ), - } -} - -fn handle_empty(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) { - match server.state.read_component_cloned::(entity) { - Some(current_pos) => { - let mut terrain_change = server.state.ecs().write_resource::(); - - for i in -1..2 { - for j in -1..2 { - for k in -2..1 { - terrain_change.set( - current_pos.0.map(|e| e.floor() as i32) + Vec3::new(i, j, k), - Block::empty(), - ); - } - } - } - } - None => server.clients.notify( - entity, - ServerMsg::Chat(String::from("You have no position!")), - ), - } -} - fn handle_build(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) { match server.state.read_component_cloned::(entity) { Some(_build_perms) => { diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 289d39e30f..afa52093d0 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -118,8 +118,6 @@ impl PlayState for SessionState { .read_component_cloned::(client.entity()) { Some(_build_perms) => { - println!("Placing block"); - let (view_mat, _, cam_pos) = self.scene.camera().compute_dependents(&client); let cam_dir = @@ -132,9 +130,12 @@ impl PlayState for SessionState { (ray.0, if let Ok(Some(_)) = ray.1 { true } else { false }) }; - if b { - let pos = (cam_pos + cam_dir * d).map(|e| e.floor() as i32); - client.place_block(pos, Block::new(1, Rgb::broadcast(255))); // TODO: Handle block color with a command + if state { + if b { + let pos = (cam_pos + cam_dir * (d - 0.01)) + .map(|e| e.floor() as i32); + client.place_block(pos, Block::new(1, Rgb::broadcast(255))); // TODO: Handle block color with a command + } } } None => { @@ -152,13 +153,31 @@ impl PlayState for SessionState { } } Event::InputUpdate(GameInput::SecondAttack, state) => { - match self - .client - .borrow() + let mut client = self.client.borrow_mut(); + match client .state() - .read_component_cloned::(self.client.borrow().entity()) + .read_component_cloned::(client.entity()) { - Some(_build_perms) => {} + Some(_build_perms) => { + let (view_mat, _, cam_pos) = + self.scene.camera().compute_dependents(&client); + let cam_dir = + (self.scene.camera().get_focus_pos() - cam_pos).normalized(); + + let (d, b) = { + let terrain = client.state().terrain(); + let ray = + terrain.ray(cam_pos, cam_pos + cam_dir * 100.0).cast(); + (ray.0, if let Ok(Some(_)) = ray.1 { true } else { false }) + }; + + if state { + if b { + let pos = (cam_pos + cam_dir * d).map(|e| e.floor() as i32); + client.remove_block(pos); // TODO: Handle block color with a command + } + } + } None => { // TODO: Handle secondary attack here }