From 1a442b793cdf65578f9ab961d2583688760b0d66 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 30 Jul 2014 18:24:59 +0200 Subject: [PATCH] Fixed Tiles/Entities not using the correct chunk type --- src/pocketmine/entity/Entity.php | 7 ++++--- src/pocketmine/level/Level.php | 13 ++++++++++--- src/pocketmine/tile/Chest.php | 3 ++- src/pocketmine/tile/Furnace.php | 3 ++- src/pocketmine/tile/Sign.php | 3 ++- src/pocketmine/tile/Spawnable.php | 3 ++- src/pocketmine/tile/Tile.php | 3 ++- 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index a6ae3d7e9..4fe825b87 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -35,6 +35,7 @@ use pocketmine\event\entity\EntitySpawnEvent; use pocketmine\event\entity\EntityTeleportEvent; use pocketmine\event\Timings; use pocketmine\level\format\Chunk; +use pocketmine\level\format\FullChunk; use pocketmine\level\Level; use pocketmine\level\Position; use pocketmine\math\AxisAlignedBB; @@ -146,7 +147,7 @@ abstract class Entity extends Position implements Metadatable{ public $closed = false; - public function __construct(Chunk $chunk, Compound $nbt){ + public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk->getLevel() === null){ throw new \Exception("Invalid garbage Chunk given to Entity"); } @@ -932,7 +933,7 @@ abstract class Entity extends Position implements Metadatable{ if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) and $this->chunk->getZ() !== ($this->z >> 4))){ - if($this->chunk instanceof Chunk){ + if($this->chunk instanceof FullChunk){ $this->chunk->removeEntity($this); } $this->getLevel()->loadChunk($this->x >> 4, $this->z >> 4); @@ -1040,7 +1041,7 @@ abstract class Entity extends Position implements Metadatable{ if($this->closed === false){ $this->closed = true; unset(Entity::$needUpdate[$this->id]); - if($this->chunk instanceof Chunk){ + if($this->chunk instanceof FullChunk){ $this->chunk->removeEntity($this); } $this->getLevel()->removeEntity($this); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 2fb978586..216776db0 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -37,6 +37,7 @@ use pocketmine\event\LevelTimings; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\item\Item; use pocketmine\level\format\Chunk; +use pocketmine\level\format\FullChunk; use pocketmine\level\format\generic\EmptyChunkSection; use pocketmine\level\format\LevelProvider; use pocketmine\level\format\SimpleChunk; @@ -1309,6 +1310,12 @@ class Level implements ChunkManager, Metadatable{ } $blockIds = []; $data = []; + + if(!$this->useSections){ + //TODO + return new SimpleChunk($x, $z, 0); + } + for($Y = 0; $Y < 8; ++$Y){ $section = $chunk->getSection($Y); $blockIds[$Y] = $section->getIdArray(); @@ -1573,13 +1580,13 @@ class Level implements ChunkManager, Metadatable{ */ public function loadChunk($x, $z, $generate = true){ if($generate === true){ - return $this->getChunkAt($x, $z, true) instanceof Chunk; + return $this->getChunkAt($x, $z, true) instanceof FullChunk; } $this->cancelUnloadChunkRequest($x, $z); $chunk = $this->provider->getChunk($x, $z, false); - if($chunk instanceof Chunk){ + if($chunk instanceof FullChunk){ $this->chunks[Level::chunkHash($x, $z)] = $chunk; return true; }else{ @@ -1587,7 +1594,7 @@ class Level implements ChunkManager, Metadatable{ $this->provider->loadChunk($x, $z); $this->timings->syncChunkLoadTimer->stopTiming(); - if(($chunk = $this->provider->getChunk($x, $z)) instanceof Chunk){ + if(($chunk = $this->provider->getChunk($x, $z)) instanceof FullChunk){ $this->chunks[Level::chunkHash($x, $z)] = $chunk; return true; } diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 569188933..45af65308 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -26,6 +26,7 @@ use pocketmine\inventory\DoubleChestInventory; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; use pocketmine\level\format\Chunk; +use pocketmine\level\format\FullChunk; use pocketmine\math\Vector3 as Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; @@ -42,7 +43,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{ /** @var DoubleChestInventory */ protected $doubleInventory = null; - public function __construct(Chunk $chunk, Compound $nbt){ + public function __construct(FullChunk $chunk, Compound $nbt){ $nbt["id"] = Tile::CHEST; parent::__construct($chunk, $nbt); $this->inventory = new ChestInventory($this); diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 36d2faa3e..43d212010 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -27,6 +27,7 @@ use pocketmine\inventory\FurnaceRecipe; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; use pocketmine\level\format\Chunk; +use pocketmine\level\format\FullChunk; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; @@ -37,7 +38,7 @@ class Furnace extends Tile implements InventoryHolder, Container{ /** @var FurnaceInventory */ protected $inventory; - public function __construct(Chunk $chunk, Compound $nbt){ + public function __construct(FullChunk $chunk, Compound $nbt){ $nbt["id"] = Tile::FURNACE; parent::__construct($chunk, $nbt); $this->inventory = new FurnaceInventory($this); diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index 1d7ceee32..d0021dc98 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -22,13 +22,14 @@ namespace pocketmine\tile; use pocketmine\level\format\Chunk; +use pocketmine\level\format\FullChunk; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\String; class Sign extends Spawnable{ - public function __construct(Chunk $chunk, Compound $nbt){ + public function __construct(FullChunk $chunk, Compound $nbt){ $nbt["id"] = Tile::SIGN; if(!isset($nbt->Text1)){ $nbt->Text1 = new String("Text1", ""); diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 062bea682..e86387670 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -22,6 +22,7 @@ namespace pocketmine\tile; use pocketmine\level\format\Chunk; +use pocketmine\level\format\FullChunk; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Compound; use pocketmine\network\protocol\EntityDataPacket; @@ -48,7 +49,7 @@ abstract class Spawnable extends Tile{ public abstract function getSpawnCompound(); - public function __construct(Chunk $chunk, Compound $nbt){ + public function __construct(FullChunk $chunk, Compound $nbt){ parent::__construct($chunk, $nbt); $this->spawnToAll(); } diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index abbd68107..84d88ff3a 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -27,6 +27,7 @@ namespace pocketmine\tile; use pocketmine\event\Timings; use pocketmine\level\format\Chunk; +use pocketmine\level\format\FullChunk; use pocketmine\level\format\LevelProvider; use pocketmine\level\Position; use pocketmine\nbt\tag\Compound; @@ -62,7 +63,7 @@ abstract class Tile extends Position{ /** @var \pocketmine\event\TimingsHandler */ public $tickTimer; - public function __construct(Chunk $chunk, Compound $nbt){ + public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk->getLevel() === null){ throw new \Exception("Invalid garbage Chunk given to Tile"); }