diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index a3f3c79f8..9819fe2c9 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -268,7 +268,7 @@ class Block extends Position implements Metadatable{ protected $meta = 0; /** @var AxisAlignedBB */ - protected $boundingBox = null; + public $boundingBox = null; /** * Backwards-compatibility with old way to define block properties @@ -724,11 +724,11 @@ class Block extends Position implements Metadatable{ * @return array */ public function getDrops(Item $item){ - if(!isset(self::$list[$this->id])){ //Unknown blocks + if(!isset(self::$list[$this->getId()])){ //Unknown blocks return []; }else{ return [ - [$this->id, $this->meta, 1], + [$this->getId(), $this->getDamage(), 1], ]; } } @@ -764,20 +764,20 @@ class Block extends Position implements Metadatable{ * @return string */ public function __toString(){ - return "Block[" . $this->getName() . "] (" . $this->id . ":" . $this->meta . ")"; + return "Block[" . $this->getName() . "] (" . $this->getId() . ":" . $this->getDamage() . ")"; } /** * Checks for collision against an AxisAlignedBB * * @param AxisAlignedBB $bb - * @param Block[] $list + * + * @return bool */ - public function collidesWithBB(AxisAlignedBB $bb, &$list = []){ + public function collidesWithBB(AxisAlignedBB $bb){ $bb2 = $this->getBoundingBox(); - if($bb2 !== null and $bb->intersectsWith($bb2)){ - $list[] = $bb2; - } + + return $bb2 !== null and $bb->intersectsWith($bb2); } /** diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 68078aee4..96119c2d7 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -236,13 +236,13 @@ abstract class Door extends Transparent{ $next = $this->getSide($face[(($direction + 2) % 4)]); $next2 = $this->getSide($face[$direction]); $metaUp = 0x08; - if($next->getId() === $this->id or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge + if($next->getId() === $this->getId() or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge $metaUp |= 0x01; } - $this->meta = $player->getDirection() & 0x03; + $this->setDamage($player->getDirection() & 0x03); $this->getLevel()->setBlock($block, $this, true, true); //Bottom - $this->getLevel()->setBlock($blockUp, $b = Block::get($this->id, $metaUp), true); //Top + $this->getLevel()->setBlock($blockUp, $b = Block::get($this->getId(), $metaUp), true); //Top return true; } @@ -250,14 +250,14 @@ abstract class Door extends Transparent{ } public function onBreak(Item $item){ - if(($this->meta & 0x08) === 0x08){ + if(($this->getDamage() & 0x08) === 0x08){ $down = $this->getSide(0); - if($down->getId() === $this->id){ + if($down->getId() === $this->getId()){ $this->getLevel()->setBlock($down, new Air(), true); } }else{ $up = $this->getSide(1); - if($up->getId() === $this->id){ + if($up->getId() === $this->getId()){ $this->getLevel()->setBlock($up, new Air(), true); } } @@ -267,11 +267,11 @@ abstract class Door extends Transparent{ } public function onActivate(Item $item, Player $player = null){ - if(($this->meta & 0x08) === 0x08){ //Top + if(($this->getDamage() & 0x08) === 0x08){ //Top $down = $this->getSide(0); - if($down->getId() === $this->id){ + if($down->getId() === $this->getId()){ $meta = $down->getDamage() ^ 0x04; - $this->getLevel()->setBlock($down, Block::get($this->id, $meta), true); + $this->getLevel()->setBlock($down, Block::get($this->getId(), $meta), true); $players = $this->getLevel()->getChunkPlayers($this->x >> 4, $this->z >> 4); if($player instanceof Player){ unset($players[$player->getLoaderId()]); diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index bba0bba77..e7c4e6410 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -310,7 +310,7 @@ abstract class Liquid extends Transparent{ $this->getLevel()->useBreakOn($block); } - $this->getLevel()->setBlock($block, Block::get($this->id, $newFlowDecay), true); + $this->getLevel()->setBlock($block, Block::get($this->getId(), $newFlowDecay), true); $this->getLevel()->scheduleUpdate($block, $this->tickRate()); } } diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index f29caff5a..016bda4ce 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -149,7 +149,7 @@ abstract class Stair extends Transparent{ public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return [ - [$this->id, 0, 1], + [$this->getId(), 0, 1], ]; }else{ return []; diff --git a/src/pocketmine/command/defaults/GarbageCollectorCommand.php b/src/pocketmine/command/defaults/GarbageCollectorCommand.php index bbb63ccd6..6794e83d6 100644 --- a/src/pocketmine/command/defaults/GarbageCollectorCommand.php +++ b/src/pocketmine/command/defaults/GarbageCollectorCommand.php @@ -54,6 +54,7 @@ class GarbageCollectorCommand extends VanillaCommand{ $chunksCollected += $diff[0] - count($level->getChunks()); $entitiesCollected += $diff[1] - count($level->getEntities()); $tilesCollected += $diff[2] - count($level->getTiles()); + $level->clearCache(true); } $cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector(); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index dbd9a996e..fb925c59f 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1246,6 +1246,7 @@ abstract class Entity extends Location implements Metadatable{ if($this instanceof Player){ if(!$this->onGround or $movY != 0){ $bb = clone $this->boundingBox; + $bb->maxY = $bb->minY + 0.5; $bb->minY -= 1; if(count($this->level->getCollisionBlocks($bb)) > 0){ $this->onGround = true; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 8dd8961b6..456702f49 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -786,9 +786,18 @@ class Level implements ChunkManager, Metadatable{ public function clearCache($full = false){ if($full){ $this->chunkCache = []; + $this->blockCache = []; + }else{ + if(count($this->chunkCache) > 1024){ + $this->chunkCache = []; + } + + if(count($this->blockCache) > 65535){ + $this->chunkCache = []; + } + } - $this->blockCache = []; } private function tickChunks(){ @@ -992,14 +1001,12 @@ class Level implements ChunkManager, Metadatable{ $collides = []; - $v = $this->temporalVector; - - for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ - for($v->x = $minX; $v->x <= $maxX; ++$v->x){ - for($v->y = $minY - 1; $v->y <= $maxY; ++$v->y){ - $block = $this->getBlock($v); - if($block->getId() !== 0){ - $block->collidesWithBB($bb, $collides); + for($z = $minZ; $z <= $maxZ; ++$z){ + for($x = $minX; $x <= $maxX; ++$x){ + for($y = $minY; $y <= $maxY; ++$y){ + $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z)); + if($block->getId() !== 0 and $block->collidesWithBB($bb)){ + $collides[] = $block; } } } @@ -1039,14 +1046,13 @@ class Level implements ChunkManager, Metadatable{ $maxZ = Math::ceilFloat($bb->maxZ); $collides = []; - $v = $this->temporalVector; - for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ - for($v->x = $minX; $v->x <= $maxX; ++$v->x){ - for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){ - $block = $this->getBlock($v); - if($block->getId() !== 0){ - $block->collidesWithBB($bb, $collides); + for($z = $minZ; $z <= $maxZ; ++$z){ + for($x = $minX; $x <= $maxX; ++$x){ + for($y = $minY; $y <= $maxY; ++$y){ + $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z)); + if($block->getId() !== 0 and $block->collidesWithBB($bb)){ + $collides[] = $block->getBoundingBox(); } } }