Fixed crash when block classes override the constructor but don't specify a fallback name

This commit is contained in:
Dylan K. Taylor 2017-09-21 16:43:33 +01:00
parent 1b5fed983b
commit 0e2e9aab2e

View File

@ -61,7 +61,7 @@ class Block extends Position implements BlockIds, Metadatable{
protected $id; protected $id;
/** @var int */ /** @var int */
protected $meta = 0; protected $meta = 0;
/** @var string */ /** @var string|null */
protected $fallbackName; protected $fallbackName;
/** @var int|null */ /** @var int|null */
protected $itemId; protected $itemId;
@ -70,12 +70,12 @@ class Block extends Position implements BlockIds, Metadatable{
public $boundingBox = null; public $boundingBox = null;
/** /**
* @param int $id The block type's ID, 0-255 * @param int $id The block type's ID, 0-255
* @param int $meta Meta value of the block type * @param int $meta Meta value of the block type
* @param string $name English name of the block type (TODO: implement translations) * @param string|null $name English name of the block type (TODO: implement translations)
* @param int $itemId The item ID of the block type, used for block picking and dropping items. * @param int $itemId The item ID of the block type, used for block picking and dropping items.
*/ */
public function __construct(int $id, int $meta = 0, string $name = "Unknown", int $itemId = null){ public function __construct(int $id, int $meta = 0, string $name = null, int $itemId = null){
$this->id = $id; $this->id = $id;
$this->meta = $meta; $this->meta = $meta;
$this->fallbackName = $name; $this->fallbackName = $name;
@ -86,7 +86,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return string * @return string
*/ */
public function getName() : string{ public function getName() : string{
return $this->fallbackName; return $this->fallbackName ?? "Unknown";
} }
/** /**