diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 88d2617a5..98fa1c79e 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -85,12 +85,15 @@ class LevelAPI{ return $output; } - public function generateLevel($name, $seed = false){ + public function generateLevel($name, $seed = false, $generator = false){ $options = array(); if($this->server->api->getProperty("generator-settings") !== false and trim($this->server->api->getProperty("generator-settings")) != ""){ $options["preset"] = $this->server->api->getProperty("generator-settings"); } - if($this->server->api->getProperty("generator") !== false and class_exists($this->server->api->getProperty("generator"))){ + + if($generator !== false and class_exists($generator)){ + $generator = new $generator($options); + }elseif($this->server->api->getProperty("generator") !== false and class_exists($this->server->api->getProperty("generator"))){ $generator = $this->server->api->getProperty("generator"); $generator = new $generator($options); }else{ diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 73329401f..74f5dab33 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -86,11 +86,11 @@ class PluginAPI extends stdClass{ return false; } console("[INFO] Loading plugin \"\x1b[32m".$info["name"]."\x1b[0m\" \x1b[35m".$info["version"]." \x1b[0mby \x1b[36m".$info["author"]."\x1b[0m"); - if(class_exists($info["class"])){ + if($info["class"] !== "none" and class_exists($info["class"])){ console("[ERROR] Failed loading plugin: class already exists"); return false; } - if(eval($info["code"]) === false or !class_exists($info["class"])){ + if(eval($info["code"]) === false or ($info["class"] !== "none" and !class_exists($info["class"]))){ console("[ERROR] Failed loading plugin: evaluation error"); return false; } @@ -100,17 +100,21 @@ class PluginAPI extends stdClass{ if(!in_array((string) CURRENT_API_VERSION, $apiversion)){ console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!"); } - - $object = new $className($this->server->api, false); - if(!($object instanceof Plugin)){ - console("[ERROR] Plugin \"\x1b[36m".$info["name"]."\x1b[0m\" doesn't use the Plugin Interface"); - if(method_exists($object, "__destruct")){ - $object->__destruct(); + + if($info["class"] !== "none"){ + $object = new $className($this->server->api, false); + if(!($object instanceof Plugin)){ + console("[ERROR] Plugin \"\x1b[36m".$info["name"]."\x1b[0m\" doesn't use the Plugin Interface"); + if(method_exists($object, "__destruct")){ + $object->__destruct(); + } + $object = null; + unset($object); + }else{ + $this->plugins[$className] = array($object, $info); } - $object = null; - unset($object); }else{ - $this->plugins[$className] = array($object, $info); + $this->plugins[md5($info["name"])] = array(new DummyPlugin($this->server->api, false), $info); } } @@ -196,4 +200,15 @@ interface Plugin{ public function __construct(ServerAPI $api, $server = false); public function init(); public function __destruct(); +} + +class DummyPlugin implements Plugin{ + public function __construct(ServerAPI $api, $server = false){ + } + + public function init(){ + } + + public function __destruct(){ + } } \ No newline at end of file diff --git a/src/constants/BlockIDs.php b/src/constants/BlockIDs.php index 1e139b215..77b098fbe 100644 --- a/src/constants/BlockIDs.php +++ b/src/constants/BlockIDs.php @@ -122,6 +122,7 @@ define("ICE", 79); define("SNOW_BLOCK", 80); define("CACTUS", 81); define("CLAY_BLOCK", 82); +define("REEDS", 83); define("SUGARCANE_BLOCK", 83); define("FENCE", 85); diff --git a/src/world/generator/noise/NoiseGeneratorOctaves.php b/src/world/generator/noise/NoiseGeneratorOctaves.php index 4b2de09ba..af2b003f4 100644 --- a/src/world/generator/noise/NoiseGeneratorOctaves.php +++ b/src/world/generator/noise/NoiseGeneratorOctaves.php @@ -40,13 +40,12 @@ class NoiseGeneratorOctaves extends NoiseGenerator{ } } - public function generateNoiseOctaves($floats, $int1, $int2, $int3, $int4, $int5, $int6, $par1 = false, $par2 = false, $par3 = false){ + 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($floats, $int1, 10, $int2, $int3, 1, $int4, $int5, 1, $int6); - } - if(!is_array($floats)){ - $floats = array(); + 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; @@ -61,14 +60,13 @@ class NoiseGeneratorOctaves extends NoiseGenerator{ $l1 = floor($d2); $l2 = floor($d4); $d2 -= $l1; - $d4 - $l2; + $d4 -= $l2; $l1 %= 16777216; $l2 %= 16777216; $d2 += $l1; $d4 += $l2; - - $this->generatorCollection[$j]->populateNouseArray($floats, $d2, $d3, $d4, $int4, $int5, $int6, $par1 * $d1, $par2 * $d1, $par3 * $d1, $d1); + $this->generatorCollection[$j]->populateNoiseArray($floats, $d2, $d3, $d4, $int4, $int5, $int6, $par1 * $d1, $par2 * $d1, $par3 * $d1, $d1); $d1 /= 2; } return $floats; diff --git a/src/world/generator/noise/NoiseGeneratorPerlin.php b/src/world/generator/noise/NoiseGeneratorPerlin.php index de11a214c..0ebd1c661 100644 --- a/src/world/generator/noise/NoiseGeneratorPerlin.php +++ b/src/world/generator/noise/NoiseGeneratorPerlin.php @@ -40,8 +40,12 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ $this->xCoord = $random->nextFloat() * 256; $this->yCoord = $random->nextFloat() * 256; $this->zCoord = $random->nextFloat() * 256; + + for($i = 0; $i < 512; ++$i){ + $this->permutations[$i] = 0; + } for($i = 0; $i < 256; ++$i){ - $this->permutations[] = $i; + $this->permutations[$i] = $i; } for($i = 0; $i < 256; ++$i){ @@ -54,14 +58,15 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ } - public final function lerp($par1, $par2, $par3){ - return $par2 + $par1 * ($par2 - $par2); + 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); } @@ -69,6 +74,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ $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); } @@ -100,17 +106,16 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ $j = $this->permutations[$i] + $i6; $k = $this->permutations[$i3 + 1]; $m = $this->permutations[$k] + $i6; - $d1 = $this->lerp($d5, $this->grad2D($this->permutations[$j], $d4, $d6), $this->grad3D($this->permutations[$m], $d4 - 1, 0, $d6)); - $d2 = $this->lerp($d5, $this->grad3D($this->permutations[$j + 1], $d4, 0, $d6 - 1), $this->grad3D($this->permutations[$m + 1], $d4 - 1, 0, $d6 - 1)); - - $d8 = $this->lerp($d7, $d1, $d2); + $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; } } return; } - + $d9 = 1 / $par7; $m = -1; $n = 0; @@ -153,15 +158,15 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ $i10 = $this->permutations[$i6 + 1] + $i17; $n = $this->permutations[$i10] + $i14; $i11 = $this->permutations[$i10 + 1] + $i14; - $d10 = $this->lerp($d7, $this->grad3D($this->permutations[$i8], $d6, $d14, $d12), $this->grad3D($this->permutations[$n], $d6 - 1, $d14, $d12)); - $d4 = $this->lerp($d7, $this->grad3D($this->permutations[$i9], $d6, $d14 - 1, $d12), $this->grad3D($this->permutations[$i11], $d6 - 1, $d14 - 1, $d12)); - $d11 = $this->lerp($d7, $this->grad3D($this->permutations[$i8 + 1], $d6, $d14, $d12 - 1), $this->grad3D($this->permutations[$n + 1], $d6 - 1, $d14, $d12 - 1)); - $d5 = $this->lerp($d7, $this->grad3D($this->permutations[$i9 + 1], $d6, $d14 - 1, $d12 - 1), $this->grad3D($this->permutations[$i11 + 1], $d6 - 1, $d14 - 1, $d12 - 1)); + $d10 = $this->curve($d7, $this->grad3D($this->permutations[$i8], $d6, $d14, $d12), $this->grad3D($this->permutations[$n], $d6 - 1, $d14, $d12)); + $d4 = $this->curve($d7, $this->grad3D($this->permutations[$i9], $d6, $d14 - 1, $d12), $this->grad3D($this->permutations[$i11], $d6 - 1, $d14 - 1, $d12)); + $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->lerp($d15, $d10, $d4); - $d17 = $this->lerp($d15, $d11, $d5); - $d18 = $this->lerp($d13, $d16, $d17); + $d16 = $this->curve($d15, $d10, $d4); + $d17 = $this->curve($d15, $d11, $d5); + $d18 = $this->curve($d13, $d16, $d17); $floats[$i++] += $d18 * $d9; } }