mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +00:00
fixed entities falling through the ground
This commit is contained in:
parent
403eb71aa6
commit
bf1169b3f2
7 changed files with 66 additions and 38 deletions
|
|
@ -211,7 +211,7 @@ class EntityAPI{
|
|||
$minChunkX = ((int)($center->x - $radius)) >> 4;
|
||||
$minChunkZ = ((int)($center->z - $radius)) >> 4;
|
||||
$maxChunkX = ((int)($center->x + $radius)) >> 4;
|
||||
$maxChunkZ = ((int)($center->z - $radius)) >> 4;
|
||||
$maxChunkZ = ((int)($center->z + $radius)) >> 4;
|
||||
$ents = [];
|
||||
//TODO also index by chunkY?
|
||||
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class Player{
|
|||
$this->blockUpdateQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
|
||||
$this->blockUpdateQueue->data = [];
|
||||
|
||||
$this->server->schedule(20 * 60, [$this, "clearQueue"], [], true);
|
||||
//$this->server->schedule(20 * 60, [$this, "clearQueue"], [], true);
|
||||
$this->server->schedule(1, [$this, "handlePacketQueues"], [], true);
|
||||
|
||||
$this->evid[] = $this->server->event("server.close", [$this, "close"]);
|
||||
|
|
|
|||
|
|
@ -728,7 +728,7 @@ class PocketMinecraftServer{
|
|||
$info["tps"] = $this->getTPS();
|
||||
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2) . "MB";
|
||||
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2) . "MB";
|
||||
$info["entities"] = count($this->entities);
|
||||
$info["entities"] = count($this->api->entity->entities);
|
||||
$info["players"] = count($this->clients);
|
||||
$info["events"] = count($this->eventsID);
|
||||
$info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true);
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ class Entity extends Position
|
|||
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true && ! $this->dead){
|
||||
$myBB = $this->boundingBox->grow(1, 0.5, 1);
|
||||
foreach($this->server->api->entity->getRadius($this, 2, ENTITY_ITEM) as $item){
|
||||
if(!$item->closed && $item->spawntime > 0 && $item->delayBeforePickup == 0){
|
||||
if(!$item->closed && $item->spawntime > 0 && $item->delayBeforePickup <= 0){
|
||||
if($item->boundingBox->intersectsWith($myBB)){
|
||||
if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array(
|
||||
"eid" => $this->player->eid,
|
||||
|
|
@ -530,11 +530,11 @@ class Entity extends Position
|
|||
|
||||
$aABB = $this->boundingBox->addCoord($dx, $dy, $dz);
|
||||
$x0 = floor($aABB->minX);
|
||||
$x1 = ceil($aABB->maxX);
|
||||
$x1 = floor($aABB->maxX) + 1;
|
||||
$y0 = floor($aABB->minY);
|
||||
$y1 = ceil($aABB->maxY);
|
||||
$y1 = floor($aABB->maxY) + 1;
|
||||
$z0 = floor($aABB->minZ);
|
||||
$z1 = ceil($aABB->maxZ);
|
||||
$z1 = floor($aABB->maxZ) + 1;
|
||||
|
||||
for($x = $x0; $x <= $x1; ++$x){
|
||||
for($y = $y0; $y <= $y1; ++$y){
|
||||
|
|
@ -583,7 +583,7 @@ class Entity extends Position
|
|||
$this->boundingBox->offset(0, 0, $dz);
|
||||
|
||||
$dy = -$this->stepHeight;
|
||||
foreach($aaBBs as $bb){ //TODO optimize
|
||||
foreach($aaBBs as $bb){
|
||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||
}
|
||||
$this->boundingBox->offset(0, $dy, 0);
|
||||
|
|
@ -600,25 +600,31 @@ class Entity extends Position
|
|||
|
||||
}
|
||||
|
||||
//TODO step
|
||||
$this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
|
||||
$this->y = $this->boundingBox->minY + $this->yOffset;// - //TODO - used when player is sneaking $this->ySize;
|
||||
$this->y = $this->boundingBox->minY + $this->yOffset;
|
||||
$this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
|
||||
//$this.isCollidedHorizontally = savedDX != dx || savedDZ != dz;
|
||||
//$this.isCollidedVertically = savedDY != dy;
|
||||
$this->onGround = $savedDY != $dy && $savedDY < 0.0;
|
||||
//$this.isCollided = this.isCollidedHorizontally || this.isCollidedVertically;
|
||||
$this->updateFallState($this->speedY);
|
||||
|
||||
|
||||
if($savedDX != $dx) $this->speedX = 0;
|
||||
if($savedDY != $dy) $this->speedY = 0;
|
||||
if($savedDZ != $dz) $this->speedZ = 0;
|
||||
|
||||
|
||||
//TODO more stuff
|
||||
|
||||
//TODO more stuff -> onEntityWalking
|
||||
|
||||
//TODO block collisions?
|
||||
//TODO deal fire damage here
|
||||
|
||||
|
||||
//TODO deal fire damage here
|
||||
if($this->level->isBoundingBoxOnFire($this->boundingBox->contract(0.001, 0.001, 0.001))){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function isInVoid(){
|
||||
|
|
@ -644,6 +650,7 @@ class Entity extends Position
|
|||
if($this->isStatic === false){
|
||||
if(!$this->isPlayer()){
|
||||
$this->updateLast();
|
||||
$this->updatePosition(); //TODO shouldnt be called in Entity
|
||||
$this->updateEntityMovement();
|
||||
/*$update = false;
|
||||
if($this->speedX > -self::MIN_POSSIBLE_SPEED && $this->speedX < self::MIN_POSSIBLE_SPEED){
|
||||
|
|
@ -698,14 +705,11 @@ class Entity extends Position
|
|||
}elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
|
||||
if($update === true){
|
||||
$hasUpdate = true;
|
||||
$this->lastSpeedZ = $this->speedZ;
|
||||
$this->lastSpeedY = $this->speedY;
|
||||
$this->lastSpeedX = $this->speedX;
|
||||
}
|
||||
$this->updateFallState($this->speedY);
|
||||
|
||||
} elseif($this->player instanceof Player){
|
||||
$prevGroundState = $this->onGround;
|
||||
$this->onGround = false;
|
||||
|
|
@ -829,10 +833,7 @@ class Entity extends Position
|
|||
$this->server->api->player->broadcastPacket($players, $pk);
|
||||
}
|
||||
}
|
||||
} else{
|
||||
$this->updatePosition();
|
||||
}
|
||||
|
||||
}
|
||||
$this->lastUpdate = $now;
|
||||
}
|
||||
|
|
@ -1235,13 +1236,16 @@ class Entity extends Position
|
|||
|
||||
public function updateLast()
|
||||
{
|
||||
$this->last[0] = $this->x;
|
||||
$this->last[1] = $this->y;
|
||||
$this->last[2] = $this->z;
|
||||
$this->last[3] = $this->yaw;
|
||||
$this->last[4] = $this->pitch;
|
||||
$this->last[5] = microtime(true);
|
||||
$this->lastX = $this->x;
|
||||
$this->lastY = $this->y;
|
||||
$this->lastZ = $this->z;
|
||||
$this->lastYaw = $this->yaw;
|
||||
$this->lastPitch = $this->pitch;
|
||||
$this->lastTime = microtime(true);
|
||||
$this->lastHeadYaw = $this->headYaw;
|
||||
$this->lastSpeedZ = $this->speedZ;
|
||||
$this->lastSpeedY = $this->speedY;
|
||||
$this->lastSpeedX = $this->speedX;
|
||||
}
|
||||
|
||||
public function getPosition($round = false)
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ class ItemEntity extends Entity{
|
|||
$this->stepHeight = 0;
|
||||
}
|
||||
|
||||
public function counterUpdate(){
|
||||
parent::counterUpdate();
|
||||
if($this->delayBeforePickup > 0) --$this->delayBeforePickup;
|
||||
}
|
||||
|
||||
public function updateEntityMovement(){
|
||||
//TODO it is weird on client side for some reason
|
||||
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
|
||||
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
|
||||
if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0;
|
||||
|
||||
$this->speedY -= 0.04;
|
||||
$this->noClip = false; //TODO pushOutofBlocks
|
||||
$this->move($this->speedX, $this->speedY, $this->speedZ);
|
||||
|
|
@ -54,8 +54,12 @@ class ItemEntity extends Entity{
|
|||
$this->speedY *= 0.98;
|
||||
$this->speedZ *= $friction;
|
||||
|
||||
//if($this->onGround) $this->speedY *= -0.5;
|
||||
if($this->onGround) $this->speedY *= -0.5;
|
||||
|
||||
//TODO ++age; despawn after age >= 6000;
|
||||
|
||||
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
|
||||
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
|
||||
if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ class LeavesBlock extends TransparentBlock{
|
|||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->hardness = 1;
|
||||
}
|
||||
|
||||
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
|
||||
return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)];
|
||||
}
|
||||
|
||||
public static function createIndex($x, $y, $z){
|
||||
return $x.".".$y.".".$z;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,12 +89,6 @@ class Level{
|
|||
$y1 = ceil($aABB->maxY);
|
||||
$z0 = floor($aABB->minZ);
|
||||
$z1 = ceil($aABB->maxZ);
|
||||
$x0 = $x0 < 0 ? 0 : $x0;
|
||||
$y0 = $y0 < 0 ? 0 : $y0;
|
||||
$z0 = $z0 < 0 ? 0 : $z0;
|
||||
$x1 = $x1 > 256 ? 256 : $x1;
|
||||
$y1 = $y1 > 128 ? 128 : $y1;
|
||||
$z1 = $z1 > 256 ? 256 : $z1;
|
||||
|
||||
for($x = $x0; $x <= $x1; ++$x) {
|
||||
for($y = $y0; $y <= $y1; ++$y) {
|
||||
|
|
@ -361,6 +355,7 @@ class Level{
|
|||
if($e instanceof Entity){
|
||||
$newChunkX = (int)$e->x >> 4;
|
||||
$newChunkZ = (int)$e->z >> 4;
|
||||
|
||||
if($e->level != $this && isset($this->entityListPositioned["$curChunkX $curChunkZ"])){
|
||||
unset($this->entityListPositioned["$curChunkX $curChunkZ"][$e->eid]);
|
||||
}else if($curChunkX != $newChunkX || $curChunkZ != $newChunkZ){
|
||||
|
|
@ -406,6 +401,26 @@ class Level{
|
|||
$this->queuedBlockUpdates = [];
|
||||
}
|
||||
|
||||
public function isBoundingBoxOnFire(AxisAlignedBB $bb){
|
||||
$minX = floor($bb->minX);
|
||||
$maxX = ceil($bb->maxX);
|
||||
$minY = floor($bb->minY);
|
||||
$maxY = ceil($bb->maxY);
|
||||
$minZ = floor($bb->minZ);
|
||||
$maxZ = ceil($bb->maxZ);
|
||||
|
||||
for($x = $minX; $x < $maxX; ++$x){
|
||||
for($y = $minY; $y < $maxY; ++$y){
|
||||
for($z = $minZ; $z < $maxZ; ++$z){
|
||||
$blockAt = $this->level->getBlockID($x, $y, $z);
|
||||
if($blockAt == FIRE || $blockAt == STILL_LAVA || $blockAt == LAVA) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getEntitiesInAABB(AxisAlignedBB $bb){
|
||||
$minChunkX = ((int)($bb->minX)) >> 4;
|
||||
$minChunkZ = ((int)($bb->minZ)) >> 4;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue