painting fix, sleeping fix

This commit is contained in:
GameHerobrine 2023-11-21 12:58:27 +03:00
parent 385c8a1bc0
commit d70d207317
3 changed files with 41 additions and 35 deletions

View file

@ -49,11 +49,11 @@ class Player{
private $ip;
private $port;
private $counter = [0, 0, 0, 0];
private $username;
private $iusername;
public $username;
public $iusername;
private $eid = false;
private $startAction = false;
private $isSleeping = false;
public $isSleeping = false;
private $chunksOrder = [];
private $lastMeasure = 0;
private $bandwidthRaw = 0;
@ -68,6 +68,9 @@ class Player{
private $chunkCount = [];
private $received = [];
public $cratingItems;
public $sleepingTime = 0;
/**
* @param integer $clientID
* @param string $ip
@ -130,7 +133,7 @@ class Player{
$this->entity->updateMetadata();
}
$this->setSpawn($pos);
$this->server->schedule(60, [$this, "checkSleep"]);
return true;
}
@ -486,6 +489,8 @@ class Player{
if(count($this->chunksOrder) <= 0 && $this->level->generatorType != 0){
$this->orderChunks();
}
if($this->isSleeping) ++$this->sleepingTime;
if($this->chunkTicker++ > 5){
$this->getNextChunk($this->level);
$this->chunkTicker = 0;
@ -607,22 +612,6 @@ class Player{
$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 $damage
@ -1540,6 +1529,7 @@ class Player{
$this->server->api->player->spawnAllPlayers($this);
$this->server->api->player->spawnToAllPlayers($this);
}
if($this->isSleeping) break;
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){
$this->lastMovement = $packet->messageIndex;
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
@ -2224,6 +2214,7 @@ class Player{
public function stopSleep(){
$this->isSleeping = false;
$this->sleepingTime = 0;
if($this->entity instanceof Entity){
$this->entity->updateMetadata();
}

View file

@ -418,20 +418,21 @@ class Entity extends Position
$endX = ceil($this->boundingBox->maxX);
$endY = ceil($this->boundingBox->maxY);
$endZ = ceil($this->boundingBox->maxZ);
for($i = 0; $i < 8; ++$i){
$x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8;
$y= ((($i >> 1) % 2) - 0.5) * 0.1;
$z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8;
if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){
for($i = 0; $i < 8; ++$i){
$x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8;
$y= ((($i >> 1) % 2) - 0.5) * 0.1;
$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);
$blockY = floor($this->y + $this->getEyeHeight() + $y);
$blockZ = floor($this->z + $z);
if($this->level->getBlockWithoutVector($blockX, $blockY, $blockZ)->isSolid){
$this->harm(1, "suffocation"); // Suffocation
$hasUpdate = true;
break;
if($this->level->getBlockWithoutVector($blockX, $blockY, $blockZ)->isSolid){
$this->harm(1, "suffocation"); // Suffocation
$hasUpdate = true;
break;
}
}
}

View file

@ -107,7 +107,21 @@ class 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){
$X = (int)$X;
$Z = (int)$Z;
@ -293,7 +307,7 @@ class Level{
}
$now = microtime(true);
$this->players = $this->server->api->player->getAll($this);
$this->checkSleep();
if(count($this->changedCount) > 0){
arsort($this->changedCount);
$resendChunks = [];