Fix bounds check on chunk functions

This commit is contained in:
Thinkofname 2016-04-03 15:42:54 +01:00
parent 74c507ec7e
commit 222c095d8c
1 changed files with 6 additions and 3 deletions

View File

@ -702,10 +702,11 @@ impl Chunk {
} }
fn set_block(&mut self, x: i32, y: i32, z: i32, b: block::Block) -> bool { fn set_block(&mut self, x: i32, y: i32, z: i32, b: block::Block) -> bool {
let s_idx = (y >> 4) as usize; let s_idx = y >> 4;
if s_idx < 0 || s_idx > 15 { if s_idx < 0 || s_idx > 15 {
return false; return false;
} }
let s_idx = s_idx as usize;
if self.sections[s_idx].is_none() { if self.sections[s_idx].is_none() {
if let block::Air {} = b { if let block::Air {} = b {
return false; return false;
@ -763,10 +764,11 @@ impl Chunk {
} }
fn set_block_light(&mut self, x: i32, y: i32, z: i32, light: u8) { fn set_block_light(&mut self, x: i32, y: i32, z: i32, light: u8) {
let s_idx = (y >> 4) as usize; let s_idx = y >> 4;
if s_idx < 0 || s_idx > 15 { if s_idx < 0 || s_idx > 15 {
return; return;
} }
let s_idx = s_idx as usize;
if self.sections[s_idx].is_none() { if self.sections[s_idx].is_none() {
if light == 0 { if light == 0 {
return; return;
@ -794,10 +796,11 @@ impl Chunk {
} }
fn set_sky_light(&mut self, x: i32, y: i32, z: i32, light: u8) { fn set_sky_light(&mut self, x: i32, y: i32, z: i32, light: u8) {
let s_idx = (y >> 4) as usize; let s_idx = y >> 4;
if s_idx < 0 || s_idx > 15 { if s_idx < 0 || s_idx > 15 {
return; return;
} }
let s_idx = s_idx as usize;
if self.sections[s_idx].is_none() { if self.sections[s_idx].is_none() {
if light == 15 { if light == 15 {
return; return;