support php8019 and some cleanup (by @D-aHTuCT)

This commit is contained in:
kotyara 2022-07-26 16:06:34 +05:00
parent cf0f9df267
commit b60f0877e1
376 changed files with 6528 additions and 13472 deletions

View file

@ -1,34 +1,16 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
interface LevelGenerator{
public function __construct(array $options = array());
public function __construct(array $options = []);
public function init(Level $level, Random $random);
public function generateChunk($chunkX, $chunkZ);
public function populateChunk($chunkX, $chunkZ);
public function populateLevel();
public function getSpawn();
}

View file

@ -1,24 +1,6 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class Populator{
public abstract function populate(Level $level, $chunkX, $chunkZ, Random $random);
}

View file

@ -1,32 +1,14 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("LevelGenerator.php");
/***REM_END***/
/***REM_END***/
class SuperflatGenerator implements LevelGenerator{
private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = array();
public function __construct(array $options = array()){
private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = [];
public function __construct(array $options = []){
$this->preset = "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)";
$this->options = $options;
if(isset($options["preset"])){
@ -36,50 +18,50 @@ class SuperflatGenerator implements LevelGenerator{
}
if(isset($this->options["decoration"])){
$ores = new OrePopulator();
$ores->setOreTypes(array(
$ores->setOreTypes([
new OreType(new CoalOreBlock(), 20, 16, 0, 128),
new OreType(New IronOreBlock(), 20, 8, 0, 64),
new OreType(new IronOreBlock(), 20, 8, 0, 64),
new OreType(new RedstoneOreBlock(), 8, 7, 0, 16),
new OreType(new LapisOreBlock(), 1, 6, 0, 32),
new OreType(new GoldOreBlock(), 2, 8, 0, 32),
new OreType(new DiamondOreBlock(), 1, 7, 0, 16),
new OreType(new DirtBlock(), 20, 32, 0, 128),
new OreType(new GravelBlock(), 10, 16, 0, 128),
));
$this->populators[] = $ores;
]);
$this->populators[] = $ores;
}
/*if(isset($this->options["mineshaft"])){
$this->populators[] = new MineshaftPopulator(isset($this->options["mineshaft"]["chance"]) ? floatval($this->options["mineshaft"]["chance"]) : 0.01);
}*/
}
public function parsePreset($preset){
$this->preset = $preset;
$preset = explode(";", $preset);
$version = (int) $preset[0];
$blocks = @$preset[1];
$biome = isset($preset[2]) ? $preset[2]:1;
$options = isset($preset[3]) ? $preset[3]:"";
$biome = isset($preset[2]) ? $preset[2] : 1;
$options = isset($preset[3]) ? $preset[3] : "";
preg_match_all('#(([0-9]{0,})x?([0-9]{1,3}:?[0-9]{0,2})),?#', $blocks, $matches);
$y = 0;
$this->structure = array();
$this->chunks = array();
$this->structure = [];
$this->chunks = [];
foreach($matches[3] as $i => $b){
$b = BlockAPI::fromString($b);
$cnt = $matches[2][$i] === "" ? 1:intval($matches[2][$i]);
$cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
for($cY = $y, $y += $cnt; $cY < $y; ++$cY){
$this->structure[$cY] = $b;
}
}
$this->floorLevel = $y;
for(;$y < 0xFF; ++$y){
for(; $y < 0xFF; ++$y){
$this->structure[$y] = new AirBlock();
}
for($Y = 0; $Y < 8; ++$Y){
$this->chunks[$Y] = "";
$startY = $Y << 4;
@ -92,16 +74,16 @@ class SuperflatGenerator implements LevelGenerator{
$blocks .= chr($this->structure[$y]->getID());
$metas .= substr(dechex($this->structure[$y]->getMetadata()), -1);
}
$this->chunks[$Y] .= $blocks.hex2bin($metas)."\x00\x00\x00\x00\x00\x00\x00\x00";
$this->chunks[$Y] .= $blocks . hex2bin($metas) . "\x00\x00\x00\x00\x00\x00\x00\x00";
}
}
}
preg_match_all('#(([0-9a-z_]{1,})\(?([0-9a-z_ =:]{0,})\)?),?#', $options, $matches);
foreach($matches[2] as $i => $option){
$params = true;
if($matches[3][$i] !== ""){
$params = array();
$params = [];
$p = explode(" ", $matches[3][$i]);
foreach($p as $k){
$k = explode("=", $k);
@ -113,29 +95,29 @@ class SuperflatGenerator implements LevelGenerator{
$this->options[$option] = $params;
}
}
public function init(Level $level, Random $random){
$this->level = $level;
$this->random = $random;
}
public function generateChunk($chunkX, $chunkZ){
for($Y = 0; $Y < 8; ++$Y){
$this->level->setMiniChunk($chunkX, $chunkZ, $Y, $this->chunks[$Y]);
}
}
public function populateChunk($chunkX, $chunkZ){
public function populateChunk($chunkX, $chunkZ){
foreach($this->populators as $populator){
$this->random->setSeed((int) ($chunkX * 0xdead + $chunkZ * 0xbeef) ^ $this->level->getSeed());
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
}
}
public function populateLevel(){
$this->random->setSeed($this->level->getSeed());
if(isset($this->options["spawn"])){
$spawn = array(10, new SandstoneBlock());
$spawn = [10, new SandstoneBlock()];
if(isset($this->options["spawn"]["radius"])){
$spawn[0] = intval($this->options["spawn"]["radius"]);
}
@ -156,7 +138,7 @@ class SuperflatGenerator implements LevelGenerator{
}
}
}
if(isset($this->options["decoration"])){
$treecount = 80;
$grasscount = 120;
@ -171,7 +153,7 @@ class SuperflatGenerator implements LevelGenerator{
$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));
TreeObject::growTree($this->level, new Vector3($centerX, $this->floorLevel, $centerZ), $this->random, $this->random->nextRange(0, 3));
}
}
for($t = 0; $t < $grasscount; ++$t){
@ -184,7 +166,7 @@ class SuperflatGenerator implements LevelGenerator{
}
}
}
public function getSpawn(){
return new Vector3(128, $this->floorLevel, 128);
}

File diff suppressed because one or more lines are too long

View file

@ -1,34 +1,17 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class WorldGenerator{
private $seed, $level, $path, $random, $generator, $width;
public function __construct(LevelGenerator $generator, $name, $seed = false, $width = 16, $height = 8){
$this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false));
$this->seed = $seed !== false ? (int) $seed : Utils::readInt(Utils::getRandomBytes(4, false));
$this->random = new Random($this->seed);
$this->width = (int) $width;
$this->height = (int) $height;
$this->path = DATA_PATH."worlds/".$name."/";
$this->path = DATA_PATH . "worlds/" . $name . "/";
$this->generator = $generator;
$level = new PMFLevel($this->path."level.pmf", array(
$level = new PMFLevel($this->path . "level.pmf", [
"name" => $name,
"seed" => $this->seed,
"time" => 0,
@ -38,20 +21,20 @@ class WorldGenerator{
"extra" => "",
"width" => $this->width,
"height" => $this->height
));
$entities = new Config($this->path."entities.yml", CONFIG_YAML);
$tiles = new Config($this->path."tiles.yml", CONFIG_YAML);
$blockUpdates = new Config($this->path."bupdates.yml", CONFIG_YAML);
]);
$entities = new Config($this->path . "entities.yml", CONFIG_YAML);
$tiles = new Config($this->path . "tiles.yml", CONFIG_YAML);
$blockUpdates = new Config($this->path . "bupdates.yml", CONFIG_YAML);
$this->level = new Level($level, $entities, $tiles, $blockUpdates, $name);
}
public function generate(){
$this->generator->init($this->level, $this->random);
for($Z = 0; $Z < $this->width; ++$Z){
for($X = 0; $X < $this->width; ++$X){
$this->generator->generateChunk($X, $Z);
}
console("[NOTICE] Generating level ".ceil((($Z + 1)/$this->width) * 100)."%");
console("[NOTICE] Generating level " . ceil((($Z + 1) / $this->width) * 100) . "%");
}
console("[NOTICE] Populating level");
$this->generator->populateLevel();
@ -59,13 +42,13 @@ class WorldGenerator{
for($X = 0; $X < $this->width; ++$X){
$this->generator->populateChunk($X, $Z);
}
console("[NOTICE] Populating level ".ceil((($Z + 1)/$this->width) * 100)."%");
console("[NOTICE] Populating level " . ceil((($Z + 1) / $this->width) * 100) . "%");
}
$this->level->setSpawn($this->generator->getSpawn());
$this->level->save(true, true);
}
public function close(){
$this->level->close();
}

View file

@ -1,24 +1,5 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class NoiseGenerator{
}

View file

@ -1,24 +1,5 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("NoiseGenerator.php");
/***REM_END***/

View file

@ -1,32 +1,14 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("NoiseGenerator.php");
/***REM_END***/
/***REM_END***/
class NoiseGeneratorPerlin extends NoiseGenerator{
private $permutations = array();
public $xCoord, $yCoord, $zCoord;
private $permutations = [];
public function __construct($random = false){
if(!($random instanceof Random)){
$random = new Random();
@ -41,7 +23,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
for($i = 0; $i < 256; ++$i){
$this->permutations[$i] = $i;
}
for($i = 0; $i < 256; ++$i){
$j = $random->nextRange(0, 256 - $i) + $i;
$k = $this->permutations[$i];
@ -49,29 +31,9 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$this->permutations[$j] = $k;
$this->permutations[$i + 256] = $this->permutations[$i];
}
}
public final function curve($par1, $par2, $par3){
return $par2 + $par1 * ($par3 - $par2);
}
public function grad2D($int, $par1, $par2){
$i = $int & 0x0F;
$d1 = (1 - (($i & 0x08) >> 3)) * $par1;
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? 0:$par2);
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
}
public function grad3D($int, $par1, $par2, $par3){
$i = $int & 0x0F;
$d1 = $i < 8 ? $par1 : $par2;
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? $par2:$par3);
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
}
public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7){
if($int2 === 1){
$n = 0;
@ -85,7 +47,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$i3 = $i2 & 0xFF;
$d4 -= $i2;
$d5 = $d4 * $d4 * $d4 * ($d4 * ($d4 * 6 - 15) + 10);
for($i4 = 0; $i4 < $int3; ++$i4){
$d6 = $par3 + $i4 * $par6 + $this->zCoord;
$i5 = (int) $d6;
@ -95,14 +57,14 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$i6 = $i5 & 0xFF;
$d6 -= $i5;
$d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10);
$i = $this->permutations[$i3];
$j = $this->permutations[$i] + $i6;
$k = $this->permutations[$i3 + 1];
$m = $this->permutations[$k] + $i6;
$d1 = $this->curve($d5, $this->grad2D($this->permutations[$j], $d4, $d6), $this->grad3D($this->permutations[$m], $d4 - 1, 0, $d6));
$d2 = $this->curve($d5, $this->grad3D($this->permutations[$j + 1], $d4, 0, $d6 - 1), $this->grad3D($this->permutations[$m + 1], $d4 - 1, 0, $d6 - 1));
$d8 = $this->curve($d7, $d1, $d2);
$floats[$n++] += $d8 * $d3;
}
@ -114,7 +76,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$m = -1;
$n = 0;
$i = 0;
for($i4 = 0; $i4 < $int1; ++$i4){
$d6 = $par1 + $i4 * $par4 + $this->xCoord;
$i5 = (int) $d6;
@ -124,7 +86,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$i6 = $i5 & 0xFF;
$d6 -= $i5;
$d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10);
for($i12 = 0; $i12 < $int3; ++$i12){
$d12 = $par3 + $i12 * $par6 + $this->zCoord;
$i13 = (int) $d12;
@ -134,7 +96,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$i14 = $i13 & 0xFF;
$d12 -= $i13;
$d13 = $d12 * $d12 * $d12 * ($d12 * ($d12 * 6 - 15) + 10);
for($i15 = 0; $i15 < $int2; ++$i15){
$d14 = $par2 + $i15 * $par5 + $this->yCoord;
$i16 = (int) $d14;
@ -157,7 +119,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$d11 = $this->curve($d7, $this->grad3D($this->permutations[$i8 + 1], $d6, $d14, $d12 - 1), $this->grad3D($this->permutations[$n + 1], $d6 - 1, $d14, $d12 - 1));
$d5 = $this->curve($d7, $this->grad3D($this->permutations[$i9 + 1], $d6, $d14 - 1, $d12 - 1), $this->grad3D($this->permutations[$i11 + 1], $d6 - 1, $d14 - 1, $d12 - 1));
}
$d16 = $this->curve($d15, $d10, $d4);
$d17 = $this->curve($d15, $d11, $d5);
$d18 = $this->curve($d13, $d16, $d17);
@ -166,4 +128,24 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
}
}
}
public final function curve($par1, $par2, $par3){
return $par2 + $par1 * ($par3 - $par2);
}
public function grad2D($int, $par1, $par2){
$i = $int & 0x0F;
$d1 = (1 - (($i & 0x08) >> 3)) * $par1;
$d2 = ($i === 12 or $i === 14) ? $par1 : ($i < 4 ? 0 : $par2);
return (($i & 0x01) === 0 ? $d1 : -$d1) + (($i & 0x02) === 0 ? $d2 : -$d2);
}
public function grad3D($int, $par1, $par2, $par3){
$i = $int & 0x0F;
$d1 = $i < 8 ? $par1 : $par2;
$d2 = ($i === 12 or $i === 14) ? $par1 : ($i < 4 ? $par2 : $par3);
return (($i & 0x01) === 0 ? $d1 : -$d1) + (($i & 0x02) === 0 ? $d2 : -$d2);
}
}

