Browse Source

Fixing BuildingUtils::fillCallback arguments

tags/1.0
Ad5001 3 years ago
parent
commit
7b4b4e1d63
4 changed files with 75 additions and 45 deletions
  1. +2
    -1
      src/Ad5001/BetterGen/populator/FallenTreePopulator.php
  2. +20
    -30
      src/Ad5001/BetterGen/populator/MineshaftPopulator.php
  3. +48
    -11
      src/Ad5001/BetterGen/structure/FallenTree.php
  4. +5
    -3
      src/Ad5001/BetterGen/utils/BuildingUtils.php

+ 2
- 1
src/Ad5001/BetterGen/populator/FallenTreePopulator.php View File

@@ -38,7 +38,8 @@ class FallenTreePopulator extends AmountPopulator {
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level;
$amount = $this->getAmount($random);
$fallenTree = new FallenTree(new TreePopulator::$types[$this->type]());
$tree = TreePopulator::$types[$this->type];
$fallenTree = new FallenTree(new $tree());
for($i = 0; $i < $amount; $i++) {
$x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
$z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);


+ 20
- 30
src/Ad5001/BetterGen/populator/MineshaftPopulator.php View File

@@ -85,15 +85,12 @@ class MineshaftPopulator extends AmountPopulator {
// First, filling everything blank.
BuildingUtils::fill($this->level, new Vector3($x, $y, $z - 1 ), new Vector3($x + 4, $y + 2, $z + 1 ), Block::get(Block::AIR ));
// Then, making sure the floor is solid.
BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z - 1 ), new Vector3($x + 4, $y - 1, $z + 1 ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z - 1 ), new Vector3($x + 4, $y - 1, $z + 1 ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
// Putting rails
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x + 4, $y, $z ), function ($v3, $params) {
$level = $params [0];
$random = $params [1];
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x + 4, $y, $z ), function ($v3, $level, $random) {
if ($random->nextBoundedInt(3 ) !== 0) {
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 1);
@@ -128,15 +125,13 @@ class MineshaftPopulator extends AmountPopulator {
// First, filling everything blank.
BuildingUtils::fill($this->level, new Vector3($x, $y, $z - 1 ), new Vector3($x - 4, $y + 2, $z + 1 ));
// Then, making sure the floor is solid.
BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z - 1 ), new Vector3($x - 4, $y - 1, $z + 1 ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z - 1 ), new Vector3($x - 4, $y - 1, $z + 1 ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
// Putting rails
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x - 4, $y, $z ), function ($v3, $params) {
$level = $params [0];
$random = $params [1];
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x - 4, $y, $z ), function ($v3, $level, $level) {
if ($random->nextBoundedInt(3 ) !== 0) {
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 1);
@@ -171,15 +166,13 @@ class MineshaftPopulator extends AmountPopulator {
// First, filling everything blank.
BuildingUtils::fill($this->level, new Vector3($x - 1, $y, $z ), new Vector3($x + 1, $y + 2, $z + 4 ));
// Then, making sure the floor is solid.
BuildingUtils::fillCallback(new Vector3($x - 1, $y - 1, $z ), new Vector3($x + 1, $y - 1, $z + 4 ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x - 1, $y - 1, $z ), new Vector3($x + 1, $y - 1, $z + 4 ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
// Putting rails
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x, $y, $z + 4 ), function ($v3, $params) {
$level = $params [0];
$random = $params [1];
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x, $y, $z + 4 ), function ($v3, $level, $random) {
if ($random->nextBoundedInt(3 ) !== 0) {
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 0);
@@ -214,15 +207,13 @@ class MineshaftPopulator extends AmountPopulator {
// First, filling everything blank.
BuildingUtils::fill($this->level, new Vector3($x - 1, $y, $z ), new Vector3($x + 1, $y + 2, $z - 4 ));
// Then, making sure the floor is solid.
BuildingUtils::fillCallback(new Vector3($x - 1, $y - 1, $z ), new Vector3($x + 1, $y - 1, $z - 4 ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x - 1, $y - 1, $z ), new Vector3($x + 1, $y - 1, $z - 4 ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
// Putting rails
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x, $y, $z - 4 ), function ($v3, $params) {
$level = $params [0];
$random = $params [1];
BuildingUtils::fillCallback(new Vector3($x, $y, $z ), new Vector3($x, $y, $z - 4 ), function ($v3, $level, $random) {
if ($random->nextBoundedInt(3 ) !== 0) {
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 0);
@@ -291,8 +282,8 @@ class MineshaftPopulator extends AmountPopulator {
}
// Then, making sure the floor is solid.
BuildingUtils::fillCallback(new Vector3($x + 1, $y - 1, $z - 1 ), new Vector3($x - 1, $y - 1, $z + 1 ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x + 1, $y - 1, $z - 1 ), new Vector3($x - 1, $y - 1, $z + 1 ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
@@ -372,32 +363,31 @@ class MineshaftPopulator extends AmountPopulator {
switch ($path) {
case self::DIR_XPLUS :
BuildingUtils::fill($this->level, new Vector3($x + $i, $y - $i - 1, $z - 2 ), new Vector3($x + $i, $y - $i + 3, $z + 2 ), Block::get(Block::AIR ));
BuildingUtils::fillCallback(new Vector3($x + $i, $y - $i - 2, $z - 2 ), new Vector3($x + $i, $y - $i - 2, $z + 2 ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x + $i, $y - $i - 2, $z - 2 ), new Vector3($x + $i, $y - $i - 2, $z + 2 ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
break;
case self::DIR_XMIN :
BuildingUtils::fill($this->level, new Vector3($x - $i, $y - $i - 1, $z - 2 ), new Vector3($x - $i, $y - $i + 3, $z + 2 ), Block::get(Block::AIR ));
BuildingUtils::fillCallback(new Vector3($x - $i, $y - $i - 2, $z - 2 ), new Vector3($x - $i, $y - $i - 2, $z + 2 ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x - $i, $y - $i - 2, $z - 2 ), new Vector3($x - $i, $y - $i - 2, $z + 2 ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
break;
case self::DIR_ZPLUS :
BuildingUtils::fill($this->level, new Vector3($x - 2, $y - $i - 1, $z + $i ), new Vector3($x + 2, $y - $i + 3, $z + $i ), Block::get(Block::AIR ));
BuildingUtils::fillCallback(new Vector3($x - 2, $y - $i - 2, $z + $i ), new Vector3($x + 2, $y - $i - 2, $z + $i ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x - 2, $y - $i - 2, $z + $i ), new Vector3($x + 2, $y - $i - 2, $z + $i ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
break;
case self::DIR_ZMIN :
BuildingUtils::fill($this->level, new Vector3($x - 2, $y - $i - 1, $z - $i ), new Vector3($x + 2, $y - $i + 3, $z - $i ), Block::get(Block::AIR ));
BuildingUtils::fillCallback(new Vector3($x - 2, $y - $i - 2, $z - $i ), new Vector3($x + 2, $y - $i - 2, $z - $i ), function ($v3, $params) {
$level = $params [0];
BuildingUtils::fillCallback(new Vector3($x - 2, $y - $i - 2, $z - $i ), new Vector3($x + 2, $y - $i - 2, $z - $i ), function ($v3, $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z ) == Block::AIR)
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);


+ 48
- 11
src/Ad5001/BetterGen/structure/FallenTree.php View File

@@ -17,13 +17,21 @@ 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;


class FallenTree extends Object {
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::LOG2 => true,
Block::LEAVES2 => true,
Block::CACTUS => true
];
protected $tree;
protected $direction;
@@ -51,6 +59,26 @@ class FallenTree extends Object {
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
$randomHeight = round($random->nextBoundedInt(6) - 3);
$this->length = $this->tree->trunkHeight + $randomHeight;
$this->direction = $random->nextBoundedInt(4);
switch($this->direction) {
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;
}, $level))) {
return false;
}
break;
case 2:
case 3:
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;
}, $level))) {
return false;
}
break;
}
return true;
}
/*
@@ -61,16 +89,25 @@ class FallenTree extends Object {
* @param $z int
*/
public function placeObject(ChunkManager $level, $x, $y, $z) {
$number = $random->nextBoundedInt(6);
$pos = new Vector3($x, $y, $z);
$this->placeLeaf($pos->x, $pos->y, $pos->z, $level);
for($i = 0; $i < $number; $i ++) {
$transfer = $random->nextBoolean ();
$direction = $random->nextBoundedInt(4);
$newPos = $pos->getSide($direction);
if ($transfer)
$pos = $newPos;
$this->placeLeaf($newPos->x, $newPos->y, $newPos->z, $level);
switch($this->direction) {
case 0:
$level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);
$level->setBlockDataAt($x, $y, $z, $this->tree->type);
$z += 2;
case 1:// Z+
BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get($this->tree->trunkBlock, $this->tree->type + 4));
break;
case 2:
$level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);
$level->setBlockDataAt($x, $y, $z, $this->tree->type);
$x += 2;
case 3:
BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get($this->tree->trunkBlock, $this->tree->type + 4));
break;
}
// Second call to build the last wood block
switch($this->direction) {

}
}


+ 5
- 3
src/Ad5001/BetterGen/utils/BuildingUtils.php View File

@@ -51,15 +51,17 @@ class BuildingUtils {
* @param $pos2 pocketmine\math\Vector3
* @param $call callback
* @param $params array
* @return void
* @return array
*/
public static function fillCallback(Vector3 $pos1, Vector3 $pos2, callable $call, ...$params) {
public static function fillCallback(Vector3 $pos1, Vector3 $pos2, callable $call, ...$params) : array {
list($pos1, $pos2 ) = self::minmax($pos1, $pos2);
$return = [];
for($x = $pos1->x; $x >= $pos2->x; $x --)
for($y = $pos1->y; $y >= $pos2->y; $y --)
for($z = $pos1->z; $z >= $pos2->z; $z --) {
call_user_func($call, new Vector3($x, $y, $z ), $params);
$return[] = call_user_func($call, new Vector3($x, $y, $z ), ...$params);
}
return $return;
}
/*


Loading…
Cancel
Save