From c20dbe17dd107bbbc77dde7d6aa59434332d6dd4 Mon Sep 17 00:00:00 2001 From: anomaluridae Date: Tue, 17 Aug 2021 22:48:47 -0700 Subject: [PATCH] build positions for place versus remove block are cleaner (less likely to fail) when apply the +0.01 modifier versus -0.01 modifier selectively. this is equivalent to current master, and is simply more explicit now --- voxygen/src/session/mod.rs | 5 +++-- voxygen/src/session/target.rs | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 48010786fb..fa53ad3810 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -494,9 +494,10 @@ impl PlayState for SessionState { if let Some(build_target) = build_target.filter(|bt| { state && can_build && is_nearest_target(shortest_dist, *bt) }) { - self.inputs.select_pos = Some(build_target.position); + let selected_pos = build_target.kind.0; + self.inputs.select_pos = Some(selected_pos); client.place_block( - build_target.position_int(), + selected_pos.map(|p| p.floor() as i32), self.selected_block, ); } else { diff --git a/voxygen/src/session/target.rs b/voxygen/src/session/target.rs index cef45106cf..39e6ecba82 100644 --- a/voxygen/src/session/target.rs +++ b/voxygen/src/session/target.rs @@ -20,7 +20,7 @@ pub struct Target { } #[derive(Clone, Copy, Debug)] -pub struct Build; +pub struct Build(pub Vec3); #[derive(Clone, Copy, Debug)] pub struct Collectable; @@ -99,7 +99,7 @@ pub(super) fn targets_under_cursor( let (mine_pos, _, mine_cam_ray) = is_mining .then(|| find_pos(|b: Block| b.mine_tool().is_some())) .unwrap_or((None, None, None)); - let (_, solid_pos, solid_cam_ray) = find_pos(|b: Block| b.is_solid()); + let (solid_pos, place_block_pos, solid_cam_ray) = find_pos(|b: Block| b.is_solid()); // Find shortest cam_dist of non-entity targets. // Note that some of these targets can technically be in Air, such as the @@ -196,11 +196,13 @@ pub(super) fn targets_under_cursor( }); let build_target = if can_build { - solid_pos.zip(solid_cam_ray).map(|(position, ray)| Target { - kind: Build, - distance: ray.0, - position, - }) + place_block_pos + .zip(solid_pos.zip(solid_cam_ray)) + .map(|(place_pos, (position, ray))| Target { + kind: Build(place_pos), + distance: ray.0, + position, + }) } else { None };