View file

@ -1,5 +1,7 @@
<?php
class NetherReactorStructure{
/*pretty long =D*/
private static $structure = [
-2 => [
@ -174,23 +176,23 @@ class NetherReactorStructure{
"NNNNNNNNNNNNNNNNN",
],
7 => [ //spaces are required
"NNNNNNNNNNNNNNNNN",
"N N",
"N N",
"N NNNNNNNNNNN N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N NNNNNNNNNNN N",
"N NN",
"N NNN",
"NNNNNNNNNNNNNNNN ",
"NNNNNNNNNNNNNNNNN",
"N N",
"N N",
"N NNNNNNNNNNN N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N N N N",
"N NNNNNNNNNNN N",
"N NN",
"N NNN",
"NNNNNNNNNNNNNNNN ",
],
8 => [
"NNNNNNNNNNNNNNNNN",
@ -589,6 +591,7 @@ class NetherReactorStructure{
" N ",
],
];
public static function buildReactor($level, $x, $y, $z){ /*use CENTER positions*/
$offsetX = 0;
$offsetZ = 0;

View file

@ -1,41 +1,23 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class OreObject{
private $random;
public $type;
private $random;
public function __construct(Random $random, OreType $type){
$this->type = $type;
$this->random = $random;
}
public function getType(){
return $this->type;
}
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() * M_PI;
@ -51,14 +33,14 @@ class OreObject{
$seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
$seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
$size = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
$startX = (int) ($seedX - $size);
$startY = (int) ($seedY - $size);
$startZ = (int) ($seedZ - $size);
$endX = (int) ($seedX + $size);
$endY = (int) ($seedY + $size);
$endZ = (int) ($seedZ + $size);
for($x = $startX; $x <= $endX; ++$x){
$sizeX = ($x + 0.5 - $seedX) / $size;
$sizeX *= $sizeX;

View file

@ -1,27 +1,9 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class OreType{
public $material, $clusterCount, $clusterSize, $maxHeight, $minHeight;
public function __construct(Block $material, $clusterCount, $clusterSize, $minHeight, $maxHeight){
$this->material = $material;
$this->clusterCount = (int) $clusterCount;

View file

@ -1,37 +1,18 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PondObject{
private $random;
public $type;
private $random;
public function __construct(Random $random, Block $type){
$this->type = $type;
$this->random = $random;
}
public function canPlaceObject(Level $level, Vector3 $pos){
}
public function placeObject(Level $level, Vector3 $pos){
}
}

View file

@ -1,35 +1,16 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class TallGrassObject{
public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){
$arr = array(
$arr = [
BlockAPI::get(DANDELION, 0),
BlockAPI::get(CYAN_FLOWER, 0),
BlockAPI::get(TALL_GRASS, 1),
BlockAPI::get(TALL_GRASS, 1),
BlockAPI::get(TALL_GRASS, 2),
BlockAPI::get(TALL_GRASS, 1)
);
];
$arrC = count($arr) - 1;
for($c = 0; $c < $count; ++$c){
$x = $random->nextRange($pos->x - $radius, $pos->x + $radius);

View file

@ -1,39 +1,20 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("src/world/generator/object/tree/TreeObject.php");
/***REM_END***/
/***REM_END***/
class BigTreeObject extends TreeObject{
protected $radiusIncrease = 0;
private $trunkHeightMultiplier = 0.618;
private $trunkHeight;
private $leafAmount = 1;
private $leafDistanceLimit = 5;
private $widthScale = 1;
private $branchSlope = 0.381;
private $totalHeight = 6;
private $leavesHeight = 3;
protected $radiusIncrease = 0;
private $addLeavesVines = false;
private $addLogVines = false;
private $addCocoaPlants = false;
@ -50,7 +31,7 @@ class BigTreeObject extends TreeObject{
$groupX = $leafGroup->getBlockX();
$groupY = $leafGrou->getBlockY();
$groupZ = $leafGroup->getBlockZ();
for ($yy = $groupY; $yy < $groupY + $this->leafDistanceLimit; ++$yy) {
for($yy = $groupY; $yy < $groupY + $this->leafDistanceLimit; ++$yy){
$this->generateGroupLayer($level, $groupX, $yy, $groupZ, $this->getLeafGroupLayerSize($yy - $groupY));
}
}

View file

@ -1,29 +1,11 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("src/world/generator/object/tree/TreeObject.php");
/***REM_END***/
/***REM_END***/
class PineTreeObject extends TreeObject{
var $type = 1;
private $totalHeight = 8;
private $leavesSizeY = -1;
@ -32,8 +14,8 @@ class PineTreeObject extends TreeObject{
public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
$this->findRandomLeavesSize($random);
$checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight; ++$yy) {
if($yy === $this->leavesSizeY) {
for($yy = 0; $yy < $this->totalHeight; ++$yy){
if($yy === $this->leavesSizeY){
$checkRadius = $this->leavesAbsoluteMaxRadius;
}
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
@ -54,7 +36,7 @@ class PineTreeObject extends TreeObject{
}
public function placeObject(Level $level, Vector3 $pos, Random $random){
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1){
$this->findRandomLeavesSize($random);
}
$level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
@ -62,19 +44,19 @@ class PineTreeObject extends TreeObject{
$leavesMaxRadius = 1;
$leavesBottomY = $this->totalHeight - $this->leavesSizeY;
$firstMaxedRadius = false;
for($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY) {
for($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY){
$yy = $this->totalHeight - $leavesY;
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx){
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz){
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0){
$level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type));
}
}
}
if($leavesRadius >= $leavesMaxRadius) {
if($leavesRadius >= $leavesMaxRadius){
$leavesRadius = $firstMaxedRadius ? 1 : 0;
$firstMaxedRadius = true;
if(++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius) {
if(++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius){
$leavesMaxRadius = $this->leavesAbsoluteMaxRadius;
}
}else{

View file

@ -1,42 +1,24 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("TreeObject.php");
/***REM_END***/
/***REM_END***/
class SmallTreeObject extends TreeObject{
public $type = 0;
private $trunkHeight = 5;
private static $leavesHeight = 4; // All trees appear to be 4 tall
private static $leafRadii = array( 1, 1.41, 2.83, 2.24 );
private static $leavesHeight = 4;
private static $leafRadii = [1, 1.41, 2.83, 2.24];
public $type = 0; // All trees appear to be 4 tall
public $treeHeight = 7;
private $trunkHeight = 5;
private $addLeavesVines = false;
private $addLogVines = false;
private $addCocoaPlants = false;
public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
$radiusToCheck = 0;
for ($yy = 0; $yy < $this->trunkHeight + 3; ++$yy) {
if($yy == 1 or $yy === $this->trunkHeight) {
for($yy = 0; $yy < $this->trunkHeight + 3; ++$yy){
if($yy == 1 or $yy === $this->trunkHeight){
++$radiusToCheck;
}
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
@ -49,27 +31,13 @@ class SmallTreeObject extends TreeObject{
}
return true;
}
protected function placeTrunk(Level $level, $x, $y, $z, Random $random, $trunkHeight){
// The base dirt block
$dirtpos = new Vector3($x, $y - 1, $z);
$level->setBlockRaw($dirtpos, new DirtBlock());
for($yy = 0; $yy < $this->treeHeight; ++$yy){
$blockId = $level->getBlock(new Vector3($x, $y + $yy, $z))->getID();
if(isset($this->overridable[$blockId])){
$trunkpos = new Vector3($x, $y + $yy, $z);
$level->setBlockRaw($trunkpos, new WoodBlock($this->type));
}
}
}
public function placeObject(Level $level, Vector3 $pos, Random $random){
$this->treeHeight = mt_rand(0, 3) + 4; //randomized tree height
$x = $pos->getX();
$y = $pos->getY();
$z = $pos->getZ();
for($yy = $y - 3 + $this->treeHeight; $yy <= $y + $this->treeHeight; ++$yy){
$yOff = $yy - ($y + $this->treeHeight);
$mid = (int) (1 - $yOff / 2);
@ -90,5 +58,19 @@ class SmallTreeObject extends TreeObject{
$this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - 1);
}
protected function placeTrunk(Level $level, $x, $y, $z, Random $random, $trunkHeight){
// The base dirt block
$dirtpos = new Vector3($x, $y - 1, $z);
$level->setBlockRaw($dirtpos, new DirtBlock());
for($yy = 0; $yy < $this->treeHeight; ++$yy){
$blockId = $level->getBlock(new Vector3($x, $y + $yy, $z))->getID();
if(isset($this->overridable[$blockId])){
$trunkpos = new Vector3($x, $y + $yy, $z);
$level->setBlockRaw($trunkpos, new WoodBlock($this->type));
}
}
}
}

View file

@ -1,29 +1,11 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("src/world/generator/object/tree/TreeObject.php");
/***REM_END***/
/***REM_END***/
class SpruceTreeObject extends TreeObject{
var $type = 1;
private $totalHeight = 8;
private $leavesBottomY = -1;
@ -32,8 +14,8 @@ class SpruceTreeObject extends TreeObject{
public function canPlaceObject(Level $level, Vector3 $pos, Random $random){
$this->findRandomLeavesSize($random);
$checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
if($yy === $this->leavesBottomY) {
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy){
if($yy === $this->leavesBottomY){
$checkRadius = $this->leavesMaxRadius;
}
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
@ -54,20 +36,20 @@ class SpruceTreeObject extends TreeObject{
}
public function placeObject(Level $level, Vector3 $pos, Random $random){
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1){
$this->findRandomLeavesSize();
}
$level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
$leavesRadius = 0;
for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx){
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz){
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0){
$level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type));
}
}
}
if($leavesRadius > 0 and $yy === ($pos->y + $this->leavesBottomY + 1)) {
if($leavesRadius > 0 and $yy === ($pos->y + $this->leavesBottomY + 1)){
--$leavesRadius;
}elseif($leavesRadius < $this->leavesMaxRadius){
++$leavesRadius;

View file

@ -1,31 +1,12 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class TreeObject{
public $overridable = array(
public $overridable = [
0 => true,
6 => true,
18 => true,
);
];
public static function growTree(Level $level, Vector3 $pos, Random $random, $type = 0){
switch($type & 0x03){
@ -49,7 +30,7 @@ class TreeObject{
/*if($random->nextRange(0, 9) === 0){
$tree = new BigTreeObject();
}else{*/
$tree = new SmallTreeObject();
$tree = new SmallTreeObject();
//}
break;
}

View file

@ -1,35 +1,17 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class MineshaftPopulator extends Populator{
private static $DISTANCE = 256;
private static $VARIATION = 16;
private static $ODD = 3;
private static $BASE_Y = 35;
private static $RAND_Y = 11;
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
if($random->nextRange(0, MineshaftPopulator::$ODD) === 0){
$mineshaft = new Mineshaft($random);
}
}
}

View file

@ -1,26 +1,9 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class OrePopulator extends Populator{
private $oreTypes = array();
private $oreTypes = [];
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
foreach($this->oreTypes as $type){
$ore = new OreObject($random, $type);
@ -34,7 +17,7 @@ class OrePopulator extends Populator{
}
}
}
public function setOreTypes(array $types){
$this->oreTypes = $types;
}

View file

@ -1,28 +1,11 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class PondPopulator extends Populator{
private $waterOdd = 4;
private $lavaOdd = 4;
private $lavaSurfaceOdd = 4;
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
if($random->nextRange(0, $this->waterOdd) === 0){
$v = new Vector3(
@ -36,7 +19,7 @@ class PondPopulator extends Populator{
}
}
}
public function setWaterOdd($waterOdd){
$this->waterOdd = $waterOdd;
}