mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
more canonical codestyle
This commit is contained in:
parent
27554d29bd
commit
2b90f6499e
30 changed files with 1388 additions and 1689 deletions
|
|
@ -17,9 +17,6 @@ return (new PhpCsFixer\Config)
|
|||
'cast_spaces' => [
|
||||
'space' => 'single'
|
||||
],
|
||||
'concat_space' => [
|
||||
'spacing' => 'one'
|
||||
],
|
||||
'elseif' => true,
|
||||
'indentation_type' => true,
|
||||
'no_closing_tag' => true,
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ class AchievementAPI{
|
|||
if(count($achs) <= 0){
|
||||
return "Player {$params[0]} unlocked 0 achievements";
|
||||
}
|
||||
$output = "Unlocked Achievements(" . count($achs) . "/" . count(self::$achievements) . "): ";
|
||||
$output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): ";
|
||||
foreach($achs as $achievement => $unlocked){
|
||||
if($unlocked && isset(self::$achievements[$achievement])){
|
||||
$info = self::$achievements[$achievement];
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ class BlockAPI{
|
|||
break;
|
||||
}
|
||||
$itemheld = $issuer->getSlot($issuer->slot);
|
||||
$output = self::getItem($itemheld->getID(), $itemheld->getMetadata()) . "";
|
||||
$output = self::getItem($itemheld->getID(), $itemheld->getMetadata())."";
|
||||
break;
|
||||
case "setblock":
|
||||
if(!($issuer instanceof Player)){
|
||||
|
|
@ -289,7 +289,7 @@ class BlockAPI{
|
|||
break;
|
||||
}else{
|
||||
$level->setBlock($pos, $block, true, false, true);
|
||||
$output .= "Placed $block in " . implode(", ", $coords) . ", w:" . $level->getName();
|
||||
$output .= "Placed $block in ".implode(", ", $coords).", w:".$level->getName();
|
||||
}
|
||||
break;
|
||||
case "give":
|
||||
|
|
@ -311,7 +311,7 @@ class BlockAPI{
|
|||
}
|
||||
|
||||
$player->addItem($item->getID(), $item->getMetadata(), $item->count);
|
||||
$output .= "Giving " . $item->count . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->username;
|
||||
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username;
|
||||
break;
|
||||
}else{
|
||||
$item = self::fromString($args[0] ?? "");
|
||||
|
|
@ -334,7 +334,7 @@ class BlockAPI{
|
|||
}
|
||||
|
||||
$issuer->addItem($item->getID(), $item->getMetadata(), $item->count);
|
||||
$output .= "Giving " . $item->count . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $issuer->username;
|
||||
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$issuer->username;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,19 +272,19 @@ class ConsoleAPI{
|
|||
}
|
||||
|
||||
public static function debug($msg){
|
||||
console("[DEBUG] " . $msg, true, true, 2);
|
||||
console("[DEBUG] ".$msg, true, true, 2);
|
||||
}
|
||||
public static function info($msg){
|
||||
console("[INFO] " . $msg);
|
||||
console("[INFO] ".$msg);
|
||||
}
|
||||
public static function notice($msg){
|
||||
console("[NOTICE] " . $msg);
|
||||
console("[NOTICE] ".$msg);
|
||||
}
|
||||
public static function warn($msg){
|
||||
console("[WARNING] " . $msg);
|
||||
console("[WARNING] ".$msg);
|
||||
}
|
||||
public static function error($msg){
|
||||
console("[ERROR] " . $msg);
|
||||
console("[ERROR] ".$msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class EntityAPI{
|
|||
$output = "";
|
||||
switch($cmd){
|
||||
case "entcnt":
|
||||
return "Total amount of entities: " . count($this->entities);
|
||||
return "Total amount of entities: ". count($this->entities);
|
||||
case "summon":
|
||||
case "spawnmob":
|
||||
if(!($issuer instanceof Player)){
|
||||
|
|
@ -81,7 +81,7 @@ class EntityAPI{
|
|||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
|
||||
}
|
||||
|
||||
return "$amount " . ($isBaby ? "Baby " : "") . "$mobName(s) spawned in $x, $y, $z.";
|
||||
return "$amount ".($isBaby ? "Baby " : "")."$mobName(s) spawned in $x, $y, $z.";
|
||||
}
|
||||
elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby]
|
||||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]);
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ class PluginAPI extends stdClass{
|
|||
if($ext2 === "phar"){
|
||||
++$pharCnt;
|
||||
$pluginInfo = []; //TODO: A PluginInfo class?
|
||||
$filePath = $this->pluginsPath() . $file;
|
||||
$p = new Phar($this->pluginsPath() . $file, 0);
|
||||
$filePath = $this->pluginsPath().$file;
|
||||
$p = new Phar($this->pluginsPath().$file, 0);
|
||||
foreach (new RecursiveIteratorIterator($p) as $file) {
|
||||
$name = $file->getFileName();
|
||||
$content = file_get_contents($file->getPathName());
|
||||
|
|
@ -149,7 +149,7 @@ class PluginAPI extends stdClass{
|
|||
break;
|
||||
}
|
||||
}
|
||||
console("[INFO] Loading PHAR plugin \"" . FORMAT_GREEN . $pluginInfo["name"] . FORMAT_RESET . "\" " . FORMAT_AQUA . $pluginInfo["version"] . FORMAT_RESET . " by " . FORMAT_AQUA . $pluginInfo["author"] . FORMAT_RESET);
|
||||
console("[INFO] Loading PHAR plugin \"".FORMAT_GREEN.$pluginInfo["name"].FORMAT_RESET."\" ".FORMAT_AQUA.$pluginInfo["version"].FORMAT_RESET." by ".FORMAT_AQUA.$pluginInfo["author"].FORMAT_RESET);
|
||||
|
||||
$aver = CURRENT_API_VERSION;
|
||||
if(!in_array((string) CURRENT_API_VERSION, $pluginInfo["api"])){
|
||||
|
|
@ -159,13 +159,13 @@ class PluginAPI extends stdClass{
|
|||
}
|
||||
|
||||
$phr = "phar://$filePath/";
|
||||
include($phr . "/src/" . $pluginInfo["classLoader"]);
|
||||
include($phr."/src/".$pluginInfo["classLoader"]);
|
||||
$class = $pluginInfo["CLClass"];
|
||||
$loader = new $class();
|
||||
$loader->loadAll($phr);
|
||||
|
||||
$pluginName = PharUtils::getNameSpaceClass($pluginInfo["mainFile"]);
|
||||
include($phr . "/src/" . $pluginInfo["mainFile"]);
|
||||
include($phr."/src/".$pluginInfo["mainFile"]);
|
||||
$plugin = new $pluginName($this->server->api, false);
|
||||
if(!($plugin instanceof Plugin)){
|
||||
console("[ERROR] Plugin \"" . $pluginInfo["name"] . "\" doesn't use the Plugin Interface");
|
||||
|
|
|
|||
1076
src/Player.php
1076
src/Player.php
File diff suppressed because it is too large
Load diff
|
|
@ -1,69 +1,18 @@
|
|||
<?php
|
||||
|
||||
class PocketMinecraftServer {
|
||||
class PocketMinecraftServer{
|
||||
|
||||
public $tCnt;
|
||||
public $ticks;
|
||||
public $extraprops;
|
||||
public $serverID;
|
||||
public $interface;
|
||||
public $database;
|
||||
public $version;
|
||||
public $invisible;
|
||||
public $tickMeasure;
|
||||
public $preparedSQL;
|
||||
public $seed;
|
||||
public $gamemode;
|
||||
public $name;
|
||||
public $maxClients;
|
||||
public $clients;
|
||||
public $eidCnt;
|
||||
public $custom;
|
||||
public $description;
|
||||
public $motd;
|
||||
public $port;
|
||||
public $saveEnabled;
|
||||
public $tCnt, $ticks;
|
||||
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
/**
|
||||
* @var ServerAPI
|
||||
*/
|
||||
public $api;
|
||||
private $serverip;
|
||||
private $evCnt;
|
||||
private $handCnt;
|
||||
private $events;
|
||||
private $eventsID;
|
||||
private $handlers;
|
||||
private $serverType;
|
||||
private $lastTick;
|
||||
private $memoryStats;
|
||||
private $async = [];
|
||||
private $asyncID = 0;
|
||||
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
|
||||
|
||||
public $doTick;
|
||||
|
||||
public $levelData;
|
||||
|
||||
public $tiles;
|
||||
|
||||
public $entities;
|
||||
|
||||
public $schedule;
|
||||
|
||||
public $scheduleCnt;
|
||||
|
||||
public $whitelist;
|
||||
|
||||
public $spawn;
|
||||
|
||||
public $difficulty;
|
||||
|
||||
public $stop;
|
||||
|
||||
public $asyncThread;
|
||||
public static $FORCE_20_TPS = false;
|
||||
public static $KEEP_CHUNKS_LOADED = true;
|
||||
public static $PACKET_READING_LIMIT = 100;
|
||||
public function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0") {
|
||||
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
|
||||
public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true, $PACKET_READING_LIMIT = 100;
|
||||
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||
$this->port = (int) $port;
|
||||
$this->doTick = true;
|
||||
$this->gamemode = (int) $gamemode;
|
||||
|
|
@ -77,7 +26,7 @@ class PocketMinecraftServer {
|
|||
|
||||
public static $SAVE_PLAYER_DATA = true;
|
||||
|
||||
private function load() {
|
||||
private function load(){
|
||||
global $dolog;
|
||||
/*if(defined("DEBUG") and DEBUG >= 0){
|
||||
@cli_set_process_title("NostalgiaCore ".MAJOR_VERSION);
|
||||
|
|
@ -120,7 +69,7 @@ class PocketMinecraftServer {
|
|||
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip);
|
||||
$this->stop = false;
|
||||
$this->ticks = 0;
|
||||
if(!defined("NO_THREADS")) {
|
||||
if(!defined("NO_THREADS")){
|
||||
$this->asyncThread = new AsyncMultipleQueue();
|
||||
}
|
||||
console("[INFO] Loading extra.properties...");
|
||||
|
|
@ -157,24 +106,24 @@ class PocketMinecraftServer {
|
|||
MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai");
|
||||
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
|
||||
NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor");
|
||||
if(self::$FORCE_20_TPS) {
|
||||
if(self::$FORCE_20_TPS){
|
||||
ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!");
|
||||
}
|
||||
if($this->extraprops->get("discord-msg")) {
|
||||
if($this->extraprops->get("discord-webhook-url") !== "none") {
|
||||
if($this->extraprops->get("discord-msg")){
|
||||
if($this->extraprops->get("discord-webhook-url") !== "none"){
|
||||
console("[INFO] Discord Logger is enabled.");
|
||||
} else {
|
||||
}else{
|
||||
console("[WARNING] Discord Logger is enabled in extra.properties,");
|
||||
console("[WARNING] but you didn't put the webhook url, so it won't work.");
|
||||
}
|
||||
} elseif($this->extraprops->get("version") == null) {
|
||||
}elseif($this->extraprops->get("version") == null){
|
||||
console("[WARNING] Your extra.properties file is corrupted!");
|
||||
console("[WARNING] To fix it - just remove it! Server will generate it again automatically.");
|
||||
}
|
||||
$dolog = $this->extraprops->get("save-console-data");
|
||||
}
|
||||
|
||||
public function onShutdown() {
|
||||
public function onShutdown(){
|
||||
console("[INFO] Saving...");
|
||||
$save = $this->saveEnabled;
|
||||
$this->saveEnabled = true;
|
||||
|
|
@ -182,7 +131,7 @@ class PocketMinecraftServer {
|
|||
$this->saveEnabled = $save;
|
||||
}
|
||||
|
||||
public function startDatabase() {
|
||||
public function startDatabase(){
|
||||
$this->preparedSQL = new stdClass();
|
||||
$this->preparedSQL->entity = new stdClass();
|
||||
$this->database = new SQLite3(":memory:");
|
||||
|
|
@ -204,16 +153,16 @@ class PocketMinecraftServer {
|
|||
$this->preparedSQL->entity->setLevel = $this->database->prepare("UPDATE entities SET level = :level WHERE EID = :eid ;");
|
||||
}
|
||||
|
||||
public function query($sql, $fetch = false) {
|
||||
public function query($sql, $fetch = false){
|
||||
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] " . $this->database->lastErrorMsg() . ". Query: " . $sql, true, true, 0);
|
||||
if($fetch === true and ($result instanceof SQLite3Result)) {
|
||||
if($fetch === true and ($result instanceof SQLite3Result)){
|
||||
$result = $result->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setType($type = "normal") {
|
||||
switch(trim(strtolower($type))) {
|
||||
public function setType($type = "normal"){
|
||||
switch(trim(strtolower($type))){
|
||||
case "normal":
|
||||
case "demo":
|
||||
$this->serverType = "MCCPP;Demo;";
|
||||
|
|
@ -224,9 +173,9 @@ class PocketMinecraftServer {
|
|||
}
|
||||
}
|
||||
|
||||
public function titleTick() {
|
||||
public function titleTick(){
|
||||
$time = microtime(true);
|
||||
if(defined("DEBUG") and DEBUG >= 0) {
|
||||
if(defined("DEBUG") and DEBUG >= 0){
|
||||
//echo "\x1b]0;NostalgiaCore " . MAJOR_VERSION . " | Online " . count($this->clients) . "/" . $this->maxClients . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "MB | U " . round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " D " . round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " kB/s | TPS " . $this->getTPS() . "\x07";
|
||||
}
|
||||
|
||||
|
|
@ -236,18 +185,18 @@ class PocketMinecraftServer {
|
|||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTPS() {
|
||||
public function getTPS(){
|
||||
$v = array_values($this->tickMeasure);
|
||||
$divval = ($v[39] - $v[0]);
|
||||
if($divval === 0) {
|
||||
if($divval === 0){
|
||||
return 0;
|
||||
}
|
||||
$tps = 40 / $divval;
|
||||
return round($tps, 4);
|
||||
}
|
||||
|
||||
public function checkTicks() {
|
||||
if($this->getTPS() < 12) {
|
||||
public function checkTicks(){
|
||||
if($this->getTPS() < 12){
|
||||
console("[WARNING] Can't keep up! Is the server overloaded?");
|
||||
}
|
||||
}
|
||||
|
|
@ -255,14 +204,14 @@ class PocketMinecraftServer {
|
|||
/**
|
||||
* @param string $reason
|
||||
*/
|
||||
public function close($reason = "server stop") {
|
||||
public function close($reason = "server stop"){
|
||||
$this->onShutdown();
|
||||
if($this->stop !== true) {
|
||||
if(is_int($reason)) {
|
||||
if($this->stop !== true){
|
||||
if(is_int($reason)){
|
||||
$reason = "signal stop";
|
||||
}
|
||||
if(($this->api instanceof ServerAPI) === true) {
|
||||
if(($this->api->chat instanceof ChatAPI) === true) {
|
||||
if(($this->api instanceof ServerAPI) === true){
|
||||
if(($this->api->chat instanceof ChatAPI) === true){
|
||||
$this->api->chat->send(false, "Stopping server...");
|
||||
self::$_tmp = new StopMessageThread($this, "[INFO] Stopping server..."); //broadcast didnt want to send message to discord for some reason
|
||||
}
|
||||
|
|
@ -270,8 +219,8 @@ class PocketMinecraftServer {
|
|||
$this->stop = true;
|
||||
$this->trigger("server.close", $reason);
|
||||
$this->interface->close();
|
||||
if(!defined("NO_THREADS")) {
|
||||
$this->asyncThread->synchronized(function ($t) {
|
||||
if(!defined("NO_THREADS")){
|
||||
$this->asyncThread->synchronized(function ($t){
|
||||
$t->stop = true;
|
||||
$t->notify();
|
||||
}, $this->asyncThread);
|
||||
|
|
@ -280,8 +229,8 @@ class PocketMinecraftServer {
|
|||
release_lock();
|
||||
}
|
||||
|
||||
public function send2Discord($msg) {
|
||||
if($this->extraprops->get("discord-msg") and $this->extraprops->get("discord-webhook-url") !== "none") {
|
||||
public function send2Discord($msg){
|
||||
if($this->extraprops->get("discord-msg") and $this->extraprops->get("discord-webhook-url") !== "none"){
|
||||
$url = $this->extraprops->get("discord-webhook-url");
|
||||
$name = $this->extraprops->get("discord-bot-name");
|
||||
$this->asyncOperation(ASYNC_CURL_POST, [
|
||||
|
|
@ -294,15 +243,15 @@ class PocketMinecraftServer {
|
|||
}
|
||||
}
|
||||
|
||||
public function asyncOperation($type, array $data, callable $callable = null) {
|
||||
if(defined("NO_THREADS")) {
|
||||
public function asyncOperation($type, array $data, callable $callable = null){
|
||||
if(defined("NO_THREADS")){
|
||||
return false;
|
||||
}
|
||||
$d = "";
|
||||
$type = (int) $type;
|
||||
switch($type) {
|
||||
switch($type){
|
||||
case ASYNC_CURL_GET:
|
||||
if(isset($data["headers"])) {
|
||||
if(isset($data["headers"])){
|
||||
$jsstr = json_encode($data["headers"]);
|
||||
}
|
||||
$d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10)) . (isset($data["headers"]) ? Utils::writeShort(strlen($jsstr)) . $jsstr : Utils::writeShort(1) . " ");
|
||||
|
|
@ -310,7 +259,7 @@ class PocketMinecraftServer {
|
|||
case ASYNC_CURL_POST:
|
||||
$d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
|
||||
$d .= Utils::writeShort(count($data["data"]));
|
||||
foreach($data["data"] as $key => $value) {
|
||||
foreach($data["data"] as $key => $value){
|
||||
$d .= Utils::writeShort(strlen($key)) . $key . Utils::writeInt(strlen($value)) . $value;
|
||||
}
|
||||
break;
|
||||
|
|
@ -323,55 +272,55 @@ class PocketMinecraftServer {
|
|||
return $ID;
|
||||
}
|
||||
|
||||
public function trigger($event, $data = "") {
|
||||
if(isset($this->events[$event])) {
|
||||
foreach($this->events[$event] as $evid => $ev) {
|
||||
if(!is_callable($ev)) {
|
||||
public function trigger($event, $data = ""){
|
||||
if(isset($this->events[$event])){
|
||||
foreach($this->events[$event] as $evid => $ev){
|
||||
if(!is_callable($ev)){
|
||||
$this->deleteEvent($evid);
|
||||
continue;
|
||||
}
|
||||
if(is_array($ev)) {
|
||||
if(is_array($ev)){
|
||||
$method = $ev[1];
|
||||
$ev[0]->$method($data, $event);
|
||||
} else {
|
||||
}else{
|
||||
$ev($data, $event);
|
||||
}
|
||||
}
|
||||
} elseif(isset(Deprecation::$events[$event])) {
|
||||
}elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false) {
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Trigger]");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteEvent($id) {
|
||||
public function deleteEvent($id){
|
||||
$id = (int) $id;
|
||||
if(isset($this->eventsID[$id])) {
|
||||
if(isset($this->eventsID[$id])){
|
||||
$ev = $this->eventsID[$id];
|
||||
$this->eventsID[$id] = null;
|
||||
unset($this->eventsID[$id]);
|
||||
$this->events[$ev][$id] = null;
|
||||
unset($this->events[$ev][$id]);
|
||||
if(count($this->events[$ev]) === 0) {
|
||||
if(count($this->events[$ev]) === 0){
|
||||
unset($this->events[$ev]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function asyncOperationChecker() {
|
||||
if(defined("NO_THREADS")) {
|
||||
public function asyncOperationChecker(){
|
||||
if(defined("NO_THREADS")){
|
||||
return false;
|
||||
}
|
||||
if(isset($this->asyncThread->output[5])) {
|
||||
if(isset($this->asyncThread->output[5])){
|
||||
$offset = 0;
|
||||
$ID = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||
$offset += 4;
|
||||
$type = Utils::readShort(substr($this->asyncThread->output, $offset, 2));
|
||||
$offset += 2;
|
||||
$data = [];
|
||||
switch($type) {
|
||||
switch($type){
|
||||
case ASYNC_CURL_GET:
|
||||
case ASYNC_CURL_POST:
|
||||
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||
|
|
@ -383,11 +332,11 @@ class PocketMinecraftServer {
|
|||
}
|
||||
|
||||
$this->asyncThread->output = substr($this->asyncThread->output, $offset);
|
||||
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])) {
|
||||
if(is_array($this->async[$ID])) {
|
||||
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){
|
||||
if(is_array($this->async[$ID])){
|
||||
$method = $this->async[$ID][1];
|
||||
$result = $this->async[$ID][0]->$method($data, $type, $ID);
|
||||
} else {
|
||||
}else{
|
||||
$result = $this->async[$ID]($data, $type, $ID);
|
||||
}
|
||||
}
|
||||
|
|
@ -401,12 +350,12 @@ class PocketMinecraftServer {
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function addHandler($event, callable $callable, $priority = 5) {
|
||||
if(!is_callable($callable)) {
|
||||
public function addHandler($event, callable $callable, $priority = 5){
|
||||
if(!is_callable($callable)){
|
||||
return false;
|
||||
} elseif(isset(Deprecation::$events[$event])) {
|
||||
}elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false) {
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Adding handle to " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . "]");
|
||||
|
|
@ -419,64 +368,64 @@ class PocketMinecraftServer {
|
|||
return $hnid;
|
||||
}
|
||||
|
||||
public function dhandle($e, $d) {
|
||||
public function dhandle($e, $d){
|
||||
return $this->handle($e, $d);
|
||||
}
|
||||
|
||||
public function handle($event, &$data) {
|
||||
public function handle($event, &$data){
|
||||
$this->preparedSQL->selectHandlers->reset();
|
||||
$this->preparedSQL->selectHandlers->clear();
|
||||
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
||||
$handlers = $this->preparedSQL->selectHandlers->execute();
|
||||
$result = null;
|
||||
if($handlers instanceof SQLite3Result) {
|
||||
if($handlers instanceof SQLite3Result){
|
||||
$call = [];
|
||||
while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false) {
|
||||
while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$call[(int) $hn["ID"]] = true;
|
||||
}
|
||||
$handlers->finalize();
|
||||
foreach($call as $hnid => $boolean) {
|
||||
if($result !== false and $result !== true) {
|
||||
foreach($call as $hnid => $boolean){
|
||||
if($result !== false and $result !== true){
|
||||
$called[$hnid] = true;
|
||||
$handler = $this->handlers[$hnid];
|
||||
if(is_array($handler)) {
|
||||
if(is_array($handler)){
|
||||
$method = $handler[1];
|
||||
$result = $handler[0]->$method($data, $event);
|
||||
} else {
|
||||
}else{
|
||||
$result = $handler($data, $event);
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif(isset(Deprecation::$events[$event])) {
|
||||
}elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false) {
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Handler]");
|
||||
}
|
||||
|
||||
if($result !== false) {
|
||||
if($result !== false){
|
||||
$this->trigger($event, $data);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function eventHandler($data, $event) {
|
||||
switch($event) {
|
||||
public function eventHandler($data, $event){
|
||||
switch($event){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function init() {
|
||||
public function init(){
|
||||
register_tick_function([$this, "tick"]);
|
||||
declare(ticks=5000); //Minimum TPS for main thread locks
|
||||
|
||||
$this->loadEvents();
|
||||
register_shutdown_function([$this, "dumpError"]);
|
||||
register_shutdown_function([$this, "close"]);
|
||||
if(function_exists("pcntl_signal")) {
|
||||
if(function_exists("pcntl_signal")){
|
||||
pcntl_signal(SIGTERM, [$this, "close"]);
|
||||
pcntl_signal(SIGINT, [$this, "close"]);
|
||||
pcntl_signal(SIGHUP, [$this, "close"]);
|
||||
|
|
@ -488,8 +437,8 @@ class PocketMinecraftServer {
|
|||
$this->process();
|
||||
}
|
||||
|
||||
public function loadEvents() {
|
||||
if(ENABLE_ANSI === true) {
|
||||
public function loadEvents(){
|
||||
if(ENABLE_ANSI === true){
|
||||
$this->schedule(30, [$this, "titleTick"], [], true);
|
||||
}
|
||||
$this->schedule(20 * 15, [$this, "checkTicks"], [], true);
|
||||
|
|
@ -497,8 +446,8 @@ class PocketMinecraftServer {
|
|||
$this->schedule(20, [$this, "asyncOperationChecker"], [], true);
|
||||
}
|
||||
|
||||
public function schedule($ticks, callable $callback, $data = [], $repeat = false, $eventName = "server.schedule") {
|
||||
if(!is_callable($callback)) {
|
||||
public function schedule($ticks, callable $callback, $data = [], $repeat = false, $eventName = "server.schedule"){
|
||||
if(!is_callable($callback)){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -511,8 +460,8 @@ class PocketMinecraftServer {
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGamemode() {
|
||||
switch($this->gamemode) {
|
||||
public function getGamemode(){
|
||||
switch($this->gamemode){
|
||||
case SURVIVAL:
|
||||
return "survival";
|
||||
case CREATIVE:
|
||||
|
|
@ -524,16 +473,17 @@ class PocketMinecraftServer {
|
|||
}
|
||||
}
|
||||
|
||||
public function process() {
|
||||
public function process()
|
||||
{
|
||||
$lastLoop = 0;
|
||||
if(self::$FORCE_20_TPS) {
|
||||
while($this->stop === false) {
|
||||
if(self::$FORCE_20_TPS){
|
||||
while($this->stop === false){
|
||||
$packetcnt = 0;
|
||||
while($packet = $this->interface->readPacket()) {
|
||||
while($packet = $this->interface->readPacket()){
|
||||
if($packet instanceof Packet) {
|
||||
$this->packetHandler($packet);
|
||||
if(++$packetcnt > self::$PACKET_READING_LIMIT) {
|
||||
ConsoleAPI::warn("Reading more than " . self::$PACKET_READING_LIMIT . " packets per tick! Forcing ticking!");
|
||||
if(++$packetcnt > self::$PACKET_READING_LIMIT){
|
||||
ConsoleAPI::warn("Reading more than ".self::$PACKET_READING_LIMIT." packets per tick! Forcing ticking!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -541,30 +491,30 @@ class PocketMinecraftServer {
|
|||
|
||||
$this->tick();
|
||||
}
|
||||
} else {
|
||||
while($this->stop === false) {
|
||||
}else{
|
||||
while($this->stop === false){
|
||||
$packetcnt = 0;
|
||||
startReadingAgain:
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet instanceof Packet) {
|
||||
if($packet instanceof Packet){
|
||||
$this->packetHandler($packet);
|
||||
$lastLoop = 0;
|
||||
if(++$packetcnt > self::$PACKET_READING_LIMIT) {
|
||||
ConsoleAPI::warn("Reading more than " . self::$PACKET_READING_LIMIT . " packets per tick! Forcing ticking!");
|
||||
} else {
|
||||
if(++$packetcnt > self::$PACKET_READING_LIMIT){
|
||||
ConsoleAPI::warn("Reading more than ".self::$PACKET_READING_LIMIT." packets per tick! Forcing ticking!");
|
||||
}else{
|
||||
goto startReadingAgain;
|
||||
}
|
||||
} elseif($this->tick() > 0) {
|
||||
} elseif($this->tick() > 0){
|
||||
$lastLoop = 0;
|
||||
} else {
|
||||
} else{
|
||||
++$lastLoop;
|
||||
if($lastLoop < 16) {
|
||||
if($lastLoop < 16){
|
||||
usleep(1);
|
||||
} elseif($lastLoop < 128) {
|
||||
} elseif($lastLoop < 128){
|
||||
usleep(100);
|
||||
} elseif($lastLoop < 256) {
|
||||
} elseif($lastLoop < 256){
|
||||
usleep(512);
|
||||
} else {
|
||||
} else{
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
|
|
@ -574,19 +524,19 @@ class PocketMinecraftServer {
|
|||
|
||||
}
|
||||
|
||||
public function packetHandler(Packet $packet) {
|
||||
public function packetHandler(Packet $packet){
|
||||
$data = &$packet;
|
||||
$CID = PocketMinecraftServer::clientID($packet->ip, $packet->port);
|
||||
if(isset($this->clients[$CID])) {
|
||||
if(isset($this->clients[$CID])){
|
||||
$this->clients[$CID]->handlePacket($packet);
|
||||
} else {
|
||||
if($this->handle("server.noauthpacket." . $packet->pid(), $packet) === false) {
|
||||
}else{
|
||||
if($this->handle("server.noauthpacket." . $packet->pid(), $packet) === false){
|
||||
return;
|
||||
}
|
||||
switch($packet->pid()) {
|
||||
switch($packet->pid()){
|
||||
case RakNetInfo::UNCONNECTED_PING:
|
||||
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
|
||||
if($this->invisible === true) {
|
||||
if($this->invisible === true){
|
||||
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
|
||||
$pk->pingID = $packet->pingID;
|
||||
$pk->serverID = $this->serverID;
|
||||
|
|
@ -596,11 +546,11 @@ class PocketMinecraftServer {
|
|||
$this->send($pk);
|
||||
break;
|
||||
}
|
||||
if(!isset($this->custom["times_" . $CID])) {
|
||||
if(!isset($this->custom["times_" . $CID])){
|
||||
$this->custom["times_" . $CID] = 0;
|
||||
}
|
||||
$ln = 15;
|
||||
if($this->description == "" or !str_ends_with($this->description, " ")) {
|
||||
if($this->description == "" or !str_ends_with($this->description, " ")){
|
||||
$this->description .= " ";
|
||||
}
|
||||
$txt = substr($this->description, $this->custom["times_" . $CID], $ln);
|
||||
|
|
@ -615,14 +565,14 @@ class PocketMinecraftServer {
|
|||
$this->custom["times_" . $CID] = ($this->custom["times_" . $CID] + 1) % strlen($this->description);
|
||||
break;
|
||||
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
|
||||
if($packet->structure !== RakNetInfo::STRUCTURE) {
|
||||
if($packet->structure !== RakNetInfo::STRUCTURE){
|
||||
console("[DEBUG] Incorrect structure #" . $packet->structure . " from " . $packet->ip . ":" . $packet->port, true, true, 2);
|
||||
$pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
|
||||
$pk->serverID = $this->serverID;
|
||||
$pk->ip = $packet->ip;
|
||||
$pk->port = $packet->port;
|
||||
$this->send($pk);
|
||||
} else {
|
||||
}else{
|
||||
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
|
||||
$pk->serverID = $this->serverID;
|
||||
$pk->mtuSize = strlen($packet->buffer);
|
||||
|
|
@ -632,7 +582,7 @@ class PocketMinecraftServer {
|
|||
}
|
||||
break;
|
||||
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
|
||||
if($this->invisible === true) {
|
||||
if($this->invisible === true){
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -648,30 +598,30 @@ class PocketMinecraftServer {
|
|||
}
|
||||
}
|
||||
|
||||
public static function clientID($ip, $port) {
|
||||
public static function clientID($ip, $port){
|
||||
return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM);
|
||||
//return $ip . ":" . $port;
|
||||
}
|
||||
|
||||
public function send(Packet $packet) {
|
||||
public function send(Packet $packet){
|
||||
return $this->interface->writePacket($packet);
|
||||
}
|
||||
|
||||
public function tick() {
|
||||
public function tick(){
|
||||
$time = microtime(true);
|
||||
if($this->lastTick <= ($time - 0.05)) {
|
||||
if($this->lastTick <= ($time - 0.05)){
|
||||
$this->tickMeasure[] = $this->lastTick = $time;
|
||||
unset($this->tickMeasure[key($this->tickMeasure)]);
|
||||
++$this->ticks;
|
||||
|
||||
foreach($this->clients as $client) {
|
||||
foreach($this->clients as $client){
|
||||
$client->handlePacketQueues();
|
||||
if($this->ticks % 40 == 0) { //2s
|
||||
if($this->ticks % 40 == 0){ //2s
|
||||
$client->sendPing();
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->api->level->levels as $l) {
|
||||
foreach($this->api->level->levels as $l){
|
||||
$l->onTick($this, $time);
|
||||
}
|
||||
$r = $this->tickerFunction($time);
|
||||
|
|
@ -680,34 +630,34 @@ class PocketMinecraftServer {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public function tickerFunction($time) {
|
||||
public function tickerFunction($time){
|
||||
//actions that repeat every x time will go here
|
||||
$this->preparedSQL->selectActions->reset();
|
||||
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$actions = $this->preparedSQL->selectActions->execute();
|
||||
|
||||
$actionCount = 0;
|
||||
if($actions instanceof SQLite3Result) {
|
||||
while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false) {
|
||||
if($actions instanceof SQLite3Result){
|
||||
while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$cid = $action["ID"];
|
||||
$this->preparedSQL->updateAction->reset();
|
||||
$this->preparedSQL->updateAction->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$this->preparedSQL->updateAction->bindValue(":id", $cid, SQLITE3_INTEGER);
|
||||
$this->preparedSQL->updateAction->execute();
|
||||
if(isset($this->schedule[$cid]) && is_array($this->schedule[$cid]) && isset($this->schedule[$cid][0]) && is_callable($this->schedule[$cid][0])) {
|
||||
if(isset($this->schedule[$cid]) && is_array($this->schedule[$cid]) && isset($this->schedule[$cid][0]) && is_callable($this->schedule[$cid][0])){
|
||||
++$actionCount;
|
||||
try {
|
||||
$return = @call_user_func($this->schedule[$cid][0] ?? function () {}, $this->schedule[$cid][1], $this->schedule[$cid][2]); //somehow args can be null
|
||||
} catch(TypeError $e) {
|
||||
$m = $e->getMessage() . "\nStack trace:\n" . $e->getTraceAsString();
|
||||
try{
|
||||
$return = @call_user_func($this->schedule[$cid][0] ?? function(){}, $this->schedule[$cid][1], $this->schedule[$cid][2]); //somehow args can be null
|
||||
}catch(TypeError $e){
|
||||
$m = $e->getMessage()."\nStack trace:\n".$e->getTraceAsString();
|
||||
ConsoleAPI::error($m);
|
||||
$return = false;
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if($action["repeat"] == 0 or $return === false) {
|
||||
if($action["repeat"] == 0 or $return === false){
|
||||
$this->query("DELETE FROM actions WHERE ID = " . $action["ID"] . ";");
|
||||
$this->schedule[$cid] = null;
|
||||
unset($this->schedule[$cid]);
|
||||
|
|
@ -718,8 +668,8 @@ class PocketMinecraftServer {
|
|||
return $actionCount;
|
||||
}
|
||||
|
||||
public function dumpError() {
|
||||
if($this->stop === true) {
|
||||
public function dumpError(){
|
||||
if($this->stop === true){
|
||||
return;
|
||||
}
|
||||
ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems
|
||||
|
|
@ -745,18 +695,18 @@ class PocketMinecraftServer {
|
|||
];
|
||||
$er["type"] = $errorConversion[$er["type"]] ?? $er["type"];
|
||||
$dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
|
||||
if(stripos($er["file"], "plugin") !== false) {
|
||||
if(stripos($er["file"], "plugin") !== false){
|
||||
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
|
||||
}
|
||||
|
||||
$dump .= "Code: \r\n";
|
||||
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
|
||||
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l) {
|
||||
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
|
||||
$dump .= "[" . ($l + 1) . "] " . @$file[$l] . "\r\n";
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
$dump .= "Backtrace: \r\n";
|
||||
foreach(getTrace() as $line) {
|
||||
foreach(getTrace() as $line){
|
||||
$dump .= "$line\r\n";
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
|
|
@ -771,21 +721,21 @@ class PocketMinecraftServer {
|
|||
global $arguments;
|
||||
$dump .= "Parameters: " . var_export($arguments, true) . "\r\n\r\n\r\n";
|
||||
$p = $this->api->getProperties();
|
||||
if($p["rcon.password"] != "") {
|
||||
if($p["rcon.password"] != ""){
|
||||
$p["rcon.password"] = "******";
|
||||
}
|
||||
$dump .= "server.properties: " . var_export($p, true) . "\r\n\r\n\r\n";
|
||||
if($this->api->plugin instanceof PluginAPI) {
|
||||
if($this->api->plugin instanceof PluginAPI){
|
||||
$plist = $this->api->plugin->getList();
|
||||
$dump .= "Loaded plugins:\r\n";
|
||||
foreach($plist as $p) {
|
||||
foreach($plist as $p){
|
||||
$dump .= $p["name"] . " " . $p["version"] . " by " . $p["author"] . "\r\n";
|
||||
}
|
||||
$dump .= "\r\n\r\n";
|
||||
}
|
||||
|
||||
$extensions = [];
|
||||
foreach(get_loaded_extensions() as $ext) {
|
||||
foreach(get_loaded_extensions() as $ext){
|
||||
$extensions[$ext] = phpversion($ext);
|
||||
}
|
||||
|
||||
|
|
@ -806,7 +756,7 @@ class PocketMinecraftServer {
|
|||
console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
|
||||
}
|
||||
|
||||
public function debugInfo($console = false) {
|
||||
public function debugInfo($console = false){
|
||||
$info = [];
|
||||
$info["tps"] = $this->getTPS();
|
||||
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2) . "MB";
|
||||
|
|
@ -820,33 +770,33 @@ class PocketMinecraftServer {
|
|||
$info["actions"] = $info["actions"]["count"];
|
||||
$info["garbage"] = gc_collect_cycles();
|
||||
$this->handle("server.debug", $info);
|
||||
if($console === true) {
|
||||
if($console === true){
|
||||
console("[INFO] TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . "), Entities: " . $info["entities"] . ", Events: " . $info["events"] . ", Handlers: " . $info["handlers"] . ", Actions: " . $info["actions"] . ", Garbage: " . $info["garbage"], true, true);
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function checkMemory() {
|
||||
public function checkMemory(){
|
||||
$info = $this->debugInfo();
|
||||
$data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"];
|
||||
$i = count($this->memoryStats) - 1;
|
||||
if($i < 0 or $this->memoryStats[$i] !== $data) {
|
||||
if($i < 0 or $this->memoryStats[$i] !== $data){
|
||||
$this->memoryStats[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function event($event, callable $func) {
|
||||
if(!is_callable($func)) {
|
||||
public function event($event, callable $func){
|
||||
if(!is_callable($func)){
|
||||
return false;
|
||||
} elseif(isset(Deprecation::$events[$event])) {
|
||||
}elseif(isset(Deprecation::$events[$event])){
|
||||
$sub = "";
|
||||
if(Deprecation::$events[$event] !== false) {
|
||||
if(Deprecation::$events[$event] !== false){
|
||||
$sub = " Substitute \"" . Deprecation::$events[$event] . "\" found.";
|
||||
}
|
||||
console("[ERROR] Event \"$event\" has been deprecated.$sub [Attach to " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . "]");
|
||||
}
|
||||
$evid = $this->evCnt++;
|
||||
if(!isset($this->events[$event])) {
|
||||
if(!isset($this->events[$event])){
|
||||
$this->events[$event] = [];
|
||||
}
|
||||
$this->events[$event][$evid] = $func;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@
|
|||
}
|
||||
}while($lang == false);
|
||||
$this->lang = new InstallerLang($lang);
|
||||
echo "[*] " . $this->lang->language_has_been_selected . "\n";
|
||||
echo "[?] " . $this->lang->skip_installer . " (y/N): ";
|
||||
echo "[*] ".$this->lang->language_has_been_selected."\n";
|
||||
echo "[?] ".$this->lang->skip_installer." (y/N): ";
|
||||
if(strtolower($this->getInput()) === "y"){
|
||||
return;
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
}
|
||||
|
||||
private function welcome(){
|
||||
echo $this->lang->welcome_to_pocketmine . "\n";
|
||||
echo $this->lang->welcome_to_pocketmine."\n";
|
||||
echo <<<LICENSE
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -50,44 +50,44 @@
|
|||
(at your option) any later version.
|
||||
|
||||
LICENSE;
|
||||
echo "\n[?] " . $this->lang->accept_license . " (y/N): ";
|
||||
echo "\n[?] ".$this->lang->accept_license." (y/N): ";
|
||||
if(strtolower($this->getInput("n")) != "y"){
|
||||
echo "[!] " . $this->lang->you_have_to_accept_the_license . "\n";
|
||||
echo "[!] ".$this->lang->you_have_to_accept_the_license."\n";
|
||||
sleep(5);
|
||||
exit(0);
|
||||
}
|
||||
echo "[*] " . $this->lang->setting_up_server_now . "\n";
|
||||
echo "[*] " . $this->lang->default_values_info . "\n";
|
||||
echo "[*] " . $this->lang->server_properties . "\n";
|
||||
echo "[*] ".$this->lang->setting_up_server_now."\n";
|
||||
echo "[*] ".$this->lang->default_values_info."\n";
|
||||
echo "[*] ".$this->lang->server_properties."\n";
|
||||
|
||||
}
|
||||
|
||||
private function generateBaseConfig(){
|
||||
$config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES);
|
||||
echo "[?] " . $this->lang->name_your_server . " (" . self::DEFAULT_NAME . "): ";
|
||||
echo "[?] ".$this->lang->name_your_server." (".self::DEFAULT_NAME."): ";
|
||||
$config->set("server-name", $this->getInput(self::DEFAULT_NAME));
|
||||
echo "[*] " . $this->lang->port_warning . "\n";
|
||||
echo "[*] ".$this->lang->port_warning."\n";
|
||||
do{
|
||||
echo "[?] " . $this->lang->server_port . " (" . self::DEFAULT_PORT . "): ";
|
||||
echo "[?] ".$this->lang->server_port." (".self::DEFAULT_PORT."): ";
|
||||
$port = (int) $this->getInput(self::DEFAULT_PORT);
|
||||
if($port <= 0 or $port > 65535){
|
||||
echo "[!] " . $this->lang->invalid_port . "\n";
|
||||
echo "[!] ".$this->lang->invalid_port."\n";
|
||||
}
|
||||
}while($port <= 0 or $port > 65535);
|
||||
$config->set("server-port", $port);
|
||||
echo "[*] " . $this->lang->ram_warning . "\n";
|
||||
echo "[?] " . $this->lang->server_ram . " (" . self::DEFAULT_MEMORY . "): ";
|
||||
$config->set("memory-limit", ((int) $this->getInput(self::DEFAULT_MEMORY)) . "M");
|
||||
echo "[*] " . $this->lang->gamemode_info . "\n";
|
||||
echo "[*] ".$this->lang->ram_warning."\n";
|
||||
echo "[?] ".$this->lang->server_ram." (".self::DEFAULT_MEMORY."): ";
|
||||
$config->set("memory-limit", ((int) $this->getInput(self::DEFAULT_MEMORY))."M");
|
||||
echo "[*] ".$this->lang->gamemode_info."\n";
|
||||
do{
|
||||
echo "[?] " . $this->lang->default_gamemode . ": (" . self::DEFAULT_GAMEMODE . "): ";
|
||||
echo "[?] ".$this->lang->default_gamemode.": (".self::DEFAULT_GAMEMODE."): ";
|
||||
$gamemode = (int) $this->getInput(self::DEFAULT_GAMEMODE);
|
||||
}while($gamemode < 0 or $gamemode > 3);
|
||||
$config->set("gamemode", $gamemode);
|
||||
echo "[?] " . $this->lang->max_players . " (" . self::DEFAULT_PLAYERS . "): ";
|
||||
echo "[?] ".$this->lang->max_players." (".self::DEFAULT_PLAYERS."): ";
|
||||
$config->set("max-players", (int) $this->getInput(self::DEFAULT_PLAYERS));
|
||||
echo "[*] " . $this->lang->spawn_protection_info . "\n";
|
||||
echo "[?] " . $this->lang->spawn_protection . " (Y/n): ";
|
||||
echo "[*] ".$this->lang->spawn_protection_info."\n";
|
||||
echo "[?] ".$this->lang->spawn_protection." (Y/n): ";
|
||||
if(strtolower($this->getInput("y")) == "n"){
|
||||
$config->set("spawn-protection", -1);
|
||||
}else{
|
||||
|
|
@ -97,21 +97,21 @@ LICENSE;
|
|||
}
|
||||
|
||||
private function generateUserFiles(){
|
||||
echo "[*] " . $this->lang->op_info . "\n";
|
||||
echo "[?] " . $this->lang->op_who . ": ";
|
||||
echo "[*] ".$this->lang->op_info."\n";
|
||||
echo "[?] ".$this->lang->op_who.": ";
|
||||
$op = strtolower($this->getInput(""));
|
||||
if($op === ""){
|
||||
echo "[!] " . $this->lang->op_warning . "\n";
|
||||
echo "[!] ".$this->lang->op_warning."\n";
|
||||
}else{
|
||||
$ops = new Config(DATA_PATH . "ops.txt", CONFIG_LIST);
|
||||
$ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST);
|
||||
$ops->set($op, true);
|
||||
$ops->save();
|
||||
}
|
||||
echo "[*] " . $this->lang->whitelist_info . "\n";
|
||||
echo "[?] " . $this->lang->whitelist_enable . " (y/N): ";
|
||||
echo "[*] ".$this->lang->whitelist_info."\n";
|
||||
echo "[?] ".$this->lang->whitelist_enable." (y/N): ";
|
||||
$config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES);
|
||||
if(strtolower($this->getInput("n")) === "y"){
|
||||
echo "[!] " . $this->lang->whitelist_warning . "\n";
|
||||
echo "[!] ".$this->lang->whitelist_warning."\n";
|
||||
$config->set("white-list", true);
|
||||
}else{
|
||||
$config->set("white-list", false);
|
||||
|
|
@ -121,42 +121,42 @@ LICENSE;
|
|||
|
||||
private function networkFunctions(){
|
||||
$config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES);
|
||||
echo "[!] " . $this->lang->query_warning1 . "\n";
|
||||
echo "[!] " . $this->lang->query_warning2 . "\n";
|
||||
echo "[?] " . $this->lang->query_disable . " (y/N): ";
|
||||
echo "[!] ".$this->lang->query_warning1."\n";
|
||||
echo "[!] ".$this->lang->query_warning2."\n";
|
||||
echo "[?] ".$this->lang->query_disable." (y/N): ";
|
||||
if(strtolower($this->getInput("n")) === "y"){
|
||||
$config->set("enable-query", false);
|
||||
}else{
|
||||
$config->set("enable-query", true);
|
||||
}
|
||||
|
||||
echo "[*] " . $this->lang->rcon_info . "\n";
|
||||
echo "[?] " . $this->lang->rcon_enable . " (y/N): ";
|
||||
echo "[*] ".$this->lang->rcon_info."\n";
|
||||
echo "[?] ".$this->lang->rcon_enable." (y/N): ";
|
||||
if(strtolower($this->getInput("n")) === "y"){
|
||||
$config->set("enable-rcon", true);
|
||||
$password = substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10);
|
||||
$config->set("rcon.password", $password);
|
||||
echo "[*] " . $this->lang->rcon_password . ": " . $password . "\n";
|
||||
echo "[*] ".$this->lang->rcon_password.": ".$password."\n";
|
||||
}else{
|
||||
$config->set("enable-rcon", false);
|
||||
}
|
||||
|
||||
$config->save();
|
||||
|
||||
echo "[*] " . $this->lang->ip_get . "\n";
|
||||
echo "[*] ".$this->lang->ip_get."\n";
|
||||
|
||||
$externalIP = Utils::getIP();
|
||||
$internalIP = gethostbyname(trim(`hostname`));
|
||||
|
||||
echo "[!] " . $this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP]) . "\n";
|
||||
echo "[!] " . $this->lang->ip_confirm;
|
||||
echo "[!] ".$this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP])."\n";
|
||||
echo "[!] ".$this->lang->ip_confirm;
|
||||
$this->getInput();
|
||||
}
|
||||
|
||||
private function endWizard(){
|
||||
echo "[*] " . $this->lang->you_have_finished . "\n";
|
||||
echo "[*] " . $this->lang->pocketmine_plugins . "\n";
|
||||
echo "[*] " . $this->lang->pocketmine_will_start . "\n\n\n";
|
||||
echo "[*] ".$this->lang->you_have_finished."\n";
|
||||
echo "[*] ".$this->lang->pocketmine_plugins."\n";
|
||||
echo "[*] ".$this->lang->pocketmine_will_start."\n\n\n";
|
||||
sleep(4);
|
||||
}
|
||||
|
||||
|
|
@ -192,11 +192,11 @@ LICENSE;
|
|||
private $lang;
|
||||
private $langfile;
|
||||
public function __construct($lang = ""){
|
||||
if(file_exists(FILE_PATH . "src/lang/Installer/" . $lang . ".ini")){
|
||||
if(file_exists(FILE_PATH."src/lang/Installer/".$lang.".ini")){
|
||||
$this->lang = $lang;
|
||||
$this->langfile = FILE_PATH . "src/lang/Installer/" . $lang . ".ini";
|
||||
$this->langfile = FILE_PATH."src/lang/Installer/".$lang.".ini";
|
||||
}else{
|
||||
$l = glob(FILE_PATH . "src/lang/Installer/" . $lang . "_*.ini");
|
||||
$l = glob(FILE_PATH."src/lang/Installer/".$lang."_*.ini");
|
||||
if(count($l) > 0){
|
||||
$files = [];
|
||||
foreach($l as $file){
|
||||
|
|
@ -207,14 +207,14 @@ LICENSE;
|
|||
$l = key($files);
|
||||
$l = substr($l, strrpos($l, "/") + 1, -4);
|
||||
$this->lang = isset(self::$languages[$l]) ? $l:$lang;
|
||||
$this->langfile = FILE_PATH . "src/lang/Installer/" . $l . ".ini";
|
||||
$this->langfile = FILE_PATH."src/lang/Installer/".$l.".ini";
|
||||
}else{
|
||||
$this->lang = "en";
|
||||
$this->langfile = FILE_PATH . "src/lang/Installer/en.ini";
|
||||
$this->langfile = FILE_PATH."src/lang/Installer/en.ini";
|
||||
}
|
||||
}
|
||||
|
||||
$this->loadLang(FILE_PATH . "src/lang/Installer/en.ini", "en");
|
||||
$this->loadLang(FILE_PATH."src/lang/Installer/en.ini", "en");
|
||||
if($this->lang !== "en"){
|
||||
$this->loadLang($this->langfile, $this->lang);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ abstract class Block extends Position{
|
|||
}
|
||||
|
||||
final public function __toString(){
|
||||
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
|
||||
return "Block ". $this->name ." (".$this->id.":".$this->meta.")";
|
||||
}
|
||||
|
||||
abstract function isBreakable(Item $item, Player $player);
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ class Item{
|
|||
}
|
||||
|
||||
public function __toString(){
|
||||
return "Item " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
|
||||
return "Item ". $this->name ." (".$this->id.":".$this->meta.")";
|
||||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class LeavesBlock extends TransparentBlock{
|
|||
}
|
||||
|
||||
public static function createIndex($x, $y, $z){
|
||||
return $x . "." . $y . "." . $z;
|
||||
return $x.".".$y.".".$z;
|
||||
}
|
||||
public static function findLog(Level $level, $x, $y, $z, array $visited, $distance){ //port from newest pocketmine
|
||||
$index = self::createIndex($x, $y, $z);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
class DummyPlugin implements Plugin {
|
||||
class DummyPlugin implements Plugin{
|
||||
|
||||
public function __construct(ServerAPI $api, $server = false) {
|
||||
public function __construct(ServerAPI $api, $server = false){
|
||||
}
|
||||
|
||||
public function init() {
|
||||
public function init(){
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
public function __destruct(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
|
||||
interface OtherPluginRequirement {
|
||||
interface OtherPluginRequirement{
|
||||
public function getRequiredPlugins();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class CraftingRecipes {
|
||||
class CraftingRecipes{
|
||||
|
||||
private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better!
|
||||
// Building
|
||||
|
|
@ -199,47 +199,47 @@ class CraftingRecipes {
|
|||
|
||||
private static $recipes = [];
|
||||
|
||||
public static function init() {
|
||||
public static function init(){
|
||||
$server = ServerAPI::request();
|
||||
$id = 1;
|
||||
foreach(CraftingRecipes::$small as $recipe) {
|
||||
foreach(CraftingRecipes::$small as $recipe){
|
||||
$recipe = CraftingRecipes::parseRecipe($recipe);
|
||||
$recipe[3] = 0; //Type
|
||||
CraftingRecipes::$recipes[$id] = $recipe;
|
||||
++$id;
|
||||
}
|
||||
foreach(CraftingRecipes::$big as $recipe) {
|
||||
foreach(CraftingRecipes::$big as $recipe){
|
||||
$recipe = CraftingRecipes::parseRecipe($recipe);
|
||||
$recipe[3] = 1;
|
||||
CraftingRecipes::$recipes[$id] = $recipe;
|
||||
++$id;
|
||||
}
|
||||
foreach(CraftingRecipes::$stone as $recipe) {
|
||||
foreach(CraftingRecipes::$stone as $recipe){
|
||||
$recipe = CraftingRecipes::parseRecipe($recipe);
|
||||
$recipe[3] = 2;
|
||||
CraftingRecipes::$recipes[$id] = $recipe;
|
||||
++$id;
|
||||
}
|
||||
|
||||
foreach(CraftingRecipes::$recipes as $id => $recipe) {
|
||||
foreach(CraftingRecipes::$recipes as $id => $recipe){
|
||||
$server->query("INSERT INTO recipes (id, type, recipe) VALUES (" . $id . ", " . $recipe[3] . ", '" . $recipe[2] . "');");
|
||||
}
|
||||
}
|
||||
|
||||
private static function parseRecipe($recipe) {
|
||||
private static function parseRecipe($recipe){
|
||||
$recipe = explode("=>", $recipe);
|
||||
$recipeItems = [];
|
||||
foreach(explode(",", $recipe[0]) as $item) {
|
||||
foreach(explode(",", $recipe[0]) as $item){
|
||||
$item = explode("x", $item);
|
||||
$id = explode(":", $item[0]);
|
||||
$meta = array_pop($id);
|
||||
$id = $id[0];
|
||||
|
||||
$it = BlockAPI::fromString($id);
|
||||
if(!isset($recipeItems[$it->getID()])) {
|
||||
if(!isset($recipeItems[$it->getID()])){
|
||||
$recipeItems[$it->getID()] = [$it->getID(), $meta === "?" ? false : intval($meta) & 0xFFFF, intval($item[1])];
|
||||
} else {
|
||||
if($it->getMetadata() !== $recipeItems[$it->getID()][1]) {
|
||||
}else{
|
||||
if($it->getMetadata() !== $recipeItems[$it->getID()][1]){
|
||||
$recipeItems[$it->getID()][1] = false;
|
||||
}
|
||||
$recipeItems[$it->getID()][2] += $it->count;
|
||||
|
|
@ -256,7 +256,7 @@ class CraftingRecipes {
|
|||
$craftItem = [$it->getID(), intval($meta) & 0xFFFF, intval($item[1])];
|
||||
|
||||
$recipeString = "";
|
||||
foreach($recipeItems as $item) {
|
||||
foreach($recipeItems as $item){
|
||||
$recipeString .= $item[0] . "x" . $item[2] . ",";
|
||||
}
|
||||
$recipeString = substr($recipeString, 0, -1) . "=>" . $craftItem[0] . "x" . $craftItem[2];
|
||||
|
|
@ -264,11 +264,11 @@ class CraftingRecipes {
|
|||
return [$recipeItems, $craftItem, $recipeString];
|
||||
}
|
||||
|
||||
public static function canCraft(array $craftItem, array $recipeItems, $type) {
|
||||
public static function canCraft(array $craftItem, array $recipeItems, $type){
|
||||
ksort($recipeItems);
|
||||
$recipeString = "";
|
||||
foreach($recipeItems as $item) {
|
||||
if($craftItem[0] === CAKE && $item[0] === BUCKET && $item[1] === 1) { //some dark magic with recipe happened in mcpe, pmmp restores it back to normal
|
||||
foreach($recipeItems as $item){
|
||||
if($craftItem[0] === CAKE && $item[0] === BUCKET && $item[1] === 1){ //some dark magic with recipe happened in mcpe, pmmp restores it back to normal
|
||||
$item[2] = 3;
|
||||
}
|
||||
$recipeString .= $item[0] . "x" . $item[2] . ",";
|
||||
|
|
@ -276,33 +276,33 @@ class CraftingRecipes {
|
|||
$recipeString = substr($recipeString, 0, -1) . "=>" . $craftItem[0] . "x" . $craftItem[2];
|
||||
$server = ServerAPI::request();
|
||||
$result = $server->query("SELECT id FROM recipes WHERE type == " . $type . " AND recipe == '" . $recipeString . "';");
|
||||
if($result instanceof SQLite3Result) {
|
||||
if($result instanceof SQLite3Result){
|
||||
$continue = true;
|
||||
while(($r = $result->fetchArray(SQLITE3_NUM)) !== false) {
|
||||
while(($r = $result->fetchArray(SQLITE3_NUM)) !== false){
|
||||
$continue = true;
|
||||
$recipe = CraftingRecipes::$recipes[$r[0]];
|
||||
foreach($recipe[0] as $item) {
|
||||
if(!isset($recipeItems[$item[0]])) {
|
||||
foreach($recipe[0] as $item){
|
||||
if(!isset($recipeItems[$item[0]])){
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
$oitem = $recipeItems[$item[0]];
|
||||
if($craftItem[0] === CAKE && $oitem[0] === BUCKET && $item[1] === 1) { //some dark magic with recipe happened in mcpe, pmmp restores it back to normal x2
|
||||
if($craftItem[0] === CAKE && $oitem[0] === BUCKET && $item[1] === 1){ //some dark magic with recipe happened in mcpe, pmmp restores it back to normal x2
|
||||
$oitem[2] = 3;
|
||||
}
|
||||
if(($oitem[1] !== $item[1] and $item[1] !== false) or $oitem[2] !== $item[2]) {
|
||||
if(($oitem[1] !== $item[1] and $item[1] !== false) or $oitem[2] !== $item[2]){
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($continue === false or $craftItem[0] !== $recipe[1][0]) {
|
||||
if($continue === false or $craftItem[0] !== $recipe[1][0]){
|
||||
$continue = false;
|
||||
continue;
|
||||
}
|
||||
$continue = $recipe;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
return $continue;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class FuelData {
|
||||
class FuelData{
|
||||
|
||||
public static $duration = [
|
||||
COAL => 80,
|
||||
|
|
@ -27,4 +27,4 @@ class FuelData {
|
|||
BUCKET => 1000,
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class SmeltingData {
|
||||
class SmeltingData{
|
||||
|
||||
public static $product = [
|
||||
COBBLESTONE => [STONE, 0],
|
||||
|
|
@ -17,4 +17,4 @@ class SmeltingData {
|
|||
RAW_CHICKEN => [COOKED_CHICKEN, 0],
|
||||
POTATO => [BAKED_POTATO, 0],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
|
||||
class RailLogic {
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
class RailLogic
|
||||
{
|
||||
public $x, $y, $z;
|
||||
public $level;
|
||||
|
||||
/**
|
||||
|
|
@ -11,7 +10,7 @@ class RailLogic {
|
|||
*/
|
||||
public $railPositions = [];
|
||||
public $isStraight;
|
||||
public function __construct(RailBaseBlock $rail) {
|
||||
public function __construct(RailBaseBlock $rail){
|
||||
$id = $rail->getID();
|
||||
$meta = $rail->getMetadata();
|
||||
$this->level = $rail->level;
|
||||
|
|
@ -22,163 +21,125 @@ class RailLogic {
|
|||
|
||||
$this->updateConnections($meta);
|
||||
}
|
||||
public function getRail($v) {
|
||||
if(($b = $this->level->getBlock($v)) instanceof RailBaseBlock) { //TODO git rid of getBlock
|
||||
public function getRail($v){
|
||||
if(($b = $this->level->getBlock($v)) instanceof RailBaseBlock){ //TODO git rid of getBlock
|
||||
return new RailLogic($b);
|
||||
} elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y + 1, $v->z)) instanceof RailBaseBlock) {
|
||||
}elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y + 1, $v->z)) instanceof RailBaseBlock){
|
||||
return new RailLogic($b);
|
||||
} elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y - 1, $v->z)) instanceof RailBaseBlock) {
|
||||
}elseif(($b = $this->level->getBlockWithoutVector($v->x, $v->y - 1, $v->z)) instanceof RailBaseBlock){
|
||||
return new RailLogic($b);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function hasRail($x, $y, $z) {
|
||||
public function hasRail($x, $y, $z){
|
||||
return RailBaseBlock::isRailBlock($this->level, $x, $y, $z) || RailBaseBlock::isRailBlock($this->level, $x, $y + 1, $z) || RailBaseBlock::isRailBlock($this->level, $x, $y - 1, $z);
|
||||
}
|
||||
|
||||
public function countPotentialConnections() {
|
||||
public function countPotentialConnections(){
|
||||
return $this->hasRail($this->x, $this->y, $this->z - 1) + $this->hasRail($this->x, $this->y, $this->z + 1) + $this->hasRail($this->x - 1, $this->y, $this->z) + $this->hasRail($this->x + 1, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function removeSoftConnections() {
|
||||
for($ind = 0; $ind < count($this->railPositions); ++$ind) {
|
||||
public function removeSoftConnections(){
|
||||
for($ind = 0; $ind < count($this->railPositions); ++$ind){
|
||||
$logic = $this->getRail($this->railPositions[$ind]);
|
||||
if($logic != null && $this->connectsTo($logic)) {
|
||||
if($logic != null && $this->connectsTo($logic)){
|
||||
$this->railPositions[$ind] = new Vector3($logic->x, $logic->y, $logic->z);
|
||||
} else {
|
||||
}else{
|
||||
unset($this->railPositions[$ind--]);
|
||||
$this->railPositions = array_values($this->railPositions); //reindexing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function connectsTo(RailLogic $logic) {
|
||||
foreach($this->railPositions as $rpos) {
|
||||
if(($rpos->x === $logic->x) && ($rpos->z === $logic->z)) {
|
||||
public function connectsTo(RailLogic $logic){
|
||||
foreach($this->railPositions as $rpos){
|
||||
if(($rpos->x === $logic->x) && ($rpos->z === $logic->z)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canConnectTo(RailLogic $rail) {
|
||||
public function canConnectTo(RailLogic $rail){
|
||||
return $this->connectsTo($rail) || !(count($this->railPositions) == 2);
|
||||
}
|
||||
|
||||
public function hasNeighborRail($x, $y, $z) {
|
||||
public function hasNeighborRail($x, $y, $z){
|
||||
$logic = $this->getRail(new Vector3($x, $y, $z));
|
||||
if($logic === null) {
|
||||
if($logic === null){
|
||||
return false;
|
||||
} else {
|
||||
}else{
|
||||
$logic->removeSoftConnections(); //i place $this here and was searching why isnt it working correctly for 2 hours
|
||||
return $logic->canConnectTo($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function place($b, $b1) {
|
||||
public function place($b, $b1){
|
||||
$hasZneg = $this->hasNeighborRail($this->x, $this->y, $this->z - 1);
|
||||
$hasZpos = $this->hasNeighborRail($this->x, $this->y, $this->z + 1);
|
||||
$hasXneg = $this->hasNeighborRail($this->x - 1, $this->y, $this->z);
|
||||
$hasXpos = $this->hasNeighborRail($this->x + 1, $this->y, $this->z);
|
||||
$state = -1;
|
||||
if(($hasZneg || $hasZpos) && !($hasXneg && $hasXpos)) {
|
||||
if(($hasZneg || $hasZpos) && !($hasXneg && $hasXpos)){
|
||||
$state = 0;
|
||||
}
|
||||
if(($hasXneg || $hasXpos) && !($hasZneg && $hasZpos)) {
|
||||
if(($hasXneg || $hasXpos) && !($hasZneg && $hasZpos)){
|
||||
$state = 1;
|
||||
}
|
||||
|
||||
if(!$this->isStraight) {
|
||||
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) {
|
||||
$state = 6;
|
||||
}
|
||||
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) {
|
||||
$state = 7;
|
||||
}
|
||||
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) {
|
||||
$state = 8;
|
||||
}
|
||||
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) {
|
||||
$state = 9;
|
||||
}
|
||||
if(!$this->isStraight){
|
||||
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) $state = 6;
|
||||
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) $state = 7;
|
||||
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) $state = 8;
|
||||
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) $state = 9;
|
||||
}
|
||||
|
||||
if($state === -1) {
|
||||
if($hasZneg || $hasZpos) {
|
||||
$state = 0;
|
||||
}
|
||||
if($hasXneg || $hasXpos) {
|
||||
$state = 1;
|
||||
}
|
||||
if($state === -1){
|
||||
if($hasZneg || $hasZpos) $state = 0;
|
||||
if($hasXneg || $hasXpos) $state = 1;
|
||||
|
||||
if(!$this->isStraight) {
|
||||
if($b) {
|
||||
if($hasZpos && $hasXpos) {
|
||||
$state = 6;
|
||||
}
|
||||
if($hasXneg && $hasZpos) {
|
||||
$state = 7;
|
||||
}
|
||||
if($hasXpos && $hasZneg) {
|
||||
$state = 9;
|
||||
}
|
||||
if($hasZneg && $hasXneg) {
|
||||
$state = 8;
|
||||
}
|
||||
} else {
|
||||
if($hasZneg && $hasXneg) {
|
||||
$state = 8;
|
||||
}
|
||||
if($hasXpos && $hasZneg) {
|
||||
$state = 9;
|
||||
}
|
||||
if($hasXneg && $hasZpos) {
|
||||
$state = 7;
|
||||
}
|
||||
if($hasZpos && $hasXpos) {
|
||||
$state = 6;
|
||||
}
|
||||
if(!$this->isStraight){
|
||||
if($b){
|
||||
if($hasZpos && $hasXpos) $state = 6;
|
||||
if($hasXneg && $hasZpos) $state = 7;
|
||||
if($hasXpos && $hasZneg) $state = 9;
|
||||
if($hasZneg && $hasXneg) $state = 8;
|
||||
}else{
|
||||
if($hasZneg && $hasXneg) $state = 8;
|
||||
if($hasXpos && $hasZneg) $state = 9;
|
||||
if($hasXneg && $hasZpos) $state = 7;
|
||||
if($hasZpos && $hasXpos) $state = 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($state === 0) {
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) {
|
||||
$state = 4;
|
||||
}
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) {
|
||||
$state = 5;
|
||||
}
|
||||
} elseif($state === 1) {
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) {
|
||||
$state = 2;
|
||||
}
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) {
|
||||
$state = 3;
|
||||
}
|
||||
} elseif($state < 0) {
|
||||
$state = 0;
|
||||
}
|
||||
if($state === 0){
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4;
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) $state = 5;
|
||||
}elseif($state === 1){
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) $state = 2;
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) $state = 3;
|
||||
}elseif($state < 0) $state = 0;
|
||||
|
||||
$this->updateConnections($state);
|
||||
$meta = $state;
|
||||
if($this->isStraight) {
|
||||
if($this->isStraight){
|
||||
$meta = $this->level->level->getBlockDamage($this->x, $this->x, $this->z) & 8 | $state;
|
||||
}
|
||||
|
||||
if($b1 || $this->level->level->getBlockDamage($this->x, $this->y, $this->z)) {
|
||||
if($b1 || $this->level->level->getBlockDamage($this->x, $this->y, $this->z)){
|
||||
//this.logicWorld.setBlockMetadataWithNotify(this.railX, this.railY, this.railZ, var8, 3);
|
||||
$bl = $this->level->getBlockWithoutVector($this->x, $this->y, $this->z);
|
||||
$bl->setMetadata($meta);
|
||||
$this->level->setBlock(new Vector3($this->x, $this->y, $this->z), $bl, true, false, true);
|
||||
foreach($this->railPositions as $rpos) {
|
||||
foreach($this->railPositions as $rpos){
|
||||
$logic = $this->getRail($rpos);
|
||||
if($logic !== null) {
|
||||
if($logic !== null){
|
||||
$logic->removeSoftConnections();
|
||||
if($logic->canConnectTo($this)) {
|
||||
if($logic->canConnectTo($this)){
|
||||
$logic->connectTo($this);
|
||||
}
|
||||
|
||||
|
|
@ -189,16 +150,14 @@ class RailLogic {
|
|||
|
||||
}
|
||||
|
||||
public function hasConnection($x, $y, $z) {
|
||||
foreach($this->railPositions as $rpos) {
|
||||
if($rpos->x === $x && $rpos->z === $z) {
|
||||
return true;
|
||||
}
|
||||
public function hasConnection($x, $y, $z){
|
||||
foreach($this->railPositions as $rpos){
|
||||
if($rpos->x === $x && $rpos->z === $z) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function connectTo(RailLogic $logic) {
|
||||
public function connectTo(RailLogic $logic){
|
||||
$this->railPositions[] = new Vector3($logic->x, $logic->y, $logic->z);
|
||||
|
||||
$hasZneg = $this->hasConnection($this->x, $this->y, $this->z - 1);
|
||||
|
|
@ -207,49 +166,27 @@ class RailLogic {
|
|||
$hasXpos = $this->hasConnection($this->x + 1, $this->y, $this->z);
|
||||
$state = -1;
|
||||
|
||||
if($hasZneg || $hasZpos) {
|
||||
$state = 0;
|
||||
}
|
||||
if($hasXneg || $hasXpos) {
|
||||
$state = 1;
|
||||
if($hasZneg || $hasZpos) $state = 0;
|
||||
if($hasXneg || $hasXpos) $state = 1;
|
||||
|
||||
if(!$this->isStraight){
|
||||
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) $state = 6;
|
||||
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) $state = 7;
|
||||
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) $state = 8;
|
||||
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) $state = 9;
|
||||
}
|
||||
|
||||
if(!$this->isStraight) {
|
||||
if($hasZpos && $hasXpos && !($hasZneg && $hasXneg)) {
|
||||
$state = 6;
|
||||
}
|
||||
if($hasZpos && $hasXneg && !($hasZneg && $hasXpos)) {
|
||||
$state = 7;
|
||||
}
|
||||
if($hasZneg && $hasXneg && !($hasZpos && $hasXpos)) {
|
||||
$state = 8;
|
||||
}
|
||||
if($hasZneg && $hasXpos && !($hasZpos && $hasXneg)) {
|
||||
$state = 9;
|
||||
}
|
||||
}
|
||||
|
||||
if($state == 0) {
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) {
|
||||
$state = 4;
|
||||
}
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) {
|
||||
$state = 5;
|
||||
}
|
||||
} elseif($state == 1) {
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) {
|
||||
$state = 2;
|
||||
}
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) {
|
||||
$state = 3;
|
||||
}
|
||||
} elseif($state < 0) {
|
||||
$state = 0;
|
||||
}
|
||||
if($state == 0){
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z - 1)) $state = 4;
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x, $this->y + 1, $this->z + 1)) $state = 5;
|
||||
}elseif($state == 1){
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x + 1, $this->y + 1, $this->z)) $state = 2;
|
||||
if(RailBaseBlock::isRailBlock($this->level, $this->x - 1, $this->y + 1, $this->z)) $state = 3;
|
||||
}elseif($state < 0) $state = 0;
|
||||
|
||||
$meta = $state;
|
||||
|
||||
if($this->isStraight) {
|
||||
if($this->isStraight){
|
||||
$meta = $this->level->level->getBlockDamage($this->x, $this->x, $this->z) & 8 | $state;
|
||||
}
|
||||
|
||||
|
|
@ -259,11 +196,11 @@ class RailLogic {
|
|||
$this->level->fastSetBlockUpdateMeta($this->x, $this->y, $this->z, $meta, true);
|
||||
}
|
||||
|
||||
public function updateConnections($meta) {
|
||||
public function updateConnections($meta){
|
||||
|
||||
$this->railPositions = [];
|
||||
|
||||
switch($meta) {
|
||||
switch($meta){
|
||||
case 0:
|
||||
$this->railPositions[] = new Vector3($this->x, $this->y, $this->z - 1);
|
||||
$this->railPositions[] = new Vector3($this->x, $this->y, $this->z + 1);
|
||||
|
|
@ -307,3 +244,4 @@ class RailLogic {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ class Utils{
|
|||
$arr = json_decode($json);
|
||||
$rarr = [];
|
||||
foreach ($arr as $key => $value){
|
||||
$rarr[] = $key . ": " . $value;
|
||||
$rarr[] = $key.": ".$value;
|
||||
}
|
||||
return $rarr;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,33 +1,33 @@
|
|||
<?php
|
||||
|
||||
class LevelImport {
|
||||
class LevelImport{
|
||||
|
||||
private $path;
|
||||
|
||||
public function __construct($path) {
|
||||
public function __construct($path){
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function import() {
|
||||
if(file_exists($this->path . "tileEntities.dat")) { //OldPM
|
||||
public function import(){
|
||||
if(file_exists($this->path . "tileEntities.dat")){ //OldPM
|
||||
$level = unserialize(file_get_contents($this->path . "level.dat"));
|
||||
console("[INFO] Importing OldPM level \"" . $level["LevelName"] . "\" to PMF format");
|
||||
$entities = new Config($this->path . "entities.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "entities.dat")));
|
||||
$entities->save();
|
||||
$tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "tileEntities.dat")));
|
||||
$tiles->save();
|
||||
} elseif(file_exists($this->path . "chunks.dat") and file_exists($this->path . "level.dat")) { //Pocket
|
||||
}elseif(file_exists($this->path . "chunks.dat") and file_exists($this->path . "level.dat")){ //Pocket
|
||||
$nbt = new NBT();
|
||||
$nbt->load(substr(file_get_contents($this->path . "level.dat"), 8));
|
||||
$level = array_shift($nbt->tree);
|
||||
if($level["LevelName"] == "") {
|
||||
if($level["LevelName"] == ""){
|
||||
$level["LevelName"] = "world" . time();
|
||||
}
|
||||
console("[INFO] Importing Pocket level \"" . $level["LevelName"] . "\" to PMF format");
|
||||
unset($level["Player"]);
|
||||
$nbt->load(substr(file_get_contents($this->path . "entities.dat"), 12));
|
||||
$entities = array_shift($nbt->tree);
|
||||
if(!isset($entities["TileEntities"])) {
|
||||
if(!isset($entities["TileEntities"])){
|
||||
$entities["TileEntities"] = [];
|
||||
}
|
||||
$tiles = $entities["TileEntities"];
|
||||
|
|
@ -36,7 +36,7 @@ class LevelImport {
|
|||
$entities->save();
|
||||
$tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, $tiles);
|
||||
$tiles->save();
|
||||
} else {
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -54,8 +54,8 @@ class LevelImport {
|
|||
$chunks = new PocketChunkParser();
|
||||
$chunks->loadFile($this->path . "chunks.dat");
|
||||
$chunks->loadMap();
|
||||
for($Z = 0; $Z < 16; ++$Z) {
|
||||
for($X = 0; $X < 16; ++$X) {
|
||||
for($Z = 0; $Z < 16; ++$Z){
|
||||
for($X = 0; $X < 16; ++$X){
|
||||
$chunk = [
|
||||
0 => "",
|
||||
1 => "",
|
||||
|
|
@ -66,18 +66,18 @@ class LevelImport {
|
|||
6 => "",
|
||||
7 => ""
|
||||
];
|
||||
for($z = 0; $z < 16; ++$z) {
|
||||
for($x = 0; $x < 16; ++$x) {
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$block = $chunks->getChunkColumn($X, $Z, $x, $z, 0);
|
||||
$meta = $chunks->getChunkColumn($X, $Z, $x, $z, 1);
|
||||
for($Y = 0; $Y < 8; ++$Y) {
|
||||
for($Y = 0; $Y < 8; ++$Y){
|
||||
$chunk[$Y] .= substr($block, $Y << 4, 16);
|
||||
$chunk[$Y] .= substr($meta, $Y << 3, 8);
|
||||
$chunk[$Y] .= "\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($chunk as $Y => $data) {
|
||||
foreach($chunk as $Y => $data){
|
||||
$pmf->setMiniChunk($X, $Z, $Y, $data);
|
||||
}
|
||||
$pmf->saveChunk($X, $Z);
|
||||
|
|
@ -86,29 +86,15 @@ class LevelImport {
|
|||
}
|
||||
$chunks->map = null;
|
||||
$chunks = null;
|
||||
if(file_exists($this->path . "level.dat")) {
|
||||
@unlink($this->path . "level.dat");
|
||||
}
|
||||
if(file_exists($this->path . "level.dat_old")) {
|
||||
@unlink($this->path . "level.dat_old");
|
||||
}
|
||||
if(file_exists($this->path . "player.dat")) {
|
||||
@unlink($this->path . "player.dat");
|
||||
}
|
||||
if(file_exists($this->path . "entities.dat")) {
|
||||
@unlink($this->path . "entities.dat");
|
||||
}
|
||||
if(file_exists($this->path . "chunks.dat")) {
|
||||
@unlink($this->path . "chunks.dat");
|
||||
}
|
||||
if(file_exists($this->path . "chunks.dat.gz")) {
|
||||
@unlink($this->path . "chunks.dat.gz");
|
||||
}
|
||||
if(file_exists($this->path . "tiles.dat")) {
|
||||
@unlink($this->path . "tiles.dat");
|
||||
}
|
||||
if(file_exists($this->path . "level.dat")) @unlink($this->path . "level.dat");
|
||||
if(file_exists($this->path . "level.dat_old")) @unlink($this->path . "level.dat_old");
|
||||
if(file_exists($this->path . "player.dat")) @unlink($this->path . "player.dat");
|
||||
if(file_exists($this->path . "entities.dat")) @unlink($this->path . "entities.dat");
|
||||
if(file_exists($this->path . "chunks.dat")) @unlink($this->path . "chunks.dat");
|
||||
if(file_exists($this->path . "chunks.dat.gz")) @unlink($this->path . "chunks.dat.gz");
|
||||
if(file_exists($this->path . "tiles.dat")) @unlink($this->path . "tiles.dat");
|
||||
unset($chunks, $level, $entities, $tiles, $nbt);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
|
||||
class MobSpawner {
|
||||
public static $spawnAnimals = false;
|
||||
public static $spawnMobs = false;
|
||||
public static $maxMobsNearPlayerAtOnce = 10;
|
||||
class MobSpawner{
|
||||
public static $spawnAnimals = false, $spawnMobs = false, $maxMobsNearPlayerAtOnce = 10;
|
||||
private $server;
|
||||
public $level;
|
||||
public $totalMobsPerPlayer;
|
||||
|
|
@ -11,30 +9,30 @@ class MobSpawner {
|
|||
public $entityAffectedPlayers = [];
|
||||
public static $MOB_LIMIT = 50;
|
||||
|
||||
public function __construct(Level $level) {
|
||||
public function __construct(Level $level){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function countEntities() {
|
||||
public function countEntities(){
|
||||
return $this->level->totalMobsAmount;
|
||||
}
|
||||
|
||||
public function checkDespawn(Living $living) {
|
||||
if(!isset($this->entityAffectedPlayers[$living->eid])) {
|
||||
public function checkDespawn(Living $living){
|
||||
if(!isset($this->entityAffectedPlayers[$living->eid])){
|
||||
return false;
|
||||
}
|
||||
|
||||
$playerID = $this->entityAffectedPlayers[$living->eid];
|
||||
$player = $this->level->entityList[$playerID] ?? false;
|
||||
if($player === false) {
|
||||
if($player === false){
|
||||
//TODO try retargetting other player?
|
||||
return true;
|
||||
} else {
|
||||
}else{
|
||||
$diffX = $living->x - $player->x;
|
||||
$diffZ = $living->z - $player->z;
|
||||
$dist = $diffX * $diffX + $diffZ * $diffZ;
|
||||
if($dist <= 512) {
|
||||
if($dist <= 512){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -43,35 +41,33 @@ class MobSpawner {
|
|||
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
if($this->countEntities() > self::$MOB_LIMIT || count($this->level->players) <= 0) {
|
||||
public function handle(){
|
||||
if($this->countEntities() > self::$MOB_LIMIT || count($this->level->players) <= 0){
|
||||
return false; //not spawning
|
||||
}
|
||||
$svd = $this->totalMobsPerPlayer;
|
||||
$this->totalMobsPerPlayer = min(ceil(self::$MOB_LIMIT / count($this->level->players)), self::$maxMobsNearPlayerAtOnce);
|
||||
if($svd != $this->totalMobsPerPlayer) {
|
||||
ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}.");
|
||||
}
|
||||
if($svd != $this->totalMobsPerPlayer) ConsoleAPI::debug("Changed total mobs per player from $svd to {$this->totalMobsPerPlayer}.");
|
||||
|
||||
return $this->spawnMobs();
|
||||
}
|
||||
|
||||
public function spawnMobs() {
|
||||
public function spawnMobs(){
|
||||
$phase = $this->server->api->time->getPhase($this->level);
|
||||
if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")) { //Animal
|
||||
if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")){ //Animal
|
||||
$type = mt_rand(10, 13);
|
||||
$baby = false;
|
||||
$grassOnly = true;
|
||||
} elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset") && $this->server->difficulty > 0) { //Monster, true night
|
||||
}elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset") && $this->server->difficulty > 0){ //Monster, true night
|
||||
$type = mt_rand(32, 35);
|
||||
$grassOnly = false;
|
||||
$baby = 2;
|
||||
} else {
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($this->level->players as $player) {
|
||||
if(isset($this->playerAffectedEIDS[$player->entity->eid]) && count($this->playerAffectedEIDS[$player->entity->eid]) > $this->totalMobsPerPlayer) {
|
||||
foreach($this->level->players as $player){
|
||||
if(isset($this->playerAffectedEIDS[$player->entity->eid]) && count($this->playerAffectedEIDS[$player->entity->eid]) > $this->totalMobsPerPlayer){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -80,36 +76,34 @@ class MobSpawner {
|
|||
$diffX = $x - $player->entity->x;
|
||||
$diffZ = $z - $player->entity->z;
|
||||
$dist = $diffX * $diffX + $diffZ * $diffZ;
|
||||
if($dist < 768) {
|
||||
if($dist < 768){
|
||||
continue;
|
||||
}
|
||||
|
||||
$cnt = mt_rand(1, 3);
|
||||
|
||||
for($i = 0; $i < $cnt; ++$i) {
|
||||
for($i = 0; $i < $cnt; ++$i){
|
||||
|
||||
$xMob = $x + mt_rand(-3, 3);
|
||||
$zMob = $z + mt_rand(-3, 3);
|
||||
|
||||
$y = $this->getSafeY($xMob, $zMob, $grassOnly, $type >= 32 && $type <= 36 && $type != 35);
|
||||
if(!$y || $y < 0) {
|
||||
if(!$y || $y < 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = $this->genPosData($xMob, $y + 0.5, $zMob);
|
||||
if($baby != 2) {
|
||||
$data["IsBaby"] = $baby;
|
||||
}
|
||||
if($baby != 2) $data["IsBaby"] = $baby;
|
||||
|
||||
$e = $this->server->api->entity->add($this->level, 2, $type, $data);
|
||||
|
||||
if($e instanceof Entity) {
|
||||
if($e instanceof Entity){
|
||||
$this->server->api->entity->spawnToAll($e);
|
||||
ConsoleAPI::debug("$type spawned at $xMob, $y, $zMob");
|
||||
}
|
||||
if(!isset($this->playerAffectedEIDS[$player->entity->eid])) {
|
||||
if(!isset($this->playerAffectedEIDS[$player->entity->eid])){
|
||||
$this->playerAffectedEIDS[$player->entity->eid] = [$e->eid => true];
|
||||
} else {
|
||||
}else{
|
||||
$this->playerAffectedEIDS[$player->entity->eid][$e->eid] = true;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +115,7 @@ class MobSpawner {
|
|||
return true;
|
||||
}
|
||||
|
||||
private function genPosData($x, $y, $z) {
|
||||
private function genPosData($x, $y, $z){
|
||||
return [
|
||||
"x" => $x + 0.5,
|
||||
"y" => $y,
|
||||
|
|
@ -129,9 +123,9 @@ class MobSpawner {
|
|||
];
|
||||
}
|
||||
|
||||
protected function getSafeY($x, $z, $grassOnly = false, $highMob = false) { //first safe block //TODO check boundingbox
|
||||
protected function getSafeY($x, $z, $grassOnly = false, $highMob = false){ //first safe block //TODO check boundingbox
|
||||
$allowed = [];
|
||||
for($y = 0; $y < 128; ++$y) {
|
||||
for($y = 0; $y < 128; ++$y){
|
||||
$b = $this->level->level->getBlockID($x, $y, $z);
|
||||
$b2 = $this->level->level->getBlockID($x, $y + 1, $z);
|
||||
$b1 = $this->level->level->getBlockID($x, $y - 1, $z);
|
||||
|
|
@ -139,7 +133,7 @@ class MobSpawner {
|
|||
!StaticBlock::getIsSolid($b) && !StaticBlock::getIsLiquid($b) &&
|
||||
(StaticBlock::getIsSolid($b1) && (!$grassOnly || $b1 === GRASS) &&
|
||||
(!$highMob || !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2)))
|
||||
) {
|
||||
){
|
||||
$allowed[] = $y;
|
||||
}
|
||||
}
|
||||
|
|
@ -147,3 +141,4 @@ class MobSpawner {
|
|||
return empty($allowed) ? -1 : $allowed[mt_rand(0, count($allowed) - 1)];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class MovingObjectPosition {
|
||||
class MovingObjectPosition{
|
||||
|
||||
/** 0 = block, 1 = entity, 2 = none*/
|
||||
public $typeOfHit = 2;
|
||||
|
|
@ -21,11 +21,11 @@ class MovingObjectPosition {
|
|||
/** @var Entity */
|
||||
public $entityHit = null;
|
||||
|
||||
protected function __construct() {
|
||||
protected function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
public function __toString(){
|
||||
return "MovingObjectPosition: {blockXYZ: {$this->blockX} {$this->blockY} {$this->blockZ}, side: {$this->sideHit} hitVec: {$this->hitVector} entityHit: {$this->entityHit}}";
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ class MovingObjectPosition {
|
|||
*
|
||||
* @return MovingObjectPosition
|
||||
*/
|
||||
public static function fromBlock($x, $y, $z, $side, Vector3 $hitVector) {
|
||||
public static function fromBlock($x, $y, $z, $side, Vector3 $hitVector){
|
||||
$ob = new MovingObjectPosition;
|
||||
$ob->typeOfHit = 0;
|
||||
$ob->blockX = $x;
|
||||
|
|
@ -52,11 +52,11 @@ class MovingObjectPosition {
|
|||
*
|
||||
* @return MovingObjectPosition
|
||||
*/
|
||||
public static function fromEntity(Entity $entity) {
|
||||
public static function fromEntity(Entity $entity){
|
||||
$ob = new MovingObjectPosition;
|
||||
$ob->typeOfHit = 1;
|
||||
$ob->entityHit = $entity;
|
||||
$ob->hitVector = new Vector3($entity->x, $entity->y, $entity->z);
|
||||
return $ob;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +1,24 @@
|
|||
<?php
|
||||
|
||||
class PocketChunkParser {
|
||||
class PocketChunkParser{
|
||||
|
||||
public $sectorLength = 4096;
|
||||
public $chunkLength = 86016; //16 * 16 * 16
|
||||
public $map; //21 * $sectorLength
|
||||
private $location;
|
||||
private $raw = b"";
|
||||
private $file;
|
||||
var $sectorLength = 4096;
|
||||
var $chunkLength = 86016; //16 * 16 * 16
|
||||
var $map; //21 * $sectorLength
|
||||
private $location, $raw = b"", $file;
|
||||
|
||||
public function loadFile($file) {
|
||||
if(file_exists($file . ".gz")) {
|
||||
public function loadFile($file){
|
||||
if(file_exists($file . ".gz")){
|
||||
$this->raw = gzinflate(file_get_contents($file . ".gz"));
|
||||
$r = @gzinflate($this->raw);
|
||||
if($r !== false and $r != "") {
|
||||
if($r !== false and $r != ""){
|
||||
$this->raw = $r;
|
||||
}
|
||||
@unlink($file . ".gz");
|
||||
file_put_contents($file, $this->raw);
|
||||
} elseif(!file_exists($file)) {
|
||||
}elseif(!file_exists($file)){
|
||||
return false;
|
||||
} else {
|
||||
}else{
|
||||
$this->raw = file_get_contents($file);
|
||||
}
|
||||
$this->file = $file;
|
||||
|
|
@ -28,32 +26,32 @@ class PocketChunkParser {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function loadRaw($raw, $file) {
|
||||
public function loadRaw($raw, $file){
|
||||
$this->file = $file;
|
||||
$this->raw = $raw;
|
||||
$this->chunkLength = $this->sectorLength * ord($this->raw[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getChunk($X, $Z) {
|
||||
public function getChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
return substr($this->raw, $this->getOffset($X, $Z), $this->chunkLength);
|
||||
}
|
||||
|
||||
private function getOffset($X, $Z) {
|
||||
private function getOffset($X, $Z){
|
||||
return $this->location[$X + ($Z << 5)];
|
||||
}
|
||||
|
||||
public function loadMap() {
|
||||
if($this->raw == "") {
|
||||
public function loadMap(){
|
||||
if($this->raw == ""){
|
||||
return false;
|
||||
}
|
||||
$this->loadLocationTable();
|
||||
console("[DEBUG] Loading chunks...", true, true, 2);
|
||||
for($x = 0; $x < 16; ++$x) {
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->map[$x] = [];
|
||||
for($z = 0; $z < 16; ++$z) {
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$this->map[$x][$z] = $this->parseChunk($x, $z);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,13 +59,13 @@ class PocketChunkParser {
|
|||
console("[DEBUG] Chunks loaded!", true, true, 2);
|
||||
}
|
||||
|
||||
private function loadLocationTable() {
|
||||
private function loadLocationTable(){
|
||||
$this->location = [];
|
||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||
for($offset = 0; $offset < 0x1000; $offset += 4) {
|
||||
for($offset = 0; $offset < 0x1000; $offset += 4){
|
||||
$data = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||
$sectors = $data & 0xff;
|
||||
if($sectors === 0) {
|
||||
if($sectors === 0){
|
||||
continue;
|
||||
}
|
||||
$sectorLocation = $data >> 8;
|
||||
|
|
@ -75,7 +73,7 @@ class PocketChunkParser {
|
|||
}
|
||||
}
|
||||
|
||||
public function parseChunk($X, $Z) {
|
||||
public function parseChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
$offset = $this->getOffset($X, $Z);
|
||||
|
|
@ -87,9 +85,9 @@ class PocketChunkParser {
|
|||
2 => [], //SkyLight
|
||||
3 => [], //BlockLight
|
||||
];
|
||||
foreach($chunk as $section => &$data) {
|
||||
foreach($chunk as $section => &$data){
|
||||
$l = $section === 0 ? 128 : 64;
|
||||
for($i = 0; $i < 256; ++$i) {
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$data[$i] = substr($this->raw, $offset, $l);
|
||||
$offset += $l;
|
||||
}
|
||||
|
|
@ -97,13 +95,13 @@ class PocketChunkParser {
|
|||
return $chunk;
|
||||
}
|
||||
|
||||
public function saveMap($final = false) {
|
||||
public function saveMap($final = false){
|
||||
console("[DEBUG] Saving chunks...", true, true, 2);
|
||||
|
||||
$fp = fopen($this->file, "r+b");
|
||||
flock($fp, LOCK_EX);
|
||||
foreach($this->map as $x => $d) {
|
||||
foreach($d as $z => $chunk) {
|
||||
foreach($this->map as $x => $d){
|
||||
foreach($d as $z => $chunk){
|
||||
fseek($fp, $this->getOffset($x, $z));
|
||||
fwrite($fp, $this->writeChunk($x, $z), $this->chunkLength);
|
||||
}
|
||||
|
|
@ -114,41 +112,41 @@ class PocketChunkParser {
|
|||
file_put_contents($this->file . ".gz", gzdeflate(gzdeflate(file_get_contents($this->file), 9), 9)); //Double compression for flat maps
|
||||
$compressed = filesize($this->file . ".gz");
|
||||
console("[DEBUG] Saved chunks.dat.gz with " . round(($compressed / $original) * 100, 2) . "% (" . round($compressed / 1024, 2) . "KB) of the original size", true, true, 2);
|
||||
if($final === true) {
|
||||
if($final === true){
|
||||
@unlink($this->file);
|
||||
}
|
||||
}
|
||||
|
||||
public function writeChunk($X, $Z) {
|
||||
public function writeChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
if(!isset($this->map[$X][$Z])) {
|
||||
if(!isset($this->map[$X][$Z])){
|
||||
return false;
|
||||
}
|
||||
$chunk = "";
|
||||
foreach($this->map[$X][$Z] as $section => $data) {
|
||||
for($i = 0; $i < 256; ++$i) {
|
||||
foreach($this->map[$X][$Z] as $section => $data){
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$chunk .= $data[$i];
|
||||
}
|
||||
}
|
||||
return Utils::writeLInt(strlen($chunk)) . $chunk;
|
||||
}
|
||||
|
||||
public function getFloor($x, $z) {
|
||||
public function getFloor($x, $z){
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$aX = $x - ($X << 4);
|
||||
$aZ = $z - ($Z << 4);
|
||||
$index = $aZ + ($aX << 4);
|
||||
for($y = 127; $y <= 0; --$y) {
|
||||
if($this->map[$X][$Z][0][$index][$y] !== "\x00") {
|
||||
for($y = 127; $y <= 0; --$y){
|
||||
if($this->map[$X][$Z][0][$index][$y] !== "\x00"){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $y;
|
||||
}
|
||||
|
||||
public function getBlock($x, $y, $z) {
|
||||
public function getBlock($x, $y, $z){
|
||||
$x = (int) $x;
|
||||
$y = (int) $y;
|
||||
$z = (int) $z;
|
||||
|
|
@ -159,20 +157,20 @@ class PocketChunkParser {
|
|||
$index = $aZ + ($aX << 4);
|
||||
$block = ord($this->map[$X][$Z][0][$index][$y]);
|
||||
$meta = ord($this->map[$X][$Z][1][$index][$y >> 1]);
|
||||
if(($y & 1) === 0) {
|
||||
if(($y & 1) === 0){
|
||||
$meta = $meta & 0x0F;
|
||||
} else {
|
||||
}else{
|
||||
$meta = $meta >> 4;
|
||||
}
|
||||
return [$block, $meta];
|
||||
}
|
||||
|
||||
public function getChunkColumn($X, $Z, $x, $z, $type = 0) {
|
||||
public function getChunkColumn($X, $Z, $x, $z, $type = 0){
|
||||
$index = $z + ($x << 4);
|
||||
return $this->map[$X][$Z][$type][$index];
|
||||
}
|
||||
|
||||
public function setBlock($x, $y, $z, $block, $meta = 0) {
|
||||
public function setBlock($x, $y, $z, $block, $meta = 0){
|
||||
$x = (int) $x;
|
||||
$y = (int) $y;
|
||||
$z = (int) $z;
|
||||
|
|
@ -183,12 +181,12 @@ class PocketChunkParser {
|
|||
$index = $aZ + ($aX << 4);
|
||||
$this->map[$X][$Z][0][$index][$y] = chr($block);
|
||||
$old_meta = ord($this->map[$X][$Z][1][$index][$y >> 1]);
|
||||
if(($y & 1) === 0) {
|
||||
if(($y & 1) === 0){
|
||||
$meta = ($old_meta & 0xF0) | ($meta & 0x0F);
|
||||
} else {
|
||||
}else{
|
||||
$meta = (($meta << 4) & 0xF0) | ($old_meta & 0x0F);
|
||||
}
|
||||
$this->map[$X][$Z][1][$index][$y >> 1] = chr($meta);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
class Position extends Vector3 {
|
||||
class Position extends Vector3{
|
||||
|
||||
public $level;
|
||||
|
||||
public function __construct($x = 0, $y = 0, $z = 0, Level $level = null) {
|
||||
if($x instanceof Vector3) {
|
||||
public function __construct($x = 0, $y = 0, $z = 0, Level $level = null){
|
||||
if($x instanceof Vector3){
|
||||
parent::__construct($x->x, $x->y, $x->z);
|
||||
} else {
|
||||
}else{
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
|
|
@ -15,25 +15,25 @@ class Position extends Vector3 {
|
|||
|
||||
$this->level = $level;
|
||||
}
|
||||
public function setXYZLevel($x, $y, $z, Level $level) {
|
||||
public function setXYZLevel($x, $y, $z, Level $level){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
$this->level = $level;
|
||||
}
|
||||
public function getSide($side, $step = 1) {
|
||||
public function getSide($side, $step = 1){
|
||||
return new Position(parent::getSide($side, $step), 0, 0, $this->level);
|
||||
}
|
||||
|
||||
public function distance($x = 0, $y = 0, $z = 0) {
|
||||
if(($x instanceof Position) and $x->level !== $this->level) {
|
||||
public function distance($x = 0, $y = 0, $z = 0){
|
||||
if(($x instanceof Position) and $x->level !== $this->level){
|
||||
return PHP_INT_MAX;
|
||||
}
|
||||
|
||||
return parent::distance($x, $y, $z);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
public function __toString(){
|
||||
return "Position(level=" . $this->level->getName() . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Tile extends Position {
|
||||
class Tile extends Position{
|
||||
|
||||
public $name;
|
||||
public $normal;
|
||||
|
|
@ -15,18 +15,16 @@ class Tile extends Position {
|
|||
public $closed;
|
||||
private $server;
|
||||
|
||||
public $scheduledUpdate;
|
||||
public $scheduledUpdate, $lastUpdate;
|
||||
|
||||
public $lastUpdate;
|
||||
|
||||
public function __construct(Level $level, $id, $class, $x, $y, $z, $data = []) {
|
||||
function __construct(Level $level, $id, $class, $x, $y, $z, $data = []){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
$this->normal = true;
|
||||
$this->class = $class;
|
||||
$this->data = $data;
|
||||
$this->closed = false;
|
||||
if($class === false) {
|
||||
if($class === false){
|
||||
$this->closed = true;
|
||||
}
|
||||
$this->name = "";
|
||||
|
|
@ -37,83 +35,83 @@ class Tile extends Position {
|
|||
$this->y = (int) $y;
|
||||
$this->z = (int) $z;
|
||||
$this->server->query("INSERT OR REPLACE INTO tiles (ID, level, class, x, y, z) VALUES (" . $this->id . ", '" . $this->level->getName() . "', '" . $this->class . "', " . $this->x . ", " . $this->y . ", " . $this->z . ");");
|
||||
switch($this->class) {
|
||||
switch($this->class){
|
||||
case TILE_CHEST:
|
||||
case TILE_SIGN:
|
||||
$this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = " . $this->id . ";");
|
||||
break;
|
||||
case TILE_FURNACE:
|
||||
if(!isset($this->data["BurnTime"]) or $this->data["BurnTime"] < 0) {
|
||||
if(!isset($this->data["BurnTime"]) or $this->data["BurnTime"] < 0){
|
||||
$this->data["BurnTime"] = 0;
|
||||
}
|
||||
if(!isset($this->data["CookTime"]) or $this->data["CookTime"] < 0 or ($this->data["BurnTime"] === 0 and $this->data["CookTime"] > 0)) {
|
||||
if(!isset($this->data["CookTime"]) or $this->data["CookTime"] < 0 or ($this->data["BurnTime"] === 0 and $this->data["CookTime"] > 0)){
|
||||
$this->data["CookTime"] = 0;
|
||||
}
|
||||
if(!isset($this->data["MaxTime"])) {
|
||||
if(!isset($this->data["MaxTime"])){
|
||||
$this->data["MaxTime"] = $this->data["BurnTime"];
|
||||
$this->data["BurnTicks"] = 0;
|
||||
}
|
||||
if($this->data["BurnTime"] > 0) {
|
||||
if($this->data["BurnTime"] > 0){
|
||||
$this->update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
if($this->closed === true) {
|
||||
public function update(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->class === TILE_FURNACE) {
|
||||
if($this->class === TILE_FURNACE){
|
||||
$fuel = $this->getSlot(1);
|
||||
$raw = $this->getSlot(0);
|
||||
$product = $this->getSlot(2);
|
||||
$smelt = $raw->getSmeltItem();
|
||||
$canSmelt = ($smelt !== false and $raw->count > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->count < $product->getMaxStackSize()) or $product->getID() === AIR));
|
||||
if($this->data["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->count > 0) {
|
||||
if($this->data["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->count > 0){
|
||||
$this->lastUpdate = microtime(true);
|
||||
$this->data["MaxTime"] = $this->data["BurnTime"] = floor($fuel->getFuelTime() * 20);
|
||||
$this->data["BurnTicks"] = 0;
|
||||
--$fuel->count;
|
||||
if($fuel->count === 0) {
|
||||
if($fuel->count === 0){
|
||||
$fuel = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
$this->setSlot(1, $fuel, false);
|
||||
$current = $this->level->getBlock($this);
|
||||
if($current->getID() === FURNACE) {
|
||||
if($current->getID() === FURNACE){
|
||||
$this->level->setBlock($this, BlockAPI::get(BURNING_FURNACE, $current->getMetadata()), true, false, true);
|
||||
}
|
||||
}
|
||||
if($this->data["BurnTime"] > 0) {
|
||||
if($this->data["BurnTime"] > 0){
|
||||
$ticks = (microtime(true) - $this->lastUpdate) * 20;
|
||||
$this->data["BurnTime"] -= $ticks;
|
||||
$this->data["BurnTicks"] = ceil(($this->data["BurnTime"] / $this->data["MaxTime"]) * 200);
|
||||
if($smelt !== false and $canSmelt) {
|
||||
if($smelt !== false and $canSmelt){
|
||||
$this->data["CookTime"] += $ticks;
|
||||
if($this->data["CookTime"] >= 200) { //10 seconds
|
||||
if($this->data["CookTime"] >= 200){ //10 seconds
|
||||
$product = BlockAPI::getItem($smelt->getID(), $smelt->getMetadata(), $product->count + 1);
|
||||
$this->setSlot(2, $product, false);
|
||||
--$raw->count;
|
||||
if($raw->count === 0) {
|
||||
if($raw->count === 0){
|
||||
$raw = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
$this->setSlot(0, $raw, false);
|
||||
$this->data["CookTime"] -= 200;
|
||||
}
|
||||
} elseif($this->data["BurnTime"] <= 0) {
|
||||
}elseif($this->data["BurnTime"] <= 0){
|
||||
$this->data["BurnTime"] = 0;
|
||||
$this->data["CookTime"] = 0;
|
||||
$this->data["BurnTicks"] = 0;
|
||||
} else {
|
||||
}else{
|
||||
$this->data["CookTime"] = 0;
|
||||
}
|
||||
|
||||
$this->server->schedule(2, [$this, "update"]);
|
||||
$this->scheduledUpdate = true;
|
||||
} else {
|
||||
}else{
|
||||
$current = $this->level->getBlock($this);
|
||||
if($current->getID() === BURNING_FURNACE) {
|
||||
if($current->getID() === BURNING_FURNACE){
|
||||
$this->level->setBlock($this, BlockAPI::get(FURNACE, $current->getMetadata()), true, false, true);
|
||||
}
|
||||
$this->data["CookTime"] = 0;
|
||||
|
|
@ -126,28 +124,28 @@ class Tile extends Position {
|
|||
$this->lastUpdate = microtime(true);
|
||||
}
|
||||
|
||||
public function getSlot($s) {
|
||||
public function getSlot($s){
|
||||
$i = $this->getSlotIndex($s);
|
||||
if($i === false or $i < 0) {
|
||||
if($i === false or $i < 0){
|
||||
return BlockAPI::getItem(AIR, 0, 0);
|
||||
} else {
|
||||
}else{
|
||||
return BlockAPI::getItem($this->data["Items"][$i]["id"], $this->data["Items"][$i]["Damage"], $this->data["Items"][$i]["Count"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSlotIndex($s) {
|
||||
if($this->class !== TILE_CHEST and $this->class !== TILE_FURNACE) {
|
||||
public function getSlotIndex($s){
|
||||
if($this->class !== TILE_CHEST and $this->class !== TILE_FURNACE){
|
||||
return false;
|
||||
}
|
||||
foreach($this->data["Items"] as $i => $slot) {
|
||||
if($slot["Slot"] === $s) {
|
||||
foreach($this->data["Items"] as $i => $slot){
|
||||
if($slot["Slot"] === $s){
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function setSlot($s, Item $item, $update = true, $offset = 0) {
|
||||
public function setSlot($s, Item $item, $update = true, $offset = 0){
|
||||
$i = $this->getSlotIndex($s);
|
||||
$d = [
|
||||
"Count" => $item->count,
|
||||
|
|
@ -155,15 +153,15 @@ class Tile extends Position {
|
|||
"id" => $item->getID(),
|
||||
"Damage" => $item->getMetadata(),
|
||||
];
|
||||
if($i === false) {
|
||||
if($i === false){
|
||||
return false;
|
||||
} elseif($item->getID() === AIR or $item->count <= 0) {
|
||||
if($i >= 0) {
|
||||
}elseif($item->getID() === AIR or $item->count <= 0){
|
||||
if($i >= 0){
|
||||
unset($this->data["Items"][$i]);
|
||||
}
|
||||
} elseif($i < 0) {
|
||||
}elseif($i < 0){
|
||||
$this->data["Items"][] = $d;
|
||||
} else {
|
||||
}else{
|
||||
$this->data["Items"][$i] = $d;
|
||||
}
|
||||
$this->server->api->dhandle("tile.container.slot", [
|
||||
|
|
@ -173,14 +171,14 @@ class Tile extends Position {
|
|||
"slotdata" => $item,
|
||||
]);
|
||||
|
||||
if($update === true and $this->scheduledUpdate === false) {
|
||||
if($update === true and $this->scheduledUpdate === false){
|
||||
$this->update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function pairWith(Tile $tile) {
|
||||
if($this->isPaired() or $tile->isPaired()) {
|
||||
public function pairWith(Tile $tile){
|
||||
if($this->isPaired() or $tile->isPaired()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -196,18 +194,18 @@ class Tile extends Position {
|
|||
$this->server->handle("tile.update", $tile);
|
||||
}
|
||||
|
||||
public function isPaired() {
|
||||
if($this->class !== TILE_CHEST) {
|
||||
public function isPaired(){
|
||||
if($this->class !== TILE_CHEST){
|
||||
return false;
|
||||
}
|
||||
if(!isset($this->data["pairx"]) or !isset($this->data["pairz"])) {
|
||||
if(!isset($this->data["pairx"]) or !isset($this->data["pairz"])){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function unpair() {
|
||||
if(!$this->isPaired()) {
|
||||
public function unpair(){
|
||||
if(!$this->isPaired()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -216,36 +214,36 @@ class Tile extends Position {
|
|||
|
||||
$this->server->api->tile->spawnToAll($this);
|
||||
$this->server->handle("tile.update", $this);
|
||||
if($tile instanceof Tile) {
|
||||
if($tile instanceof Tile){
|
||||
$this->server->api->tile->spawnToAll($tile);
|
||||
$this->server->handle("tile.update", $tile);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPair() {
|
||||
if($this->isPaired()) {
|
||||
public function getPair(){
|
||||
if($this->isPaired()){
|
||||
return $this->server->api->tile->get(new Position((int) $this->data["pairx"], $this->y, (int) $this->data["pairz"], $this->level));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function openInventory(Player $player) {
|
||||
if($this->class === TILE_CHEST) {
|
||||
public function openInventory(Player $player){
|
||||
if($this->class === TILE_CHEST){
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 99);
|
||||
if(($pair = $this->getPair()) !== false) {
|
||||
if(($pair->x + ($pair->z << 13)) > ($this->x + ($this->z << 13))) { //Order them correctly
|
||||
if(($pair = $this->getPair()) !== false){
|
||||
if(($pair->x + ($pair->z << 13)) > ($this->x + ($this->z << 13))){ //Order them correctly
|
||||
$player->windows[$id] = [
|
||||
$pair,
|
||||
$this
|
||||
];
|
||||
} else {
|
||||
}else{
|
||||
$player->windows[$id] = [
|
||||
$this,
|
||||
$pair
|
||||
];
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
$player->windows[$id] = $this;
|
||||
}
|
||||
|
||||
|
|
@ -259,9 +257,9 @@ class Tile extends Position {
|
|||
$player->dataPacket($pk);
|
||||
$slots = [];
|
||||
|
||||
if(is_array($player->windows[$id])) {
|
||||
if(is_array($player->windows[$id])){
|
||||
$all = $this->server->api->player->getAll($this->level);
|
||||
foreach($player->windows[$id] as $ob) {
|
||||
foreach($player->windows[$id] as $ob){
|
||||
$pk = new TileEventPacket;
|
||||
$pk->x = $ob->x;
|
||||
$pk->y = $ob->y;
|
||||
|
|
@ -269,16 +267,16 @@ class Tile extends Position {
|
|||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
$this->server->api->player->broadcastPacket($all, $pk);
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s) {
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $ob->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0) {
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
} else {
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
$pk = new TileEventPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
|
|
@ -286,11 +284,11 @@ class Tile extends Position {
|
|||
$pk->case1 = 1;
|
||||
$pk->case2 = 2;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk);
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s) {
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $this->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0) {
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
} else {
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -301,7 +299,7 @@ class Tile extends Position {
|
|||
$pk->slots = $slots;
|
||||
$player->dataPacket($pk);
|
||||
return true;
|
||||
} elseif($this->class === TILE_FURNACE) {
|
||||
}elseif($this->class === TILE_FURNACE){
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(2, $player->windowCnt % 99);
|
||||
$player->windows[$id] = $this;
|
||||
|
|
@ -316,11 +314,11 @@ class Tile extends Position {
|
|||
$player->dataPacket($pk);
|
||||
|
||||
$slots = [];
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s) {
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
||||
$slot = $this->getSlot($s);
|
||||
if($slot->getID() > AIR and $slot->count > 0) {
|
||||
if($slot->getID() > AIR and $slot->count > 0){
|
||||
$slots[] = $slot;
|
||||
} else {
|
||||
}else{
|
||||
$slots[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -332,14 +330,14 @@ class Tile extends Position {
|
|||
}
|
||||
}
|
||||
|
||||
public function spawn($player) {
|
||||
if($this->closed) {
|
||||
public function spawn($player){
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
if(!($player instanceof Player)) {
|
||||
if(!($player instanceof Player)){
|
||||
$player = $this->server->api->player->get($player);
|
||||
}
|
||||
switch($this->class) {
|
||||
switch($this->class){
|
||||
case TILE_CHEST:
|
||||
$nbt = new NBT();
|
||||
$nbt->write(chr(NBT::TAG_COMPOUND) . "\x00\x00");
|
||||
|
|
@ -360,7 +358,7 @@ class Tile extends Position {
|
|||
$nbt->writeTAG_String("z");
|
||||
$nbt->writeTAG_Int((int) $this->z);
|
||||
|
||||
if($this->isPaired()) {
|
||||
if($this->isPaired()){
|
||||
$nbt->write(chr(NBT::TAG_INT));
|
||||
$nbt->writeTAG_String("pairx");
|
||||
$nbt->writeTAG_Int((int) $this->data["pairx"]);
|
||||
|
|
@ -427,8 +425,8 @@ class Tile extends Position {
|
|||
}
|
||||
}
|
||||
|
||||
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = "") {
|
||||
if($this->class !== TILE_SIGN) {
|
||||
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
|
||||
if($this->class !== TILE_SIGN){
|
||||
return false;
|
||||
}
|
||||
$this->data["Text1"] = $line1;
|
||||
|
|
@ -440,7 +438,7 @@ class Tile extends Position {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function getText() {
|
||||
public function getText(){
|
||||
return [
|
||||
$this->data["Text1"],
|
||||
$this->data["Text2"],
|
||||
|
|
@ -449,23 +447,23 @@ class Tile extends Position {
|
|||
];
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function close() {
|
||||
if($this->closed === false) {
|
||||
public function close(){
|
||||
if($this->closed === false){
|
||||
$this->closed = true;
|
||||
$this->server->api->tile->remove($this->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setPosition(Vector3 $pos) {
|
||||
if($pos instanceof Position) {
|
||||
public function setPosition(Vector3 $pos){
|
||||
if($pos instanceof Position){
|
||||
$this->level = $pos->level;
|
||||
$this->server->query("UPDATE tiles SET level = '" . $this->level->getName() . "' WHERE ID = " . $this->id . ";");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,36 +4,36 @@
|
|||
require_once("NoiseGenerator.php");
|
||||
/***REM_END***/
|
||||
|
||||
class NoiseGeneratorOctaves extends NoiseGenerator {
|
||||
class NoiseGeneratorOctaves extends NoiseGenerator{
|
||||
public $octaves;
|
||||
private $generatorCollection;
|
||||
public function __construct(MTRandom $random, $octaves) {
|
||||
public function __construct(MTRandom $random, $octaves){
|
||||
$this->generatorCollection = [];
|
||||
$this->octaves = (int) $octaves;
|
||||
for($o = 0; $o < $this->octaves; ++$o) {
|
||||
for($o = 0; $o < $this->octaves; ++$o){
|
||||
$this->generatorCollection[$o] = new NoiseGeneratorPerlin($random);
|
||||
}
|
||||
}
|
||||
|
||||
public function getValue($x, $y) {
|
||||
public function getValue($x, $y){
|
||||
$noise = 0;
|
||||
$scale = 1;
|
||||
for($i = 0; $i < $this->octaves; ++$i) {
|
||||
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) {
|
||||
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_fill(0, $int4 * $int5 * $int6, 0);
|
||||
$d1 = 1;
|
||||
|
||||
for($j = 0; $j < $this->octaves; ++$j) {
|
||||
for($j = 0; $j < $this->octaves; ++$j){
|
||||
$d2 = $int1 * $d1 * $par1;
|
||||
$d3 = $int2 * $d1 * $par2;
|
||||
$d4 = $int3 * $d1 * $par3;
|
||||
|
|
@ -51,4 +51,4 @@ class NoiseGeneratorOctaves extends NoiseGenerator {
|
|||
}
|
||||
return $floats;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,23 +4,21 @@
|
|||
require_once("NoiseGenerator.php");
|
||||
|
||||
/***REM_END***/
|
||||
class NoiseGeneratorPerlin extends NoiseGenerator {
|
||||
class NoiseGeneratorPerlin extends NoiseGenerator{
|
||||
|
||||
public $xCoord;
|
||||
public $yCoord;
|
||||
public $zCoord;
|
||||
public $xCoord, $yCoord, $zCoord;
|
||||
private $permutations = [];
|
||||
|
||||
public function __construct(MTRandom $random) {
|
||||
public function __construct(MTRandom $random){
|
||||
$this->xCoord = $random->nextFloat() * 256;
|
||||
$this->yCoord = $random->nextFloat() * 256;
|
||||
$this->zCoord = $random->nextFloat() * 256;
|
||||
|
||||
for($i = 0; $i < 512; ++$i) {
|
||||
for($i = 0; $i < 512; ++$i){
|
||||
$this->permutations[$i] = $i < 256 ? $i : 0;
|
||||
}
|
||||
|
||||
for($i = 0; $i < 256; ++$i) {
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$j = $random->nextInt(256 - $i) + $i;
|
||||
$k = $this->permutations[$i];
|
||||
$this->permutations[$i] = $this->permutations[$j];
|
||||
|
|
@ -30,7 +28,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator {
|
|||
|
||||
}
|
||||
|
||||
public function getValue($d, $d1, $d2 = 0) {
|
||||
public function getValue($d, $d1, $d2 = 0){
|
||||
$d3 = $d + $this->xCoord;
|
||||
$d4 = $d1 + $this->yCoord;
|
||||
$d5 = $d2 + $this->zCoord;
|
||||
|
|
@ -66,18 +64,18 @@ class NoiseGeneratorPerlin extends NoiseGenerator {
|
|||
);
|
||||
}
|
||||
|
||||
public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7) {
|
||||
if($int2 === 1) {
|
||||
public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7){
|
||||
if($int2 === 1){
|
||||
$n = 0;
|
||||
$d3 = 1 / $par7;
|
||||
for($i1 = 0; $i1 < $int1; ++$i1) {
|
||||
for($i1 = 0; $i1 < $int1; ++$i1){
|
||||
$d4 = $par1 + $i1 * $par4 + $this->xCoord;
|
||||
$i2 = floor($d4);
|
||||
$i3 = $i2 & 0xFF;
|
||||
$d4 -= $i2;
|
||||
$d5 = $d4 * $d4 * $d4 * ($d4 * ($d4 * 6 - 15) + 10);
|
||||
|
||||
for($i4 = 0; $i4 < $int3; ++$i4) {
|
||||
for($i4 = 0; $i4 < $int3; ++$i4){
|
||||
$d6 = $par3 + $i4 * $par6 + $this->zCoord;
|
||||
$i5 = floor($d6);
|
||||
$i6 = $i5 & 0xFF;
|
||||
|
|
@ -103,28 +101,28 @@ class NoiseGeneratorPerlin extends NoiseGenerator {
|
|||
$n = 0;
|
||||
$i = 0;
|
||||
|
||||
for($i4 = 0; $i4 < $int1; ++$i4) {
|
||||
for($i4 = 0; $i4 < $int1; ++$i4){
|
||||
$d6 = $par1 + $i4 * $par4 + $this->xCoord;
|
||||
$i5 = floor($d6);
|
||||
$i6 = $i5 & 0xFF;
|
||||
$d6 -= $i5;
|
||||
$d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10);
|
||||
|
||||
for($i12 = 0; $i12 < $int3; ++$i12) {
|
||||
for($i12 = 0; $i12 < $int3; ++$i12){
|
||||
$d12 = $par3 + $i12 * $par6 + $this->zCoord;
|
||||
$i13 = floor($d12);
|
||||
$i14 = $i13 & 0xFF;
|
||||
$d12 -= $i13;
|
||||
$d13 = $d12 * $d12 * $d12 * ($d12 * ($d12 * 6 - 15) + 10);
|
||||
|
||||
for($i15 = 0; $i15 < $int2; ++$i15) {
|
||||
for($i15 = 0; $i15 < $int2; ++$i15){
|
||||
$d14 = $par2 + $i15 * $par5 + $this->yCoord;
|
||||
$i16 = floor($d14);
|
||||
$i17 = $i16 & 0xff;
|
||||
$d14 -= $i16;
|
||||
$d15 = $d14 * $d14 * $d14 * ($d14 * ($d14 * 6 - 15) + 10);
|
||||
|
||||
if($i15 == 0 or $i17 != $m) {
|
||||
if($i15 == 0 or $i17 != $m){
|
||||
$m = $i17;
|
||||
$i7 = $this->permutations[$i6] + $i17;
|
||||
$i8 = $this->permutations[$i7] + $i14;
|
||||
|
|
@ -147,22 +145,22 @@ class NoiseGeneratorPerlin extends NoiseGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
final public static function curve($par1, $par2, $par3) {
|
||||
public static final function curve($par1, $par2, $par3){
|
||||
return $par2 + $par1 * ($par3 - $par2);
|
||||
}
|
||||
|
||||
public static function grad2D($int, $par1, $par2) {
|
||||
public static function grad2D($int, $par1, $par2){
|
||||
$i = $int & 0x0F;
|
||||
$d1 = (1 - (($i & 0x08) >> 3)) * $par1;
|
||||
$d2 = ($i == 12 || $i == 14) ? $par1 : (($i >= 4) * $par2);
|
||||
return (($i & 0x01) ? -$d1 : $d1) + (($i & 0x02) ? -$d2 : $d2);
|
||||
}
|
||||
|
||||
public static function grad3D($int, $par1, $par2, $par3) {
|
||||
public static function grad3D($int, $par1, $par2, $par3){
|
||||
$i = $int & 0x0F;
|
||||
$d1 = $i < 8 ? $par1 : $par2;
|
||||
$d2 = ($i == 12 or $i == 14) ? $par1 : ($i < 4 ? $par2 : $par3);
|
||||
|
||||
return (($i & 0x01) ? -$d1 : $d1) + (($i & 0x02) ? -$d2 : $d2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
define("EMPTY_MINI_CHUNK", str_repeat("\x00", 8192));
|
||||
define("EMPTY_16x16_ARR", array_fill(0, 256, 0));
|
||||
class VanillaGenerator implements LevelGenerator {
|
||||
class VanillaGenerator implements LevelGenerator
|
||||
{
|
||||
/**
|
||||
* @var Level
|
||||
*/
|
||||
|
|
@ -22,14 +23,7 @@ class VanillaGenerator implements LevelGenerator {
|
|||
* @var NoiseGeneratorOctaves $depthNoise
|
||||
* @var NoiseGeneratorOctaves $treeNoise
|
||||
*/
|
||||
private $upperInterpolationNoise;
|
||||
private $lowerInterpolationNoise;
|
||||
private $interpolationNoise;
|
||||
private $beachNoise;
|
||||
private $surfaceDepthNoise;
|
||||
private $biomeNoise;
|
||||
private $depthNoise;
|
||||
private $treeNoise;
|
||||
private $upperInterpolationNoise, $lowerInterpolationNoise, $interpolationNoise, $beachNoise, $surfaceDepthNoise, $biomeNoise, $depthNoise, $treeNoise;
|
||||
/**
|
||||
* @var float[] $biomeNoises
|
||||
* @var float[] $depthNoises
|
||||
|
|
@ -42,16 +36,7 @@ class VanillaGenerator implements LevelGenerator {
|
|||
* @var float[] $gravelNoises
|
||||
* @var float[] $surfaceDepthNoises
|
||||
*/
|
||||
private $biomeNoises;
|
||||
private $depthNoises;
|
||||
private $interpolationNoises;
|
||||
private $upperInterpolationNoises;
|
||||
private $lowerInterpolationNoises;
|
||||
private $biomes;
|
||||
private $heights;
|
||||
private $sandNoises;
|
||||
private $gravelNoises;
|
||||
private $surfaceDepthNoises;
|
||||
private $biomeNoises, $depthNoises, $interpolationNoises, $upperInterpolationNoises, $lowerInterpolationNoises, $biomes, $heights, $sandNoises, $gravelNoises, $surfaceDepthNoises;
|
||||
/**
|
||||
* @var BiomeSource
|
||||
*/
|
||||
|
|
@ -59,10 +44,12 @@ class VanillaGenerator implements LevelGenerator {
|
|||
|
||||
private $heightMap = [];
|
||||
|
||||
public function __construct(array $options = []) {
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
|
||||
}
|
||||
public function init(Level $level, Random $random) {
|
||||
public function init(Level $level, Random $random)
|
||||
{
|
||||
$this->level = $level;
|
||||
$this->biomeSource = new BiomeSource($level);
|
||||
$this->rand = new MTRandom($level->getSeed());
|
||||
|
|
@ -76,11 +63,13 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$this->treeNoise = new NoiseGeneratorOctaves($this->rand, 8);
|
||||
}
|
||||
|
||||
public function getSpawn() {
|
||||
public function getSpawn()
|
||||
{
|
||||
return new Vector3(128, 64, 128);
|
||||
}
|
||||
|
||||
public function populateChunk($chunkX, $chunkZ) {
|
||||
public function populateChunk($chunkX, $chunkZ)
|
||||
{
|
||||
$chunkXWorld = $chunkX * 16;
|
||||
$chunkZWorld = $chunkZ * 16;
|
||||
//HeavyTile::instaFall = 1; TODO instant sand/gravel fall
|
||||
|
|
@ -89,7 +78,7 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$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((($chunkX * $i1 + $chunkZ * $j1) & 0xffffffff) ^ $this->level->getSeed());
|
||||
for($i2 = 0; $i2 < 10; ++$i2) {
|
||||
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) {
|
||||
|
|
@ -101,37 +90,29 @@ class VanillaGenerator implements LevelGenerator {
|
|||
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) {
|
||||
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) {
|
||||
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($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);
|
||||
}
|
||||
|
||||
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), DIAMOND_ORE, 7);
|
||||
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);
|
||||
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), DIAMOND_ORE, 7);
|
||||
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.5, $chunkZWorld * 0.5) / 8) + ($this->rand->nextFloat() * 4)) + 4) / 3);
|
||||
$treesAmount = $this->rand->nextInt(10) == 0;
|
||||
if($biome == Biome::$forest) {
|
||||
$treesAmount += $sample + 2;
|
||||
} elseif($biome == Biome::$rainForest) {
|
||||
$treesAmount += $sample + 2;
|
||||
} elseif($biome == Biome::$seasonalForest) {
|
||||
$treesAmount += $sample + 1;
|
||||
} elseif($biome == Biome::$taiga) {
|
||||
$treesAmount += $sample + 1;
|
||||
} elseif($biome == Biome::$desert) {
|
||||
$treesAmount -= 20;
|
||||
} elseif($biome == Biome::$tundra) {
|
||||
$treesAmount -= 20;
|
||||
} elseif($biome == Biome::$plains) {
|
||||
$treesAmount -= 20;
|
||||
}
|
||||
for($l8 = 0; $l8 < $treesAmount; ++$l8) {
|
||||
if($biome == Biome::$forest) $treesAmount += $sample + 2;
|
||||
elseif($biome == Biome::$rainForest) $treesAmount += $sample + 2;
|
||||
elseif($biome == Biome::$seasonalForest) $treesAmount += $sample + 1;
|
||||
elseif($biome == Biome::$taiga) $treesAmount += $sample + 1;
|
||||
elseif($biome == Biome::$desert) $treesAmount -= 20;
|
||||
elseif($biome == Biome::$tundra) $treesAmount -= 20;
|
||||
elseif($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;
|
||||
/**
|
||||
|
|
@ -140,25 +121,25 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$tree = $biome->getTreeFeature($this->rand);
|
||||
$tree->place($this->level, $this->rand, $l12, $this->getHeightValue($l12, $j15), $j15);
|
||||
}
|
||||
for($i9 = 0; $i9 < 2; ++$i9) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
|
|
@ -166,7 +147,8 @@ class VanillaGenerator implements LevelGenerator {
|
|||
}
|
||||
|
||||
}
|
||||
public function generateChunk($chunkX, $chunkZ) {
|
||||
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
|
||||
|
|
@ -174,7 +156,7 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$this->buildSurfaces($chunkX, $chunkZ, $chunkz, $this->biomes);
|
||||
$this->generateHeightmap($chunkX, $chunkZ, $chunkz);
|
||||
|
||||
for($Y = 0; $Y < 8; ++$Y) {
|
||||
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;
|
||||
|
|
@ -184,34 +166,30 @@ class VanillaGenerator implements LevelGenerator {
|
|||
|
||||
}
|
||||
|
||||
public function populateLevel() {
|
||||
}
|
||||
public function setHeightValue($x, $z, $hv) {
|
||||
if($x > 255 || $x < 0 || $z > 255 || $z < 0) {
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
|
|
@ -233,12 +211,12 @@ class VanillaGenerator implements LevelGenerator {
|
|||
* @param array $chunks
|
||||
* @param Biome[] $biomes
|
||||
*/
|
||||
public function buildSurfaces($chunkX, $chunkZ, &$chunks, $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) {
|
||||
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;
|
||||
|
|
@ -247,28 +225,28 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$i = -1;
|
||||
$b = $biome->topBlock;
|
||||
$b2 = $biome->fillerBlock;
|
||||
for($blockY = 127; $blockY >= 0; --$blockY) {
|
||||
if($blockY <= $this->rand->nextInt(5)) {
|
||||
for($blockY = 127; $blockY >= 0; --$blockY){
|
||||
if($blockY <= $this->rand->nextInt(5)){
|
||||
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = "\x07";
|
||||
} else {
|
||||
}else{
|
||||
$b3 = ord($chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)]);
|
||||
if($b3 == 0) {
|
||||
if($b3 == 0){
|
||||
$i = -1;
|
||||
} elseif($b3 == STONE) {
|
||||
if($i == -1) {
|
||||
if($nextFloat > 0) {
|
||||
if($blockY >= 60 && $blockY <= 65) {
|
||||
if($z) {
|
||||
}elseif($b3 == STONE){
|
||||
if($i == -1){
|
||||
if($nextFloat > 0){
|
||||
if($blockY >= 60 && $blockY <= 65){
|
||||
if($z){
|
||||
$b2 = $b = SAND;
|
||||
} elseif($z2) {
|
||||
}elseif($z2){
|
||||
$b = 0;
|
||||
$b2 = GRAVEL;
|
||||
} else {
|
||||
}else{
|
||||
$b = $biome->topBlock;
|
||||
$b2 = $biome->fillerBlock;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
$b = 0;
|
||||
$b2 = STONE;
|
||||
}
|
||||
|
|
@ -276,10 +254,10 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$b = $blockY < 64 && $b == 0 ? STILL_WATER : $b;
|
||||
$i = $nextFloat;
|
||||
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = $blockY >= 63 ? chr($b) : chr($b2);
|
||||
} elseif($i > 0) {
|
||||
}elseif($i > 0){
|
||||
--$i;
|
||||
$chunks[$blockY >> 4][($blockY & 0xf) + ($blockZ << 5) + ($blockX << 9)] = chr($b2);
|
||||
if($i == 0 && $b2 == SAND) {
|
||||
if($i == 0 && $b2 == SAND){
|
||||
$i = $this->rand->nextInt(4);
|
||||
$b2 = SANDSTONE;
|
||||
}
|
||||
|
|
@ -291,12 +269,12 @@ class VanillaGenerator implements LevelGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public function prepareHeights($chunkX, $chunkZ, &$chunks, $biomes, $temperatures) {
|
||||
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) {
|
||||
for($unkX = 0; $unkX < 4; ++$unkX){
|
||||
for($unkZ = 0; $unkZ < 4; ++$unkZ){
|
||||
for($unkY = 0; $unkY < 16; ++$unkY){
|
||||
$f = $this->heights[(((($unkX) * 5) + $unkZ) * 17) + $unkY];
|
||||
$f2 = $this->heights[(((($unkX) * 5) + $unkZ + 1) * 17) + $unkY];
|
||||
$f3 = $this->heights[(((($unkX + 1) * 5) + $unkZ) * 17) + $unkY];
|
||||
|
|
@ -307,19 +285,19 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$f7 = ($this->heights[(((($unkX + 1) * 5) + ($unkZ)) * 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) {
|
||||
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) {
|
||||
for($unkXX = 0; $unkXX < 4; ++$unkXX){
|
||||
$f13 = $f9;
|
||||
$f14 = ($f10 - $f9) * 0.25;
|
||||
for($unkZZ = 0; $unkZZ < 4; ++$unkZZ) {
|
||||
for($unkZZ = 0; $unkZZ < 4; ++$unkZZ){
|
||||
$d15 = $temperatures[((($unkX * 4) + $unkXX) * 16) + ($unkZ * 4) + $unkZZ];
|
||||
$i3 = $f13 > 0; //true -> STONE, false -> AIR
|
||||
|
||||
if(!$i3 && ($unkY * 8) + $unkYY < 64) {
|
||||
if(!$i3 && ($unkY * 8) + $unkYY < 64){
|
||||
$i3 = $d15 < 0.5 && (($unkY * 8) + $unkYY) >= 63 ? ICE : STILL_WATER;
|
||||
}
|
||||
|
||||
|
|
@ -342,7 +320,7 @@ class VanillaGenerator implements LevelGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public function getHeights($chunkX, $chunkY, $chunkZ, $scaleX, $scaleY, $scaleZ) {
|
||||
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;
|
||||
|
|
@ -353,9 +331,9 @@ class VanillaGenerator implements LevelGenerator {
|
|||
$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) {
|
||||
for($j2 = 0; $j2 < $scaleX; ++$j2){
|
||||
$k2 = (int) ($j2 * $i2 + $i2 / 2);
|
||||
for($l2 = 0; $l2 < $scaleZ; ++$l2) {
|
||||
for($l2 = 0; $l2 < $scaleZ; ++$l2){
|
||||
$i3 = (int) ($l2 * $i2 + $i2 / 2);
|
||||
$d2 = $tempNoises[$k2 * 16 + $i3];
|
||||
$d3 = $rainNoises[$k2 * 16 + $i3] * $d2;
|
||||
|
|
@ -366,58 +344,42 @@ class VanillaGenerator implements LevelGenerator {
|
|||
|
||||
$d5 = (($this->biomeNoises[$l1] + 256) / 512);
|
||||
$d5 *= $d4;
|
||||
if($d5 > 1) {
|
||||
$d5 = 1;
|
||||
}
|
||||
if($d5 > 1) $d5 = 1;
|
||||
$d6 = $this->depthNoises[$l1] / 8000;
|
||||
if($d6 < 0) {
|
||||
$d6 = -$d6 * 0.3;
|
||||
}
|
||||
if($d6 < 0) $d6 = -$d6 * 0.3;
|
||||
|
||||
$d6 = $d6 * 3 - 2;
|
||||
if($d6 < 0) {
|
||||
if($d6 < 0){
|
||||
$d6 /= 2;
|
||||
if($d6 < -1) {
|
||||
$d6 = -1;
|
||||
}
|
||||
if($d6 < -1) $d6 = -1;
|
||||
$d6 /= 1.4;
|
||||
$d6 /= 2;
|
||||
$d5 = 0;
|
||||
} else {
|
||||
if($d6 > 1) {
|
||||
$d6 = 1;
|
||||
}
|
||||
}else{
|
||||
if($d6 > 1) $d6 = 1;
|
||||
$d6 /= 8;
|
||||
}
|
||||
|
||||
if($d5 < 0) {
|
||||
$d5 = 0;
|
||||
}
|
||||
if($d5 < 0) $d5 = 0;
|
||||
|
||||
$d5 += 0.5;
|
||||
$d6 = ($d6 * $scaleY) / 16;
|
||||
$d7 = ($scaleY / 2 + $d6 * 4);
|
||||
++$l1;
|
||||
for($j3 = 0; $j3 < $scaleY; ++$j3) {
|
||||
for($j3 = 0; $j3 < $scaleY; ++$j3){
|
||||
$d8 = 0;
|
||||
$d9 = (((float) $j3 - $d7) * 12) / $d5;
|
||||
if($d9 < 0) {
|
||||
$d9 *= 4;
|
||||
}
|
||||
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;
|
||||
} elseif($d12 > 1) {
|
||||
$d8 = $d11;
|
||||
} else {
|
||||
$d8 = $d10 + ($d11 - $d10) * $d12;
|
||||
}
|
||||
if($d12 < 0) $d8 = $d10;
|
||||
elseif($d12 > 1) $d8 = $d11;
|
||||
else $d8 = $d10 + ($d11 - $d10) * $d12;
|
||||
|
||||
$d8 -= $d9;
|
||||
if($j3 > $scaleY - 4) {
|
||||
if($j3 > $scaleY - 4){
|
||||
$d13 = ($j3 - ($scaleY - 4)) / 3;
|
||||
$d8 = $d8 * (1 - $d13) + -10 * $d13;
|
||||
}
|
||||
|
|
@ -431,3 +393,4 @@ class VanillaGenerator implements LevelGenerator {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +1,39 @@
|
|||
<?php
|
||||
|
||||
class TreeFeature extends Feature {
|
||||
public function place(Level $level, MTRandom $rand, $x, $y, $z) {
|
||||
class TreeFeature extends Feature
|
||||
{
|
||||
public function place(Level $level, MTRandom $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) {
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
if($tileID != 0 && $tileID != LEAVES){
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($z2) {
|
||||
if($z2){
|
||||
$tileID = $level->level->getBlockID($x, $y - 1, $z);
|
||||
if(($tileID == GRASS || $tileID == DIRT) && $y < (128 - $nextInt) - 1) {
|
||||
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) {
|
||||
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) {
|
||||
for($i8 = $x - $i7; $i8 <= $x + $i7; ++$i8){
|
||||
$i9 = $i8 - $x;
|
||||
for($i10 = $z - $i7; $i10 <= $z + $i7; ++$i10) {
|
||||
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);
|
||||
|
|
@ -44,12 +41,13 @@ class TreeFeature extends Feature {
|
|||
}
|
||||
}
|
||||
}
|
||||
for($i12 = 0; $i12 < $nextInt; ++$i12) {
|
||||
for($i12 = 0; $i12 < $nextInt; ++$i12){
|
||||
$tileID = $level->level->getBlockID($x, $y + $i12, $z);
|
||||
if($tileID == 0 || $tileID == LEAVES) {
|
||||
if($tileID == 0 || $tileID == LEAVES){
|
||||
$level->level->setBlockID($x, $y + $i12, $z, WOOD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue