mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-09 23:39:43 +00:00
Implement new dye types, split bonemeal and cocoa beans into their own classes
This commit is contained in:
parent
2bfcd25848
commit
3037f45a0c
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\block\utils\TreeType;
|
use pocketmine\block\utils\TreeType;
|
||||||
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
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{
|
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->age++;
|
||||||
$this->level->setBlock($this, $this);
|
$this->level->setBlock($this, $this);
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\event\block\BlockGrowEvent;
|
use pocketmine\event\block\BlockGrowEvent;
|
||||||
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
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{
|
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 = clone $this;
|
||||||
$block->age += mt_rand(2, 5);
|
$block->age += mt_rand(2, 5);
|
||||||
if($block->age > 7){
|
if($block->age > 7){
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\event\block\BlockSpreadEvent;
|
use pocketmine\event\block\BlockSpreadEvent;
|
||||||
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Hoe;
|
use pocketmine\item\Hoe;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
@ -94,7 +95,7 @@ class Grass extends Solid{
|
|||||||
if($face !== Facing::UP){
|
if($face !== Facing::UP){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){
|
if($item instanceof Fertilizer){
|
||||||
$item->pop();
|
$item->pop();
|
||||||
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
|
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\TreeType;
|
use pocketmine\block\utils\TreeType;
|
||||||
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\generator\object\Tree;
|
use pocketmine\level\generator\object\Tree;
|
||||||
use pocketmine\math\Facing;
|
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{
|
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);
|
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType);
|
||||||
|
|
||||||
$item->pop();
|
$item->pop();
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\event\block\BlockGrowEvent;
|
use pocketmine\event\block\BlockGrowEvent;
|
||||||
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
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{
|
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){
|
if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
|
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
|
||||||
|
34
src/pocketmine/item/CocoaBeans.php
Normal file
34
src/pocketmine/item/CocoaBeans.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\item;
|
||||||
|
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\block\BlockFactory;
|
||||||
|
|
||||||
|
class CocoaBeans extends Item{
|
||||||
|
|
||||||
|
public function getBlock() : Block{
|
||||||
|
return BlockFactory::get(Block::COCOA);
|
||||||
|
}
|
||||||
|
}
|
@ -23,20 +23,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\item;
|
namespace pocketmine\item;
|
||||||
|
|
||||||
use pocketmine\block\Block;
|
|
||||||
use pocketmine\block\BlockFactory;
|
|
||||||
|
|
||||||
class Dye extends Item{
|
class Dye extends Item{
|
||||||
public function __construct(int $variant, string $name){
|
public function __construct(int $variant, string $name){
|
||||||
parent::__construct(self::DYE, $variant, $name);
|
parent::__construct(self::DYE, $variant, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlock() : Block{
|
|
||||||
if($this->meta === 3){ //cocoa beans
|
|
||||||
return BlockFactory::get(Block::COCOA);
|
|
||||||
}
|
|
||||||
return parent::getBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: names
|
|
||||||
}
|
}
|
||||||
|
28
src/pocketmine/item/Fertilizer.php
Normal file
28
src/pocketmine/item/Fertilizer.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\item;
|
||||||
|
|
||||||
|
class Fertilizer extends Item{
|
||||||
|
|
||||||
|
}
|
@ -154,11 +154,22 @@ class ItemFactory{
|
|||||||
self::register(new Item(Item::GLOWSTONE_DUST, 0, "Glowstone Dust"));
|
self::register(new Item(Item::GLOWSTONE_DUST, 0, "Glowstone Dust"));
|
||||||
self::register(new RawFish());
|
self::register(new RawFish());
|
||||||
self::register(new CookedFish());
|
self::register(new CookedFish());
|
||||||
|
|
||||||
|
self::register(new Item(Item::DYE, 0, "Ink Sac"));
|
||||||
|
self::register(new CocoaBeans(Item::DYE, 3, "Cocoa Beans"));
|
||||||
|
self::register(new Item(Item::DYE, 4, "Lapis Lazuli"));
|
||||||
|
self::register(new Fertilizer(Item::DYE, 15, "Bone Meal"));
|
||||||
|
|
||||||
|
/** @var int[]|\SplObjectStorage $dyeMap */
|
||||||
|
$dyeMap = new \SplObjectStorage();
|
||||||
|
$dyeMap[DyeColor::BLACK()] = 16;
|
||||||
|
$dyeMap[DyeColor::BROWN()] = 17;
|
||||||
|
$dyeMap[DyeColor::BLUE()] = 18;
|
||||||
|
$dyeMap[DyeColor::WHITE()] = 19;
|
||||||
foreach(DyeColor::getAll() as $color){
|
foreach(DyeColor::getAll() as $color){
|
||||||
//TODO: use colour object directly
|
//TODO: use colour object directly
|
||||||
//TODO: add interface to dye-colour objects
|
//TODO: add interface to dye-colour objects
|
||||||
//TODO: new dedicated dyes
|
self::register(new Dye($dyeMap[$color] ?? $color->getInvertedMagicNumber(), $color->getDisplayName() . " Dye"));
|
||||||
self::register(new Dye($color->getInvertedMagicNumber(), $color->getDisplayName() . " Dye"));
|
|
||||||
self::register(new Bed($color->getMagicNumber(), $color->getDisplayName() . " Bed"));
|
self::register(new Bed($color->getMagicNumber(), $color->getDisplayName() . " Bed"));
|
||||||
self::register(new Banner($color->getInvertedMagicNumber(), $color->getDisplayName() . " Banner"));
|
self::register(new Banner($color->getInvertedMagicNumber(), $color->getDisplayName() . " Banner"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user