mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 20:49:43 +00:00
painting fix, sleeping fix
This commit is contained in:
parent
385c8a1bc0
commit
d70d207317
3 changed files with 41 additions and 35 deletions
|
|
@ -49,11 +49,11 @@ class Player{
|
||||||
private $ip;
|
private $ip;
|
||||||
private $port;
|
private $port;
|
||||||
private $counter = [0, 0, 0, 0];
|
private $counter = [0, 0, 0, 0];
|
||||||
private $username;
|
public $username;
|
||||||
private $iusername;
|
public $iusername;
|
||||||
private $eid = false;
|
private $eid = false;
|
||||||
private $startAction = false;
|
private $startAction = false;
|
||||||
private $isSleeping = false;
|
public $isSleeping = false;
|
||||||
private $chunksOrder = [];
|
private $chunksOrder = [];
|
||||||
private $lastMeasure = 0;
|
private $lastMeasure = 0;
|
||||||
private $bandwidthRaw = 0;
|
private $bandwidthRaw = 0;
|
||||||
|
|
@ -68,6 +68,9 @@ class Player{
|
||||||
private $chunkCount = [];
|
private $chunkCount = [];
|
||||||
private $received = [];
|
private $received = [];
|
||||||
public $cratingItems;
|
public $cratingItems;
|
||||||
|
|
||||||
|
public $sleepingTime = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param integer $clientID
|
* @param integer $clientID
|
||||||
* @param string $ip
|
* @param string $ip
|
||||||
|
|
@ -130,7 +133,7 @@ class Player{
|
||||||
$this->entity->updateMetadata();
|
$this->entity->updateMetadata();
|
||||||
}
|
}
|
||||||
$this->setSpawn($pos);
|
$this->setSpawn($pos);
|
||||||
$this->server->schedule(60, [$this, "checkSleep"]);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -486,6 +489,8 @@ class Player{
|
||||||
if(count($this->chunksOrder) <= 0 && $this->level->generatorType != 0){
|
if(count($this->chunksOrder) <= 0 && $this->level->generatorType != 0){
|
||||||
$this->orderChunks();
|
$this->orderChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->isSleeping) ++$this->sleepingTime;
|
||||||
if($this->chunkTicker++ > 5){
|
if($this->chunkTicker++ > 5){
|
||||||
$this->getNextChunk($this->level);
|
$this->getNextChunk($this->level);
|
||||||
$this->chunkTicker = 0;
|
$this->chunkTicker = 0;
|
||||||
|
|
@ -607,22 +612,6 @@ class Player{
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkSleep(){
|
|
||||||
if($this->isSleeping !== false){
|
|
||||||
if($this->server->api->time->getPhase($this->level) === "night"){
|
|
||||||
foreach($this->server->api->player->getAll($this->level) as $p){
|
|
||||||
if($p->isSleeping === false){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->server->api->time->set("day", $this->level);
|
|
||||||
foreach($this->server->api->player->getAll($this->level) as $p){
|
|
||||||
$p->stopSleep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $type
|
* @param $type
|
||||||
* @param $damage
|
* @param $damage
|
||||||
|
|
@ -1540,6 +1529,7 @@ class Player{
|
||||||
$this->server->api->player->spawnAllPlayers($this);
|
$this->server->api->player->spawnAllPlayers($this);
|
||||||
$this->server->api->player->spawnToAllPlayers($this);
|
$this->server->api->player->spawnToAllPlayers($this);
|
||||||
}
|
}
|
||||||
|
if($this->isSleeping) break;
|
||||||
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){
|
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){
|
||||||
$this->lastMovement = $packet->messageIndex;
|
$this->lastMovement = $packet->messageIndex;
|
||||||
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
|
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
|
||||||
|
|
@ -2224,6 +2214,7 @@ class Player{
|
||||||
|
|
||||||
public function stopSleep(){
|
public function stopSleep(){
|
||||||
$this->isSleeping = false;
|
$this->isSleeping = false;
|
||||||
|
$this->sleepingTime = 0;
|
||||||
if($this->entity instanceof Entity){
|
if($this->entity instanceof Entity){
|
||||||
$this->entity->updateMetadata();
|
$this->entity->updateMetadata();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -418,20 +418,21 @@ class Entity extends Position
|
||||||
$endX = ceil($this->boundingBox->maxX);
|
$endX = ceil($this->boundingBox->maxX);
|
||||||
$endY = ceil($this->boundingBox->maxY);
|
$endY = ceil($this->boundingBox->maxY);
|
||||||
$endZ = ceil($this->boundingBox->maxZ);
|
$endZ = ceil($this->boundingBox->maxZ);
|
||||||
|
if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){
|
||||||
for($i = 0; $i < 8; ++$i){
|
for($i = 0; $i < 8; ++$i){
|
||||||
$x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8;
|
$x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8;
|
||||||
$y= ((($i >> 1) % 2) - 0.5) * 0.1;
|
$y= ((($i >> 1) % 2) - 0.5) * 0.1;
|
||||||
$z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8;
|
$z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8;
|
||||||
|
|
||||||
|
$blockX = floor($this->x + $x);
|
||||||
|
$blockY = floor($this->y + $this->getEyeHeight() + $y);
|
||||||
|
$blockZ = floor($this->z + $z);
|
||||||
|
|
||||||
$blockX = floor($this->x + $x);
|
if($this->level->getBlockWithoutVector($blockX, $blockY, $blockZ)->isSolid){
|
||||||
$blockY = floor($this->y + $this->getEyeHeight() + $y);
|
$this->harm(1, "suffocation"); // Suffocation
|
||||||
$blockZ = floor($this->z + $z);
|
$hasUpdate = true;
|
||||||
|
break;
|
||||||
if($this->level->getBlockWithoutVector($blockX, $blockY, $blockZ)->isSolid){
|
}
|
||||||
$this->harm(1, "suffocation"); // Suffocation
|
|
||||||
$hasUpdate = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,21 @@ class Level{
|
||||||
unset($this->mobSpawner->level);
|
unset($this->mobSpawner->level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkSleep(){ //TODO events?
|
||||||
|
if(count($this->players) == 0) return false;
|
||||||
|
if($this->server->api->time->getPhase($this->level) === "night"){ //TODO vanilla
|
||||||
|
foreach($this->players as $p){
|
||||||
|
if($p->isSleeping == false || $p->sleepingTime < 100){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->server->api->time->set("day", $this->level);
|
||||||
|
}
|
||||||
|
foreach($this->players as $p){
|
||||||
|
$p->stopSleep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getOrderedFullChunk($X, $Z){
|
public function getOrderedFullChunk($X, $Z){
|
||||||
$X = (int)$X;
|
$X = (int)$X;
|
||||||
$Z = (int)$Z;
|
$Z = (int)$Z;
|
||||||
|
|
@ -293,7 +307,7 @@ class Level{
|
||||||
}
|
}
|
||||||
$now = microtime(true);
|
$now = microtime(true);
|
||||||
$this->players = $this->server->api->player->getAll($this);
|
$this->players = $this->server->api->player->getAll($this);
|
||||||
|
$this->checkSleep();
|
||||||
if(count($this->changedCount) > 0){
|
if(count($this->changedCount) > 0){
|
||||||
arsort($this->changedCount);
|
arsort($this->changedCount);
|
||||||
$resendChunks = [];
|
$resendChunks = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue