unfinished vanilla generator

This commit is contained in:
GameHerobrine 2023-06-14 17:04:04 +03:00
parent 75ddac1a73
commit 8e241171a3
26 changed files with 1156 additions and 28 deletions

View file

@ -28,6 +28,9 @@ require_once(FILE_PATH."/src/dependencies.php");
$server = new ServerAPI();
$server->start();
/*console(Utils::getSeedNumeric("nyan")*543321);
$mtrand = new MersenneTwister(Utils::getSeedNumeric("nyan")*543321);
$nois = new NoiseGeneratorOctaves($mtrand, 2);
var_dump($nois->generateNoiseOctaves(2 << 4, 6 << 4, 16, 16, 0.025, 0.025, 0.25));*/
kill(getmypid()); //Fix for ConsoleAPI being blocked
exit(0);

View file

@ -133,10 +133,16 @@ class LevelAPI{
if($generator !== false and class_exists($generator)){
$generator = new $generator($options);
}else{
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
$generator = new SuperflatGenerator($options);
}else{
$generator = new TemporalGenerator($options);
switch(strtoupper($this->server->api->getProperty("level-type"))){
case "FLAT":
$generator = new SuperflatGenerator($options);
break;
case "VANILLA":
$generator = new VanillaGenerator($options);
break;
default:
$generator = new TemporalGenerator($options);
break;
}
}
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);

View file

@ -155,7 +155,7 @@ class ServerAPI{
UPnP_PortForward($this->getProperty("server-port"));
}
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed : false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0");
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), Utils::getSeedNumeric($this->getProperty("level-seed")), $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0");
$this->server->api = $this;
self::$serverRequest = $this->server;
$this->server->send2Discord("[INFO] Starting Minecraft PE server version " . CURRENT_MINECRAFT_VERSION);

View file

@ -33,6 +33,8 @@ class PocketMinecraftServer{
}*/
console("[INFO] Starting Minecraft PE server on " . ($this->serverip === "0.0.0.0" ? "*" : $this->serverip) . ":" . $this->port);
EntityRegistry::registerEntities();
Feature::init();
Biome::init();
define("BOOTUP_RANDOM", Utils::getRandomBytes(16));
$this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)) : $this->serverID;
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : $this->seed;
@ -418,6 +420,7 @@ class PocketMinecraftServer{
pcntl_signal(SIGINT, [$this, "close"]);
pcntl_signal(SIGHUP, [$this, "close"]);
}
console("[INFO] Default game type: " . strtoupper($this->getGamemode()));
$this->trigger("server.start", microtime(true));
console('[INFO] Done (' . round(microtime(true) - START_TIME, 3) . 's)! For help, type "help" or "?"');

View file

@ -128,6 +128,7 @@ require_once(FILE_PATH . "/src/plugin/OtherPluginRequirement.php");
require_once(FILE_PATH . "/src/plugin/DummyPlugin.php");
require_once(FILE_PATH . "/src/plugin/phar/IClassLoader.php");
require_once(FILE_PATH . "/src/plugin/phar/PharUtils.php");
require_once(FILE_PATH . "/src/world/generator/vanilla/feature/Feature.php");
require_all(FILE_PATH . "src/");

View file

