Added BlockMetadataStore to Level and Block

This commit is contained in:
Shoghi Cervantes 2014-06-14 20:06:42 +02:00
parent 694ccf2bc5
commit f3e6c726b0
2 changed files with 26 additions and 11 deletions

View File

@ -25,12 +25,14 @@
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\math\AxisAlignedBB;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\Player;
use pocketmine\plugin\Plugin;
use pocketmine\Server;
abstract class Block extends Position implements Metadatable{
const AIR = 0;
@ -774,21 +776,27 @@ abstract class Block extends Position implements Metadatable{
*/
abstract function onUpdate($type);
//TODO: Level block metadata
public function setMetadata($metadataKey, MetadataValue $metadataValue){
//$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue);
}
}
public function getMetadata($metadataKey){
return null; //return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
}
}
public function hasMetadata($metadataKey){
return false; //return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->hasMetadata($this, $metadataKey);
}
}
public function removeMetadata($metadataKey, Plugin $plugin){
//$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->removeMetadata($this, $metadataKey, $plugin);
}
}
}

View File

@ -41,6 +41,7 @@ use pocketmine\level\generator\populator\Populator;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\metadata\BlockMetadataStore;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\tag\Byte;
@ -67,11 +68,6 @@ class Level implements ChunkManager, Metadatable{
private static $levelIdCounter = 1;
/** @var Generator */
private $generator;
/** @var Populator[] */
private $populators;
const BLOCK_UPDATE_NORMAL = 1;
const BLOCK_UPDATE_RANDOM = 2;
@ -121,6 +117,9 @@ class Level implements ChunkManager, Metadatable{
private $autoSave = true;
/** @var BlockMetadataStore */
private $blockMetadata;
/**
* Returns the chunk unique hash/key
*
@ -151,6 +150,7 @@ class Level implements ChunkManager, Metadatable{
*/
public function __construct(Server $server, $name, $path, $provider){
$this->levelId = static::$levelIdCounter++;
$this->blockMetadata = new BlockMetadataStore($this);
$this->server = $server;
if(is_subclass_of($provider, "pocketmine\\level\\format\\LevelProvider", true)){
$this->provider = new $provider($this, $path);
@ -168,6 +168,13 @@ class Level implements ChunkManager, Metadatable{
$this->nextSave = microtime(true) + 90;
}
/**
* @return BlockMetadataStore
*/
public function getBlockMetadata(){
return $this->blockMetadata;
}
/**
* @return Server
*/