mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
emerald gen changes + nc 0.8 fixes
This commit is contained in:
parent
1bba9b83d1
commit
3ee0bd14c1
11 changed files with 29 additions and 119 deletions
|
|
@ -262,9 +262,9 @@ class EntityAPI{
|
|||
"y" => $pos->y + 0.19,
|
||||
"z" => $pos->z + mt_rand(-10, 10) / 50,
|
||||
"level" => $pos->level,
|
||||
"speedX" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"speedX" => lcg_value() * 0.2 - 0.1,
|
||||
"speedY" => 0.2,
|
||||
"speedZ" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"speedZ" => lcg_value() * 0.2 - 0.1,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
|
|
|
|||
|
|
@ -60,9 +60,9 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
public function spawnChild()
|
||||
{
|
||||
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||
"x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"x" => $this->x + lcg_value() * mt_rand(-1, 1),
|
||||
"y" => $this->y,
|
||||
"z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"z" => $this->z + lcg_value() * mt_rand(-1, 1),
|
||||
"IsBaby" => true,
|
||||
"Age" => -24000,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -1239,8 +1239,8 @@ class Entity extends Position
|
|||
if ($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false) {
|
||||
$d = $entity->x - $this->x;
|
||||
|
||||
for ($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (Utils::randomFloat() - Utils::randomFloat()) * 0.01) {
|
||||
$d = (Utils::randomFloat() - Utils::randomFloat()) * 0.01;
|
||||
for ($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (lcg_value() - lcg_value()) * 0.01) {
|
||||
$d = (lcg_value() - lcg_value()) * 0.01;
|
||||
}
|
||||
// attackedAtYaw = (float)((Math.atan2($d1, $d) * 180D) / 3.1415927410125732D) >
|
||||
$this->knockBack($d, $d1);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class TaskLookAround extends TaskBase
|
|||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return !$ai->entity->inPanic && !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath(); /*Vanilla value*/
|
||||
return !$ai->entity->inPanic && !$ai->entity->isMoving() && lcg_value() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath(); /*Vanilla value*/
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class TaskLookAtPlayer extends TaskBase{
|
|||
public $target = false;
|
||||
private $state, $yaw, $pitch;
|
||||
public function canBeExecuted(EntityAI $ai){
|
||||
return !$ai->entity->inPanic && Utils::randomFloat() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
return !$ai->entity->inPanic && lcg_value() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
}
|
||||
|
||||
protected function findTarget($e, $r){
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class TaskSwimming extends TaskBase
|
|||
$this->reset();
|
||||
}
|
||||
|
||||
if(Utils::randomFloat() < 0.8){ #1.5.2 method
|
||||
if(lcg_value() < 0.8){ #1.5.2 method
|
||||
$ai->entity->speedY = 0.42;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class NetherReactorBlock extends SolidBlock{
|
|||
for($a = $aOne; $a < $aTwo; $a += $aThree) { //wth those cycles are? TODO simplify if possible(makes server lag)
|
||||
for($b = $bOne; $b < $bTwo; $b += $bThree) {
|
||||
for($c = $cOne; $c < $cTwo; $c += $cThree) {
|
||||
if ($this->level->getBlock(new Vector3($x+$a, $y+$b, $z+$c))->getID() === 87 && Utils::randomFloat() > 0.75){
|
||||
if ($this->level->getBlock(new Vector3($x+$a, $y+$b, $z+$c))->getID() === 87 && lcg_value() > 0.75){
|
||||
$this->level->setBlock(new Vector3($x+$a, $y+$b, $z+$c), new AirBlock());
|
||||
}
|
||||
}
|
||||
|
|
@ -91,23 +91,23 @@ class NetherReactorBlock extends SolidBlock{
|
|||
$forceAmount = $data[3];
|
||||
$server = ServerAPI::request();
|
||||
if(!$forceAmount){
|
||||
$spawnNumber = $minAmount + floor(Utils::randomFloat()*($maxAmount-$minAmount+1));
|
||||
$spawnNumber = $minAmount + floor(lcg_value()*($maxAmount-$minAmount+1));
|
||||
}
|
||||
else{
|
||||
$spawnNumber = $maxAmount;
|
||||
}
|
||||
for($i = 0; $i < $spawnNumber; $i++) {
|
||||
$randomRange = floor(Utils::randomFloat()*5+3);
|
||||
$shiftX = cos(floor(Utils::randomFloat()*360)*(pi()/180));
|
||||
$shiftZ = sin(floor(Utils::randomFloat()*360)*(pi()/180));
|
||||
$randomRange = floor(lcg_value()*5+3);
|
||||
$shiftX = cos(floor(lcg_value()*360)*(pi()/180));
|
||||
$shiftZ = sin(floor(lcg_value()*360)*(pi()/180));
|
||||
if(Utils::chance(5)) $randomID = $this->rarePossibleLoot[array_rand($this->rarePossibleLoot)];
|
||||
else $randomID = $this->possibleLoot[array_rand($this->possibleLoot)];
|
||||
$server->api->entity->drop(new Position($x+($shiftX*$randomRange)+0.5, $y, $z+($shiftZ*$randomRange)+0.5, $this->level), BlockAPI::getItem($randomID, 0, 1));
|
||||
}
|
||||
for($i = 0; $i < $pigmen; $i++) {
|
||||
$randomRange = floor(Utils::randomFloat()*5+3);
|
||||
$shiftX = cos(floor(Utils::randomFloat()*360)*(pi()/180));
|
||||
$shiftZ = sin(floor(Utils::randomFloat()*360)*(pi()/180));
|
||||
$randomRange = floor(lcg_value()*5+3);
|
||||
$shiftX = cos(floor(lcg_value()*360)*(pi()/180));
|
||||
$shiftZ = sin(floor(lcg_value()*360)*(pi()/180));
|
||||
$data = array(
|
||||
"x" => $x+($shiftX*$randomRange)+0.5,
|
||||
"y" => $y,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class SmallFarmStructure extends Structure{
|
|||
|
||||
protected function getMappingFor($char){
|
||||
if($char === "R"){
|
||||
$f = Utils::randomFloat();
|
||||
$f = lcg_value();
|
||||
|
||||
if($f <= 0.5){
|
||||
return [WHEAT_BLOCK, 0];
|
||||
|
|
|
|||
|
|
@ -456,107 +456,17 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0){
|
||||
static $lastRandom = "";
|
||||
$output = b"";
|
||||
$length = abs((int) $length);
|
||||
$secureValue = "";
|
||||
$rounds = 0;
|
||||
$drop = 0;
|
||||
while(!isset($output[$length - 1])){
|
||||
//some entropy, but works ^^
|
||||
$weakEntropy = [
|
||||
is_array($startEntropy) ? implode($startEntropy) : $startEntropy,
|
||||
serialize(@stat(__FILE__)),
|
||||
__DIR__,
|
||||
PHP_OS,
|
||||
microtime(),
|
||||
(string) lcg_value(),
|
||||
(string) PHP_MAXPATHLEN,
|
||||
PHP_SAPI,
|
||||
(string) PHP_INT_MAX . "." . PHP_INT_SIZE,
|
||||
serialize($_SERVER),
|
||||
serialize(get_defined_constants()),
|
||||
get_current_user(),
|
||||
serialize(ini_get_all()),
|
||||
(string) memory_get_usage() . "." . memory_get_peak_usage(),
|
||||
php_uname(),
|
||||
phpversion(),
|
||||
//extension_loaded("gmp") ? gmp_strval(gmp_random(4)):microtime(),
|
||||
zend_version(),
|
||||
(string) getmypid(),
|
||||
(string) getmyuid(),
|
||||
(string) mt_rand(),
|
||||
(string) getmyinode(),
|
||||
(string) getmygid(),
|
||||
(string) rand(),
|
||||
function_exists("zend_thread_id") ? ((string) zend_thread_id()) : microtime(),
|
||||
function_exists("getrusage") ? @implode(getrusage()) : microtime(),
|
||||
function_exists("sys_getloadavg") ? @implode(sys_getloadavg()) : microtime(),
|
||||
serialize(get_loaded_extensions()),
|
||||
sys_get_temp_dir(),
|
||||
(string) disk_free_space("."),
|
||||
(string) disk_total_space("."),
|
||||
uniqid(microtime(), true),
|
||||
file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : microtime(),
|
||||
];
|
||||
|
||||
shuffle($weakEntropy);
|
||||
$value = hash("sha512", implode($weakEntropy), true);
|
||||
$lastRandom .= $value;
|
||||
foreach($weakEntropy as $k => $c){ //mixing entropy values with XOR and hash randomness extractor
|
||||
$value ^= hash("sha256", $c . microtime() . $k, true) . hash("sha256", mt_rand() . microtime() . $k . $c, true);
|
||||
$value ^= hash("sha512", ((string) lcg_value()) . $c . microtime() . $k, true);
|
||||
}
|
||||
unset($weakEntropy);
|
||||
|
||||
if($secure === true){
|
||||
$strongEntropyValues = [
|
||||
is_array($startEntropy) ? hash("sha512", $startEntropy[($rounds + $drop) % count($startEntropy)], true) : hash("sha512", $startEntropy, true), //Get a random index of the startEntropy, or just read it
|
||||
file_exists("/dev/urandom") ? fread(fopen("/dev/urandom", "rb"), 64) : str_repeat("\x00", 64),
|
||||
(function_exists("openssl_random_pseudo_bytes") and version_compare(PHP_VERSION, "5.3.4", ">=")) ? openssl_random_pseudo_bytes(64) : str_repeat("\x00", 64),
|
||||
function_exists("mcrypt_create_iv") ? mcrypt_create_iv(64, MCRYPT_DEV_URANDOM) : str_repeat("\x00", 64),
|
||||
$value,
|
||||
];
|
||||
$strongEntropy = array_pop($strongEntropyValues);
|
||||
foreach($strongEntropyValues as $value){
|
||||
$strongEntropy = $strongEntropy ^ $value;
|
||||
}
|
||||
$value = "";
|
||||
//Von Neumann randomness extractor, increases entropy
|
||||
$bitcnt = 0;
|
||||
for($j = 0; $j < 64; ++$j){
|
||||
$a = ord($strongEntropy[$j]);
|
||||
for($i = 0; $i < 8; $i += 2){
|
||||
$b = ($a & (1 << $i)) > 0 ? 1 : 0;
|
||||
if($b != (($a & (1 << ($i + 1))) > 0 ? 1 : 0)){
|
||||
$secureValue = $b << $bitcnt;
|
||||
if($bitcnt == 7){
|
||||
$value .= chr($secureValue);
|
||||
$secureValue = 0;
|
||||
$bitcnt = 0;
|
||||
}else{
|
||||
++$bitcnt;
|
||||
}
|
||||
++$drop;
|
||||
}else{
|
||||
$drop += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$output .= substr($value, 0, min($length - strlen($output), $length));
|
||||
unset($value);
|
||||
++$rounds;
|
||||
}
|
||||
$lastRandom = hash("sha512", $lastRandom, true);
|
||||
return $raw === false ? bin2hex($output) : $output;
|
||||
return $raw ? random_bytes($length) : bin2hex(random_bytes($length)); //nobody would ever notice other parameters
|
||||
}
|
||||
|
||||
public static function chance($i){//GameHerobrine's code
|
||||
return self::randomFloat() <= $i / 100;
|
||||
public static function chance($i){
|
||||
return lcg_value() <= $i / 100;
|
||||
}
|
||||
|
||||
public static function randomFloat(){//GameHerobrine's code
|
||||
/**
|
||||
* @deprecated use lcg_value() instead.
|
||||
* @return number
|
||||
*/
|
||||
public static function randomFloat(){
|
||||
return rand() / getrandmax();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
|
|||
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 EmeraldOreBlock(), 1, 7, 0, 16), //TODO vanilla
|
||||
new OreType(new EmeraldOreBlock(), 1, 2, 0, 16), //TODO vanilla
|
||||
|
||||
new OreType(new DirtBlock(), 20, 32, 0, 128),
|
||||
new OreType(new GravelBlock(), 10, 16, 0, 128),
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
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 EmeraldOreBlock(), 1, 7, 0, 16), //TODO vanilla
|
||||
new OreType(new EmeraldOreBlock(), 1, 2, 0, 16), //TODO vanilla
|
||||
|
||||
new OreType(new DirtBlock(), 20, 32, 0, 128),
|
||||
new OreType(new GravelBlock(), 10, 16, 0, 128),
|
||||
|
|
@ -70,7 +70,7 @@ class NormalGenerator implements NewLevelGenerator{
|
|||
$i = ($z << 4) + $x;
|
||||
$hills[$i] = $this->noiseHills->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 0.11, 12, true);
|
||||
$patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true);
|
||||
$patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true);
|
||||
//$patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true);
|
||||
$base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 16, true);
|
||||
if($base[$i] < 0){
|
||||
$base[$i] *= 0.5;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue