mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Faster level generator
This commit is contained in:
@ -127,7 +127,7 @@ class SuperflatGenerator implements LevelGenerator{
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ){
|
||||
foreach($this->populators as $populator){
|
||||
$this->random->setSeed((int) ($chunkX * 0xdead + $chunkZ * 0xbeef));
|
||||
$this->random->setSeed((int) ($chunkX * 0xdead + $chunkZ * 0xbeef) ^ $this->level->getSeed());
|
||||
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
|
||||
}
|
||||
}
|
||||
@ -167,17 +167,17 @@ class SuperflatGenerator implements LevelGenerator{
|
||||
$grasscount = intval($this->options["spawn"]["grasscount"]);
|
||||
}
|
||||
for($t = 0; $t < $treecount; ++$t){
|
||||
$centerX = $this->random->nextRange(0, 256);
|
||||
$centerZ = $this->random->nextRange(0, 256);
|
||||
$down = $this->level->getBlock(new Vector3($centerX, $this->floorLevel - 1, $centerZ))->getID();
|
||||
$centerX = $this->random->nextRange(0, 255);
|
||||
$centerZ = $this->random->nextRange(0, 255);
|
||||
$down = $this->level->level->getBlockID($centerX, $this->floorLevel - 1, $centerZ);
|
||||
if($down === DIRT or $down === GRASS or $down === FARMLAND){
|
||||
TreeObject::growTree($this->level, new Vector3($centerX, $this->floorLevel, $centerZ), $this->random, $this->random->nextRange(0,3));
|
||||
}
|
||||
}
|
||||
for($t = 0; $t < $grasscount; ++$t){
|
||||
$centerX = $this->random->nextRange(0, 256);
|
||||
$centerZ = $this->random->nextRange(0, 256);
|
||||
$down = $this->level->getBlock(new Vector3($centerX, $this->floorLevel - 1, $centerZ))->getID();
|
||||
$centerX = $this->random->nextRange(0, 255);
|
||||
$centerZ = $this->random->nextRange(0, 255);
|
||||
$down = $this->level->level->getBlockID($centerX, $this->floorLevel - 1, $centerZ);
|
||||
if($down === GRASS){
|
||||
TallGrassObject::growGrass($this->level, new Vector3($centerX, $this->floorLevel - 1, $centerZ), $this->random, $this->random->nextRange(8, 40));
|
||||
}
|
||||
|
@ -32,13 +32,13 @@ class OreObject{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function canPlaceObject(Level $level, Vector3 $pos){
|
||||
return ($level->getBlock($pos)->getID() !== AIR);
|
||||
public function canPlaceObject(Level $level, $x, $y, $z){
|
||||
return ($level->level->getBlockID($x, $y, $z) != AIR);
|
||||
}
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos){
|
||||
$clusterSize = (int) $this->type->clusterSize;
|
||||
$angle = $this->random->nextFloat() * pi();
|
||||
$angle = $this->random->nextFloat() * M_PI;
|
||||
$offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8);
|
||||
$x1 = $pos->x + 8 + $offset->x;
|
||||
$x2 = $pos->x + 8 - $offset->x;
|
||||
@ -50,7 +50,7 @@ class OreObject{
|
||||
$seedX = $x1 + ($x2 - $x1) * $count / $clusterSize;
|
||||
$seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
|
||||
$seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
|
||||
$size = ((sin($count * (pi() / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
|
||||
$size = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
|
||||
|
||||
$startX = (int) ($seedX - $size);
|
||||
$startY = (int) ($seedY - $size);
|
||||
@ -67,9 +67,8 @@ class OreObject{
|
||||
if($y > 0 and ($sizeX + $sizeY) < 1){
|
||||
for($z = $startZ; $z <= $endZ; ++$z){
|
||||
$sizeZ = pow(($z + 0.5 - $seedZ) / $size, 2);
|
||||
$v = new Vector3($x, $y, $z);
|
||||
if(($sizeX + $sizeY + $sizeZ) < 1 and $level->getBlock($v)->getID() === STONE){
|
||||
$level->setBlockRaw($v, $this->type->material);
|
||||
if(($sizeX + $sizeY + $sizeZ) < 1 and $level->level->getBlockID($x, $y, $z) === STONE){
|
||||
$level->setBlockRaw(new Vector3($x, $y, $z), $this->type->material);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,23 +23,21 @@
|
||||
class TallGrassObject{
|
||||
public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15){
|
||||
$arr = array(
|
||||
array(DANDELION, 0),
|
||||
array(CYAN_FLOWER, 0),
|
||||
array(TALL_GRASS, 1),
|
||||
array(TALL_GRASS, 1),
|
||||
array(TALL_GRASS, 1),
|
||||
array(TALL_GRASS, 1),
|
||||
array(AIR, 0),
|
||||
BlockAPI::get(DANDELION, 0),
|
||||
BlockAPI::get(CYAN_FLOWER, 0),
|
||||
BlockAPI::get(TALL_GRASS, 1),
|
||||
BlockAPI::get(TALL_GRASS, 1),
|
||||
BlockAPI::get(TALL_GRASS, 1),
|
||||
BlockAPI::get(TALL_GRASS, 1)
|
||||
);
|
||||
$radius = ceil(sqrt($count) / 2);
|
||||
$radius = 10;
|
||||
$arrC = count($arr) - 1;
|
||||
for($c = 0; $c < $count; ++$c){
|
||||
$x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
|
||||
$z = $random->nextRange($pos->z - $radius, $pos->z + $radius);
|
||||
$b = $level->getBlock(new Vector3($x, $pos->y + 1, $z));
|
||||
$d = $level->getBlock(new Vector3($x, $pos->y, $z));
|
||||
if($b->getID() === AIR and $d->getID() === GRASS){
|
||||
$t = $arr[$random->nextRange(0, count($arr) - 1)];
|
||||
$level->setBlockRaw($b, BlockAPI::get($t[0], $t[1]));
|
||||
if($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS){
|
||||
$t = $arr[$random->nextRange(0, $arrC)];
|
||||
$level->setBlockRaw(new Vector3($x, $pos->y + 1, $z), $t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ class PineTreeObject extends TreeObject{
|
||||
}
|
||||
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
|
||||
for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
|
||||
$block = $level->getBlock(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz));
|
||||
if(!isset($this->overridable[$block->getID()])){
|
||||
if(!isset($this->overridable[$level->level->getBlockID($pos->x + $xx, $pos->y + $yy, $pos->z + $zz)])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,7 @@ class SmallTreeObject extends TreeObject{
|
||||
}
|
||||
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
|
||||
for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){
|
||||
$block = $level->getBlock(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz));
|
||||
if(!isset($this->overridable[$block->getID()])){
|
||||
if(!isset($this->overridable[$level->level->getBlockID($pos->x + $xx, $pos->y + $yy, $pos->z + $zz)])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -53,7 +52,7 @@ class SmallTreeObject extends TreeObject{
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos, Random $random){
|
||||
// The base dirt block
|
||||
$dirtpos = new Vector3( $pos->x, $pos->y -1, $pos->z );
|
||||
$dirtpos = new Vector3( $pos->x, $pos->y - 1, $pos->z );
|
||||
$level->setBlockRaw( $dirtpos, new DirtBlock() );
|
||||
|
||||
// Adjust the tree trunk's height randomly
|
||||
|
@ -38,8 +38,7 @@ class SpruceTreeObject extends TreeObject{
|
||||
}
|
||||
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
|
||||
for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
|
||||
$block = $level->getBlock(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz));
|
||||
if(!isset($this->overridable[$block->getID()])){
|
||||
if(!isset($this->overridable[$level->level->getBlockID($pos->x + $xx, $pos->y + $yy, $pos->z + $zz)])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -25,13 +25,11 @@ class OrePopulator extends Populator{
|
||||
foreach($this->oreTypes as $type){
|
||||
$ore = new OreObject($random, $type);
|
||||
for($i = 0; $i < $ore->type->clusterCount; ++$i){
|
||||
$v = new Vector3(
|
||||
$random->nextRange($chunkX << 4, ($chunkX << 4) + 16),
|
||||
$random->nextRange($ore->type->minHeight, $ore->type->maxHeight),
|
||||
$random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16)
|
||||
);
|
||||
if($ore->canPlaceObject($level, $v)){
|
||||
$ore->placeObject($level, $v);
|
||||
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
|
||||
$y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
|
||||
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
|
||||
if($ore->canPlaceObject($level, $x, $y, $z)){
|
||||
$ore->placeObject($level, new Vector3($x, $y, $z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user