diff --git a/src/pocketmine/item/Banner.php b/src/pocketmine/item/Banner.php index 35671965d..d4f160e33 100644 --- a/src/pocketmine/item/Banner.php +++ b/src/pocketmine/item/Banner.php @@ -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; } diff --git a/src/pocketmine/item/Bed.php b/src/pocketmine/item/Bed.php index 892152da6..6433b8f58 100644 --- a/src/pocketmine/item/Bed.php +++ b/src/pocketmine/item/Bed.php @@ -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; } diff --git a/src/pocketmine/item/BeetrootSeeds.php b/src/pocketmine/item/BeetrootSeeds.php index a329cb8af..3e3c091a7 100644 --- a/src/pocketmine/item/BeetrootSeeds.php +++ b/src/pocketmine/item/BeetrootSeeds.php @@ -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); + } } diff --git a/src/pocketmine/item/Carrot.php b/src/pocketmine/item/Carrot.php index d39588d26..24b525fdb 100644 --- a/src/pocketmine/item/Carrot.php +++ b/src/pocketmine/item/Carrot.php @@ -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; } diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index e74616c02..03751187b 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -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; } diff --git a/src/pocketmine/item/ItemBlock.php b/src/pocketmine/item/ItemBlock.php index 5db8fee54..2adcec413 100644 --- a/src/pocketmine/item/ItemBlock.php +++ b/src/pocketmine/item/ItemBlock.php @@ -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(); } } diff --git a/src/pocketmine/item/MelonSeeds.php b/src/pocketmine/item/MelonSeeds.php index ab457e421..a536f9396 100644 --- a/src/pocketmine/item/MelonSeeds.php +++ b/src/pocketmine/item/MelonSeeds.php @@ -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); + } } diff --git a/src/pocketmine/item/Potato.php b/src/pocketmine/item/Potato.php index 46735fd11..b2531bb7d 100644 --- a/src/pocketmine/item/Potato.php +++ b/src/pocketmine/item/Potato.php @@ -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; } diff --git a/src/pocketmine/item/PumpkinSeeds.php b/src/pocketmine/item/PumpkinSeeds.php index 0ad4a84aa..ec8e840bd 100644 --- a/src/pocketmine/item/PumpkinSeeds.php +++ b/src/pocketmine/item/PumpkinSeeds.php @@ -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); + } } diff --git a/src/pocketmine/item/Redstone.php b/src/pocketmine/item/Redstone.php index 9f1784f2e..a3456a325 100644 --- a/src/pocketmine/item/Redstone.php +++ b/src/pocketmine/item/Redstone.php @@ -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); + } } diff --git a/src/pocketmine/item/Sign.php b/src/pocketmine/item/Sign.php index 7248d369c..56a06749d 100644 --- a/src/pocketmine/item/Sign.php +++ b/src/pocketmine/item/Sign.php @@ -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; } diff --git a/src/pocketmine/item/StringItem.php b/src/pocketmine/item/StringItem.php index aac043008..75fc199a3 100644 --- a/src/pocketmine/item/StringItem.php +++ b/src/pocketmine/item/StringItem.php @@ -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); + } } diff --git a/src/pocketmine/item/WheatSeeds.php b/src/pocketmine/item/WheatSeeds.php index 8a97131b3..5bf2dccdd 100644 --- a/src/pocketmine/item/WheatSeeds.php +++ b/src/pocketmine/item/WheatSeeds.php @@ -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); + } }