@ -6,11 +6,11 @@ class PMFLevel extends PMF{
public $isLoaded = true;
private $levelData = [];
private $locationTable = [];
public $locationTable = [];
private $log = 4;
private $payloadOffset = 0;
private $chunks = [];
private $chunkChange = [];
public $chunks = [];
public $chunkChange = [];
public $level;
public function __construct($file, $blank = false){
if(is_array($blank)){

View file

@ -19,7 +19,9 @@
Only the class `twister' is part of the API; everything else is private.
http://kingfisher.nfshost.com/sw/twister/
Who made such a weird names? - GameHerobrine
*/
const N = 624;
const M = 397;
@ -41,7 +43,7 @@ $val = MASK31 | (MASK31 << 1);
define("MASK32", $val);
class MersenneTwister{ //Does it even used? //rename back if any problems will be spotted
class MersenneTwister{
const N = N;
# the class constant is not used anywhere in this namespace,
@ -202,7 +204,7 @@ class MersenneTwister{ //Does it even used? //rename back if any problems will b
return $y;
}
/* generates a random number on [0,1]-real-interval */
function real_closed(){
@ -330,6 +332,19 @@ class MersenneTwister{ //Does it even used? //rename back if any problems will b
($this->int32() & MASK26)) *
(1.0 / 9007199254740992.0);
}
function nextInt($bound = null){
return $bound == null ? ($this->int32() >> 1) : ($this->int32() % $bound);
}
function nextFloat(){
return $this->int32() * 2.3283064365386963E-010;
}
function setSeed($seed){
$this->init_with_integer($seed);
}
}
function signed2unsigned($signed_integer){

View file

@ -44,6 +44,29 @@ class Utils{
$angle = fmod($angle, 360);
return $angle < 0 ? $angle + 360 : $angle;
}
public static function getSeedNumeric($seed){
if($seed === "") return false;
else if(is_int($seed)) return (int)$seed;
else{
$i = 0;
for($j = 0; $j < strlen($seed); ++$j){
$i = $i * 31 + ord($seed[$j]);
}
return (int)$i;
}
}
public static function sint32($r){
$r &= 0xFFFFFFFF;
if ($r & 0x80000000)
{
$r &= ~0x80000000;
return -2147483648 + $r;
}
return $r;
}
public static function wrapAngleTo180($angle)
{
$angle = fmod($angle+180, 360);

View file

@ -34,8 +34,9 @@ class WorldGenerator{
for($X = 0; $X < $this->width; ++$X){
$this->generator->generateChunk($X, $Z);
}
console("[NOTICE] Generating level " . ceil((($Z + 1) / $this->width) * 100) . "%");
}
}//$this->generator->generateChunk(7, 5);
console("[NOTICE] Populating level");
$this->generator->populateLevel();
for($Z = 0; $Z < $this->width; ++$Z){
@ -43,7 +44,8 @@ class WorldGenerator{
$this->generator->populateChunk($X, $Z);
}
console("[NOTICE] Populating level " . ceil((($Z + 1) / $this->width) * 100) . "%");
}
}//
//$this->generator->populateChunk(7, 7);
$this->level->setSpawn($this->generator->getSpawn());
$this->level->save(true, true);

View file

@ -7,7 +7,7 @@ require_once("NoiseGenerator.php");
class NoiseGeneratorOctaves extends NoiseGenerator{
public $octaves;
private $generatorCollection;
public function __construct(Random $random, $octaves){
public function __construct(MersenneTwister $random, $octaves){
$this->generatorCollection = array();
$this->octaves = (int) $octaves;
for($o = 0; $o < $this->octaves; ++$o){
@ -15,17 +15,22 @@ class NoiseGeneratorOctaves extends NoiseGenerator{
}
}
public function getValue($x, $y){
$noise = 0;
$scale = 1;
for($i = 0; $i < $this->octaves; ++$i){
$noise += $this->generatorCollection[$i]->getValue($x * $scale, $y * $scale) / $scale;
$scale /= 2;
}
return $noise;
}
public function generateNoiseOctaves($int1, $int2, $int3, $int4, $int5, $int6, $par1 = false, $par2 = false, $par3 = false){
if($par1 === false or $par2 === false or $par3 === false){
return $this->generateNoiseOctaves($int1, 10, $int2, $int3, 1, $int4, $int5, 1, $int6);
}
$floats = array();
$cnt = $int4 * $int5 * $int6;
for($i = 0; $i < $cnt; ++$i){
$floats[$i] = 0;
}
$floats = array_fill(0, $int4 * $int5 * $int6, 0);
$d1 = 1;
for($j = 0; $j < $this->octaves; ++$j){

View file

@ -9,10 +9,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
public $xCoord, $yCoord, $zCoord;
private $permutations = [];
public function __construct($random = false){
if(!($random instanceof Random)){
$random = new Random();
}
public function __construct(MersenneTwister $random){
$this->xCoord = $random->nextFloat() * 256;
$this->yCoord = $random->nextFloat() * 256;
$this->zCoord = $random->nextFloat() * 256;
@ -25,7 +22,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
}
for($i = 0; $i < 256; ++$i){
$j = $random->nextRange(0, 256 - $i) + $i;
$j = $random->nextInt(256 - $i) + $i;
$k = $this->permutations[$i];
$this->permutations[$i] = $this->permutations[$j];
$this->permutations[$j] = $k;
@ -33,7 +30,46 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
}
}
public function getValue($d, $d1, $d2 = 0){
$d3 = $d + $this->xCoord;
$d4 = $d1 + $this->yCoord;
$d5 = $d2 + $this->zCoord;
$i = (int) $d3;
$j = (int) $d4;
$k = (int) $d5;
if($d3 < $i) --$i;
if($d4 < $j) --$j;
if($d5 < $k) --$k;
$l = $i & 0xff;
$i1 = $j & 0xff;
$j1 = $k & 0xff;
$d3 -= $i;
$d4 -= $j;
$d5 -= $k;
$d6 = $d3 * $d3 * $d3 * ($d3 * ($d3 * 6 - 15) + 10);
$d7 = $d4 * $d4 * $d4 * ($d4 * ($d4 * 6 - 15) + 10);
$d8 = $d5 * $d5 * $d5 * ($d5 * ($d5 * 6 - 15) + 10);
$k1 = (int) ($this->permutations[$l] + $i1);
$l1 = (int) ($this->permutations[$k1] + $j1);
$i2 = (int) ($this->permutations[$k1 + 1] + $j1);
$j2 = (int) ($this->permutations[$l + 1] + $i1);
$k2 = (int) ($this->permutations[$j2] + $j1);
$l2 = (int) ($this->permutations[$j2 + 1] + $j1);
return $this->curve($d8,
$this->curve($d7,
$this->curve($d6, $this->grad3D($this->permutations[$l1], $d3, $d4, $d5), $this->grad3D($this->permutations[$k2], $d3 - 1, $d4, $d5)),
$this->curve($d6, $this->grad3D($this->permutations[$i2], $d3, $d4 - 1, $d5), $this->grad3D($this->permutations[$l2], $d3 - 1, $d4 - 1, $d5))
),
$this->curve($d7,
$this->curve($d6, $this->grad3D($this->permutations[$l1 + 1], $d3, $d4, $d5 - 1), $this->grad3D($this->permutations[$k2 + 1], $d3 - 1, $d4, $d5 - 1)),
$this->curve($d6, $this->grad3D($this->permutations[$i2 + 1], $d3, $d4 - 1, $d5 - 1), $this->grad3D($this->permutations[$l2 + 1], $d3 - 1, $d4 - 1, $d5 - 1))
)
);
}
public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7){
if($int2 === 1){
$n = 0;
@ -103,6 +139,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
if($d14 < $i16){
--$i16;
}
$i17 = $i16 & 0xff;
$d14 -= $i16;
$d15 = $d14 * $d14 * $d14 * ($d14 * ($d14 * 6 - 15) + 10);

View file

@ -0,0 +1,83 @@
<?php
class BiomeSource
{
/**
* @var NoiseGeneratorOctaves $temperatureNoise
* @var NoiseGeneratorOctaves $rainfallNoise
* @var NoiseGeneratorOctaves $detailNoise
*/
public $temperatureNoise, $rainfallNoise, $detailNoise;
/**
*
* @var float[] $tempNoises
* @var float[] $rainfallNoises
* @var float[] $detailNoises
*/
public $temperatureNoises, $rainfallNoises, $detailNoises;
public function __construct(Level $level){
$this->temperatureNoise = new NoiseGeneratorOctaves(new MersenneTwister($level->getSeed() * 9871), 4);
$this->rainfallNoise = new NoiseGeneratorOctaves(new MersenneTwister($level->getSeed() * 39811), 4);
$this->detailNoise = new NoiseGeneratorOctaves(new MersenneTwister($level->getSeed() * 543321), 2);
}
public function getBiome($x, $z){
return $this->getBiomeBlock($x, $z, 1, 1)[0];
}
public function getTemperatureBlock($x, $z, $xSize, $zSize){
$this->temperatureNoises = $this->temperatureNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.025, 0.025, 0.25);
$this->detailNoises = $this->detailNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.25, 0.25, 0.588);
$index = 0;
for($blockX = 0; $blockX < $xSize; ++$blockX){
for($blockZ = 0; $blockZ < $zSize; ++$blockZ){
//float f = 1.0f - ((((this.detailNoises[index] * 1.1f) + 0.5f) * 0.01f) + (((this.temperatureNoises[index] * 0.15f) + 0.7f) * 0.99f));
//float f1 = 1.0f - (f*f);
$f = 1 - (((($this->detailNoises[$index] * 1.1) + 0.5) * 0.01) + ((($this->temperatureNoises[$index] * 0.15) + 0.7) * 0.99));
$f1 = 1 - ($f*$f);
if($f1 < 0) $f1 = 0;
else if($f1 > 1) $f1 = 1;
$this->temperatureNoises[$index++] = $f1;
}
}
return $this->temperatureNoises;
}
public function getBiomeBlock($x, $z, $xSize, $zSize){
$this->temperatureNoises = $this->temperatureNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.025, 0.025, 0.25);
$this->rainfallNoises = $this->rainfallNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.05, 0.05, 0.3333);
$this->detailNoises = $this->detailNoise->generateNoiseOctaves($x, $z, $xSize, $zSize, 0.25, 0.25, 0.588);
$localBiomeArray = [];
$index = 0;
for($blockX = 0; $blockX < $xSize; ++$blockX){
for($blockZ = 0; $blockZ < $zSize; ++$blockZ){
//rain =((($this->detailNoises[$index] * 1.1) + 0.5) * 0.002) + ((($this->rainfallNoises[$index] * 0.15) + 0.5) * 0.998);
$rain = ((($this->detailNoises[$index] * 1.1) + 0.5) * 0.002) + ((($this->rainfallNoises[$index] * 0.15) + 0.5) * 0.998);
//1 - ((((this.detailNoises[index] * 1.1f) + 0.5f) * 0.01f) + (((this.temperatureNoises[index] * 0.15f) + 0.7f) * 0.99f));
$f1 = 1 - ((((($this->detailNoises[$index]) * 1.1) + 0.5) * 0.01) + ((($this->temperatureNoises[$index] * 0.15) + 0.7) * 0.99));
$blockTemp = 1 - ($f1 * $f1);
if($blockTemp < 0) $blockTemp = 0;
else if($blockTemp > 1) $blockTemp = 1;
if($rain < 0) $rain = 0;
else if($rain > 1) $rain = 1;
$this->temperatureNoises[$index] = $blockTemp;
$this->rainfallNoises[$index] = $rain;
$localBiomeArray[$index++] = Biome::getBiome($blockTemp, $rain);
}
}
return $localBiomeArray;
}
}

View file

@ -0,0 +1,417 @@
<?php
define("EMPTY_MINI_CHUNK", str_repeat("\x00", 8192));
define("EMPTY_16x16_ARR", array_fill(0, 256, 0));
class VanillaGenerator implements LevelGenerator
{
/**
* @var Level
*/
public $level;
/**
* @var MersenneTwister
*/
private $rand;
/**
*
* @var NoiseGeneratorOctaves $upperInterpolationNoise
* @var NoiseGeneratorOctaves $lowerInterpolationNoise
* @var NoiseGeneratorOctaves $interpolationNoise
* @var NoiseGeneratorOctaves $beachNoise
* @var NoiseGeneratorOctaves $surfaceDepthNoise
* @var NoiseGeneratorOctaves $biomeNoise
* @var NoiseGeneratorOctaves $depthNoise
* @var NoiseGeneratorOctaves $treeNoise
*/
private $upperInterpolationNoise, $lowerInterpolationNoise, $interpolationNoise, $beachNoise, $surfaceDepthNoise, $biomeNoise, $depthNoise, $treeNoise;
/**
* @var float[] $biomeNoises
* @var float[] $depthNoises
* @var float[] $interpolationNoises
* @var float[] $upperInterpolationNoises
* @var float[] $lowerInterpolationNoises
* @var Biome[] $biomes
* @var float[] $heights
* @var float[] $sandNoises
* @var float[] $gravelNoises
* @var float[] $surfaceDepthNoises
*/
private $biomeNoises, $depthNoises, $interpolationNoises, $upperInterpolationNoises, $lowerInterpolationNoises, $biomes, $heights, $sandNoises, $gravelNoises, $surfaceDepthNoises;
/**
* @var BiomeSource
*/
private $biomeSource;
private $heightMap = [];
public function __construct(array $options = [])
{
}
public function init(Level $level, Random $random)
{
$this->level = $level;
$this->biomeSource = new BiomeSource($level);
$this->rand = new MersenneTwister($level->getSeed());
$this->upperInterpolationNoise = new NoiseGeneratorOctaves($this->rand, 16);
$this->lowerInterpolationNoise = new NoiseGeneratorOctaves($this->rand, 16);
$this->interpolationNoise = new NoiseGeneratorOctaves($this->rand, 8);
$this->beachNoise = new NoiseGeneratorOctaves($this->rand, 4);
$this->surfaceDepthNoise = new NoiseGeneratorOctaves($this->rand, 4);
$this->biomeNoise = new NoiseGeneratorOctaves($this->rand, 10);
$this->depthNoise = new NoiseGeneratorOctaves($this->rand, 16);
$this->treeNoise = new NoiseGeneratorOctaves($this->rand, 8);
}
public function getSpawn()
{
return new Vector3(128, 64, 128);
}
public function populateChunk($chunkX, $chunkZ)
{
$chunkXWorld = $chunkX * 16;
$chunkZWorld = $chunkZ * 16;
//HeavyTile::instaFall = 1; TODO instant sand/gravel fall
$biome = $this->biomeSource->getBiome($chunkXWorld + 16, $chunkZWorld + 16);
$this->rand->setSeed($this->level->getSeed());
$i1 = (int)(((int)($this->rand->nextInt() / 2)) * 2 + 1); //why php integers are so big....???????????????????????????????????????
$j1 = (int)(((int)($this->rand->nextInt() / 2)) * 2 + 1);
$this->rand->setSeed(Utils::sint32($chunkX * $i1 + $chunkZ * $j1) ^ $this->level->getSeed());
for($i2 = 0; $i2 < 10; ++$i2){
ClayFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(128), $chunkZWorld + $this->rand->nextInt(16));
}
for ($i3 = 0; $i3 < 20; ++$i3) {
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(128), $chunkZWorld + $this->rand->nextInt(16), DIRT, 32);
}
for ($i4 = 0; $i4 < 10; ++$i4) {
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(128), $chunkZWorld + $this->rand->nextInt(16), GRAVEL, 32);
}
for ($i5 = 0; $i5 < 20; ++$i5) {
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(128), $chunkZWorld + $this->rand->nextInt(16), COAL_ORE, 16);
}
for($i6 = 0; $i6 < 20; ++$i6){
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(64), $chunkZWorld + $this->rand->nextInt(16), IRON_ORE, 8);
}
for($i7 = 0; $i7 < 2; ++$i7){
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(32), $chunkZWorld + $this->rand->nextInt(16), GOLD_ORE, 8);
}
for($i8 = 0; $i8 < 8; ++$i8){
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), REDSTONE_ORE, 7);
}
for($i9 = 0; $i9 < 1; ++$i9){ //TODO loop is not neccessary
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), DIAMOND_ORE, 7);
}
for($i10 = 0; $i10 < 1; ++$i10){
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16) + $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), LAPIS_ORE, 6);
}
//sample= (int) ((((this.treeNoise.getValue(chunkXWorld * 0.5f, chunkZWorld * 0.5f) / 8.0f) + (this.rand.nextFloat() * 4.0f)) + 4.0f) / 3.0f);
$sample = (int) (((($this->treeNoise->getValue($chunkXWorld * 0.5, $chunkZWorld * 0.5) / 8) + ($this->rand->nextFloat() * 4)) + 4) / 3);
$treesAmount = $this->rand->nextInt(10) == 0;
if($biome == Biome::$forest) $treesAmount += $sample + 2;
else if($biome == Biome::$rainForest) $treesAmount += $sample + 2;
else if($biome == Biome::$seasonalForest) $treesAmount += $sample + 1;
else if($biome == Biome::$taiga) $treesAmount += $sample + 1;
else if($biome == Biome::$desert) $treesAmount -= 20;
else if($biome == Biome::$tundra) $treesAmount -= 20;
else if($biome == Biome::$plains) $treesAmount -= 20;
for($l8 = 0; $l8 < $treesAmount; ++$l8){
$l12 = $chunkXWorld + $this->rand->nextInt(16) + 8;
$j15 = $chunkZWorld + $this->rand->nextInt(16) + 8;
/**
* @var Feature $tree
*/
$tree = $biome->getTreeFeature($this->rand);
$tree->place($this->level, $this->rand, $l12, $this->getHeightValue($l12, $j15), $j15);
}
for($i9 = 0; $i9 < 2; ++$i9){
$i13 = $chunkXWorld + $this->rand->nextInt(16) + 8;
$k15 = $this->rand->nextInt(128);
$l17 = $chunkZWorld + $this->rand->nextInt(16) + 8;
Feature::$FLOWER_YELLOW->place($this->level, $this->rand, $i13, $k15, $l17);
}
if($this->rand->nextInt(2) == 0){
$j9 = $chunkXWorld + $this->rand->nextInt(16) + 8;
$j13 = $this->rand->nextInt(128);
$l15 = $chunkZWorld + $this->rand->nextInt(16) + 8;
Feature::$FLOWER_RED->place($this->level, $this->rand, $j9, $j13, $l15);
}
if($this->rand->nextInt(4) == 0){
$j9 = $chunkXWorld + $this->rand->nextInt(16) + 8;
$j13 = $this->rand->nextInt(128);
$l15 = $chunkZWorld + $this->rand->nextInt(16) + 8;
Feature::$MUSHROOM_BROWN->place($this->level, $this->rand, $j9, $j13, $l15);
}
if($this->rand->nextInt(8) == 0){
$j9 = $chunkXWorld + $this->rand->nextInt(16) + 8;
$j13 = $this->rand->nextInt(128);
$l15 = $chunkZWorld + $this->rand->nextInt(16) + 8;
Feature::$MUSHROOM_RED->place($this->level, $this->rand, $j9, $j13, $l15);
}
}
public function generateChunk($chunkX, $chunkZ)
{
$this->rand->setSeed(341872712 * $chunkX + 132899541 * $chunkZ);
$this->biomes = $this->biomeSource->getBiomeBlock($chunkX * 16, $chunkZ * 16, 16, 16);
$chunkz = array_fill(0, 8, EMPTY_MINI_CHUNK); //[$blockY >> 4][($blockY & 0xf) + ($blockX << 5) + ($blockZ << 9)]. y&f+x&f+z&f
$this->prepareHeights($chunkX, $chunkZ, $chunkz, $this->biomes, $this->biomeSource->temperatureNoises);
$this->buildSurfaces($chunkX, $chunkZ, $chunkz, $this->biomes);
//c.generateHeightMap(); my 0.1.3 core also has this for easier top block search...
$this->generateHeightmap($chunkX, $chunkZ, $chunkz);
for($Y = 0; $Y < 8; ++$Y){
$index = ($chunkZ << 4) + $chunkX;
$this->level->level->chunks[$index][$Y] = $chunkz[$Y];
$this->level->level->chunkChange[$index][$Y] = 8192;
$this->level->level->locationTable[$index][0] |= 1 << $Y; //TODO mv out of loop
}
$this->level->level->chunkChange[$index][-1] = true;
//console($this->level->level->getBlockID($chunkX*16, 20, $chunkZ*16));
}
public function populateLevel()
{}
public function setHeightValue($x, $z, $hv){
if($x > 255 || $x < 0 || $z > 255 || $z < 0) return;
$cX = $x >> 4;
$cZ = $z >> 4;
$bX = $x & 0xf;
$bZ = $z & 0xf;
$this->heightMap[$cX + ($cZ * 16)][$bX + ($bZ * 16)] = $hv;
}
public function getHeightValue($x, $z){
if($x > 255 || $x < 0 || $z > 255 || $z < 0) return 0;
$cX = $x >> 4;
$cZ = $z >> 4;
$bX = $x & 0xf;
$bZ = $z & 0xf;
return $this->heightMap[$cX + ($cZ * 16)][$bX + ($bZ * 16)];
}
public function generateHeightmap($x, $z, &$chunkz){
$heightmapCPtr = EMPTY_16x16_ARR;
for($blockX = 0; $blockX < 16; ++$blockX){
for($blockZ = 0; $blockZ < 16; ++$blockZ){
for($Y = 7; $Y >= 0; --$Y){
for($cY = 15; $cY >= 0; --$cY){
$blockY = $Y*16 + $cY;
$blockID = ord($chunkz[$Y][$cY + ($blockX << 5) + ($blockZ << 9)]);
if($blockID > 0) {
$heightmapCPtr[$blockX + ($blockZ * 16)] = $blockY + 1 ;
break 2;
}
}
}
}
}
$this->heightMap[$x + ($z * 16)] = $heightmapCPtr;
}
/**Vanilla Functions Implementation starts here**/
/**
* Decorate terrain with grass, water & other stuff. Uses ZXY placement format
* @param int $chunkX
* @param int $chunkZ
* @param array $chunks
* @param Biome[] $biomes
*/
public function buildSurfaces($chunkX, $chunkZ, &$chunks, $biomes){
$this->sandNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.03125, 0.03125, 1);
$this->gravelNoises = $this->beachNoise->generateNoiseOctaves($chunkX * 16, 109.01, $chunkZ * 16, 16, 1, 16, 0.03125, 1, 0.03125);
$this->surfaceDepthNoises = $this->surfaceDepthNoise->generateNoiseOctaves($chunkX * 16, $chunkZ * 16, 0, 16, 16, 1, 0.0625, 0.0625, 0.0625);
for($blockX = 0; $blockX < 16; ++$blockX){
for($blockZ = 0; $blockZ < 16; ++$blockZ){
/** @var Biome $biome **/
$biome = $biomes[$blockX + ($blockZ * 16)];
$z = ($this->sandNoises[$blockX + ($blockZ * 16)] + ($this->rand->nextFloat() * 0.2)) > 0;
$z2 = ($this->gravelNoises[$blockX + ($blockZ * 16)] + ($this->rand->nextFloat() * 0.2)) > 3;
$nextFloat = (int)(($this->surfaceDepthNoises[$blockX + ($blockZ * 16)] / 3) + 3 + ($this->rand->nextFloat() * 0.25));
$i = -1;
$b = $biome->topBlock;
$b2 = $biome->fillerBlock;
for($blockY = 127; $blockY >= 0; --$blockY){
$i2 = ((($blockZ * 16) + $blockX) * 128) + $blockY;
if($blockY <= (0 + $this->rand->nextInt(5))){
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = "\x07";
}else{
$b3 = ord($chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)]);
if($b3 == 0){
$i = -1;
}else if($b3 == STONE){
if($i == -1){
if($nextFloat > 0){
if($blockY >= 64-4 && $blockY <= 64+1){
$b = $biome->topBlock;
$b2 = $biome->fillerBlock;
if($z2){
$b = 0;
$b2 = GRAVEL;
}
if($z){
$b = SAND;
$b2 = SAND;
}
}
}else{
$b = 0;
$b2 = STONE;
}
if($blockY < 64 && $b == 0){
$b = STILL_WATER;
}
$i = $nextFloat;
if($blockY >= 64 - 1){
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = chr($b);
}else{
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = chr($b2);
}
}else if($i > 0){
--$i;
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = chr($b2);
if($i == 0 && $b2 == SAND){
$i = $this->rand->nextInt(4);
$b2 = SANDSTONE;
}
}
}
}
}
}
}
}
public function prepareHeights($chunkX, $chunkZ, &$chunks, $biomes, $temperatures){
$this->heights = $this->getHeights($chunkX * 4, 0, $chunkZ * 4, 5, 17, 5);
//if($chunkX == 15 && $chunkZ == 15) var_dump($this->heights);
for($unkX = 0; $unkX < 4; ++$unkX){
for($unkZ = 0; $unkZ < 4; ++$unkZ){
for($unkY = 0; $unkY < 16; ++$unkY){
$f = $this->heights[(((($unkX + 0) * 5) + $unkZ + 0) * 17) + $unkY + 0];
$f2 = $this->heights[(((($unkX + 0) * 5) + $unkZ + 1) * 17) + $unkY + 0];
$f3 = $this->heights[(((($unkX + 1) * 5) + $unkZ + 0) * 17) + $unkY + 0];
$f4 = $this->heights[(((($unkX + 1) * 5) + $unkZ + 1) * 17) + $unkY + 0];
$f5 = ($this->heights[(((($unkX + 0) * 5) + ($unkZ + 0)) * 17) + ($unkY + 1)] - $f) * 0.125;
$f6 = ($this->heights[(((($unkX + 0) * 5) + ($unkZ + 1)) * 17) + ($unkY + 1)] - $f2) * 0.125;
$f7 = ($this->heights[(((($unkX + 1) * 5) + ($unkZ + 0)) * 17) + ($unkY + 1)] - $f3) * 0.125;
$f8 = ($this->heights[(((($unkX + 1) * 5) + ($unkZ + 1)) * 17) + ($unkY + 1)] - $f4) * 0.125;
for($unkYY = 0; $unkYY < 8; ++$unkYY){
$f9 = $f;
$f10 = $f2;
$f11 = ($f3 - $f) * 0.25;
$f12 = ($f4 - $f2) * 0.25;
for($unkXX = 0; $unkXX < 4; ++$unkXX){
//int i2 = ((unkXX + (unkX * 4)) << 11) | ((0 + (unkZ * 4)) << 7) | ((unkY * 8) + unkYY);
$i2 = (($unkXX + ($unkX * 4)) << 11) | ((0 + ($unkZ * 4)) << 7) | (($unkY * 8) + $unkYY);
$f13 = $f9;
$f14 = ($f10 - $f9) * 0.25;
for($unkZZ = 0; $unkZZ < 4; ++$unkZZ){
$d15 = $temperatures[((($unkX * 4) + $unkXX) * 16) + ($unkZ * 4) + $unkZZ];
$i3 = 0;
if(($unkY * 8) + $unkYY < 64){
if($d15 < 0.5 && (($unkY * 8) + $unkYY) >= 63){ //64-1
$i3 = ICE;
}else{
$i3 = STILL_WATER;
}
}
if($f13 > 0) $i3 = STONE;
$fx = ($unkXX + ($unkX * 4));
$fy = (($unkY * 8) + $unkYY);
$fz = ($unkZZ + ($unkZ * 4));
//if($fx == 0 && $fy == 20 && $fz == 0) console("P:".$i3);
$chunks[$fy >> 4][($fy & 0xf) + ($fx << 5) + ($fz << 9)] = chr($i3); // ($aY + ($aX << 5) + ($aZ << 9))
//$this->level->level->setBlockID(($chunkX * 16) + ($unkXX + ($unkX * 4)), (($unkY * 8) + $unkYY), ($unkZZ + ($unkZ * 4)), $i3);
$i2 += 128;
$f13 += $f14;
}
$f9 += $f11;
$f10 += $f12;
}
$f += $f5;
$f2 += $f6;
$f3 += $f7;
$f4 += $f8;
}
}
}
}
}
public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ){
$heights = array_fill(0, $scaleX*$scaleY*$scaleZ, 0);
$rainNoises = $this->biomeSource->rainfallNoises;
$tempNoises = $this->biomeSource->temperatureNoises;
$this->biomeNoises = $this->biomeNoise->generateNoiseOctaves($chunkX, $chunkZ, $scaleX, $scaleZ, 1.121, 1.121, 0.5);
$this->depthNoises = $this->depthNoise->generateNoiseOctaves($chunkX, $chunkZ, $scaleX, $scaleZ, 200, 200, 0.5);
$this->interpolationNoises = $this->interpolationNoise->generateNoiseOctaves($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ, 8.5552, 4.2776, 8.5552);
$this->upperInterpolationNoises = $this->upperInterpolationNoise->generateNoiseOctaves($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ, 684.41, 684.41, 684.41);
$this->lowerInterpolationNoises = $this->lowerInterpolationNoise->generateNoiseOctaves($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ, 684.41, 684.41, 684.41);
$k1 = $l1 = 0;
$i2 = ((int)(16 / $scaleX));
for($j2 = 0; $j2 < $scaleX; ++$j2){
$k2 = (int)($j2 * $i2 + $i2 / 2);
for($l2 = 0; $l2 < $scaleZ; ++$l2){
$i3 = (int)($l2 * $i2 + $i2 / 2);
$d2 = $tempNoises[$k2 * 16 + $i3];
$d3 = $rainNoises[$k2 * 16 + $i3] * $d2;
$d4 = 1 - $d3;
$d4 *= $d4;
$d4 *= $d4;
$d4 = 1 - $d4;
$d5 = (($this->biomeNoises[$l1] + 256) / 512);
$d5 *= $d4;
if($d5 > 1) $d5 = 1;
$d6 = $this->depthNoises[$l1] / 8000;
if($d6 < 0) $d6 = -$d6 * 0.3;
$d6 = $d6 * 3 - 2;
if($d6 < 0){
$d6 /= 2;
if($d6 < -1) $d6 = -1;
$d6 /= 1.4;
$d6 /= 2;
$d5 = 0;
}else{
if($d6 > 1) $d6 = 1;
$d6 /= 8;
}
if($d5 < 0) $d5 = 0;
$d5 += 0.5;
$d6 = ($d6 * $scaleY) / 16;
$d7 = ($scaleY / 2 + $d6 * 4);
++$l1;
for($j3 = 0; $j3 < $scaleY; ++$j3){
$d8 = 0;
$d9 = (((float)$j3 - $d7) * 12) / $d5;
if($d9 < 0) $d9 *= 4;
$d10 = $this->upperInterpolationNoises[$k1] / 512;
$d11 = $this->lowerInterpolationNoises[$k1] / 512;
$d12 = ($this->interpolationNoises[$k1] / 10 + 1) / 2;
if($d12 < 0) $d8 = $d10;
else if($d12 > 1) $d8 = $d11;
else $d8 = $d10 + ($d11 - $d10) * $d12;
$d8 -= $d9;
if($j3 > $scaleY - 4){
$d13 = ($j3 - ($scaleY - 4)) / 3;
$d8 = $d8 * (1 - $d13) + -10 * $d13;
}
$heights[$k1] = $d8;
++$k1;
}
}
}
return $heights;
}
}

View file

@ -0,0 +1,87 @@
<?php
class Biome
{
/**
* @var Biome[]
*/
public static $biomes = [];
/**
* @var Biome $rainForest
* @var Biome $swampLand
* @var Biome $seasonalForest
* @var Biome $forest
* @var Biome $savanna
* @var Biome $shrubland
* @var Biome $taiga
* @var Biome $desert
* @var Biome $plains
* @var Biome $iceDesert
* @var Biome $tundra
*/
public static $rainForest, $swampLand, $seasonalForest, $forest, $savanna, $shrubland, $taiga, $desert, $plains, $iceDesert, $tundra;
public static function init(){
Biome::$rainForest = new Biome("Rainforest");
Biome::$swampLand = new Biome("Swampland");
Biome::$seasonalForest = new Biome("Seasonal Forest");
Biome::$forest = new ForestBiome("Forest");
Biome::$savanna = new Biome("Savanna");
Biome::$shrubland = new Biome("Shrubland");
Biome::$taiga = new TaigaBiome("Taiga");
Biome::$desert = new FlatBiome("Desert");
Biome::$plains = new FlatBiome("Plains");
Biome::$iceDesert = new FlatBiome("Ice Desert"); //unsed
Biome::$tundra = new Biome("Tundra");
Biome::recalc();
}
public static function recalc(){
for($i = 0; $i < 64; ++$i){
for($j = 0; $j < 64; ++$j){
Biome::$biomes[$i + ($j * 64)] = Biome::__getBiome(((float) $i / 63), ((float) $j / 63));
}
}
Biome::$desert->topBlock = Biome::$desert->fillerBlock = SAND;
Biome::$iceDesert->topBlock = Biome::$iceDesert->fillerBlock = SAND;
}
public static function getBiome($temp, $rain){
$i = ((int) ($temp * 63));
$j = ((int) ($rain * 63));
return Biome::$biomes[$i + $j*64];
}
public static function __getBiome($temp, $rain){
$rain *= $temp;
if($temp < 0.1) return Biome::$tundra;
if($rain < 0.2){
if($temp < 0.5) return Biome::$tundra;
if($temp < 0.95) return Biome::$savanna;
else return Biome::$desert;
}
if($rain > 0.5 && $temp < 0.7) return Biome::$swampLand;
if($temp < 0.5) return Biome::$taiga;
if($temp < 0.97){
if($rain < 0.45) return Biome::$shrubland;
else return Biome::$forest;
}
if($rain < 0.45) return Biome::$plains;
if($rain < 0.9) return Biome::$seasonalForest;
return Biome::$rainForest;
}
public function __construct($name){
$this->name = $name;
}
public function getTreeFeature(MersenneTwister $rand){
$rand->nextInt(); //it is necessary
return Feature::$TREE;
}
public $name;
public $topBlock = GRASS, $fillerBlock = DIRT;
}

View file

@ -0,0 +1,6 @@
<?php
class FlatBiome extends Biome
{
}

View file

@ -0,0 +1,13 @@
<?php
class ForestBiome extends Biome
{
public function getTreeFeature(MersenneTwister $rand){
if($rand->nextInt(5) == 0){
return Feature::$BIRCH_TREE;
}
$rand->nextInt(); //it is necessary
return Feature::$TREE;
}
}

View file

@ -0,0 +1,13 @@
<?php
class TaigaBiome extends Biome
{
public function getTreeFeature(MersenneTwister $rand){
if($rand->nextInt(3) == 0){
return Feature::$PINE_TREE;
}else{
return Feature::$SPRUCE_TREE;
}
}
}

View file

@ -0,0 +1,62 @@
<?php
class BirchFeature extends Feature
{
public function place(Level $level, MersenneTwister $rand, $x, $y, $z){
$nextInt = $rand->nextInt(3) + 5;
$z2 = true;
if($y < 1 || $y + $nextInt + 1 > 128){
return false;
}
for($i = $y; $i <= $y + 1 + $nextInt; ++$i){
$i2 = $i != $y;
if($i >= (($y + 1) + $nextInt) - 2){
$i2 = 2;
}
for($i3 = $x - $i2; $i3 <= $x + $i2 && $z2; ++$i3){
for($i4 = $z - $i2; $i4 <= $z + $i2 && $z2; ++$i4){
if($i >= 0 && $i < 128){
$blockID = $level->level->getBlockID($i3, $i, $i4);
if($blockID != 0 && $blockID != LEAVES){
$z2 = false;
}
}else{
$z2 = false;
}
}
}
}
if($z2){
$blockID = $level->level->getBlockID($x, $y - 1, $z);
if(($blockID == GRASS || $blockID == DIRT) && $y < (128 - $nextInt) - 1){
$level->level->setBlockID($x, $y - 1, $z, DIRT);
for($i5 = ($y - 3) + $nextInt; $i5 <= $y + $nextInt; ++$i5){
$i6 = $i5 - ($y + $nextInt);
$i7 = (int) (1 - ($i6 / 2));
for($i8 = $x - $i7; $i8 <= $x + $i7; ++$i8){
$i9 = $i8 - $x;
for($i10 = $z - $i7; $i10 <= $z + $i7; ++$i10){
$i11 = $i10 - $z;
if((abs($i9) != $i7 || abs($i11) != $i7 || ($rand->nextInt(2) != 0 && $i6 != 0))/* && !Block.FULL_OPAQUE[world.getBlockIDAt(i8, i5, i10)]TODO opaque*/) {
$level->level->setBlock($i8, $i5, $i10, LEAVES, 2);
}
}
}
}
for($i12 = 0; $i12 < $nextInt; ++$i12){
$blockID = $level->level->getBlockID($x, $y + $i12, $z);
if($blockID == 0 || $blockID == LEAVES){
$level->level->setBlock($x, $y + $i12, $z, WOOD, 2);
}
}
return true;
}
return false;
}
return false;
}
}

View file

@ -0,0 +1,51 @@
<?php
class ClayFeature
{
public static function place(Level $level, MersenneTwister $rand, $x, $y, $z){
$size = 32;
$clayid = CLAY_BLOCK;
$id = $level->level->getBlockID($x, $y, $z);
if($id != WATER && $id != STILL_WATER) return false;
$nextFloat = $rand->nextFloat() * 3.1416;
$sin = (float)($x + 8 + ((sin($nextFloat) * $size) / 8));
$sin2 = (float)(($x + 8) - ((sin($nextFloat) * $size) / 8));
$cos = (float)($z + 8 + ((cos($nextFloat) * $size) / 8));
$cos2 = (float)(($z + 8) - ((cos($nextFloat) * $size) / 8));
$nextInt = $y + $rand->nextInt(3) + 2;
$nextInt2 = $y + $rand->nextInt(3) + 2;
for($i = 0; $i <= $size; ++$i){
$d = $sin + ((($sin2 - $sin) * $i) / $size);
$d2 = $nextInt + ((($nextInt2 - $nextInt) * $i) / $size);
$d3 = $cos + ((($cos2 - $cos) * $i) / $size);
$nextFloat = ($rand->nextFloat() * $size) / 16;
$sin3 = (((sin(($i * 3.1416) / $size) + 1) * $nextFloat) + 1);
$sin4 = (((sin(($i * 3.1416) / $size) + 1) * $nextFloat) + 1);//TODO optimize a bit?
$floor = floor($d - ($sin3 / 2));
$floor2 = floor($d + ($sin3 / 2));
$floor3 = floor($d2 - ($sin4 / 2.0));
$floor4 = floor($d2 + ($sin4 / 2.0));
$floor5 = floor($d3 - ($sin3 / 2.0));
$floor6 = floor($d3 + ($sin3 / 2.0));
for($i2 = $floor; $i2 <= $floor2; ++$i2){
for($i3 = $floor3; $i3 <= $floor4; ++$i3){
for($i4 = $floor5; $i4 <= $floor6; ++$i4){
$d4 = (($i2 + 0.5) - $d) / ($sin3 / 2);
$d5 = (($i3 + 0.5) - $d2) / ($sin4 / 2);
$d6 = (($i4 + 0.5) - $d3) / ($sin3 / 2);
if(($d4*$d4)+($d5*$d5)+($d6*$d6)<1 && $level->level->getBlockID($i2, $i3, $i4) == SAND){
$level->level->setBlockID($i2, $i3, $i4, $clayid);
console("Placed clay at".$i2.":".$i4);
}
}
}
}
}
}
}

View file

@ -0,0 +1,22 @@
<?php
abstract class Feature
{
public static $TREE, $BIRCH_TREE, $PINE_TREE, $SPRUCE_TREE;
public static $FLOWER_RED, $FLOWER_YELLOW, $MUSHROOM_BROWN, $MUSHROOM_RED;
public static function init(){
Feature::$TREE = new TreeFeature();
Feature::$BIRCH_TREE = new BirchFeature();
Feature::$PINE_TREE = new PineFeature();
Feature::$SPRUCE_TREE = new SpruceFeature();
Feature::$FLOWER_RED = new FlowerFeature(ROSE);
Feature::$FLOWER_YELLOW = new FlowerFeature(DANDELION);
Feature::$MUSHROOM_BROWN = new FlowerFeature(BROWN_MUSHROOM);
Feature::$MUSHROOM_RED = new FlowerFeature(RED_MUSHROOM);
}
public function place(Level $level, MersenneTwister $rand, $x, $y, $z){ //TODO pass VanillaGenerator instance and update heightmap on ceratin block placement
}
}

View file

@ -0,0 +1,29 @@
<?php
class FlowerFeature extends Feature
{
private $id;
public function __construct($id){
$this->id = $id;
}
public function place(Level $level, MersenneTwister $rand, $x, $y, $z){ //TODO pass VanillaGenerator instance and update heightmap on ceratin block placement
for($i = 0; $i < 64; ++$i){
$xPos = ($x + $rand->nextInt(8)) - $rand->nextInt(8);
$yPos = ($y + $rand->nextInt(4)) - $rand->nextInt(4);
$zPos = ($z + $rand->nextInt(8)) - $rand->nextInt(8);
if($level->level->getBlockID($xPos, $yPos, $zPos) == 0){
//TODO placement checking is a bit harder
/*boolean res = world.canSeeSky(x, y, z);
if(/*Level::getRawBrightness(a2, a3, a4, a5) > 7 TODO light ||*//* res) {
int id = world.getBlockIDAt(x, y - 1, z);
return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.farmland.blockID;
}
return res;*/
$idDown = $level->level->getBlockID($xPos, $yPos - 1, $zPos);
if($idDown == GRASS || $idDown == DIRT || $idDown == FARMLAND) $level->level->setBlockID($xPos, $yPos, $zPos, $this->id);
}
}
}
}

View file

@ -0,0 +1,53 @@
<?php
class OreFeature
{
public static function place(Level $level, MersenneTwister $rand, $x, $y, $z, $id, $amount){
$nextFloat = $rand->nextFloat() * 3.1415927;
$sin = ($x + 8 + ((sin($nextFloat) * $amount) / 8));
$sin2 = (($x + 8) - ((sin($nextFloat) * $amount) / 8));
$cos = ($z + 8 + ((cos($nextFloat) * $amount) / 8));
$cos2 = (($z + 8) - ((cos($nextFloat) * $amount) / 8));
$nextInt = $y + $rand->nextInt(3) + 2;
$nextInt2 = $y + $rand->nextInt(3) + 2;
for($i = 0; $i <= $amount; ++$i){
$d = $sin + ((($sin2 - $sin) * $i) / $amount);
$d2 = $nextInt + ((($nextInt2 - $nextInt) * $i) / $amount);
$d3 = $cos + ((($cos2 - $cos) * $i) / $amount);
$nextFloat = ($rand->nextFloat() * $amount) / 16;
$sin3 = (((sin(($i * 3.1415927) / $amount) + 1) * $nextFloat) + 1.0);
$sin4 = (((sin(($i * 3.1415927) / $amount) + 1) * $nextFloat) + 1.0);
$floor = floor($d - ($sin3 / 2));
$floor2 = floor($d2 - ($sin4 / 2));
$floor3 = floor($d3 - ($sin3 / 2.0));
$floor4 = floor($d + ($sin3 / 2.0));
$floor5 = floor($d2 + ($sin4 / 2.0));
$floor6 = floor($d3 + ($sin3 / 2.0));
for($i2 = $floor; $i2 <= $floor4; ++$i2){
$d4 = (($i2 + 0.5) - $d) / ($sin3 / 2);
$d4sqrd = $d4*$d4;
if($d4sqrd < 1){
for($i3 = $floor2; $i3 <= $floor5; ++$i3){
$d5 = (($i3 + 0.5) - $d2) / ($sin4 / 2);
$d5sqrd = $d5*$d5;
if($d4sqrd+$d5sqrd < 1){
for($i4 = $floor3; $i4 <= $floor6; ++$i4){
$d6 = (($i4 + 0.5) - $d3) / ($sin3 / 2);
if($d4sqrd+$d5sqrd+($d6*$d6) < 1 && $level->level->getBlockID($i2, $i3, $i4) == STONE){
$level->level->setBlockID($i2, $i3, $i4, $id);
}
}
}
}
}
}
}
}
}

View file

@ -0,0 +1,68 @@
<?php
class PineFeature extends Feature
{
public function place(Level $level, MersenneTwister $rand, $x, $y, $z){
$l = $rand->nextInt(5) + 7;
$i1 = $l - $rand->nextInt(2) - 3;
$j1 = $l - $i1;
$k1 = 1 + $rand->nextInt($j1 + 1);
$flag = true;
if($y < 1 || $y + $l + 1 > 128){
return false;
}
for($l1 = $y; $l1 <= $y + 1 + $l && $flag; ++$l1){
$j2 = 1;
if($l1 - $y < $i1){
$j2 = 0;
}else{
$j2 = $k1;
}
for($l2 = $x - $j2; $l2 <= $x + $j2 && $flag; ++$l2){
for($k3 = $z - $j2; $k3 <= $z + $j2 && $flag; ++$k3){
if($l1 >= 0 && $l1 < 128){
$j4 = $level->level->getBlockID($l2, $l1, $k3);
if($j4 != 0 && $j4 != LEAVES){
$flag = false;
}
}else{
$flag = false;
}
}
}
}
if(!$flag) return false;
$i2 = $level->level->getBlockID($x, $y - 1, $z);
if(($i2 != GRASS && $i2 != DIRT) || $y >= 128 - $l - 1) return false;
$level->level->setBlockID($x, $y - 1, $z, DIRT);
$k2 = 0;
for($i3 = $y + $l; $i3 >= $y + $i1; --$i3){
for($l3 = $x - $k2; $l3 <= $x + $k2; ++$l3){
$k4 = $l3 - $x;
for($l4 = $z - $k2; $l4 <= $z + $k2; ++$l4){
$i5 = $l4 - $z;
if((abs($k4) != $k2 || abs($i5) != $k2 || $k2 <= 0)/* && !Block.opaqueCubeLookup[world.getBlockId(l3, i3, l4)] TODO opaque*/){
$level->level->setBlock($l3, $i3, $l4, LEAVES, 1);
}
}
}
if($k2 >= 1 && $i3 == $y + $i1 + 1){
--$k2;
continue;
}
if($k2 < $k1){
++$k2;
}
}
for($j3 = 0; $j3 < $l - 1; ++$j3){
$i4 = $level->level->getBlockID($x, $y + $j3, $z);
if($i4 == 0 || $i4 == LEAVES){
$level->level->setBlock($x, $y + $j3, $z, WOOD, 1);
}
}
}
}

View file

@ -0,0 +1,77 @@
<?php
class SpruceFeature extends Feature
{
public function place(Level $level, MersenneTwister $rand, $x, $y, $z){
$nextInt = $rand->nextInt(4) + 6;
$nextInt2 = 1 + $rand->nextInt(2);
$i2 = $nextInt - $nextInt2;
$nextInt3 = 2 + $rand->nextInt(2);
$z2 = true;
if($y < 1 || $y + $nextInt + 1 > 128){
return false;
}
for($i3 = $y; $i3 <= $y + 1 + $nextInt && $z2; ++$i3){
if($i3 - $y < $nextInt2){
$i = 0;
}else{
$i = $nextInt3;
}
for($i4 = $x - $i; $i4 <= $x + $i && $z2; ++$i4){
for($i5 = $z - $i; $i5 <= $z + $i && $z2; ++$i5){
if($i3 >= 0 && $i3 < 128){
$blockID = $level->level->getBlockID($i4, $i3, $i5);
if($blockID != 0 && $blockID != LEAVES){
$z2 = false;
}
}else{
$z2 = false;
}
}
}
}
if($z2){
$blockID = $level->level->getBlockID($x, $y - 1, $z);
if(($blockID == GRASS || $blockID == DIRT) && $y < (128 - $nextInt) - 1){
$level->level->setBlock($x, $y - 1, $z, DIRT);
$nextInt4 = $rand->nextInt(2);
$i6 = 1;
$i7 = 0;
for($i8 = 0; $i8 <= $i2; ++$i8){
$i9 = ($y + $nextInt) - $i8;
for($i10 = $x - $nextInt4; $i10 <= $x + $nextInt4; ++$i10){
$i11 = $i10 - $x;
for($i12 = $z - $nextInt4; $i12 <= $z + $nextInt4; ++$i12){
$i13 = $i12 - $z;
if((abs($i11) != $nextInt4 || abs($i13) != $nextInt4 || $nextInt4 <= 0)/* && !Block.FULL_OPAQUE[world.getBlockIDAt(i10, i9, i12)]TODO opaque*/) {
$level->level->setBlock($i10, $i9, $i12, LEAVES, 1);
}
}
}
if($nextInt4 >= $i6){
$nextInt4 = $i7;
$i7 = 1;
if(++$i6 > $nextInt3){
$i6 = $nextInt3;
}
}else{
++$nextInt4;
}
}
$nextInt5 = $rand->nextInt(3);
for($i14 = 0; $i14 < $nextInt - $nextInt5; ++$i14){
$blockID = $level->level->getBlockID($x, $y + $i14, $z);
if($blockID == 0 || $blockID == LEAVES){
$level->level->setBlock($x, $y + $i14, $z, WOOD, 1);
}
}
return true;
}
return false;
}
return false;
}
}

View file

@ -0,0 +1,52 @@
<?php
class TreeFeature extends Feature
{
public function place(Level $level, MersenneTwister $rand, $x, $y, $z){
$nextInt = $rand->nextInt(3) + 4;
$z2 = true;
if($y < 1 || $y + $nextInt + 1 > 128) return false;
for($i = $y; $i <= $y + 1 + $nextInt; ++$i){
$i2 = ($i == $y) ? 0 : 1;
if($i >= (($y + 1) + $nextInt) - 2) $i2 = 2;
for($i3 = $x - $i2; $i3 <= $x + $i2 && $z2; ++$i3){
for($i4 = $z - $i2; $i4 <= $z + $i2 && $z2; ++$i4){
if($i >= 0 && $i < 128){
$tileID = $level->level->getBlockID($i3, $i, $i4);
if($tileID != 0 && $tileID != LEAVES){
$z2 = false;
}
}else{
$z2 = false;
}
}
}
}
if($z2){
$tileID = $level->level->getBlockID($x, $y - 1, $z);
if(($tileID == GRASS || $tileID == DIRT) && $y < (128 - $nextInt) - 1){
$level->level->setBlockID($x, $y - 1, $z, DIRT);
}
for($i5 = ($y - 3) + $nextInt; $i5 <= $y + $nextInt; ++$i5){
$i6 = $i5 - ($y + $nextInt);
$i7 = (int)(1 - ($i6 / 2));
for($i8 = $x - $i7; $i8 <= $x + $i7; ++$i8){
$i9 = $i8 - $x;
for($i10 = $z - $i7; $i10 <= $z + $i7; ++$i10){
$i11 = $i10 - $z;
if((abs($i9) != $i7 || abs($i11) != $i7 || ($rand->nextInt(2) != 0 && $i6 != 0))/* && !Block.FULL_OPAQUE[world.getBlockIDAt(i8, i5, i10)]TODO opaque?*/) {
$level->level->setBlockID($i8, $i5, $i10, LEAVES);
}
}
}
}
for($i12 = 0; $i12 < $nextInt; ++$i12){
$tileID = $level->level->getBlockID($x, $y + $i12, $z);
if($tileID == 0 || $tileID == LEAVES){
$level->level->setBlockID($x, $y + $i12, $z, WOOD);
}
}
}
}
}

View file

@ -3,7 +3,7 @@ TITLE NostalgiaCore server software for Minecraft: Pocket Edition
cd /d %~dp0
if exist bin\php\php.exe (
if exist bin\mintty.exe (
start "" bin\mintty.exe -o Columns=88 -o Rows=32 -o AllowBlinking=0 -o FontQuality=3 -o CursorType=0 -o CursorBlinks=1 -h error -t "NostalgiaCore" -i bin/pocketmine.ico -w max bin\php\php.exe -d enable_dl=On PocketMine-MP.php --enable-ansi %*
start "" bin\mintty.exe -o Columns=88 -o Rows=32 -o AllowBlinking=0 -o FontQuality=3 -o CursorType=0 -o CursorBlinks=1 -h error -t "NostalgiaCore" -i bin/pocketmine.ico -w max bin\php8test\php.exe -d enable_dl=On PocketMine-MP.php --enable-ansi %*
) else (
bin\php\php.exe -d enable_dl=On PocketMine-MP.php %*
)