forked from Ad5001/BetterGen
Introducing officially an not bugged FallenTree #2
This commit is contained in:
parent
6bd501a78b
commit
e8f2961eab
2 changed files with 28 additions and 15 deletions
|
@ -53,6 +53,7 @@ class FallenTreePopulator extends AmountPopulator {
|
||||||
$x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
|
$x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
|
||||||
$z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
|
$z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
|
||||||
$y = $this->getHighestWorkableBlock($x, $z);
|
$y = $this->getHighestWorkableBlock($x, $z);
|
||||||
|
if(isset(FallenTree::$overridable[$level->getBlockIdAt($x, $y, $z)])) $y--; // Changing $y if 1 block to high.
|
||||||
if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y + 1, $z, $random )) {
|
if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y + 1, $z, $random )) {
|
||||||
$fallenTree->placeObject($level, $x, $y + 1, $z);
|
$fallenTree->placeObject($level, $x, $y + 1, $z);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,31 +60,41 @@ class FallenTree extends Object {
|
||||||
*/
|
*/
|
||||||
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
|
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) {
|
||||||
echo "Checking at $x $y $z FallenTree\n";
|
echo "Checking at $x $y $z FallenTree\n";
|
||||||
$randomHeight = round($random->nextBoundedInt(6) - 3);
|
$randomHeight = round($random->nextBoundedInt($this->tree->trunkHeight < 6 ? 6 : $this->tree->trunkHeight) - ($this->tree->trunkHeight < 6 ? 3 : $this->tree->trunkHeight / 2));
|
||||||
$this->length = ($this->tree->trunkHeight??5) + $randomHeight;
|
$this->length = ($this->tree->trunkHeight ?? 5) + $randomHeight;
|
||||||
$this->direction = $random->nextBoundedInt(4);
|
$this->direction = $random->nextBoundedInt(4);
|
||||||
$this->random = $random;
|
$this->random = $random;
|
||||||
switch ($this->direction) {
|
switch ($this->direction) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:// Z+
|
case 1:// Z+
|
||||||
$return = BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), function($v3, $level) {
|
$return = array_merge(BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), function($v3, $level) {
|
||||||
if(!isset(\Ad5001\BetterGen\structure\FallenTree::$overridable[$level->getBlockIdAt($v3->x, $v3->y, $v3->z)])) {
|
if(!isset(\Ad5001\BetterGen\structure\FallenTree::$overridable[$level->getBlockIdAt($v3->x, $v3->y, $v3->z)])) {
|
||||||
echo $level->getBlockIdAt($v3->x, $v3->y, $v3->z) . " is not overridable";
|
echo "$v3 is not overwritable (" . $level->getBlockIdAt($v3->x, $v3->y, $v3->z) . ").\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, $level);
|
}, $level), BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z), new Vector3($x, $y - 1, $z + $this->length), function($v3, $level) {
|
||||||
|
if(isset(\Ad5001\BetterGen\structure\FallenTree::$overridable[$level->getBlockIdAt($v3->x, $v3->y, $v3->z)])) {
|
||||||
|
echo "$v3 is overwritable (" . $level->getBlockIdAt($v3->x, $v3->y, $v3->z) . ").\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, $level));
|
||||||
if(in_array(false, $return, true)) {
|
if(in_array(false, $return, true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
case 3: // X+
|
case 3: // X+
|
||||||
$return = BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x + $this->length, $y, $z), function($v3, $level) {
|
$return = array_merge(BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x + $this->length, $y, $z), function($v3, $level) {
|
||||||
if(!isset(\Ad5001\BetterGen\structure\FallenTree::$overridable[$level->getBlockIdAt($v3->x, $v3->y, $v3->z)])) {
|
if(!isset(\Ad5001\BetterGen\structure\FallenTree::$overridable[$level->getBlockIdAt($v3->x, $v3->y, $v3->z)])) {
|
||||||
echo $level->getBlockIdAt($v3->x, $v3->y, $v3->z) . " is not overridable";
|
echo "$v3 is not overwritable (" . $level->getBlockIdAt($v3->x, $v3->y, $v3->z) . ").\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, $level);
|
}, $level), BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z), new Vector3($x + $this->length, $y - 1, $z), function($v3, $level) {
|
||||||
|
if(isset(\Ad5001\BetterGen\structure\FallenTree::$overridable[$level->getBlockIdAt($v3->x, $v3->y, $v3->z)])) {
|
||||||
|
echo "$v3 is overwritable (" . $level->getBlockIdAt($v3->x, $v3->y, $v3->z) . ").\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, $level));
|
||||||
if(in_array(false, $return, true)) {
|
if(in_array(false, $return, true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +111,7 @@ class FallenTree extends Object {
|
||||||
* @param $z int
|
* @param $z int
|
||||||
*/
|
*/
|
||||||
public function placeObject(ChunkManager $level, $x, $y, $z) {
|
public function placeObject(ChunkManager $level, $x, $y, $z) {
|
||||||
echo "Placing at $x $y $z FallenTree\n";
|
echo "Placing at $x $y $z FallenTree D: $this->direction, L: $this->length\n";
|
||||||
switch ($this->direction) {
|
switch ($this->direction) {
|
||||||
case 0:
|
case 0:
|
||||||
$level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);
|
$level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);
|
||||||
|
@ -109,9 +119,9 @@ class FallenTree extends Object {
|
||||||
$z += 2;
|
$z += 2;
|
||||||
break;
|
break;
|
||||||
case 1:// Z+
|
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));
|
BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get($this->tree->trunkBlock, $this->tree->type + 8));
|
||||||
BuildingUtils::fillRandom($level, new Vector3($x + 1, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get(Block::VINE), $this->random);
|
BuildingUtils::fillRandom($level, new Vector3($x + 1, $y, $z), new Vector3($x + 1, $y, $z + $this->length), Block::get(Block::VINE), $this->random);
|
||||||
BuildingUtils::fillRandom($level, new Vector3($x - 1, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get(Block::VINE), $this->random);
|
BuildingUtils::fillRandom($level, new Vector3($x - 1, $y, $z), new Vector3($x - 1, $y, $z + $this->length), Block::get(Block::VINE), $this->random);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
$level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);
|
$level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);
|
||||||
|
@ -119,18 +129,20 @@ class FallenTree extends Object {
|
||||||
$x += 2;
|
$x += 2;
|
||||||
break;
|
break;
|
||||||
case 3: // X+
|
case 3: // X+
|
||||||
BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x + $this->length, $y, $z), Block::get($this->tree->trunkBlock, $this->tree->type + 8));
|
BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x + $this->length, $y, $z), Block::get($this->tree->trunkBlock, $this->tree->type + 4));
|
||||||
BuildingUtils::fillRandom($level, new Vector3($x, $y, $z + 1), new Vector3($x + $this->length, $y, $z), Block::get(Block::VINE), $this->random);
|
BuildingUtils::fillRandom($level, new Vector3($x, $y, $z + 1), new Vector3($x + $this->length, $y, $z + 1), Block::get(Block::VINE), $this->random);
|
||||||
BuildingUtils::fillRandom($level, new Vector3($x, $y, $z - 1), new Vector3($x + $this->length, $y, $z), Block::get(Block::VINE), $this->random);
|
BuildingUtils::fillRandom($level, new Vector3($x, $y, $z - 1), new Vector3($x + $this->length, $y, $z - 1), Block::get(Block::VINE), $this->random);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Second call to build the last wood block
|
// Second call to build the last wood block
|
||||||
switch ($this->direction) {
|
switch ($this->direction) {
|
||||||
case 1:
|
case 1:
|
||||||
$level->setBlockIdAt($x, $y, $z + $this->length + 2, $this->tree->trunkBlock);
|
$level->setBlockIdAt($x, $y, $z + $this->length + 2, $this->tree->trunkBlock);
|
||||||
|
$level->setBlockDataAt($x, $y, $z + $this->length + 2, $this->tree->type);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$level->setBlockIdAt($x + $this->length + 2, $y, $z, $this->tree->trunkBlock);
|
$level->setBlockIdAt($x + $this->length + 2, $y, $z, $this->tree->trunkBlock);
|
||||||
|
$level->setBlockDataAt($x + $this->length + 2, $y, $z, $this->tree->type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue