diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index ccd63ced9..61284cfdd 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -30,6 +30,7 @@ use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Bamboo as ItemBamboo; use pocketmine\item\Fertilizer; use pocketmine\item\Item; +use pocketmine\item\VanillaItems; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -243,4 +244,8 @@ class Bamboo extends Transparent{ $world->setBlock($this->position, $this); } } + + public function asItem() : Item{ + return VanillaItems::BAMBOO(); + } } diff --git a/src/block/BambooSapling.php b/src/block/BambooSapling.php index 66b816241..6171657c4 100644 --- a/src/block/BambooSapling.php +++ b/src/block/BambooSapling.php @@ -29,6 +29,7 @@ use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Bamboo as ItemBamboo; use pocketmine\item\Fertilizer; use pocketmine\item\Item; +use pocketmine\item\VanillaItems; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; @@ -126,6 +127,6 @@ final class BambooSapling extends Flowable{ } public function asItem() : Item{ - return VanillaBlocks::BAMBOO()->asItem(); + return VanillaItems::BAMBOO(); } } diff --git a/src/block/BaseBanner.php b/src/block/BaseBanner.php index 3cc59ae78..fd2b225bf 100644 --- a/src/block/BaseBanner.php +++ b/src/block/BaseBanner.php @@ -28,9 +28,9 @@ use pocketmine\block\utils\BannerPatternLayer; use pocketmine\block\utils\ColoredTrait; use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\SupportType; -use pocketmine\data\bedrock\DyeColorIdMap; use pocketmine\item\Banner as ItemBanner; use pocketmine\item\Item; +use pocketmine\item\VanillaItems; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -129,10 +129,6 @@ abstract class BaseBanner extends Transparent{ } } - protected function writeStateToItemMeta() : int{ - return DyeColorIdMap::getInstance()->toInvertedId($this->color); - } - public function getDropsForCompatibleTool(Item $item) : array{ $drop = $this->asItem(); if($drop instanceof ItemBanner && count($this->patterns) > 0){ @@ -149,4 +145,8 @@ abstract class BaseBanner extends Transparent{ } return $result; } + + public function asItem() : Item{ + return VanillaItems::BANNER()->setColor($this->color); + } } diff --git a/src/block/Bed.php b/src/block/Bed.php index 025c8c652..46d21a23a 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -33,6 +33,7 @@ use pocketmine\block\utils\SupportType; use pocketmine\entity\Entity; use pocketmine\entity\Living; use pocketmine\item\Item; +use pocketmine\item\VanillaItems; use pocketmine\lang\KnownTranslationFactory; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -218,4 +219,9 @@ class Bed extends Transparent{ private function canBeSupportedBy(Block $block) : bool{ return !$block->getSupportType(Facing::UP)->equals(SupportType::NONE()); } + + public function asItem() : Item{ + //TODO: we might be able to get rid of this + return VanillaItems::BED()->setColor($this->color); + } } diff --git a/src/block/Beetroot.php b/src/block/Beetroot.php index 5afbe4412..b87a841ea 100644 --- a/src/block/Beetroot.php +++ b/src/block/Beetroot.php @@ -42,7 +42,7 @@ class Beetroot extends Crops{ ]; } - public function getPickedItem(bool $addUserData = false) : Item{ + public function asItem() : Item{ return VanillaItems::BEETROOT_SEEDS(); } } diff --git a/src/block/Carrot.php b/src/block/Carrot.php index c03d10737..895b0a37d 100644 --- a/src/block/Carrot.php +++ b/src/block/Carrot.php @@ -35,7 +35,7 @@ class Carrot extends Crops{ ]; } - public function getPickedItem(bool $addUserData = false) : Item{ + public function asItem() : Item{ return VanillaItems::CARROT(); } } diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index 89f8bccf6..572a098ee 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -147,7 +147,7 @@ class CocoaBlock extends Transparent{ ]; } - public function getPickedItem(bool $addUserData = false) : Item{ + public function asItem() : Item{ return VanillaItems::COCOA_BEANS(); } } diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index cf9d5ece0..6dcd5420a 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -25,9 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataReader; use pocketmine\block\utils\BlockDataWriter; -use pocketmine\data\bedrock\CoralTypeIdMap; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\VanillaItems; use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -39,14 +38,6 @@ use function rad2deg; final class FloorCoralFan extends BaseCoral{ private int $axis = Axis::X; - public function getLegacyItemId() : int{ - return $this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN; - } - - protected function writeStateToItemMeta() : int{ - return CoralTypeIdMap::getInstance()->toId($this->coralType); - } - public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; } protected function decodeState(BlockDataReader $r) : void{ @@ -98,4 +89,8 @@ final class FloorCoralFan extends BaseCoral{ private function canBeSupportedBy(Block $block) : bool{ return $block->getSupportType(Facing::UP)->hasCenterSupport(); } + + public function asItem() : Item{ + return VanillaItems::CORAL_FAN()->setCoralType($this->coralType)->setDead($this->dead); + } } diff --git a/src/block/MelonStem.php b/src/block/MelonStem.php index d0282a546..8ead526af 100644 --- a/src/block/MelonStem.php +++ b/src/block/MelonStem.php @@ -23,9 +23,16 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\item\Item; +use pocketmine\item\VanillaItems; + class MelonStem extends Stem{ protected function getPlant() : Block{ return VanillaBlocks::MELON(); } + + public function asItem() : Item{ + return VanillaItems::MELON_SEEDS(); + } } diff --git a/src/block/Potato.php b/src/block/Potato.php index 209107156..47d39f612 100644 --- a/src/block/Potato.php +++ b/src/block/Potato.php @@ -39,7 +39,7 @@ class Potato extends Crops{ return $result; } - public function getPickedItem(bool $addUserData = false) : Item{ + public function asItem() : Item{ return VanillaItems::POTATO(); } } diff --git a/src/block/PumpkinStem.php b/src/block/PumpkinStem.php index d7b8e2588..9151ce2dc 100644 --- a/src/block/PumpkinStem.php +++ b/src/block/PumpkinStem.php @@ -23,9 +23,16 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\item\Item; +use pocketmine\item\VanillaItems; + class PumpkinStem extends Stem{ protected function getPlant() : Block{ return VanillaBlocks::PUMPKIN(); } + + public function asItem() : Item{ + return VanillaItems::PUMPKIN_SEEDS(); + } } diff --git a/src/block/RedstoneWire.php b/src/block/RedstoneWire.php index aff8ec32e..7c770e9c4 100644 --- a/src/block/RedstoneWire.php +++ b/src/block/RedstoneWire.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait; use pocketmine\item\Item; +use pocketmine\item\VanillaItems; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -54,4 +55,8 @@ class RedstoneWire extends Flowable{ private function canBeSupportedBy(Block $block) : bool{ return $block->getSupportType(Facing::UP)->hasCenterSupport(); } + + public function asItem() : Item{ + return VanillaItems::REDSTONE_DUST(); + } } diff --git a/src/block/Skull.php b/src/block/Skull.php index 461446cbe..5eb2749e7 100644 --- a/src/block/Skull.php +++ b/src/block/Skull.php @@ -31,6 +31,7 @@ use pocketmine\block\utils\BlockDataWriterHelper; use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\SkullType; use pocketmine\item\Item; +use pocketmine\item\VanillaItems; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -153,7 +154,8 @@ class Skull extends Flowable{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - protected function writeStateToItemMeta() : int{ - return $this->skullType->getMagicNumber(); + public function asItem() : Item{ + //TODO: we might be able to get rid of this + return VanillaItems::MOB_HEAD()->setSkullType($this->skullType); } } diff --git a/src/block/WallCoralFan.php b/src/block/WallCoralFan.php index d713c4164..4ab9251c0 100644 --- a/src/block/WallCoralFan.php +++ b/src/block/WallCoralFan.php @@ -26,9 +26,8 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataReader; use pocketmine\block\utils\BlockDataWriter; use pocketmine\block\utils\HorizontalFacingTrait; -use pocketmine\data\bedrock\CoralTypeIdMap; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\VanillaItems; use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -38,14 +37,6 @@ use pocketmine\world\BlockTransaction; final class WallCoralFan extends BaseCoral{ use HorizontalFacingTrait; - public function getLegacyItemId() : int{ - return $this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN; - } - - protected function writeStateToItemMeta() : int{ - return CoralTypeIdMap::getInstance()->toId($this->coralType); - } - public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 2; } protected function decodeState(BlockDataReader $r) : void{ @@ -77,4 +68,8 @@ final class WallCoralFan extends BaseCoral{ private function canBeSupportedBy(Block $block, int $face) : bool{ return $block->getSupportType($face)->hasCenterSupport(); } + + public function asItem() : Item{ + return VanillaItems::CORAL_FAN()->setCoralType($this->coralType)->setDead($this->dead); + } } diff --git a/src/block/Wheat.php b/src/block/Wheat.php index ccccd015a..15701c976 100644 --- a/src/block/Wheat.php +++ b/src/block/Wheat.php @@ -42,7 +42,7 @@ class Wheat extends Crops{ } } - public function getPickedItem(bool $addUserData = false) : Item{ + public function asItem() : Item{ return VanillaItems::WHEAT_SEEDS(); } }