Item: Removed protected block field, items should now override getBlock()

This commit is contained in:
Dylan K. Taylor
2018-02-15 18:44:25 +00:00
parent 2cabdca3f7
commit 88a05845c2
13 changed files with 50 additions and 37 deletions

View File

@ -42,7 +42,6 @@ use pocketmine\nbt\tag\NamedTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\Binary;
use pocketmine\utils\Config;
@ -176,8 +175,6 @@ class Item implements ItemIds, \JsonSerializable{
return -1;
}
/** @var Block|null */
protected $block;
/** @var int */
protected $id;
/** @var int */
@ -206,10 +203,6 @@ class Item implements ItemIds, \JsonSerializable{
$this->id = $id & 0xffff;
$this->setDamage($meta);
$this->name = $name;
if(!isset($this->block) and $this->id <= 0xff){
$this->block = BlockFactory::get($this->id, $this->meta);
$this->name = $this->block->getName();
}
}
/**
@ -648,7 +641,7 @@ class Item implements ItemIds, \JsonSerializable{
* @return bool
*/
final public function canBePlaced() : bool{
return $this->block !== null and $this->block->canBePlaced();
return $this->getBlock()->canBePlaced();
}
/**
@ -656,11 +649,7 @@ class Item implements ItemIds, \JsonSerializable{
* @return Block
*/
public function getBlock() : Block{
if($this->block instanceof Block){
return clone $this->block;
}else{
return BlockFactory::get(self::AIR);
}
return BlockFactory::get(self::AIR);
}
/**
@ -997,10 +986,6 @@ class Item implements ItemIds, \JsonSerializable{
}
public function __clone(){
if($this->block !== null){
$this->block = clone $this->block;
}
$this->cachedNBT = null;
}