From 8472349caf1a993cc2ab69ad980fa82c78fd86b7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 12 Oct 2014 17:02:27 +0200 Subject: [PATCH] Improved global block cache --- src/pocketmine/entity/Entity.php | 9 ++++----- src/pocketmine/level/Explosion.php | 6 +++--- src/pocketmine/level/Level.php | 7 ++++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 9b615ee7de..4c3cce7d13 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -471,12 +471,11 @@ abstract class Entity extends Position implements Metadatable{ $this->justCreated = false; $isPlayer = $this instanceof Player; - if($this->dead === true and !$isPlayer){ - $this->close(); - Timings::$tickEntityTimer->stopTiming(); - return false; - }elseif($this->dead === true){ + if($this->dead === true){ $this->despawnFromAll(); + if(!$isPlayer){ + $this->close(); + } Timings::$tickEntityTimer->stopTiming(); return false; } diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 52cb6faae7..4db4486fc5 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -21,6 +21,7 @@ namespace pocketmine\level; +use pocketmine\block\Air; use pocketmine\block\Block; use pocketmine\block\TNT; use pocketmine\entity\Entity; @@ -98,10 +99,9 @@ class Explosion{ if($vBlock->y < 0 or $vBlock->y > 127){ break; } - $blockID = $this->level->getBlockIdAt($vBlock->x, $vBlock->y, $vBlock->z); + $block = $this->level->getBlock($vBlock); - if($blockID > 0){ - $block = Block::get($blockID, 0); + if(!($block instanceof Air)){ $block->x = $vBlock->x; $block->y = $vBlock->y; $block->z = $vBlock->z; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index e7ffd00048..e0bf52de0a 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -872,14 +872,15 @@ class Level implements ChunkManager, Metadatable{ * Gets the Block object on the Vector3 location * * @param Vector3 $pos + * @param boolean $cached * * @return Block */ - public function getBlock(Vector3 $pos){ + public function getBlock(Vector3 $pos, $cached = true){ $blockId = 0; $meta = 0; $index = "{$pos->x}:{$pos->y}:{$pos->z}"; - if(isset($this->blockCache[$index])){ + if($cached and isset($this->blockCache[$index])){ return $this->blockCache[$index]; }elseif($pos->y >= 0 and $pos->y < 128 and ($chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, true)) !== null){ $chunk->getBlock($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f, $blockId, $meta); @@ -891,7 +892,7 @@ class Level implements ChunkManager, Metadatable{ $air->y = $pos->y; $air->z = $pos->z; $air->level = $this; - return $air; + return $this->blockCache[$index] = $air; } return $this->blockCache[$index] = Block::get($blockId, $meta, new Position($pos->x, $pos->y, $pos->z, $this));