Dog194 cocoa beans (#832)

* ※Now Cocoa Beans can be cropped
Add Cocoa Beans Block and so on....
This commit is contained in:
dog194 2016-04-19 17:14:43 -05:00 committed by Tatsuyuki Ishi
commit 8582c3647b
5 changed files with 105 additions and 14 deletions

View file

@ -223,6 +223,7 @@ class Block extends Position implements Metadatable{
const ACTIVATOR_RAIL = 126;
const COCOA_BLOCK = 127;
const COCOA_PODS = 127;
const SANDSTONE_STAIRS = 128;
const EMERALD_ORE = 129;

View file

@ -2,30 +2,36 @@
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
* _____ _____ __ _ _ _____ __ __ _____
* / ___| | ____| | \ | | | | / ___/ \ \ / / / ___/
* | | | |__ | \| | | | | |___ \ \/ / | |___
* | | _ | __| | |\ | | | \___ \ \ / \___ \
* | |_| | | |___ | | \ | | | ___| | / / ___| |
* \_____/ |_____| |_| \_| |_| /_____/ /_/ /_____/
*
* 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
* it under the terms of the GNU 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/
* @author iTX Technologies
* @link https://mcper.cn
*
*
*/
*/
namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\Player;
use pocketmine\Server;
class CocoaBlock extends Solid {
protected $id = self::COCOA_BLOCK;
public function __construct($meta = 0){
public function __construct($meta = 0) {
$this->meta = $meta;
}
@ -37,7 +43,81 @@ class CocoaBlock extends Solid {
return 0.2;
}
public function getResistance(){
public function getResistance() {
return 15;
}
public function canBeActivated() : bool {
return true;
}
public function onActivate(Item $item, Player $player = null) {
if ($item->getId() === Item::DYE and $item->getDamage() === 0x0F) {
$block = clone $this;
if ($block->meta > 7) {
return false;
}
$block->meta += 4;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if (!$ev->isCancelled()) {
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
}
$item->count--;
return true;
}
return false;
}
public function onUpdate($type) {
if ($type === Level::BLOCK_UPDATE_NORMAL) {
$faces = [3, 4, 2, 5, 3, 4, 2, 5, 3, 4, 2, 5];
if ($this->getSide($faces[$this->meta])->isTransparent() === true) {
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
} elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
if (mt_rand(0, 2) === 1) {
if ($this->meta < 7) {
$block = clone $this;
$block->meta += 4;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if (!$ev->isCancelled()) {
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
} else {
return Level::BLOCK_UPDATE_RANDOM;
}
}
} else {
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) {
if ($target->getId() === Block::WOOD and $target->getDamage() === 3) {
if ($face !== 0 and $face !== 1) {
$faces = [
2 => 0,
3 => 2,
4 => 3,
5 => 1,
];
$this->meta = $faces[$face];
$this->getLevel()->setBlock($block, Block::get(Item::COCOA_BLOCK, $this->meta), true);
return true;
}
}
return false;
}
public function getDrops(Item $item) : array {
$drops = [];
if ($this->meta >= 8) {
$drops[] = [Item::DYE, 3, 3];
} else {
$drops[] = [Item::DYE, 3, 1];
}
return $drops;
}
}

View file

@ -21,6 +21,8 @@
namespace pocketmine\item;
use pocketmine\block\Block;
class Dye extends Item{
const BLACK = 0;
const RED = 1;
@ -39,8 +41,13 @@ class Dye extends Item{
const ORANGE = 14;
const WHITE = 15;
public function __construct($meta = 0, $count = 1){
parent::__construct(self::DYE, $meta, $count, "Dye");
public function __construct($meta = 0, $count = 1) {
if ($meta === 3) {
$this->block = Block::get(Item::COCOA_BLOCK);
parent::__construct(self::DYE, 3, $count, "Cocoa Beans");
} else {
parent::__construct(self::DYE, $meta, $count, "Dye");
}
}
}

View file

@ -221,6 +221,7 @@ class Item{
const ACTIVATOR_RAIL = 126;
const COCOA_BLOCK = 127;
const COCOA_PODS = 127;
const SANDSTONE_STAIRS = 128;
const EMERALD_ORE = 129;

View file

@ -45,6 +45,7 @@ use pocketmine\block\Sapling;
use pocketmine\block\SnowLayer;
use pocketmine\block\Sugarcane;
use pocketmine\block\Wheat;
use pocketmine\block\CocoaBlock;
use pocketmine\entity\Arrow;
use pocketmine\entity\Entity;
use pocketmine\entity\Item as DroppedItem;
@ -247,6 +248,7 @@ class Level implements ChunkManager, Metadatable{
Block::SAPLING => Sapling::class,
Block::LEAVES => Leaves::class,
Block::WHEAT_BLOCK => Wheat::class,
Block::COCOA_BLOCK => CocoaBlock::class,
Block::FARMLAND => Farmland::class,
Block::SNOW_LAYER => SnowLayer::class,
Block::ICE => Ice::class,