mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Limit build mode to bounding box
This commit is contained in:
parent
eade0540b2
commit
120a0cd9a7
@ -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>>;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user