Implement new dye types, split bonemeal and cocoa beans into their own classes

This commit is contained in:
Dylan K. Taylor
2019-02-22 11:43:11 +00:00
parent 2bfcd25848
commit 3037f45a0c
9 changed files with 85 additions and 19 deletions

View 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);
}
}

View File

@ -23,20 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Dye extends Item{
public function __construct(int $variant, string $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
}

View 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{
}

View File

@ -154,11 +154,22 @@ class ItemFactory{
self::register(new Item(Item::GLOWSTONE_DUST, 0, "Glowstone Dust"));
self::register(new RawFish());
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){
//TODO: use colour object directly
//TODO: add interface to dye-colour objects
//TODO: new dedicated dyes
self::register(new Dye($color->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"));
}