Level-independient time change

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-15 21:10:29 +02:00
parent e63677a23d
commit 5ee2cda4a6
4 changed files with 17 additions and 14 deletions

View File

@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class Deprecation{ class Deprecation{
public static $events = array( public static $events = array(
"server.time" => "time.change",
"world.block.change" => "block.change", "world.block.change" => "block.change",
"block.drop" => "item.drop", "block.drop" => "item.drop",
"api.op.check" => "op.check", "api.op.check" => "op.check",

View File

@ -441,10 +441,12 @@ class Player{
"eid" => $data->eid, "eid" => $data->eid,
)); ));
break; break;
case "server.time": case "time.change":
$this->dataPacket(MC_SET_TIME, array( if($data["level"] === $this->level){
"time" => $data, $this->dataPacket(MC_SET_TIME, array(
)); "time" => $data["time"],
));
}
break; break;
case "entity.animate": case "entity.animate":
if($data["eid"] === $this->eid or $data["entity"]->level !== $this->level){ if($data["eid"] === $this->eid or $data["entity"]->level !== $this->level){
@ -906,7 +908,7 @@ class Player{
$this->entity->z = $this->data->get("position")["z"]; $this->entity->z = $this->data->get("position")["z"];
$this->entity->setName($this->username); $this->entity->setName($this->username);
$this->entity->data["clientID"] = $this->clientID; $this->entity->data["clientID"] = $this->clientID;
$this->evid[] = $this->server->event("server.time", array($this, "eventHandler")); $this->evid[] = $this->server->event("time.change", array($this, "eventHandler"));
$this->evid[] = $this->server->event("server.chat", array($this, "eventHandler")); $this->evid[] = $this->server->event("server.chat", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler")); $this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.move", array($this, "eventHandler")); $this->evid[] = $this->server->event("entity.move", array($this, "eventHandler"));

View File

@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
class PocketMinecraftServer{ class PocketMinecraftServer{
public $tCnt; public $tCnt;
public $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond; public $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd;
private $port, $serverip, $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick; private $port, $serverip, $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick;
private function load(){ private function load(){
@ -65,8 +65,6 @@ class PocketMinecraftServer{
$this->whitelist = false; $this->whitelist = false;
$this->clients = array(); $this->clients = array();
$this->spawn = false; $this->spawn = false;
$this->time = 0;
$this->timePerSecond = 20;
$this->tickMeasure = array_fill(0, 40, 0); $this->tickMeasure = array_fill(0, 40, 0);
$this->setType("normal"); $this->setType("normal");
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false, $this->serverip); $this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false, $this->serverip);
@ -102,7 +100,6 @@ class PocketMinecraftServer{
if(ENABLE_ANSI === true){ if(ENABLE_ANSI === true){
$this->action(1500000, '$this->titleTick();'); $this->action(1500000, '$this->titleTick();');
} }
$this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->api->dhandle("server.time", $this->time);');
$this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}'); $this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}');
$this->action(1000000 * 15, 'if($this->getTPS() < 15){console("[WARNING] Can\'t keep up! Is the server overloaded?");}'); $this->action(1000000 * 15, 'if($this->getTPS() < 15){console("[WARNING] Can\'t keep up! Is the server overloaded?");}');
$this->action(1000000 * 60 * 10, '$this->custom = array();'); $this->action(1000000 * 60 * 10, '$this->custom = array();');

View File

@ -41,6 +41,14 @@ class Level{
$this->name = $name; $this->name = $name;
} }
public function checkThings(){
$now = microtime(true);
$time = $this->startTime + ($now - $this->startCheck) * 20;
if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){
$this->time = $time;
}
}
public function __destruct(){ public function __destruct(){
$this->save(); $this->save();
unset($this->level); unset($this->level);
@ -142,11 +150,6 @@ class Level{
$this->startCheck = microtime(true); $this->startCheck = microtime(true);
} }
public function checkThings(){
$now = microtime(true);
$this->time = $this->startTime + ($now - $this->startCheck) * 20;
}
public function getSeed(){ public function getSeed(){
return (int) $this->level->getData("seed"); return (int) $this->level->getData("seed");
} }