mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Item: Removed protected block field, items should now override getBlock()
This commit is contained in:
parent
2cabdca3f7
commit
88a05845c2
@ -38,10 +38,13 @@ class Banner extends Item{
|
||||
public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME;
|
||||
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::STANDING_BANNER);
|
||||
parent::__construct(self::BANNER, $meta, "Banner");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::STANDING_BANNER);
|
||||
}
|
||||
|
||||
public function getMaxStackSize() : int{
|
||||
return 16;
|
||||
}
|
||||
|
@ -28,10 +28,13 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class Bed extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::BED_BLOCK);
|
||||
parent::__construct(self::BED, $meta, "Bed");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::BED_BLOCK);
|
||||
}
|
||||
|
||||
public function getMaxStackSize() : int{
|
||||
return 1;
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class BeetrootSeeds extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::BEETROOT_BLOCK);
|
||||
parent::__construct(self::BEETROOT_SEEDS, $meta, "Beetroot Seeds");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::BEETROOT_BLOCK);
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,13 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class Carrot extends Food{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::CARROT_BLOCK);
|
||||
parent::__construct(self::CARROT, $meta, "Carrot");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::CARROT_BLOCK);
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 3;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,8 @@ use pocketmine\block\BlockFactory;
|
||||
* Class used for Items that can be Blocks
|
||||
*/
|
||||
class ItemBlock extends Item{
|
||||
/** @var int */
|
||||
protected $blockId;
|
||||
|
||||
/**
|
||||
* @param int $blockId
|
||||
@ -37,21 +39,16 @@ class ItemBlock extends Item{
|
||||
* @param int|null $itemId
|
||||
*/
|
||||
public function __construct(int $blockId, int $meta = 0, int $itemId = null){
|
||||
$this->block = BlockFactory::get($blockId, $meta & 0xf);
|
||||
parent::__construct($itemId ?? $this->block->getId(), $meta, $this->block->getName());
|
||||
}
|
||||
|
||||
public function setDamage(int $meta) : Item{
|
||||
$this->block->setDamage($meta !== -1 ? $meta & 0xf : 0);
|
||||
return parent::setDamage($meta);
|
||||
$this->blockId = $blockId;
|
||||
parent::__construct($itemId ?? $blockId, $meta, $this->getBlock()->getName());
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return clone $this->block;
|
||||
return BlockFactory::get($this->blockId, $this->meta === -1 ? 0 : $this->meta & 0xf);
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
return $this->block->getFuelTime();
|
||||
return $this->getBlock()->getFuelTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class MelonSeeds extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::MELON_STEM);
|
||||
parent::__construct(self::MELON_SEEDS, $meta, "Melon Seeds");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::MELON_STEM);
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,13 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class Potato extends Food{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::POTATO_BLOCK);
|
||||
parent::__construct(self::POTATO, $meta, "Potato");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::POTATO_BLOCK);
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
return 1;
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class PumpkinSeeds extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::PUMPKIN_STEM);
|
||||
parent::__construct(self::PUMPKIN_SEEDS, $meta, "Pumpkin Seeds");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::PUMPKIN_STEM);
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,11 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class Redstone extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::REDSTONE_WIRE);
|
||||
parent::__construct(self::REDSTONE, $meta, "Redstone");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::REDSTONE_WIRE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,13 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class Sign extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::SIGN_POST);
|
||||
parent::__construct(self::SIGN, $meta, "Sign");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::SIGN_POST);
|
||||
}
|
||||
|
||||
public function getMaxStackSize() : int{
|
||||
return 16;
|
||||
}
|
||||
|
@ -28,9 +28,11 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class StringItem extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::TRIPWIRE);
|
||||
parent::__construct(self::STRING, $meta, "String");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::TRIPWIRE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,10 @@ use pocketmine\block\BlockFactory;
|
||||
|
||||
class WheatSeeds extends Item{
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::WHEAT_BLOCK);
|
||||
parent::__construct(self::WHEAT_SEEDS, $meta, "Wheat Seeds");
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(Block::WHEAT_BLOCK);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user