falling tile physics rewritten, (hopefully) fixed entity collisions(only with solid blocks)

This commit is contained in:
GameHerobrine 2023-10-25 18:11:53 +03:00
parent ef4b991374
commit 466d57d64b
2 changed files with 30 additions and 43 deletions

View file

@ -95,7 +95,7 @@ class Player{
$this->packetStats = [0, 0]; $this->packetStats = [0, 0];
$this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
$this->buffer->data = []; $this->buffer->data = [];
$this->server->schedule(2, [$this, "handlePacketQueues"], [], true); $this->server->schedule(1, [$this, "handlePacketQueues"], [], true);
$this->server->schedule(20 * 60, [$this, "clearQueue"], [], true); $this->server->schedule(20 * 60, [$this, "clearQueue"], [], true);
$this->evid[] = $this->server->event("server.close", [$this, "close"]); $this->evid[] = $this->server->event("server.close", [$this, "close"]);
console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2); console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2);
@ -340,7 +340,7 @@ class Player{
$this->bufferLen = 0; $this->bufferLen = 0;
$this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
$this->buffer->data = []; $this->buffer->data = [];
$this->nextBuffer = microtime(true) + 0.1; $this->nextBuffer = microtime(true) + 0.05;
} }
/** /**
@ -1110,7 +1110,7 @@ class Player{
} }
} }
if($this->nextBuffer <= $time and $this->bufferLen > 0){ if($this->bufferLen > 0){
$this->sendBuffer(); $this->sendBuffer();
} }
@ -1470,7 +1470,7 @@ class Player{
$this->server->api->entity->spawnToAll($this->entity); $this->server->api->entity->spawnToAll($this->entity);
//$this->server->schedule(5, [$this->entity, "update"], [], true); //$this->server->schedule(5, [$this->entity, "update"], [], true);
$this->server->schedule(2, [$this->entity, "updateMovement"], [], true); //$this->server->schedule(2, [$this->entity, "updateMovement"], [], true);
$this->sendArmor(); $this->sendArmor();
$array = explode("@n", (string)$this->server->motd); $array = explode("@n", (string)$this->server->motd);
foreach($array as $msg){ foreach($array as $msg){

View file

@ -526,8 +526,27 @@ class Entity extends Position
if(Utils::in_range($this->speedY, -0.007, 0.007)){ if(Utils::in_range($this->speedY, -0.007, 0.007)){
$this->speedY = 0; $this->speedY = 0;
} }
$horizontalMultiplyFactor = 0.91;
if($this->onGround){
$horizontalMultiplyFactor = 0.54;
$b = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minX) - 1, floor($this->z));
if($b > 0){
$horizontalMultiplyFactor = StaticBlock::getSlipperiness($b) * 0.91;
}
}
if($this->inWater){
$this->speedX *= 0.8;
$this->speedY *= 0.8;
$this->speedZ *= 0.8;
}else{
$this->speedX *= $horizontalMultiplyFactor;
$this->speedY *= 0.98;
$this->speedZ *= $horizontalMultiplyFactor;
}
$savedSpeedY = $this->speedY; $savedSpeedY = $this->speedY;
if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)){ if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT) || $this->class === ENTITY_FALLING){
$water = false; $water = false;
$aABB = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ); $aABB = $this->boundingBox->addCoord($this->speedX, $this->speedY, $this->speedZ);
$x0 = floor($aABB->minX); $x0 = floor($aABB->minX);
@ -560,23 +579,7 @@ class Entity extends Position
$this->inWater = $water; $this->inWater = $water;
} }
$support = $savedSpeedY != $this->speedY && $savedSpeedY < 0; $support = $savedSpeedY != $this->speedY && $savedSpeedY < 0;
$horizontalMultiplyFactor = 0.91;
if($support){
$horizontalMultiplyFactor = 0.54;
$b = $this->level->level->getBlockID(floor($this->x), floor($this->boundingBox->minX) - 1, floor($this->z));
if($b > 0){
$horizontalMultiplyFactor = StaticBlock::getSlipperiness($b) * 0.91;
}
}
if($this->inWater){
$this->speedX *= 0.8;
$this->speedY *= 0.8;
$this->speedZ *= 0.8;
}else{
$this->speedX *= $horizontalMultiplyFactor;
$this->speedY *= 0.98;
$this->speedZ *= $horizontalMultiplyFactor;
}
if($this->speedX != 0){ if($this->speedX != 0){
$this->x += $this->speedX; $this->x += $this->speedX;
$update = true; $update = true;
@ -587,26 +590,10 @@ class Entity extends Position
} }
if($this->speedY != 0){ if($this->speedY != 0){
$ny = $this->y + $this->speedY; $ny = $this->y + $this->speedY;
if($this->class === ENTITY_FALLING && $ny <= $this->y){ if($this->class === ENTITY_FALLING && $support){
$x = (int) ($this->x - 0.5); $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->data["Tile"], 0);
$z = (int) ($this->z - 0.5); $this->close();
$lim = (int) floor($ny); return;
for($y = floor($this->y); $y >= $lim; --$y){
if(StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z))){
//$support = true;
$this->y = $ny;
$fall = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y)), intval($this->z - 0.5)));
$down = $this->level->getBlock(new Vector3(intval($this->x - 0.5), intval(ceil($this->y) - 1), intval($this->z - 0.5)));
if($fall->isFullBlock === false or $down->isFullBlock === false){
$this->server->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"] & 0xFFFF, 0, 1), true);
} else{
$this->level->setBlock($fall, BlockAPI::get($this->data["Tile"]), true, false, true);
}
$this->server->api->handle("entity.motion", $this);
$this->close();
return false;
}
}
} }
$this->y = $ny; $this->y = $ny;
@ -700,7 +687,7 @@ class Entity extends Position
if($this->lastHeadYaw != $this->headYaw){ if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw(); $this->sendHeadYaw();
} }
if($this->class !== ENTITY_PLAYER && $update){ if($this->isPlayer() || $update){
$this->updateMovement(); $this->updateMovement();
} }