Blocks now save their bounding box, fixed entity block collision check

This commit is contained in:
Shoghi Cervantes
2014-10-29 15:43:23 +01:00
parent 6f64af3066
commit 289bc56b4b
26 changed files with 64 additions and 30 deletions

View File

@ -35,7 +35,7 @@ class Bed extends Transparent{
$this->hardness = 1;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y,

View File

@ -528,6 +528,9 @@ class Block extends Position implements Metadatable{
public $z = 0;
public $frictionFactor = 0.6;
/** @var AxisAlignedBB */
protected $boundingBox = null;
public static function init(){
if(count(self::$list) === 0){
self::$list = [
@ -897,6 +900,17 @@ class Block extends Position implements Metadatable{
* @return AxisAlignedBB
*/
public function getBoundingBox(){
if($this->boundingBox !== null){
return $this->boundingBox;
}else{
return $this->boundingBox = $this->recalculateBoundingBox();
}
}
/**
* @return AxisAlignedBB
*/
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y,

View File

@ -42,7 +42,7 @@ class Cactus extends Transparent{
$this->hardness = 2;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x + 0.0625,

View File

@ -37,7 +37,7 @@ class Cake extends Transparent{
$this->hardness = 2.5;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = (1 + $this->getDamage() * 2) / 16;

View File

@ -53,7 +53,7 @@ class Carpet extends Flowable{
$this->isSolid = true;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -42,7 +42,7 @@ class Chest extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x + 0.0625,

View File

@ -52,7 +52,7 @@ abstract class Door extends Transparent{
return $first & 0x07 | ($flag ? 8 : 0) | ($flag1 ? 0x10 : 0);
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = 0.1875;
$damage = $this->getFullDamage();

View File

@ -29,7 +29,7 @@ class EndPortal extends Solid{
$this->hardness = 18000000;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -30,7 +30,7 @@ class Farmland extends Solid{
$this->hardness = 3;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -31,7 +31,7 @@ class Fence extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$flag = $this->canConnect($this->getSide(2));
$flag1 = $this->canConnect($this->getSide(3));

View File

@ -38,7 +38,7 @@ class FenceGate extends Transparent{
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->getDamage() & 0x04) > 0){
return null;

View File

@ -43,7 +43,7 @@ class Ladder extends Transparent{
$entity->onGround = true;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = 0.125;

View File

@ -47,7 +47,7 @@ class Slab extends Transparent{
$this->hardness = 30;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->meta & 0x08) > 0){
return AxisAlignedBB::getBoundingBoxFromPool(

View File

@ -30,7 +30,7 @@ class SoulSand extends Solid{
$this->hardness = 2.5;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -113,7 +113,7 @@ abstract class Stair extends Transparent{
}
*/
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->getDamage() & 0x04) > 0){
return AxisAlignedBB::getBoundingBoxFromPool(

View File

@ -36,7 +36,7 @@ class StoneWall extends Transparent{
$this->hardness = 30;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$flag = $this->canConnect($this->getSide(2));
$flag1 = $this->canConnect($this->getSide(3));

View File

@ -29,7 +29,7 @@ abstract class Thin extends Transparent{
public $isFullBlock = false;
public $isSolid = false;
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = 0.4375;
$f1 = 0.5625;

View File

@ -37,7 +37,7 @@ class Trapdoor extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$damage = $this->getDamage();

View File

@ -43,7 +43,7 @@ class Vine extends Transparent{
$entity->fallDistance = 0;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f1 = 1;
$f2 = 1;

View File

@ -45,7 +45,7 @@ class WoodSlab extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->meta & 0x08) > 0){
return AxisAlignedBB::getBoundingBoxFromPool(