Limit build mode to bounding box

This commit is contained in:
Louis Pearson 2021-03-23 04:26:43 -06:00
parent eade0540b2
commit 120a0cd9a7
4 changed files with 11 additions and 8 deletions

View File

@ -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<i32>,
}
impl Component for CanBuild {
type Storage = DerefFlaggedStorage<Self, IdvStorage<Self>>;

View File

@ -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::<comp::CanBuild>()
.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,

View File

@ -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);
}
}

View File

@ -317,10 +317,7 @@ impl PlayState for SessionState {
.state()
.read_storage::<comp::CanBuild>()
.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