diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 0c5d6f3ea..9353e9c01 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -32,7 +32,7 @@ class BanAPI{ private $ops; /** @var Config */ private $bannedIPs; - private $cmdWL = array();//Command WhiteList + private $cmdWhitelist = array();//Command WhiteList function __construct(){ $this->server = ServerAPI::request(); } @@ -104,7 +104,6 @@ class BanAPI{ } } return; - break; case "console.command"://Checks if a command is allowed with the current user permissions. if(isset($this->cmdWhitelist[$data["cmd"]])){ return; @@ -118,7 +117,6 @@ class BanAPI{ return; } return false; - break; } } @@ -152,7 +150,7 @@ class BanAPI{ $player = $this->server->api->player->get($user); if(!($player instanceof Player)){ $this->ops->set($user); - $this->ops->save($user); + $this->ops->save(); $output .= $user." is now op\n"; break; } diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 4ee73014a..5abdf9fb4 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -516,13 +516,9 @@ class BlockAPI{ public function nextRandomUpdate(Position $pos){ if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){ - $X = (($pos->x >> 4) << 4); - $Y = (($pos->y >> 4) << 4); - $Z = (($pos->z >> 4) << 4); $time = microtime(true); - $i = 0; $offset = 0; - while(true){ + do{ $t = $offset + Utils::getRandomUpdateTicks() * 0.05; $update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '".$pos->level->getName()."' AND type = ".BLOCK_UPDATE_RANDOM." AND delay >= ".($time + $t - 1)." AND delay <= ".($time + $t + 1).";"); if($update instanceof SQLite3Result){ @@ -534,7 +530,7 @@ class BlockAPI{ break; } $offset += mt_rand(25, 75); - } + }while(true); $this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM); } } diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 0ac1583e6..0dfb688f3 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -26,7 +26,6 @@ class ConsoleAPI{ $this->cmds = array(); $this->alias = array(); $this->server = ServerAPI::request(); - $this->last = microtime(true); } public function init(){ @@ -250,7 +249,7 @@ class ConsoleAPI{ if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){ $output = "You don't have permissions to use this command.\n"; - }elseif($d1 !== true and $d2 !== true){ + }elseif($d1 !== true and (isset($d2) and $d2 !== true)){ if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ $output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias); }elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){ @@ -326,7 +325,7 @@ class ConsoleLoop extends Thread{ } if(!extension_loaded("readline")){ - @fclose($fp); + @fclose($this->fp); } exit(0); } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index e93e6df31..d5d92929f 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -198,7 +198,6 @@ class LevelAPI{ $t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile); } - $timeu = microtime(true); foreach($blockUpdates->getAll() as $bupdate){ $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]); } diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 788d6bbd1..4468ca2c7 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -111,7 +111,6 @@ class PlayerAPI{ } $this->server->api->chat->broadcast($data["player"]->username . $message); return true; - break; } } diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 7581e263a..65a7dcd73 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -196,19 +196,6 @@ class PluginAPI extends stdClass{ return $path; } - private function fillDefaults($default, &$yaml){ - foreach($default as $k => $v){ - if(is_array($v)){ - if(!isset($yaml[$k]) or !is_array($yaml[$k])){ - $yaml[$k] = array(); - } - $this->fillDefaults($v, $yaml[$k]); - }elseif(!isset($yaml[$k])){ - $yaml[$k] = $v; - } - } - } - public function readYAML($file){ return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file))); } diff --git a/src/Player.php b/src/Player.php index 82589d8e6..e1f4a8e2c 100644 --- a/src/Player.php +++ b/src/Player.php @@ -222,7 +222,6 @@ class Player{ $Y = $id[1]; $x = $X << 4; $z = $Z << 4; - $y = $Y << 4; $this->level->useChunk($X, $Z, $this); $Yndex = 1 << $Y; for($iY = 0; $iY < 8; ++$iY){ @@ -328,7 +327,7 @@ class Player{ $this->chunksLoaded = array(); $this->chunksOrder = array(); $this->chunkCount = array(); - $this->cratingItems = array(); + $this->craftingItems = array(); $this->received = array(); } } @@ -698,11 +697,10 @@ class Player{ return; }else{ $message = $data->get(); - $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", $message["message"]), $message["player"]); //Remove ANSI codes from chat + $this->sendChat($message["message"], $message["player"]); } }else{ - $message = (string) $data; - $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", (string) $data)); //Remove ANSI codes from chat + $this->sendChat((string) $data); } break; } @@ -1377,8 +1375,8 @@ class Player{ $inv[] = array($item[0], $item[1], 1); } } + $this->data->set("inventory", $inv); } - $this->data->set("inventory", $inv); } $this->achievements = $this->data->get("achievements"); $this->data->set("caseusername", $this->username); @@ -2007,6 +2005,7 @@ class Player{ $packet->item = $this->getSlot($this->slot); $this->craftingItems = array(); $this->toCraft = array(); + $data = array(); $data["eid"] = $packet->eid; $data["unknown"] = $packet->unknown; $data["item"] = $packet->item; @@ -2374,7 +2373,7 @@ class Player{ return $cnts; } - public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true){ + public function directDataPacket(RakNetDataPacket $packet, $recover = true){ if($this->connected === false){ return false; } @@ -2382,7 +2381,6 @@ class Player{ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ return array(); } - $packet->encode(); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk->data[] = $packet; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 32afc47d2..408c4a1c2 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -21,8 +21,8 @@ class PocketMinecraftServer{ public $tCnt; - public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; - private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = array(), $asyncID = 0; + public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $seed, $stop, $gamemode, $difficulty$name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; + private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0; /** * @var ServerAPI @@ -45,10 +45,7 @@ class PocketMinecraftServer{ $this->eventsID = array(); $this->handlers = array(); $this->invisible = false; - $this->levelData = false; $this->difficulty = 1; - $this->tiles = array(); - $this->entities = array(); $this->custom = array(); $this->evCnt = 1; $this->handCnt = 1; @@ -57,7 +54,6 @@ class PocketMinecraftServer{ $this->schedule = array(); $this->scheduleCnt = 1; $this->description = ""; - $this->whitelist = false; $this->memoryStats = array(); $this->clients = array(); $this->spawn = false; @@ -129,7 +125,7 @@ class PocketMinecraftServer{ public function startDatabase(){ $this->preparedSQL = new stdClass(); $this->preparedSQL->entity = new stdClass(); - $this->database = new SQLite3(":memory:"); + $this->database = new SQLite3(":memory:", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $this->query("PRAGMA journal_mode = OFF;"); $this->query("PRAGMA encoding = \"UTF-8\";"); $this->query("PRAGMA secure_delete = OFF;"); @@ -316,7 +312,6 @@ class PocketMinecraftServer{ $handlers->finalize(); foreach($call as $hnid => $boolean){ if($result !== false and $result !== true){ - $called[$hnid] = true; $handler = $this->handlers[$hnid]; if(is_array($handler)){ $method = $handler[1]; diff --git a/src/build/compile.sh b/src/build/compile.sh index 7744230a8..cabcc1a12 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -51,7 +51,7 @@ elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -Wl,-rpath,@loader_path/../lib"; + [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; export DYLD_LIBRARY_PATH="@loader_path/../lib" OPENSSL_TARGET="darwin-i386-cc" echo "[INFO] Compiling for Intel MacOS x86" @@ -59,7 +59,7 @@ elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -Wl,-rpath,@loader_path/../lib"; + [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; export DYLD_LIBRARY_PATH="@loader_path/../lib" OPENSSL_TARGET="darwin64-x86_64-cc" echo "[INFO] Compiling for Intel MacOS x86_64" diff --git a/src/event/EventHandler.php b/src/event/EventHandler.php index 7498cfaff..2a9b1becd 100644 --- a/src/event/EventHandler.php +++ b/src/event/EventHandler.php @@ -22,7 +22,6 @@ abstract class EventHandler{ public static function callEvent(BaseEvent $event){ - $status = BaseEvent::NORMAL; foreach($event::$handlerPriority as $priority => $handlerList){ if(count($handlerList) > 0){ $event->setPrioritySlot($priority); diff --git a/src/functions.php b/src/functions.php index 6fcdcf891..75ed19015 100644 --- a/src/functions.php +++ b/src/functions.php @@ -140,7 +140,7 @@ function arguments ( $args ){ $args = array(); } array_shift( $args ); - $args = join( $args, ' ' ); + $args = implode( $args, ' ' ); preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match ); $args = array_shift( $match ); @@ -158,7 +158,7 @@ function arguments ( $args ){ $value = preg_split( '/[= ]/', $arg, 2 ); $com = substr( array_shift($value), 2 ); - $value = join($value); + $value = implode($value); $ret['commands'][$com] = !empty($value) ? $value : true; continue; diff --git a/src/material/block/attachable/SignPost.php b/src/material/block/attachable/SignPost.php index 743d35adc..948476b3b 100644 --- a/src/material/block/attachable/SignPost.php +++ b/src/material/block/attachable/SignPost.php @@ -41,7 +41,7 @@ class SignPostBlock extends TransparentBlock{ return true; }else{ $this->meta = $faces[$face]; - $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta, true, false, true)); + $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta), true, false, true); return true; } } diff --git a/src/material/item/generic/SpawnEgg.php b/src/material/item/generic/SpawnEgg.php index 2c9d1329f..8c78182e0 100644 --- a/src/material/item/generic/SpawnEgg.php +++ b/src/material/item/generic/SpawnEgg.php @@ -43,7 +43,6 @@ class SpawnEggItem extends Item{ --$this->count; } return true; - break; } return false; } diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 587131a2d..7a4266266 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -30,7 +30,6 @@ class MinecraftInterface{ exit(1); } $this->bandwidth = array(0, 0, microtime(true)); - $this->start = microtime(true); $this->packets = array(); } @@ -90,7 +89,7 @@ class MinecraftInterface{ if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){ return 0; }elseif($packet instanceof RakNetPacket){ - $codec = new RakNetCodec($packet); + new RakNetCodec($packet); } $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); $this->bandwidth[1] += $write; diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index ee9df38e0..8dc30c717 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -22,7 +22,7 @@ class UDPSocket{ - public $connected, $sock, $server; + public $connected, $sock, $server, $port; function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){ $this->server = $server; $this->port = $port; diff --git a/src/network/raknet/RakNetCodec.php b/src/network/raknet/RakNetCodec.php index a009f63d2..c0c908760 100644 --- a/src/network/raknet/RakNetCodec.php +++ b/src/network/raknet/RakNetCodec.php @@ -21,6 +21,7 @@ class RakNetCodec{ public $packet; + private $buffer; public function __construct(RakNetPacket $packet){ $this->packet = $packet; $this->buffer =& $this->packet->buffer; diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index 75ebc44b7..b2452f77c 100644 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -76,8 +76,8 @@ abstract class RakNetDataPacket extends stdClass{ $this->buffer .= Utils::writeLong($v); } - protected function getInt($unsigned = false){ - return Utils::readInt($this->get(4), $unsigned); + protected function getInt(){ + return Utils::readInt($this->get(4)); } protected function putInt($v){ diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index 98699be9c..a8d99a2ca 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -50,8 +50,8 @@ class RakNetParser{ return Utils::readLong($this->get(8), $unsigned); } - private function getInt($unsigned = false){ - return Utils::readInt($this->get(4), $unsigned); + private function getInt(){ + return Utils::readInt($this->get(4)); } private function getShort($unsigned = false){ diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 46f6bb98d..acb8776cf 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -95,7 +95,7 @@ class PMFLevel extends PMF{ } private function createBlank(){ - $this->saveData(false); + $this->saveData(); @mkdir(dirname($this->file)."/chunks/", 0755); if(!file_exists(dirname($this->file)."/entities.yml")){ $entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML); diff --git a/src/utils/Config.php b/src/utils/Config.php index ace15d218..f491e9a52 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -76,7 +76,6 @@ class Config{ */ public function __construct($file, $type = CONFIG_DETECT, $default = array(), &$correct = null){ $this->load($file, $type, $default); - $correct = $this->check(); } public function reload(){ @@ -84,7 +83,6 @@ class Config{ unset($this->correct); unset($this->type); $this->load($this->file); - $correct = $this->check(); } public function fixYAMLIndexes($str){ @@ -141,7 +139,6 @@ class Config{ default: $this->correct = false; return false; - break; } if(!is_array($this->config)){ $this->config = $default; diff --git a/src/utils/NBT.php b/src/utils/NBT.php index f85f637bd..daa6b3932 100644 --- a/src/utils/NBT.php +++ b/src/utils/NBT.php @@ -107,7 +107,7 @@ class NBT{ } public function writeTAG_FLOAT($v){ - $this->binary .= Utils::writeLFloar($v); + $this->binary .= Utils::writeLFloat($v); } public function writeTAG_DOUBLE($v){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index fff7aa293..761e76a05 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -620,7 +620,7 @@ class Utils{ } public static function writeLLong($value){ - return strrev(Utils::writeLong($str)); + return strrev(Utils::writeLong($value)); } diff --git a/src/utils/VersionString.php b/src/utils/VersionString.php index 7fccc28b2..f0a398ab8 100644 --- a/src/utils/VersionString.php +++ b/src/utils/VersionString.php @@ -33,6 +33,7 @@ class VersionString{ private $release; private $minor; private $development = false; + private $generation; public function __construct($version = MAJOR_VERSION){ if(is_int($version)){ $this->minor = $version & 0x1F; diff --git a/src/utils/pthreads.php b/src/utils/pthreads.php index 134fd3f3a..d4a3faaf0 100644 --- a/src/utils/pthreads.php +++ b/src/utils/pthreads.php @@ -87,7 +87,7 @@ class AsyncMultipleQueue extends Thread{ $d = array(); for($c = 0; $c < $cnt; ++$c){ $key = $this->get(Utils::readShort($this->get(2), false)); - $d[$key] = $this->get(Utils::readInt($this->get(4), false)); + $d[$key] = $this->get(Utils::readInt($this->get(4))); } $res = (string) Utils::curl_post($url, $d, $timeout); $this->lock(); diff --git a/src/installer/Installer.php b/src/wizard/Installer.php similarity index 100% rename from src/installer/Installer.php rename to src/wizard/Installer.php diff --git a/src/world/Entity.php b/src/world/Entity.php index a8bb3d26d..b93775abc 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -43,8 +43,16 @@ class Entity extends Position{ public $attach; public $closed; public $player; + public $status; public $fallY; + public $health; + public $fire; + public $crouched; + public $invincible; public $fallStart; + public $stack; + public $meta; + private $position; private $tickCounter; private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0); private $server; @@ -526,8 +534,8 @@ class Entity extends Position{ } }elseif($this->fallY !== false){ //Fall damage! if($y < $this->fallY){ - $d = $this->level->getBlock(new Vector3($x, $y + 1, $z)); - $d2 = $this->level->getBlock(new Vector3($x, $y + 2, $z)); + $d = $this->level->getBlock(new Vector3($this->x, $y + 1, $this->z)); + $d2 = $this->level->getBlock(new Vector3($this->x, $y + 2, $this->z)); $dmg = ($this->fallY - $y) - 3; if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and $d->getID() !== COBWEB and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER and $d2->getID() !== COBWEB){ $this->harm($dmg, "fall"); @@ -562,10 +570,10 @@ class Entity extends Position{ if($this->isStatic === false and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){ if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){ if($this->server->api->handle("entity.move", $this) === false){ - if($this->class === ENTITY_PLAYER){ + if($this->class === ENTITY_PLAYER and $this->player instanceof Player){ $this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]); }else{ - $this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]); + $this->setPosition(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]); } }else{ $this->updateLast(); @@ -593,7 +601,7 @@ class Entity extends Position{ } } }else{ - $this->updatePosition($this->x, $this->y, $this->z, $this->yaw, $this->pitch); + $this->updatePosition(); } } $this->lastUpdate = $now; @@ -658,7 +666,7 @@ class Entity extends Position{ } switch($this->class){ case ENTITY_PLAYER: - if($this->player->connected !== true or $this->player->spawned === false){ + if(!($this->player instanceof Player) or $this->player->connected !== true or $this->player->spawned === false){ return false; } diff --git a/src/world/PocketChunkParser.php b/src/world/PocketChunkParser.php index 589ece0e2..333f40fed 100644 --- a/src/world/PocketChunkParser.php +++ b/src/world/PocketChunkParser.php @@ -19,14 +19,19 @@ * */ +/** + * WARNING: This code is old, and only supports the file format partially (reverse engineering) + * It can break, lock, or hit you in the face in any moment. + * + */ + class PocketChunkParser{ private $location, $raw = b"", $file; - var $sectorLength = 4096; //16 * 16 * 16 - var $chunkLength = 86016; //21 * $sectorLength - var $map; + public $sectorLength = 4096; //16 * 16 * 16 + public $chunkLength = 86016; //21 * $sectorLength + public $map = array(); - function __construct(){ - $map = array(); + public function __construct(){ } private function loadLocationTable(){ diff --git a/src/world/Tile.php b/src/world/Tile.php index b7ccd4283..c2b89fbef 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -31,6 +31,8 @@ class Tile extends Position{ public $attach; public $metadata; public $closed; + private $lastUpdate; + private $scheduledUpdate; private $server; function __construct(Level $level, $id, $class, $x, $y, $z, $data = array()){ $this->server = ServerAPI::request(); diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index bf24d7649..1b65e3c85 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -80,6 +80,7 @@ class NormalGenerator implements LevelGenerator{ public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $hills = array(); + $patches = array(); $patchesSmall = array(); $base = array(); for($z = 0; $z < 16; ++$z){ diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index d57874456..5de375ed4 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -24,7 +24,7 @@ require_once("LevelGenerator.php"); /***REM_END***/ class SuperflatGenerator implements LevelGenerator{ - private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = array(); + private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = array(); public function getSettings(){ return $this->options; diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 9825adea5..9e7d52393 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -20,7 +20,7 @@ */ class WorldGenerator{ - private $seed, $level, $path, $random, $generator, $width; + private $seed, $level, $path, $random, $generator, $height; public function __construct(LevelGenerator $generator, $name, $seed = false, $height = 8){ $this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false)); $this->random = new Random($this->seed); diff --git a/src/world/generator/noise/OctaveGenerator.php b/src/world/generator/noise/OctaveGenerator.php deleted file mode 100644 index 962801bec..000000000 --- a/src/world/generator/noise/OctaveGenerator.php +++ /dev/null @@ -1,108 +0,0 @@ -octaves = $octaves; - } - - public function setScale($scale){ - $this->setXScale($scale); - $this->setYScale($scale); - $this->setZScale($scale); - } - - public function getXScale(){ - return $this->xScale; - } - - public function setXScale($scale){ - $this->xScale = $scale; - } - - public function getYScale(){ - return $this->yScale; - } - - public function setYScale($scale){ - $this->yScale = $scale; - } - - public function getZScale(){ - return $this->zScale; - } - - public function setZScale($scale){ - $this->zScale = $scale; - } - - public function getOctaves(){ - $array = array(); - foreach($this->octaves as $index => $value){ - $array[$index] = clone $value; - } - return $array; - } - - //1D-noise - public function noise1D($x, $frequency, $amplitude, $normalized = false){ - return $this->noise3D($x, 0, 0, $frequency, $amplitude, $normalized); - } - - //2D-noise - public function noise2D($x, $y, $frequency, $amplitude, $normalized = false){ - return $this->noise3D($x, $y, 0, $frequency, $amplitude, $normalized); - } - - //3D-noise - public function noise3D($x, $y, $z, $frequency, $amplitude, $normalized = false){ - $result = 0; - $amp = 1; - $freq = 1; - $max = 0; - - $x *= $this->xScale; - $y *= $this->yScale; - $z *= $this->zScale; - - foreach($this->octaves as $noiseGenerator){ - $result += $octave->noise($x * $freq, $y * $freq, $z * $freq) * $amp; - $max += $amp; - $freq *= $frequency; - $amp *= $amplitude; - } - if($normalized === true){ - $result /= $max; - } - - return $result; - } - - /*public function generateNoiseOctaves($x, $y, $z, $frequency, $amplitude){ - - }*/ -} \ No newline at end of file diff --git a/src/world/generator/noise/PerlinOctaveGenerator.php b/src/world/generator/noise/PerlinOctaveGenerator.php deleted file mode 100644 index 53a79884c..000000000 --- a/src/world/generator/noise/PerlinOctaveGenerator.php +++ /dev/null @@ -1,63 +0,0 @@ -octaves = array(); - for($o = 0; $o < $octaves; ++$o){ - $this->octaves[$o] = new NoiseGeneratorPerlin($random); - } - } - - /*public function generateNoiseOctaves($x, $y, $z, $sizeX, $sizeY, $sizeZ, $fX, $fY, $fZ){ - $adouble = array_fill(0, $sizeX * $sizeY * $sizeZ, 0.0); - - $d3 = 1.0; - - foreach($this->octaves as $octave){ - $dX = $x * $d3 * $fX; - $dY = $y * $d3 * $fY; - $dZ = $x * $d3 * $fZ; - - $x1 = NoiseGenerator::floor($dX); - $z1 = NoiseGenerator::floor($dZ); - - $dX -= $x1; - $dZ -= $z1; - - $x1 %= 16777216; - $z1 %= 16777216; - //$x1 &= 0xFFFFFF; - //$z1 &= 0xFFFFFF; - - $dX += $x1; - $dZ += $z1; - $octave->populateNoiseArray($adouble, $dX, $dY, $dZ, $sizeX, $sizeY, $sizeZ, $fX * $d3, $fY * $d3, $fZ * $d3, $d3); - $d3 *= 0.5; - } - - return $adouble; - }*/ -} \ No newline at end of file diff --git a/src/world/generator/object/tree/SpruceTreeObject.php b/src/world/generator/object/tree/SpruceTreeObject.php index e705764df..0f78ac2a5 100644 --- a/src/world/generator/object/tree/SpruceTreeObject.php +++ b/src/world/generator/object/tree/SpruceTreeObject.php @@ -55,7 +55,7 @@ class SpruceTreeObject extends TreeObject{ public function placeObject(Level $level, Vector3 $pos, Random $random){ if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) { - $this->findRandomLeavesSize(); + $this->findRandomLeavesSize($random); } $level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock()); $leavesRadius = 0; diff --git a/src/world/generator/object/tree/TreeObject.php b/src/world/generator/object/tree/TreeObject.php index 109702334..9a1638f44 100644 --- a/src/world/generator/object/tree/TreeObject.php +++ b/src/world/generator/object/tree/TreeObject.php @@ -47,8 +47,8 @@ class TreeObject{ $tree = new SmallTreeObject(); $tree->type = SaplingBlock::JUNGLE; break; - default: case SaplingBlock::OAK: + default: /*if($random->nextRange(0, 9) === 0){ $tree = new BigTreeObject(); }else{*/