diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index 7cb805802..fca8c5078 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\block\utils\TreeType; +use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\AxisAlignedBB; @@ -85,7 +86,7 @@ class CocoaBlock extends Transparent{ } public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->age < 2 and $item->getId() === Item::DYE and $item->getDamage() === 15){ //bone meal + if($this->age < 2 and $item instanceof Fertilizer){ $this->age++; $this->level->setBlock($this, $this); diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index f38e970db..50eb5aad4 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\event\block\BlockGrowEvent; +use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -57,7 +58,7 @@ abstract class Crops extends Flowable{ public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->age < 7 and $item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal + if($this->age < 7 and $item instanceof Fertilizer){ $block = clone $this; $block->age += mt_rand(2, 5); if($block->age > 7){ diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 5d32b8bdc..39c4eaa30 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\event\block\BlockSpreadEvent; +use pocketmine\item\Fertilizer; use pocketmine\item\Hoe; use pocketmine\item\Item; use pocketmine\item\ItemFactory; @@ -94,7 +95,7 @@ class Grass extends Solid{ if($face !== Facing::UP){ return false; } - if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ + if($item instanceof Fertilizer){ $item->pop(); TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2); diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 0211ece7b..e6d789be6 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\TreeType; +use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\level\generator\object\Tree; use pocketmine\math\Facing; @@ -66,7 +67,7 @@ class Sapling extends Flowable{ } public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal + if($item instanceof Fertilizer){ Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType); $item->pop(); diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index 221e1e531..2b1bc5862 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\event\block\BlockGrowEvent; +use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -48,7 +49,7 @@ class Sugarcane extends Flowable{ } public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal + if($item instanceof Fertilizer){ if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); diff --git a/src/pocketmine/item/CocoaBeans.php b/src/pocketmine/item/CocoaBeans.php new file mode 100644 index 000000000..18ad28c5d --- /dev/null +++ b/src/pocketmine/item/CocoaBeans.php @@ -0,0 +1,34 @@ +meta === 3){ //cocoa beans - return BlockFactory::get(Block::COCOA); - } - return parent::getBlock(); - } - - //TODO: names } diff --git a/src/pocketmine/item/Fertilizer.php b/src/pocketmine/item/Fertilizer.php new file mode 100644 index 000000000..3399147c6 --- /dev/null +++ b/src/pocketmine/item/Fertilizer.php @@ -0,0 +1,28 @@ +getInvertedMagicNumber(), $color->getDisplayName() . " Dye")); + self::register(new Dye($dyeMap[$color] ?? $color->getInvertedMagicNumber(), $color->getDisplayName() . " Dye")); self::register(new Bed($color->getMagicNumber(), $color->getDisplayName() . " Bed")); self::register(new Banner($color->getInvertedMagicNumber(), $color->getDisplayName() . " Banner")); }