From 451f5d0cd75ead705ada9e73d0f55a2114722538 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 3 Nov 2017 12:17:38 +0000 Subject: [PATCH] Fixed block-pick on crops giving the crop block itself --- src/pocketmine/Player.php | 4 +--- src/pocketmine/block/Beetroot.php | 4 ++++ src/pocketmine/block/Block.php | 8 ++++++++ src/pocketmine/block/Carrot.php | 4 ++++ src/pocketmine/block/MelonStem.php | 4 ++++ src/pocketmine/block/Potato.php | 4 ++++ src/pocketmine/block/PumpkinStem.php | 4 ++++ src/pocketmine/block/Wheat.php | 4 ++++ 8 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 61807ab9d..b4baf44f8 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2580,9 +2580,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ $block = $this->level->getBlockAt($packet->blockX, $packet->blockY, $packet->blockZ); - //TODO: this doesn't handle crops correctly (need more API work) - $item = Item::get($block->getItemId(), $block->getVariant()); - + $item = $block->getPickedItem(); if($packet->addUserData){ $tile = $this->getLevel()->getTile($block); if($tile instanceof Tile){ diff --git a/src/pocketmine/block/Beetroot.php b/src/pocketmine/block/Beetroot.php index d8f2e0571..1fb15267f 100644 --- a/src/pocketmine/block/Beetroot.php +++ b/src/pocketmine/block/Beetroot.php @@ -50,4 +50,8 @@ class Beetroot extends Crops{ ItemFactory::get(Item::BEETROOT_SEEDS, 0, 1) ]; } + + public function getPickedItem() : Item{ + return ItemFactory::get(Item::BEETROOT_SEEDS); + } } \ No newline at end of file diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index cd19e73be..a8813f885 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -425,6 +425,14 @@ class Block extends Position implements BlockIds, Metadatable{ ]; } + /** + * Returns the item that players will equip when middle-clicking on this block. + * @return Item + */ + public function getPickedItem() : Item{ + return ItemFactory::get($this->getItemId(), $this->getVariant()); + } + /** * Returns the time in ticks which the block will fuel a furnace for. * @return int diff --git a/src/pocketmine/block/Carrot.php b/src/pocketmine/block/Carrot.php index 7c41eb1b1..ae07e7fb9 100644 --- a/src/pocketmine/block/Carrot.php +++ b/src/pocketmine/block/Carrot.php @@ -43,4 +43,8 @@ class Carrot extends Crops{ ItemFactory::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1) ]; } + + public function getPickedItem() : Item{ + return ItemFactory::get(Item::CARROT); + } } \ No newline at end of file diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index fde7f63d7..642d11932 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -88,4 +88,8 @@ class MelonStem extends Crops{ ItemFactory::get(Item::MELON_SEEDS, 0, mt_rand(0, 2)) ]; } + + public function getPickedItem() : Item{ + return ItemFactory::get(Item::MELON_SEEDS); + } } \ No newline at end of file diff --git a/src/pocketmine/block/Potato.php b/src/pocketmine/block/Potato.php index c18aeaafa..861438c08 100644 --- a/src/pocketmine/block/Potato.php +++ b/src/pocketmine/block/Potato.php @@ -43,4 +43,8 @@ class Potato extends Crops{ ItemFactory::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1) ]; } + + public function getPickedItem() : Item{ + return ItemFactory::get(Item::POTATO); + } } \ No newline at end of file diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index d2aaa2c5a..dd21a30e5 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -88,4 +88,8 @@ class PumpkinStem extends Crops{ ItemFactory::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)) ]; } + + public function getPickedItem() : Item{ + return ItemFactory::get(Item::PUMPKIN_SEEDS); + } } \ No newline at end of file diff --git a/src/pocketmine/block/Wheat.php b/src/pocketmine/block/Wheat.php index 622026719..1a854c29a 100644 --- a/src/pocketmine/block/Wheat.php +++ b/src/pocketmine/block/Wheat.php @@ -50,4 +50,8 @@ class Wheat extends Crops{ ]; } } + + public function getPickedItem() : Item{ + return ItemFactory::get(Item::WHEAT_SEEDS); + } } \ No newline at end of file