Skip to content

Commit

Permalink
Made Leaves drops more generic, fix dark oak leaves not dropping apples
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Dec 13, 2017
1 parent dc064df commit 66562f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
29 changes: 17 additions & 12 deletions src/pocketmine/block/Leaves.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,26 @@ public function getVariantBitmask() : int{
}

public function getDrops(Item $item) : array{
$drops = [];

$variantMeta = $this->getVariant();

if($item->isShears()){
$drops[] = ItemFactory::get($this->getItemId(), $variantMeta, 1);
}else{
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = ItemFactory::get(Item::SAPLING, $variantMeta, 1);
}
if($variantMeta === self::OAK and mt_rand(1, 200) === 1){ //Apples
$drops[] = ItemFactory::get(Item::APPLE, 0, 1);
}
return parent::getDrops($item);
}

$drops = [];
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = $this->getSaplingItem();
}
if($this->canDropApples() and mt_rand(1, 200) === 1){ //Apples
$drops[] = ItemFactory::get(Item::APPLE, 0, 1);
}

return $drops;
}

public function getSaplingItem() : Item{
return ItemFactory::get(Item::SAPLING, $this->getVariant());
}

public function canDropApples() : bool{
return $this->meta === self::OAK;
}
}
20 changes: 6 additions & 14 deletions src/pocketmine/block/Leaves2.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,11 @@ public function getName() : string{
return $names[$this->getVariant()] ?? "Unknown";
}

public function getDrops(Item $item) : array{
$variantMeta = $this->getVariant();

if($item->isShears()){
return [
ItemFactory::get($this->getItemId(), $variantMeta, 1)
];
}elseif(mt_rand(1, 20) === 1){ //Saplings
return [
ItemFactory::get(Item::SAPLING, $variantMeta + 4, 1)
];
}

return [];
public function getSaplingItem() : Item{
return ItemFactory::get(Item::SAPLING, $this->getVariant() + 4);
}

public function canDropApples() : bool{
return $this->meta === self::DARK_OAK;
}
}

1 comment on commit 66562f2

@zKoz210
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix drop cobweb

Please sign in to comment.