better(hopefully) onground check

This commit is contained in:
GameHerobrine 2025-05-14 04:30:41 +03:00
parent 1cbd62629a
commit a8f504ad88
2 changed files with 71 additions and 17 deletions

View file

@ -729,7 +729,7 @@ class Player{
}else{ }else{
$level = $pos->level; $level = $pos->level;
} }
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); $this->spawnPosition = new Position($pos->x, $pos->y + 1, $pos->z, $level);
$pk = new SetSpawnPositionPacket; $pk = new SetSpawnPositionPacket;
$pk->x = (int) $this->spawnPosition->x; $pk->x = (int) $this->spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y; $pk->y = (int) $this->spawnPosition->y;
@ -1731,7 +1731,7 @@ class Player{
$pk = new StartGamePacket; $pk = new StartGamePacket;
$pk->seed = $this->level->getSeed(); $pk->seed = $this->level->getSeed();
$pk->x = $this->data->get("position")["x"]; $pk->x = $this->data->get("position")["x"];
$pk->y = ceil($this->data->get("position")["y"]); $pk->y = $this->data->get("position")["y"]+1;
$pk->z = $this->data->get("position")["z"]; $pk->z = $this->data->get("position")["z"];
$pk->generator = 0; $pk->generator = 0;
$pk->gamemode = $this->gamemode & 0x01; $pk->gamemode = $this->gamemode & 0x01;
@ -1857,7 +1857,7 @@ class Player{
break; break;
} }
if($this->isSleeping) break; if($this->isSleeping) break;
if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){ if(($this->entity instanceof Entity) && $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);
if($this->forceMovement instanceof Vector3){ if($this->forceMovement instanceof Vector3){
@ -1877,6 +1877,8 @@ class Player{
$this->entity->setPosition($newPos, $packet->yaw, $packet->pitch, $packet->bodyYaw); $this->entity->setPosition($newPos, $packet->yaw, $packet->pitch, $packet->bodyYaw);
} }
$this->entity->updateAABB(); $this->entity->updateAABB();
}else{
console("skipping movement packet");
} }
break; break;
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:

View file

@ -787,32 +787,84 @@ class Entity extends Position
$bbbottom->minZ = round($this->z, 3) - $this->radius; $bbbottom->minZ = round($this->z, 3) - $this->radius;
$bbbottom->maxZ = round($this->z, 3) + $this->radius; $bbbottom->maxZ = round($this->z, 3) + $this->radius;
$handleFire = false; $maxx = $this->x;
$handleCactus = false; $minx = $this->lastX;
for($x = floor($this->boundingBox->minX); $x < ceil($this->boundingBox->maxX); ++$x){ $maxy = $this->y;
for($z = floor($this->boundingBox->minZ); $z < ceil($this->boundingBox->maxZ); ++$z){ $miny = $this->lastY;
for($y = floor($this->boundingBox->minY - 1); $y < ceil($this->boundingBox->maxY); ++$y){ $maxz = $this->z;
$intersects = 0; $minz = $this->lastZ;
if($this->x < $this->lastX){
$minx = $this->x;
$maxx = $this->lastX;
}
if($this->y < $this->lastY){
$miny = $this->y;
$maxy = $this->lastY;
}
if($this->z < $this->lastZ){
$minz = $this->z;
$maxz = $this->lastZ;
}
$useOldGroundCheck = false;
$distBetweenLastAndCurrent = sqrt(($this->lastX-$this->x)*($this->lastX-$this->x) + ($this->lastY-$this->y)*($this->lastY-$this->y) + ($this->lastZ-$this->z)*($this->lastZ-$this->z));
if($distBetweenLastAndCurrent > 10){
ConsoleAPI::warn("{$this->player} is moving too fast! (Old: {$this->lastX} {$this->lastY} {$this->lastZ}, New: {$this->x} {$this->y} {$this->z}). Skipping new onground check!");
$useOldGroundCheck = true;
goto skip_new_onground_check;
}
$bbGround = new AxisAlignedBB($minx - $this->radius, $miny, $minz - $this->radius, $maxx + $this->radius, $maxy, $maxz + $this->radius);
for($x = floor($bbGround->minX); $x <= ceil($bbGround->maxX); ++$x){
for($z = floor($bbGround->minZ); $z <= ceil($bbGround->maxZ); ++$z){
for($y = floor($bbGround->minY-1); $y <= ceil($bbGround->maxY); ++$y){
$id = $this->level->level->getBlockID($x, $y, $z); $id = $this->level->level->getBlockID($x, $y, $z);
$bounds = StaticBlock::$prealloc[$id]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this); $bounds = StaticBlock::$prealloc[$id]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this);
foreach($bounds as $bb){ foreach($bounds as $bb){
if($bbbottom->intersectsWith($bb)){ if($bbGround->intersectsWith($bb)){
++$intersects; $this->onGround = true;
} }
} }
}
}
}
skip_new_onground_check:
$handleFire = false;
$handleCactus = false;
for($x = floor($this->boundingBox->minX); $x < ceil($this->boundingBox->maxX); ++$x){
for($z = floor($this->boundingBox->minZ); $z < ceil($this->boundingBox->maxZ); ++$z){
for($y = floor($this->boundingBox->minY - 1); $y < ceil($this->boundingBox->maxY); ++$y){
[$id, $meta] = $this->level->level->getBlock($x, $y, $z);
if($useOldGroundCheck){
$intersects = 0;
$bounds = StaticBlock::$prealloc[$id]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this);
foreach($bounds as $bb){
if($bbbottom->intersectsWith($bb)){
++$intersects;
}
}
}
if($id == WATER || $id === STILL_WATER || $id === COBWEB || $id == LAVA || $id === STILL_LAVA){ if($id == WATER || $id === STILL_WATER || $id === COBWEB || $id == LAVA || $id === STILL_LAVA){
$this->notOnGroundTicks = 0; $this->notOnGroundTicks = 0;
} }
intersects: if($useOldGroundCheck){
if($y <= floor($this->boundingBox->minY) && !$this->onGround){ intersects:
if($intersects > 0) $this->onGround = count($bounds) > 0; if($y <= floor($this->boundingBox->minY) && !$this->onGround){
if($intersects > 0) $this->onGround = count($bounds) > 0;
}
} }
if($y >= floor($this->boundingBox->minY)){ if($y >= floor($this->boundingBox->minY)){
$block = $this->level->level->getBlock($x, $y, $z);
$id = $block[0];
$meta = $block[1];
$handleFire = $handleFire || (($id == FIRE || $id == STILL_LAVA || $id == LAVA) && $x >= $fireMinX && $x < $fireMaxX && $y >= $fireMinY && $y < $fireMaxY && $z >= $fireMinZ && $z < $fireMaxZ); $handleFire = $handleFire || (($id == FIRE || $id == STILL_LAVA || $id == LAVA) && $x >= $fireMinX && $x < $fireMaxX && $y >= $fireMinY && $y < $fireMaxY && $z >= $fireMinZ && $z < $fireMaxZ);
$handleCactus = $handleCactus || ($id == CACTUS && $x >= $fireMinX && $x < $fireMaxX && $y >= $fireMinY && $y < $fireMaxY && $z >= $fireMinZ && $z < $fireMaxZ); $handleCactus = $handleCactus || ($id == CACTUS && $x >= $fireMinX && $x < $fireMaxX && $y >= $fireMinY && $y < $fireMaxY && $z >= $fireMinZ && $z < $fireMaxZ);