diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index b9fb1e060..fccd98fcc 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -36,7 +36,11 @@ class Bed extends Transparent{ } public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index d53602eb0..d7ca18d93 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -513,6 +513,7 @@ class Block extends Position implements Metadatable{ protected $name = "Unknown"; protected $breakTime = 0.20; protected $hardness = 10; + protected $boundingBox = null; public $hasEntityCollision = false; public $isActivable = false; public $breakable = true; @@ -820,6 +821,7 @@ class Block extends Position implements Metadatable{ $this->y = (int) $v->y; $this->z = (int) $v->z; $this->level = $v->level; + $this->boundingBox = null; } /** @@ -898,7 +900,11 @@ class Block extends Position implements Metadatable{ * @return AxisAlignedBB */ public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 9d2b1e401..e2eaa2d06 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -43,7 +43,11 @@ class Cactus extends Transparent{ } public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x + 0.0625, $this->y, $this->z + 0.0625, diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index bd7e5145c..0f98dc373 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -38,9 +38,13 @@ class Cake extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $f = (1 + $this->getDamage() * 2) / 16; - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x + $f, $this->y, $this->z + 0.0625, diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 1786ce36a..dc51e0e63 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -54,7 +54,11 @@ class Carpet extends Flowable{ } public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index c127ed952..d053f4d1b 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -43,7 +43,11 @@ class Chest extends Transparent{ } public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x + 0.0625, $this->y, $this->z + 0.0625, diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 88db0adf6..a28598740 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -53,6 +53,10 @@ abstract class Door extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $f = 0.1875; $damage = $this->getFullDamage(); @@ -195,7 +199,7 @@ abstract class Door extends Transparent{ } } - return $bb; + return $this->boundingBox = $bb; } public function onUpdate($type){ diff --git a/src/pocketmine/block/EndPortal.php b/src/pocketmine/block/EndPortal.php index 7a12da12a..46eaefeb6 100644 --- a/src/pocketmine/block/EndPortal.php +++ b/src/pocketmine/block/EndPortal.php @@ -30,7 +30,11 @@ class EndPortal extends Solid{ } public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 49c3217c1..ec170171a 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -31,7 +31,11 @@ class Farmland extends Solid{ } public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index aff403b33..5ff6694b0 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -32,6 +32,10 @@ class Fence extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $flag = $this->canConnect($this->getSide(2)); $flag1 = $this->canConnect($this->getSide(3)); $flag2 = $this->canConnect($this->getSide(4)); @@ -42,7 +46,7 @@ class Fence extends Transparent{ $f2 = $flag ? 0 : 0.375; $f3 = $flag1 ? 1 : 0.625; - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x + $f, $this->y, $this->z + $f2, diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 9e144b55c..2d8f6a235 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -39,13 +39,17 @@ class FenceGate extends Transparent{ public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + if(($this->getDamage() & 0x04) > 0){ return null; } $i = ($this->getDamage() & 0x03); if($i === 2 and $i === 0){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z + 0.375, @@ -54,7 +58,7 @@ class FenceGate extends Transparent{ $this->z + 0.625 ); }else{ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x + 0.375, $this->y, $this->z, diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index 71cf358a0..3ce78534e 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -44,10 +44,14 @@ class Ladder extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $f = 0.125; if($this->meta === 2){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z + 1 - $f, @@ -56,7 +60,7 @@ class Ladder extends Transparent{ $this->z + 1 ); }elseif($this->meta === 3){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, @@ -65,7 +69,7 @@ class Ladder extends Transparent{ $this->z + $f ); }elseif($this->meta === 4){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x + 1 - $f, $this->y, $this->z, @@ -74,7 +78,7 @@ class Ladder extends Transparent{ $this->z + 1 ); }elseif($this->meta === 5){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index b1bcbadb6..726844205 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -36,10 +36,6 @@ class Lava extends Liquid{ $this->hardness = 0; } - public function getBoundingBox(){ - return null; - } - public function onEntityCollide(Entity $entity){ $entity->fallDistance *= 0.5; $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index 4813f4aaf..96c173939 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -414,4 +414,8 @@ abstract class Liquid extends Transparent{ } } } + + public function getBoundingBox(){ + return null; + } } \ No newline at end of file diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 76137e929..241f62d80 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -48,8 +48,12 @@ class Slab extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + if(($this->meta & 0x08) > 0){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y + 0.5, $this->z, @@ -58,7 +62,7 @@ class Slab extends Transparent{ $this->z + 1 ); }else{ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/SoulSand.php b/src/pocketmine/block/SoulSand.php index 9e4f6cd71..cde302304 100644 --- a/src/pocketmine/block/SoulSand.php +++ b/src/pocketmine/block/SoulSand.php @@ -31,7 +31,11 @@ class SoulSand extends Solid{ } public function getBoundingBox(){ - return new AxisAlignedBB( + if($this->boundingBox !== null){ + return $this->boundingBox; + } + + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index f84a0d9e9..74afea529 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -114,8 +114,12 @@ abstract class Stair extends Transparent{ */ public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + if(($this->getDamage() & 0x04) > 0){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y + 0.5, $this->z, @@ -124,7 +128,7 @@ abstract class Stair extends Transparent{ $this->z + 1 ); }else{ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z, diff --git a/src/pocketmine/block/StillLava.php b/src/pocketmine/block/StillLava.php index 978d0db15..57195c2ac 100644 --- a/src/pocketmine/block/StillLava.php +++ b/src/pocketmine/block/StillLava.php @@ -27,8 +27,4 @@ class StillLava extends Lava{ $this->hardness = 500; } - public function getBoundingBox(){ - return null; - } - } \ No newline at end of file diff --git a/src/pocketmine/block/StoneWall.php b/src/pocketmine/block/StoneWall.php index 23f758c97..8abf9688a 100644 --- a/src/pocketmine/block/StoneWall.php +++ b/src/pocketmine/block/StoneWall.php @@ -37,6 +37,10 @@ class StoneWall extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $flag = $this->canConnect($this->getSide(2)); $flag1 = $this->canConnect($this->getSide(3)); $flag2 = $this->canConnect($this->getSide(4)); @@ -58,7 +62,7 @@ class StoneWall extends Transparent{ $f3 = 0.6875; } - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x + $f, $this->y, $this->z + $f2, diff --git a/src/pocketmine/block/Thin.php b/src/pocketmine/block/Thin.php index 3ee911a14..dd621ec7a 100644 --- a/src/pocketmine/block/Thin.php +++ b/src/pocketmine/block/Thin.php @@ -30,6 +30,10 @@ abstract class Thin extends Transparent{ public $isSolid = false; public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $f = 0.4375; $f1 = 0.5625; $f2 = 0.4375; @@ -62,7 +66,7 @@ abstract class Thin extends Transparent{ $f3 = 1; } - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x + $f, $this->y, $this->z + $f2, diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 71719bb61..d6093df8c 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -38,6 +38,10 @@ class Trapdoor extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $damage = $this->getDamage(); $f = 0.1875; @@ -104,7 +108,7 @@ class Trapdoor extends Transparent{ } } - return $bb; + return $this->boundingBox = $bb; } public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index d7b2e5ba3..f58196204 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -44,6 +44,10 @@ class Vine extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + $f1 = 1; $f2 = 1; $f3 = 1; @@ -92,7 +96,7 @@ class Vine extends Transparent{ $f6 = 1; } - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x + $f1, $this->y + $f2, $this->z + $f3, diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 1881a0e0f..e80d1e3a4 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -30,10 +30,6 @@ class Water extends Liquid{ parent::__construct(self::WATER, $meta, "Water"); $this->hardness = 500; } - - public function getBoundingBox(){ - return null; - } public function onEntityCollide(Entity $entity){ $entity->fallDistance = 0; diff --git a/src/pocketmine/block/WoodSlab.php b/src/pocketmine/block/WoodSlab.php index 73e180adf..e3d38d964 100644 --- a/src/pocketmine/block/WoodSlab.php +++ b/src/pocketmine/block/WoodSlab.php @@ -46,8 +46,12 @@ class WoodSlab extends Transparent{ } public function getBoundingBox(){ + if($this->boundingBox !== null){ + return $this->boundingBox; + } + if(($this->meta & 0x08) > 0){ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y + 0.5, $this->z, @@ -56,7 +60,7 @@ class WoodSlab extends Transparent{ $this->z + 1 ); }else{ - return new AxisAlignedBB( + return $this->boundingBox = new AxisAlignedBB( $this->x, $this->y, $this->z,