diff --git a/src/config.php b/src/config.php index a53cf9d0..cc63e55a 100644 --- a/src/config.php +++ b/src/config.php @@ -52,7 +52,7 @@ define("MAJOR_VERSION", "2.0.0dev"); define("CODENAME", "Breadfence"); //i'm not very creative - kotyaralih define("CURRENT_MINECRAFT_VERSION", "v0.9.5 alpha"); define("CURRENT_API_VERSION", '13.1'); -define("CURRENT_PHP_VERSION", "5.5"); +define("CURRENT_PHP_VERSION", "8.0"); $gitsha1 = false; if(file_exists(FILE_PATH . ".git/refs/heads/master")){ //Found Git information! define("GIT_COMMIT", strtolower(trim(file_get_contents(FILE_PATH . ".git/refs/heads/master")))); diff --git a/src/dependencies.php b/src/dependencies.php index 94734f6d..aff3def1 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -22,6 +22,8 @@ if(version_compare("8.0.0", PHP_VERSION) > 0){ ++$errors; } +define("USE_NATIVE_RANDOM", version_compare("8.2.0", PHP_VERSION) <= 0); + if(php_sapi_name() !== "cli"){ console("[ERROR] You must run NostalgiaCore using the CLI.", true, true, 0); ++$errors; diff --git a/src/entity/object/Minecart.php b/src/entity/object/Minecart.php index 9cf5fe16..3bf1519f 100644 --- a/src/entity/object/Minecart.php +++ b/src/entity/object/Minecart.php @@ -15,11 +15,8 @@ class Minecart extends Vehicle{ $this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z; $this->setHealth(3, "generic"); //$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type)); - $this->width = 1; - /*$this->moveVector[Entity::NORTH] = new Vector3(-1, 0, 0); - $this->moveVector[Entity::SOUTH] = new Vector3(1, 0, 0); - $this->moveVector[Entity::EAST] = new Vector3(0, 0, -1); - $this->moveVector[Entity::WEST] = new Vector3(0, 0, 1);*/ + $this->width = 0.98; + $this->height = 0.7; $this->update(); } diff --git a/src/utils/MTRandom.php b/src/utils/MTRandom.php index 5cc5d5c3..a3ceae43 100644 --- a/src/utils/MTRandom.php +++ b/src/utils/MTRandom.php @@ -1,56 +1,83 @@ setSeed($seed == null ? (int)microtime(1) : $seed); - } - - public function setSeed($seed){ - $this->mt[0] = $seed & 0xffffffff; - for($this->index = 1; $this->index < 624; ++$this->index){ - $this->mt[$this->index] = (0x6c078965 * ($this->mt[$this->index-1] >> 30 ^ $this->mt[$this->index - 1]) + $this->index) & 0xffffffff; +if(USE_NATIVE_RANDOM){ +eval(' + class MTRandom + { + public $native; + public function __construct($seed = null){ + $this->native = new \Random\Randomizer(new \Random\Engine\Mt19937($seed)); } - } - - public function genRandInt(){ - if($this->index >= 624 || $this->index < 0){ - if($this->index >= 625 || $this->index < 0) $this->setSeed(4357); - - for($kk = 0; $kk < 227; ++$kk){ - $y = ($this->mt[$kk] & 0x80000000) | ($this->mt[$kk + 1] & 0x7fffffff); - $this->mt[$kk] = $this->mt[$kk+397] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; - } - - for(;$kk < 623; ++$kk){ - $y = ($this->mt[$kk] & 0x80000000) | ($this->mt[$kk + 1] & 0x7fffffff); - $this->mt[$kk] = $this->mt[$kk-227] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; - } - - $y = ($this->mt[623] & 0x80000000) | ($this->mt[0] & 0x7fffffff); - $this->mt[623] = $this->mt[396] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; - $this->index = 0; + public function setSeed($seed){ + $this->native = new \Random\Randomizer(new \Random\Engine\Mt19937($seed)); } - $y = $this->mt[$this->index++]; - $y ^= ($y >> 11); - $y ^= ($y << 7) & 0x9d2c5680; - $y ^= ($y << 15) & 0xefc60000; - $y ^= ($y >> 18); - return $y; + public function genRandInt(){ + return $this->native->getInt(0, 0x7fffffff); + } + + public function nextInt($bound = null){ + return $bound == null ? $this->native->nextInt() : $this->native->getInt(0, $bound - 1); + } + + public function nextFloat(){ + return $this->native->getInt(0, 0x7fffffff) / 0x7fffffff; + } } - - public function nextInt($bound = null){ - return $bound == null ? $this->genRandInt() >> 1 : $this->genRandInt() % $bound; - } - - public function nextFloat(){ - return $this->genRandInt() / 0xffffffff; +'); +}else{ +eval(' + class MTRandom + { + const MAG = [0, 0x9908b0df]; + public $mt; + public $index = 0; + public function __construct($seed = null){ + $this->setSeed($seed == null ? (int)microtime(1) : $seed); + } + + public function setSeed($seed){ + $this->mt[0] = $seed & 0xffffffff; + for($this->index = 1; $this->index < 624; ++$this->index){ + $this->mt[$this->index] = (0x6c078965 * ($this->mt[$this->index-1] >> 30 ^ $this->mt[$this->index - 1]) + $this->index) & 0xffffffff; + } + } + + public function genRandInt(){ + if($this->index >= 624 || $this->index < 0){ + if($this->index >= 625 || $this->index < 0) $this->setSeed(4357); + + for($kk = 0; $kk < 227; ++$kk){ + $y = ($this->mt[$kk] & 0x80000000) | ($this->mt[$kk + 1] & 0x7fffffff); + $this->mt[$kk] = $this->mt[$kk+397] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; + } + + for(;$kk < 623; ++$kk){ + $y = ($this->mt[$kk] & 0x80000000) | ($this->mt[$kk + 1] & 0x7fffffff); + $this->mt[$kk] = $this->mt[$kk-227] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; + } + + $y = ($this->mt[623] & 0x80000000) | ($this->mt[0] & 0x7fffffff); + $this->mt[623] = $this->mt[396] ^ ($y >> 1) ^ MTRandom::MAG[$y & 0x1]; + $this->index = 0; + } + + $y = $this->mt[$this->index++]; + $y ^= ($y >> 11); + $y ^= ($y << 7) & 0x9d2c5680; + $y ^= ($y << 15) & 0xefc60000; + $y ^= ($y >> 18); + return $y; + } + + public function nextInt($bound = null){ + return $bound == null ? $this->genRandInt() >> 1 : $this->genRandInt() % $bound; + } + + public function nextFloat(){ + return $this->genRandInt() / 0xffffffff; + } } +'); } + diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index cdb72170..15c71b4c 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -152,7 +152,7 @@ class NormalGenerator implements NewLevelGenerator{ $this->level->level->setBiomeIdArrayForChunk($chunkX, $chunkZ, $biomes); $this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk); } - //$this->caveGenerator->generate($this->level, $chunkX, $chunkZ); TODO speedup + //$this->caveGenerator->generate($this->level, $chunkX, $chunkZ); //TODO speedup } public function populateChunk($chunkX, $chunkZ){