first shot making Block not extend Position

this makes some stuff a lot less pretty, but this seems to be the bare minimum necessary to do this task. It can be enhanced later.
This commit is contained in:
Dylan K. Taylor
2019-08-05 16:44:09 +01:00
parent cf271dab2b
commit 53ab860db5
75 changed files with 337 additions and 325 deletions

View File

@ -27,6 +27,7 @@ use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use function mt_rand;
use pocketmine\world\Position;
class Mycelium extends Opaque{
@ -46,16 +47,16 @@ class Mycelium extends Opaque{
public function onRandomTick() : void{
//TODO: light levels
$x = mt_rand($this->x - 1, $this->x + 1);
$y = mt_rand($this->y - 2, $this->y + 2);
$z = mt_rand($this->z - 1, $this->z + 1);
$block = $this->getWorld()->getBlockAt($x, $y, $z);
$x = mt_rand($this->pos->x - 1, $this->pos->x + 1);
$y = mt_rand($this->pos->y - 2, $this->pos->y + 2);
$z = mt_rand($this->pos->z - 1, $this->pos->z + 1);
$block = $this->pos->getWorld()->getBlockAt($x, $y, $z);
if($block->getId() === BlockLegacyIds::DIRT){
if($block->getSide(Facing::UP) instanceof Transparent){
$ev = new BlockSpreadEvent($block, $this, VanillaBlocks::MYCELIUM());
$ev->call();
if(!$ev->isCancelled()){
$this->getWorld()->setBlock($block, $ev->getNewState());
$this->pos->getWorld()->setBlock($block->pos, $ev->getNewState());
}
}
}