Skip to content

Commit

Permalink
Adding fallen trees + some tweaking..
Browse files Browse the repository at this point in the history
  • Loading branch information
Ad5001 committed May 11, 2017
1 parent b73d3c9 commit 5362a4c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
3 changes: 0 additions & 3 deletions src/Ad5001/BetterGen/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine
$options["preset"] = json_encode($options);
if((int) $seed == 0/*String*/){
$seed = $this->generateRandomSeed();
echo "Rechoosen seed";
}
$this->getServer()->broadcastMessage(Main::PREFIX . "§aGenerating level $name with generator $generatorName and seed $seed..");
$this->getServer()->generateLevel($name, $seed, $generator, $options);
Expand Down Expand Up @@ -211,7 +210,6 @@ public function onInteract(PlayerInteractEvent $event) {
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
if($event->getBlock()->getId() !== Block::CHEST) return;
if(!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return;
echo "Doing {$event->getBlock()}";
$chest = new \pocketmine\block\Chest(0);
$nbt = new CompoundTag("", [
new ListTag("Items", []),
Expand All @@ -236,7 +234,6 @@ public function onBlockBreak(BlockBreakEvent $event) {
$cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON);
if($event->getBlock()->getId() !== Block::CHEST) return;
if(!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return;
echo "Doing {$event->getBlock()}";
$chest = new \pocketmine\block\Chest(0);
$nbt = new CompoundTag("", [
new ListTag("Items", []),
Expand Down
10 changes: 9 additions & 1 deletion src/Ad5001/BetterGen/biome/BetterForest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Ad5001\BetterGen\Main;
use Ad5001\BetterGen\populator\TreePopulator;
use Ad5001\BetterGen\populator\BushPopulator;
use Ad5001\BetterGen\populator\FallenTreePopulator;


class BetterForest extends ForestBiome implements Mountainable {
static $types = [
Expand All @@ -41,6 +43,12 @@ public function __construct($type = 0, array $infos = [0.6, 0.5]) {
$bush = new BushPopulator($type);
$bush->setBaseAmount(10);
$this->addPopulator($bush);

$ft = new FallenTreePopulator($type);
$ft->setBaseAmount(0);
$ft->setRandomAmount(4);
$this->addPopulator($ft);

$trees = new TreePopulator($type);
$trees->setBaseAmount((null !== @constant(TreePopulator::$types [$type] . "::maxPerChunk" )) ? constant(TreePopulator::$types [$type] . "::maxPerChunk" ) : 5);
$this->addPopulator($trees);
Expand All @@ -50,7 +58,7 @@ public function __construct($type = 0, array $infos = [0.6, 0.5]) {

$this->addPopulator($tallGrass);

$this->setElevation(63, 81);
$this->setElevation(63, 69);

$this->temperature = $infos [0];
$this->rainfall = $infos [1];
Expand Down
1 change: 0 additions & 1 deletion src/Ad5001/BetterGen/generator/BetterNormal.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ public function init(ChunkManager $level, Random $random) {
*/
public static function registerBiome(Biome $biome): bool {
if(\Ad5001\BetterGen\utils\CommonUtils::in_arrayi($biome->getName(), self::$options["deleteBiomes"])) {
echo "Removing " . $biome->getName() . "...\n";
return false;
}
foreach(self::$levels as $lvl ) if(isset($lvl->selector)) $lvl->selector->addBiome($biome); // If no selector created, it would cause errors. These will be added when selectoes
Expand Down
2 changes: 1 addition & 1 deletion src/Ad5001/BetterGen/populator/CavePopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
}
// echo "Finished Populating chunk $chunkX, $chunkZ !" . PHP_EOL;
// Filling water & lava sources randomly
for($i = 0; $i < $random->nextBoundedInt(10 ) + 15; $i ++) {
for($i = 0; $i < $random->nextBoundedInt(5) + 3; $i ++) {
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
$y = $random->nextRange(10, $this->getHighestWorkableBlock($x, $z ));
Expand Down
7 changes: 4 additions & 3 deletions src/Ad5001/BetterGen/populator/FallenTreePopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Ad5001\BetterGen\structure\FallenTree;
use Ad5001\BetterGen\populator\AmountPopulator;


class FallenTreePopulator extends AmountPopulator {
protected $level;
protected $type;
Expand All @@ -28,7 +29,7 @@ class FallenTreePopulator extends AmountPopulator {
* @param $type int
*/
public function __construct(int $type = 0) {

$this->type = $type;
$this->setBaseAmount(1);
$this->setRandomAmount(2);
}
Expand All @@ -49,8 +50,8 @@ public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
$x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
$z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
$y = $this->getHighestWorkableBlock($x, $z);
if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y, $z, $random )) {
$fallenTree->placeObject($level, $x, $y, $z, $random);
if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y + 1, $z, $random )) {
$fallenTree->placeObject($level, $x, $y + 1, $z, $random);
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/Ad5001/BetterGen/structure/FallenTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use pocketmine\math\Vector3;
use pocketmine\level\generator\object\Tree;
use pocketmine\level\generator\normal\object\Tree as Tree2;
use pocketmine\level\generator\object\Object;
use Ad5001\BetterGen\utils\BuildingUtils;

Expand All @@ -44,13 +42,10 @@ class FallenTree extends Object {

/*
* Constructs the class
* @param $tree Tree
* @param $tree Tree
* @throws Exeption
*/
public function __construct($tree) {
if(!is_subclass_of($tree, Tree::class) && !is_subclass_of($tree, Tree2::class)) {
throw new Exception("Argument 1 passed to \\Ad5001\\BetterGen\\structure\\FallenTree must be an instance of pocketmine\\level\\generator\\normal\\object\\Tree or pocketmine\\level\\generator\\object\\Tree. Instance of " . get_class($tree) . " given.");
}
public function __construct(Tree $tree) {
$this->tree = $tree;
}

Expand All @@ -71,15 +66,15 @@ public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random)
case 0:
case 1:// Z+
if(in_array(false, BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), function($v3, $level) {
if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), \Ad5001\BetterGen\structure\FallenTree::$overridable)) return false;
if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), $this->overridable)) return false;
}, $level))) {
return false;
}
break;
case 2:
case 3: // X+
if(in_array(false, BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x + $this->length, $y, $z), function($v3, $level) {
if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), \Ad5001\BetterGen\structure\FallenTree::$overridable)) return false;
if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), $this->overridable)) return false;
}, $level))) {
return false;
}
Expand All @@ -96,6 +91,7 @@ public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random)
* @param $z int
*/
public function placeObject(ChunkManager $level, $x, $y, $z) {
echo "Placing at $x $y $z FallenTree\n";
switch($this->direction) {
case 0:
$level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);
Expand Down

0 comments on commit 5362a4c

Please sign in to comment.