Updated Levels :D

This commit is contained in:
Shoghi Cervantes
2014-06-09 11:35:52 +02:00
parent 920e2a7c7e
commit 115b4cf4ac
41 changed files with 1492 additions and 270 deletions

View File

@ -25,6 +25,7 @@ use pocketmine\inventory\ChestInventory;
use pocketmine\inventory\DoubleChestInventory;
use pocketmine\inventory\InventoryHolder;
use pocketmine\item\Item;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\math\Vector3 as Vector3;
use pocketmine\nbt\NBT;
@ -44,9 +45,9 @@ class Chest extends Spawnable implements InventoryHolder, Container{
/** @var DoubleChestInventory */
protected $doubleInventory = null;
public function __construct(Level $level, Compound $nbt){
public function __construct(Chunk $chunk, Compound $nbt){
$nbt["id"] = Tile::CHEST;
parent::__construct($level, $nbt);
parent::__construct($chunk, $nbt);
$this->inventory = new ChestInventory($this);
for($i = 0; $i < $this->getSize(); ++$i){
$this->inventory->setItem($i, $this->getItem($i));

View File

@ -26,9 +26,22 @@ use pocketmine\item\Item;
use pocketmine\Network;
interface Container{
/**
* @param int $index
*
* @return Item
*/
public function getItem($index);
/**
* @param int $index
* @param Item $item
*/
public function setItem($index, Item $item);
/**
* @return int
*/
public function getSize();
}

View File

@ -26,6 +26,7 @@ use pocketmine\inventory\FurnaceInventory;
use pocketmine\inventory\FurnaceRecipe;
use pocketmine\inventory\InventoryHolder;
use pocketmine\item\Item;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte;
@ -37,9 +38,9 @@ class Furnace extends Tile implements InventoryHolder, Container{
/** @var FurnaceInventory */
protected $inventory;
public function __construct(Level $level, Compound $nbt){
public function __construct(Chunk $chunk, Compound $nbt){
$nbt["id"] = Tile::FURNACE;
parent::__construct($level, $nbt);
parent::__construct($chunk, $nbt);
$this->inventory = new FurnaceInventory($this);
for($i = 0; $i < $this->getSize(); ++$i){
$this->inventory->setItem($i, $this->getItem($i));

View File

@ -21,6 +21,7 @@
namespace pocketmine\tile;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
@ -31,9 +32,9 @@ use pocketmine\Player;
class Sign extends Spawnable{
public function __construct(Level $level, Compound $nbt){
public function __construct(Chunk $chunk, Compound $nbt){
$nbt["id"] = Tile::SIGN;
parent::__construct($level, $nbt);
parent::__construct($chunk, $nbt);
}
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
@ -42,7 +43,6 @@ class Sign extends Spawnable{
$this->namedtag->Text3 = $line3;
$this->namedtag->Text4 = $line4;
$this->spawnToAll();
$this->server->handle("tile.update", $this);
return true;
}

View File

@ -21,6 +21,7 @@
namespace pocketmine\tile;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\nbt\tag\Compound;
use pocketmine\Player;
@ -28,8 +29,8 @@ use pocketmine\Player;
abstract class Spawnable extends Tile{
public abstract function spawnTo(Player $player);
public function __construct(Level $level, Compound $nbt){
parent::__construct($level, $nbt);
public function __construct(Chunk $chunk, Compound $nbt){
parent::__construct($chunk, $nbt);
$this->spawnToAll();
}

View File

@ -25,11 +25,10 @@
*/
namespace pocketmine\tile;
use pocketmine\level\format\pmf\LevelFormat;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\nbt\tag\Compound;
use pocketmine\Server;
abstract class Tile extends Position{
const SIGN = "Sign";
@ -45,7 +44,8 @@ abstract class Tile extends Position{
*/
public static $needUpdate = [];
public $chunkIndex;
/** @var Chunk */
public $chunk;
public $name;
public $id;
public $x;
@ -63,9 +63,10 @@ abstract class Tile extends Position{
}
public function __construct(Level $level, Compound $nbt){
$this->server = Server::getInstance();
$this->setLevel($level, true); //Strong reference
public function __construct(Chunk $chunk, Compound $nbt){
$this->server = $chunk->getLevel()->getLevel()->getServer();
$this->chunk = $chunk;
$this->setLevel($chunk->getLevel()->getLevel(), true); //Strong reference
$this->namedtag = $nbt;
$this->closed = false;
$this->name = "";
@ -75,10 +76,8 @@ abstract class Tile extends Position{
$this->y = (int) $this->namedtag["y"];
$this->z = (int) $this->namedtag["z"];
$index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4);
$this->chunkIndex = $index;
$this->chunk->addTile($this);
$this->getLevel()->addTile($this);
$this->getLevel()->chunkTiles[$this->chunkIndex][$this->id] = $this;
}
public function saveNBT(){
@ -100,7 +99,7 @@ abstract class Tile extends Position{
$this->closed = true;
unset(Tile::$needUpdate[$this->id]);
$this->getLevel()->removeTile($this);
unset($this->getLevel()->chunkTiles[$this->chunkIndex][$this->id]);
$this->chunk->removeTile($this);
}
}