BetterGen/src/Ad5001/BetterGen/structure/Well.php

134 lines
3.6 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 Well extends Object {
/** @var ChunkManager */
2017-05-13 15:03:39 +00:00
protected $level;
2017-04-23 14:42:51 +00:00
public $overridable = [
Block::AIR => true,
6 => true,
17 => true,
18 => true,
Block::DANDELION => true,
Block::POPPY => true,
Block::SNOW_LAYER => true,
Block::LOG2 => true,
Block::LEAVES2 => true,
Block::CACTUS => true
];
protected $directions = [
[
1,
1
],
[
1,
- 1
],
[
- 1,
- 1
],
[
- 1,
1
]
];
2017-05-14 19:03:47 +00:00
/**
* Checks if a Well is placable
*
* @param ChunkManager $level
* @param int $x
* @param int $y
* @param int $z
* @param Random $random
* @return void
2017-04-23 14:42:51 +00:00
*/
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
$this->level = $level;
2017-04-23 14:42:51 +00:00
for($xx = $x - 2; $xx <= $x + 2; $xx ++)
for($yy = $y; $yy <= $y + 3; $yy ++)
for($zz = $z - 2; $zz <= $z + 2; $zz ++)
2017-05-13 21:42:44 +00:00
if (! isset($this->overridable[$level->getBlockIdAt($xx, $yy, $zz)]))
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 well
2017-05-14 19:03:47 +00:00
*
* @param ChunkManager $level
* @param int $x
* @param int $y
* @param int $z
* @param Random $random
* @return void
2017-04-23 14:42:51 +00:00
*/
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) {
$this->level = $level;
2017-05-13 21:27:10 +00:00
foreach($this->directions as $direction) {
// Building pillars
2017-04-23 14:42:51 +00:00
for($yy = $y; $yy < $y + 3; $yy ++)
2017-04-29 09:59:44 +00:00
$this->placeBlock($x + $direction [0], $yy, $z + $direction [1], Block::SANDSTONE);
2017-04-23 14:42:51 +00:00
// Building corners
2017-04-29 09:59:44 +00:00
$this->placeBlock($x + ($direction [0] * 2), $y, $z + $direction [1], Block::SANDSTONE);
$this->placeBlock($x + $direction [0], $y, $z + ($direction [1] * 2), Block::SANDSTONE);
$this->placeBlock($x + ($direction [0] * 2), $y, $z + ($direction [1] * 2), Block::SANDSTONE);
2017-04-23 14:42:51 +00:00
// Building slabs on the sides. Places two times due to all directions.
2017-05-13 15:03:39 +00:00
$this->placeBlock($x + ($direction [0] * 2), $y, $z, 44, 1);
$this->placeBlock($x, $y, $z + ($direction [1] * 2), 44, 1);
2017-04-23 14:42:51 +00:00
// Placing water.Places two times due to all directions.
2017-04-29 09:59:44 +00:00
$this->placeBlock($x + $direction [0], $y, $z, Block::WATER);
$this->placeBlock($x, $y, $z + $direction [1], Block::WATER);
2017-04-23 14:42:51 +00:00
}
// Final things
2017-04-23 14:42:51 +00:00
for($xx = $x - 1; $xx <= $x + 1; $xx ++)
for($zz = $z - 1; $zz <= $z + 1; $zz ++)
$this->placeBlock($xx, $y + 3, $zz);
$this->placeBlock($x, $y + 3, $z, Block::SANDSTONE, 1);
$this->placeBlock($x, $y, $z, Block::WATER);
2017-04-23 14:42:51 +00:00
}
2017-05-14 19:03:47 +00:00
/**
* Places a block
*
* @param int $x
* @param int $y
* @param int $z
* @param int $id
* @param int $meta
2017-04-23 14:42:51 +00:00
* @return void
*/
public function placeBlock($x, $y, $z, $id = 0, $meta = 0) {
2017-04-29 09:59:44 +00:00
$this->level->setBlockIdAt($x, $y, $z, $id);
$this->level->setBlockDataAt($x, $y, $z, $meta);
2017-04-23 14:42:51 +00:00
}
}