Time now is displayed correctly

This commit is contained in:
Shoghi Cervantes 2013-06-08 14:17:38 +02:00
parent 28480424c5
commit 16a8566fca
3 changed files with 25 additions and 11 deletions

View File

@ -712,6 +712,9 @@ class Player{
$this->chunksLoaded = array(); $this->chunksLoaded = array();
$this->server->api->entity->spawnToAll($this->entity); $this->server->api->entity->spawnToAll($this->entity);
$this->server->api->entity->spawnAll($this); $this->server->api->entity->spawnAll($this);
$this->dataPacket(MC_SET_TIME, array(
"time" => $this->level->getTime(),
));
$terrain = true; $terrain = true;
} }
$this->lastCorrect = $pos; $this->lastCorrect = $pos;
@ -1102,6 +1105,9 @@ class Player{
$this->sendSettings(); $this->sendSettings();
$this->server->schedule(50, array($this, "orderChunks"), array(), true); $this->server->schedule(50, array($this, "orderChunks"), array(), true);
$this->blocked = false; $this->blocked = false;
$this->dataPacket(MC_SET_TIME, array(
"time" => $this->level->getTime(),
));
$this->teleport(new Position($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"], $this->level)); $this->teleport(new Position($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"], $this->level));
$this->server->handle("player.spawn", $this); $this->server->handle("player.spawn", $this);
break; break;

View File

@ -192,9 +192,9 @@ class CustomPacketHandler{
break; break;
case MC_SET_TIME: case MC_SET_TIME:
if($this->c === false){ if($this->c === false){
$this->data["time"] = Utils::readLong($this->get(4)); $this->data["time"] = Utils::readInt($this->get(4));
}else{ }else{
$this->raw .= Utils::writeLong($this->data["time"]); $this->raw .= Utils::writeInt($this->data["time"]);
} }
break; break;
case MC_START_GAME: case MC_START_GAME:

View File

@ -39,7 +39,7 @@ class Level{
$this->nextSave = $this->startCheck = microtime(true); $this->nextSave = $this->startCheck = microtime(true);
$this->nextSave += 90; $this->nextSave += 90;
$this->server->schedule(15, array($this, "checkThings"), array(), true); $this->server->schedule(15, array($this, "checkThings"), array(), true);
$this->server->event("server.close", array($this, "save")); $this->server->schedule(20 * 13, array($this, "checkTime"), array(), true);
$this->name = $name; $this->name = $name;
$this->usedChunks = array(); $this->usedChunks = array();
$this->changedBlocks = array(); $this->changedBlocks = array();
@ -65,23 +65,31 @@ class Level{
unset($this->usedChunks[$i][$player->CID]); unset($this->usedChunks[$i][$player->CID]);
} }
} }
public function freeChunk($X, $Z, Player $player){ public function freeChunk($X, $Z, Player $player){
unset($this->usedChunks[$X.".".$Z][$player->CID]); unset($this->usedChunks[$X.".".$Z][$player->CID]);
} }
public function checkTime(){
if(!isset($this->level)){
return false;
}
$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;
$this->server->api->player->broadcastPacket($this->players, MC_SET_TIME, array(
"time" => (int) $this->time,
));
}
}
public function checkThings(){ public function checkThings(){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return false;
} }
$this->players = $this->server->api->player->getAll($this);
$now = microtime(true); $now = microtime(true);
$time = $this->startTime + ($now - $this->startCheck) * 20; $this->players = $this->server->api->player->getAll($this);
if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){
$this->time = $time;
$this->server->api->player->broadcastPacket($this->players, MC_SET_TIME, array(
"time" => $this->time,
));
}
if(count($this->changedCount) > 0){ if(count($this->changedCount) > 0){
arsort($this->changedCount); arsort($this->changedCount);