diff --git a/common/src/comp/inputs.rs b/common/src/comp/inputs.rs index 2590aef4b6..81ea5e4f39 100644 --- a/common/src/comp/inputs.rs +++ b/common/src/comp/inputs.rs @@ -1,10 +1,12 @@ use serde::{Deserialize, Serialize}; use specs::{Component, DerefFlaggedStorage}; use specs_idvs::IdvStorage; +use vek::geom::Aabb; #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct CanBuild { pub building_is_on: bool, + pub build_area: Aabb, } impl Component for CanBuild { type Storage = DerefFlaggedStorage>; diff --git a/server/src/cmd.rs b/server/src/cmd.rs index f1e7deff02..93179389dd 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1124,7 +1124,7 @@ fn handle_permit_build( args: String, action: &ChatCommand, ) { - if let (Some(target_alias), xlo_opt, xhi_opt, ylo_opt, yhi_opt, zlo_opt, zhi_opt) = scan_fmt_some!( + if let (Some(target_alias), Some(xlo), Some(xhi), Some(ylo), Some(yhi), Some(zlo), Some(zhi)) = scan_fmt_some!( &args, &action.arg_fmt(), String, @@ -1161,6 +1161,10 @@ fn handle_permit_build( ecs.write_storage::() .insert(target_player, comp::CanBuild { building_is_on: false, + build_area: Aabb { + min: Vec3::new(xlo, ylo, zlo), + max: Vec3::new(xhi, yhi, zhi), + }, }); server.notify_client( client, diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index 8dec535bef..ea5561bb64 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -103,8 +103,8 @@ impl Sys { }, ClientGeneral::BreakBlock(pos) => { if let Some(comp_can_build) = can_build.get(entity) { - if comp_can_build.building_is_on { - if let Some(block) = terrain.get(pos).ok() { + if comp_can_build.building_is_on && comp_can_build.build_area.contains_point(pos) { + if let Ok(block) = terrain.get(pos) { block_changes.set(pos, block.into_vacant()); } } @@ -112,7 +112,7 @@ impl Sys { }, ClientGeneral::PlaceBlock(pos, block) => { if let Some(comp_can_build) = can_build.get(entity) { - if comp_can_build.building_is_on { + if comp_can_build.building_is_on && comp_can_build.build_area.contains_point(pos) { block_changes.try_set(pos, block); } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index c20a66e555..016219eb17 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -317,10 +317,7 @@ impl PlayState for SessionState { .state() .read_storage::() .get(player_entity) - .unwrap_or_else(|| &comp::CanBuild { - building_is_on: false, - }) - .building_is_on; + .map_or_else(|| false, |cb| cb.building_is_on); let is_mining = self .client