diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index cc6a870e1..8f7c6185f 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -26,6 +26,7 @@ use pocketmine\item\Item; use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\level\Level; use pocketmine\level\Position; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; use pocketmine\utils\Random; @@ -54,9 +55,8 @@ class Grass extends Solid{ $x = mt_rand($this->x - 1, $this->x + 1); $y = mt_rand($this->y - 2, $this->y + 2); $z = mt_rand($this->z - 1, $this->z + 1); - $block = $this->getLevel()->getBlockIdAt($x, $y, $z); - if($block === Block::DIRT){ - $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); + $block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); + if($block->getID() === Block::DIRT){ if($block->getSide(1) instanceof Transparent){ Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Grass())); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 6052f5157..5e0096112 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -25,6 +25,7 @@ use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\level\Position; +use pocketmine\math\Vector3; use pocketmine\Server; class Mycelium extends Solid{ @@ -45,9 +46,8 @@ class Mycelium extends Solid{ $x = mt_rand($this->x - 1, $this->x + 1); $y = mt_rand($this->y - 2, $this->y + 2); $z = mt_rand($this->z - 1, $this->z + 1); - $block = $this->getLevel()->getBlockIdAt($x, $y, $z); - if($block === Block::DIRT){ - $block = Block::get($block, $this->getLevel()->getBlockDataAt($x, $y, $z), Position::createPosition($x, $y, $z, $this->getLevel())); + $block = $this->getLevel()->getBlock(Vector3::createVector($x, $y, $z)); + if($block->getID() === Block::DIRT){ if($block->getSide(1) instanceof Transparent){ Server::getInstance()->getPluginManager()->callEvent($ev = BlockSpreadEvent::createEvent($block, $this, new Mycelium())); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index ac77d4093..b65a397df 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -424,15 +424,17 @@ abstract class Entity extends Location implements Metadatable{ $list = $this->level->getCollisionBlocks($this->boundingBox); - if(count($list) === 0 and !$this->level->isFullBlock(Vector3::createVector($i, $j, $k))){ + $v = Vector3::createVector($i, $j, $k); + + if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){ return false; }else{ - $flag = !$this->level->isFullBlock(Vector3::createVector($i - 1, $j, $k)); - $flag1 = !$this->level->isFullBlock(Vector3::createVector($i + 1, $j, $k)); - //$flag2 = !$this->level->isFullBlock(Vector3::createVector($i, $j - 1, $k)); - $flag3 = !$this->level->isFullBlock(Vector3::createVector($i, $j + 1, $k)); - $flag4 = !$this->level->isFullBlock(Vector3::createVector($i, $j, $k - 1)); - $flag5 = !$this->level->isFullBlock(Vector3::createVector($i, $j, $k + 1)); + $flag = !$this->level->isFullBlock($v->setComponents($i - 1, $j, $k)); + $flag1 = !$this->level->isFullBlock($v->setComponents($i + 1, $j, $k)); + //$flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k)); + $flag3 = !$this->level->isFullBlock($v->setComponents($i, $j + 1, $k)); + $flag4 = !$this->level->isFullBlock($v->setComponents($i, $j, $k - 1)); + $flag5 = !$this->level->isFullBlock($v->setComponents($i, $j, $k + 1)); $direction = 3; //UP! $limit = 9999; @@ -782,10 +784,10 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfWater(){ - $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); + $block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); if($block instanceof Water){ - $f = ($pos->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); + $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); return $y < $f; } @@ -793,7 +795,7 @@ abstract class Entity extends Location implements Metadatable{ } public function isInsideOfSolid(){ - $block = $this->level->getBlock($pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); + $block = $this->level->getBlock(Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z)->floor()); $bb = $block->getBoundingBox(); @@ -816,8 +818,7 @@ abstract class Entity extends Location implements Metadatable{ if($this->keepMovement){ $this->boundingBox->offset($dx, $dy, $dz); - $pos = Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2); - $this->setPosition($pos); + $this->setPosition(Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); $this->onGround = $this instanceof Player ? true : false; }else{ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 232590831..6279f3f42 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -176,7 +176,10 @@ class Level implements ChunkManager, Metadatable{ private $useSections; private $blockOrder; + /** @var Position */ private $temporalPosition; + /** @var Vector3 */ + private $temporalVector; protected $chunkTickRadius; protected $chunkTickList = []; @@ -270,6 +273,7 @@ class Level implements ChunkManager, Metadatable{ $this->timings = new LevelTimings($this); $this->temporalPosition = new Position(0, 0, 0, $this); + $this->temporalVector = new Vector3(0, 0, 0); } public function initLevel(){ @@ -746,7 +750,7 @@ class Level implements ChunkManager, Metadatable{ $collides = []; - $v = Vector3::createVector(0, 0, 0); + $v = $this->temporalVector; for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ for($v->x = $minX; $v->x < $maxX; ++$v->x){ @@ -793,7 +797,7 @@ class Level implements ChunkManager, Metadatable{ $maxZ = Math::floorFloat($bb->maxZ + 1); $collides = []; - $v = Vector3::createVector(0, 0, 0); + $v = $this->temporalVector; for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ for($v->x = $minX; $v->x < $maxX; ++$v->x){ diff --git a/src/pocketmine/math/AxisAlignedBB.php b/src/pocketmine/math/AxisAlignedBB.php index bb233da62..c871036b2 100644 --- a/src/pocketmine/math/AxisAlignedBB.php +++ b/src/pocketmine/math/AxisAlignedBB.php @@ -101,39 +101,36 @@ class AxisAlignedBB{ } public function addCoord($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); + $minX = $this->minX; + $minY = $this->minY; + $minZ = $this->minZ; + $maxX = $this->maxX; + $maxY = $this->maxY; + $maxZ = $this->maxZ; if($x < 0){ - $vec->minX += $x; + $minX += $x; }elseif($x > 0){ - $vec->maxX += $x; + $maxX += $x; } if($y < 0){ - $vec->minY += $y; + $minY += $y; }elseif($y > 0){ - $vec->maxY += $y; + $maxY += $y; } if($z < 0){ - $vec->minZ += $z; + $minZ += $z; }elseif($z > 0){ - $vec->maxZ += $z; + $maxZ += $z; } - return $vec; + return self::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ); } public function grow($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); - $vec->minX -= $x; - $vec->minY -= $y; - $vec->minZ -= $z; - $vec->maxX += $x; - $vec->maxY += $y; - $vec->maxZ += $z; - - return $vec; + return self::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function expand($x, $y, $z){ @@ -159,15 +156,7 @@ class AxisAlignedBB{ } public function shrink($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); - $vec->minX += $x; - $vec->minY += $y; - $vec->minZ += $z; - $vec->maxX -= $x; - $vec->maxY -= $y; - $vec->maxZ -= $z; - - return $vec; + return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z); } public function contract($x, $y, $z){ @@ -192,15 +181,7 @@ class AxisAlignedBB{ } public function getOffsetBoundingBox($x, $y, $z){ - $vec = self::cloneBoundingBoxFromPool($this); - $vec->minX += $x; - $vec->minY += $y; - $vec->minZ += $z; - $vec->maxX += $x; - $vec->maxY += $y; - $vec->maxZ += $z; - - return $vec; + return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z); } public function calculateXOffset(AxisAlignedBB $bb, $x){ diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index 1c1abfcd5..3384c5bc5 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -21,10 +21,6 @@ namespace pocketmine\math; -/** - * WARNING: This class is available on the PocketMine-MP Zephir project. - * If this class is modified, remember to modify the PHP C extension. - */ class Vector3{ /** @var Vector3[] */ @@ -76,6 +72,11 @@ class Vector3{ return self::$vectorList[self::$nextVector++]->setComponents($x, $y, $z); } + /** + * @param Vector3 $vector + * + * @return Vector3 + */ public static function cloneVector(Vector3 $vector){ if(self::$nextVector >= count(self::$vectorList)){ self::$vectorList[] = new Vector3(0, 0, 0);