Removed some copy-pasted code, fix leaves2 drops

This commit is contained in:
Dylan K. Taylor
2017-02-21 13:03:23 +00:00
parent 3e141afe48
commit 21887b283f
4 changed files with 31 additions and 199 deletions

View File

@ -27,8 +27,8 @@ use pocketmine\event\block\LeavesDecayEvent;
use pocketmine\item\Item;
use pocketmine\item\Tool;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
use pocketmine\Server;
class Leaves extends Transparent{
const OAK = 0;
@ -39,6 +39,7 @@ class Leaves extends Transparent{
const DARK_OAK = 1;
protected $id = self::LEAVES;
protected $woodType = self::WOOD;
public function __construct($meta = 0){
$this->meta = $meta;
@ -66,18 +67,18 @@ class Leaves extends Transparent{
return true;
}
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
protected function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
++$check;
$index = $pos->x . "." . $pos->y . "." . $pos->z;
if(isset($visited[$index])){
return false;
}
if($pos->getId() === self::WOOD){
if($pos->getId() === $this->woodType){
return true;
}elseif($pos->getId() === self::LEAVES and $distance < 3){
}elseif($pos->getId() === $this->id and $distance < 3){
$visited[$index] = true;
$down = $pos->getSide(0)->getId();
if($down === Item::WOOD){
$down = $pos->getSide(Vector3::SIDE_DOWN)->getId();
if($down === $this->woodType){
return true;
}
if($fromSide === null){
@ -143,7 +144,7 @@ class Leaves extends Transparent{
$visited = [];
$check = 0;
Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this));
$this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this));
if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){
$this->getLevel()->setBlock($this, $this, false, false);
@ -166,7 +167,7 @@ class Leaves extends Transparent{
public function getDrops(Item $item){
$drops = [];
if($item->isShears()){
$drops[] = [Item::LEAVES, $this->meta & 0x03, 1];
$drops[] = [$this->id, $this->meta & 0x03, 1];
}else{
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = [Item::SAPLING, $this->meta & 0x03, 1];