BetterGen/src/Ad5001/BetterGen/structure/Cactus.php

67 lines
2.2 KiB
PHP
Raw Normal View History

2017-04-23 14:42:51 +00:00
<?php
/**
* ____ __ __ ____
* /\ _`\ /\ \__ /\ \__ /\ _`\
* \ \ \L\ \ __ \ \ ,_\\ \ ,_\ __ _ __ \ \ \L\_\ __ ___
* \ \ _ <' /'__`\\ \ \/ \ \ \/ /'__`\/\`'__\\ \ \L_L /'__`\ /' _ `\
* \ \ \L\ \/\ __/ \ \ \_ \ \ \_ /\ __/\ \ \/ \ \ \/, \/\ __/ /\ \/\ \
* \ \____/\ \____\ \ \__\ \ \__\\ \____\\ \_\ \ \____/\ \____\\ \_\ \_\
* \/___/ \/____/ \/__/ \/__/ \/____/ \/_/ \/___/ \/____/ \/_/\/_/
* Tomorrow's pocketmine generator.
2017-05-14 18:13:15 +00:00
* @author Ad5001 <mail@ad5001.eu>, XenialDan <https://github.com/thebigsmileXD>
* @link https://github.com/Ad5001/BetterGen
2017-05-14 18:13:15 +00:00
* @category World Generator
* @api 3.0.0
* @version 1.1
2017-04-23 14:42:51 +00:00
*/
namespace Ad5001\BetterGen\structure;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\generator\object\Object;
2017-05-11 12:07:26 +00:00
use pocketmine\utils\Random;
2017-04-23 14:42:51 +00:00
class Cactus extends Object {
protected $totalHeight;
2017-05-11 12:07:26 +00:00
2017-05-14 19:03:47 +00:00
/**
* Checks if a cactus is placeable
*
* @param ChunkManager $level
* @param int $x
* @param int $y
* @param int $z
* @param Random $random
* @return bool
*/
2017-04-23 14:42:51 +00:00
public function canPlaceObject(ChunkManager $level, int $x, int $y, int $z, Random $random): bool {
2017-04-29 09:59:44 +00:00
$this->totalHeight = 1 + $random->nextBoundedInt(3);
$below = $level->getBlockIdAt($x, $y - 1, $z);
2017-05-11 12:07:26 +00:00
for($yy = $y; $yy <= $y + $this->totalHeight; $yy ++) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($x, $yy, $z) !== Block::AIR || ($below !== Block::SAND && $below !== Block::CACTUS) || ($level->getBlockIdAt($x - 1, $yy, $z) !== Block::AIR || $level->getBlockIdAt($x + 1, $yy, $z) !== Block::AIR || $level->getBlockIdAt($x, $yy, $z - 1) !== Block::AIR || $level->getBlockIdAt($x, $yy, $z + 1) !== Block::AIR)) {
2017-04-23 14:42:51 +00:00
return false;
}
}
return true;
}
2017-05-14 19:03:47 +00:00
/**
2017-04-23 14:42:51 +00:00
* Places a cactus
2017-05-14 19:03:47 +00:00
*
* @param ChunkManager $level
* @param int $x
* @param int $y
* @param int $z
* @return void
2017-04-23 14:42:51 +00:00
*/
public function placeObject(ChunkManager $level, int $x, int $y, int $z) {
for($yy = 0; $yy < $this->totalHeight; $yy ++) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($x, $y + $yy, $z) != Block::AIR) {
2017-04-23 14:42:51 +00:00
return;
}
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($x, $y + $yy, $z, Block::CACTUS);
2017-04-23 14:42:51 +00:00
}
}
}