From 3b10613f984c7e1ced173d073481ae2d918cae66 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Mon, 14 Jan 2013 17:13:53 +0100 Subject: [PATCH] Corrected block placement area --- src/classes/math/Vector3.php | 8 ++++++++ src/classes/world/Entity.php | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/classes/math/Vector3.php b/src/classes/math/Vector3.php index 9c76c5c0..4e6d5eca 100644 --- a/src/classes/math/Vector3.php +++ b/src/classes/math/Vector3.php @@ -132,6 +132,14 @@ class Vector3{ return pow($this->x - $x, 2) + pow($this->y - $y, 2) + pow($this->z - $z, 2); } } + + public function maxPlainDistance($x = 0, $z = 0){ + if(($x instanceof Vector3) === true){ + return $this->maxPlainDistance($x->x, $x->z); + }else{ + return max(abs($this->x - $x), abs($this->z - $z)); + } + } public function __toString(){ return "Vector3(x=".$this->x.",y=".$this->y.",z=".$this->z.")"; diff --git a/src/classes/world/Entity.php b/src/classes/world/Entity.php index 31290593..90f208ea 100644 --- a/src/classes/world/Entity.php +++ b/src/classes/world/Entity.php @@ -232,8 +232,7 @@ class Entity extends stdClass{ public function inBlock($x, $y, $z){ $block = new Vector3($x + 0.5, $y, $z + 0.5); $me = new Vector3($this->x, $this->y, $this->z); - $up = new Vector3($this->x, $this->y + 1, $this->z); - if($block->distance($me) < 0.8 or $block->distance($up) < 0.8){ + if(($y == ((int) $this->y) or $y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < 0.8){ return true; } return false;