Fixing a bad formatting

This commit is contained in:
Adsooi 2017-04-29 11:59:44 +02:00
parent 36956495ee
commit 2d6bb2c679
32 changed files with 1403 additions and 1264 deletions

View file

@ -253,8 +253,8 @@ class BetterNormal extends Generator {
$biomeCache = [ ]; $biomeCache = [ ];
for($x = 0; $x < 16; ++ $x) { for($x = 0; $x < 16; $x++) {
for($z = 0; $z < 16; ++ $z) { for($z = 0; $z < 16; $z++) {
$minSum = 0; $minSum = 0;
$maxSum = 0; $maxSum = 0;
$weightSum = 0; $weightSum = 0;
@ -262,8 +262,8 @@ class BetterNormal extends Generator {
$biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z); $biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
$chunk->setBiomeId($x, $z, $biome->getId ()); $chunk->setBiomeId($x, $z, $biome->getId ());
for($sx = - self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++ $sx) { for($sx = - self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; $sx++) {
for($sz = - self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++ $sz) { for($sz = - self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; $sz++) {
$weight = self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE]; $weight = self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE];
@ -289,7 +289,7 @@ class BetterNormal extends Generator {
$smoothHeight = ($maxSum - $minSum) / 2; $smoothHeight = ($maxSum - $minSum) / 2;
for($y = 0; $y < 128; ++ $y) { for($y = 0; $y < 128; $y++) {
if ($y < 3 || ($y < 5 && $this->random->nextBoolean ())) { if ($y < 3 || ($y < 5 && $this->random->nextBoolean ())) {
$chunk->setBlockId($x, $y, $z, Block::BEDROCK); $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
continue; continue;
@ -353,10 +353,10 @@ class BetterNormal extends Generator {
$bellSize = 1 / self::$SMOOTH_SIZE; $bellSize = 1 / self::$SMOOTH_SIZE;
$bellHeight = 2 * self::$SMOOTH_SIZE; $bellHeight = 2 * self::$SMOOTH_SIZE;
for($sx = - self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++ $sx) { for($sx = - self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; $sx++) {
self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] = [ ]; self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] = [ ];
for($sz = - self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++ $sz) { for($sz = - self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; $sz++) {
$bx = $bellSize * $sx; $bx = $bellSize * $sx;
$bz = $bellSize * $sz; $bz = $bellSize * $sz;
self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE] = $bellHeight * exp(- ($bx * $bx + $bz * $bz) / 2); self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE] = $bellHeight * exp(- ($bx * $bx + $bz * $bz) / 2);
@ -402,7 +402,7 @@ class BetterNormal extends Generator {
} }
} }
return ++ $y; return $y++;
} }
/* /*

View file

@ -37,7 +37,7 @@ class BushPopulator extends AmountPopulator {
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level; $this->level = $level;
$amount = $this->getAmount($random); $amount = $this->getAmount($random);
for($i = 0; $i < $amount; ++ $i) { for($i = 0; $i < $amount; $i++) {
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
$y = $this->getHighestWorkableBlock($x, $z); $y = $this->getHighestWorkableBlock($x, $z);
@ -65,6 +65,6 @@ class BushPopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
} }

View file

@ -36,7 +36,7 @@ class CactusPopulator extends AmountPopulator {
$this->level = $level; $this->level = $level;
$amount = $this->getAmount($random); $amount = $this->getAmount($random);
$cactus = new Cactus (); $cactus = new Cactus ();
for($i = 0; $i < $amount; ++ $i) { for($i = 0; $i < $amount; $i++) {
$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);
@ -58,6 +58,6 @@ class CactusPopulator extends AmountPopulator {
break; break;
} }
} }
return $y === 0 ? - 1 : ++ $y; return $y === 0 ? - 1 : $y++;
} }
} }

View file

@ -30,7 +30,7 @@ class CavePopulator extends AmountPopulator {
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level; $this->level = $level;
$amount = $this->getAmount($random); $amount = $this->getAmount($random);
for($i = 0; $i < $amount; ++ $i) { for($i = 0; $i < $amount; $i++) {
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
$y = $random->nextRange(10, $this->getHighestWorkableBlock($x, $z )); $y = $random->nextRange(10, $this->getHighestWorkableBlock($x, $z ));
@ -68,7 +68,7 @@ class CavePopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
/* /*
@ -91,7 +91,6 @@ class CavePopulator extends AmountPopulator {
} }
} }
} }
/* /*
* Generates a cave branch. * Generates a cave branch.
* @param $x int * @param $x int

View file

@ -27,7 +27,7 @@ class DeadbushPopulator extends AmountPopulator {
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level; $this->level = $level;
$amount = $this->getAmount($random); $amount = $this->getAmount($random);
for($i = 0; $i < $amount; ++ $i) { for($i = 0; $i < $amount; $i++) {
$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);
@ -50,6 +50,6 @@ class DeadbushPopulator extends AmountPopulator {
break; break;
} }
} }
return $y === 0 ? - 1 : ++ $y; return $y === 0 ? - 1 : $y++;
} }
} }

View file

@ -0,0 +1,64 @@
<?php
/*
* FallenTreePopulator from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\populator;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use Ad5001\BetterGen\structure\FallenTree;
use Ad5001\BetterGen\populator\AmountPopulator;
class FallenTreePopulator extends AmountPopulator {
protected $level;
/*
* Constructs the class
* @param $type int
*/
public function __construct() {
$this->setBaseAmount(1);
$this->setRandomAmount(2);
}
/*
* Populate the chunk
* @param $level pocketmine\level\ChunkManager
* @param $chunkX int
* @param $chunkZ int
* @param $random pocketmine\utils\Random
*/
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level;
$amount = $this->getAmount($random);
$fallenTree = new FallenTree();
for($i = 0; $i < $amount; $i++) {
$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);
}
}
}
/*
* Gets the top block (y) on an x and z axes
* @param $x int
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y >= 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) {
break;
}
}
return $y === 0 ? - 1 : $y++;
}
}

View file

@ -68,7 +68,7 @@ class FloatingIslandPopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }

View file

@ -51,6 +51,6 @@ class IglooPopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
} }

View file

@ -60,6 +60,6 @@ class LakePopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
} }

View file

@ -77,7 +77,7 @@ class RavinePopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
/* /*

View file

@ -36,7 +36,7 @@ class SugarCanePopulator extends AmountPopulator {
$this->level = $level; $this->level = $level;
$amount = $this->getAmount($random); $amount = $this->getAmount($random);
$sugarcane = new SugarCane (); $sugarcane = new SugarCane ();
for($i = 0; $i < $amount; ++ $i) { for($i = 0; $i < $amount; $i++) {
$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);
@ -58,6 +58,6 @@ class SugarCanePopulator extends AmountPopulator {
break; break;
} }
} }
return $y === 0 ? - 1 : ++ $y; return $y === 0 ? - 1 : $y++;
} }
} }

View file

@ -49,6 +49,6 @@ class TemplePopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
} }

View file

@ -41,7 +41,7 @@ class TreePopulator extends AmountPopulator {
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level; $this->level = $level;
$amount = $this->getAmount($random); $amount = $this->getAmount($random);
for($i = 0; $i < $amount; ++ $i) { for($i = 0; $i < $amount; $i++) {
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
$y = $this->getHighestWorkableBlock($x, $z); $y = $this->getHighestWorkableBlock($x, $z);
@ -70,6 +70,6 @@ class TreePopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
} }

View file

@ -49,6 +49,6 @@ class WellPopulator extends AmountPopulator {
} }
} }
return ++ $y; return $y++;
} }
} }

View file

@ -0,0 +1,76 @@
<?php
/*
* Bush from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\structure;
use pocketmine\block\Leaves;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use pocketmine\math\Vector3;
use pocketmine\level\generator\object\Object;
class Bush extends Object {
public $overridable = [
Block::AIR => true,
17 => true,
Block::SNOW_LAYER => true,
Block::LOG2 => true
];
protected $trunk;
protected $direction;
/*
* Constructs the class
* @param $trunkId int
* @param $trunkData int
*/
public function __construct($trunk = Block::WOOD, $trunkData = 0) {
$this->trunk = [
$trunkId,
$trunkData
];
}
/*
* Places a fallen tree
* @param $level pocketmine\level\ChunkManager
* @param $x int
* @param $y int
* @param $z int
* @param $random pocketmine\utils\Random
*/
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) {
$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);
}
}
/*
* Places a Block
* @param $x int
* @param $y int
* @param $z int
* @param $level pocketmine\level\ChunkManager
*/
public function placeBlock($x, $y, $z, ChunkManager $level) {
if (isset($this->overridable [$level->getBlockIdAt($x, $y, $z )] ) && ! isset($this->overridable [$level->getBlockIdAt($x, $y - 1, $z )] )) {
$level->setBlockIdAt($x, $y, $z, $this->trunk [0]);
$level->setBlockDataAt($x, $y, $z, $this->trunk [1]);
}
}
}