Fixed AxisAlignedBB infinite expansion

This commit is contained in:
Shoghi Cervantes 2014-08-28 21:11:49 +02:00
parent 9fb46d8fe8
commit e2986992c7
4 changed files with 37 additions and 54 deletions

View File

@ -1065,7 +1065,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return true; return true;
} }
$hasUpdate = $this->entityBaseTick(); $hasUpdate = $this->entityBaseTick();
foreach($this->getLevel()->getNearbyEntities($this->boundingBox->expand(1, 1, 1), $this) as $entity){ foreach($this->getLevel()->getNearbyEntities($this->boundingBox->grow(1, 1, 1), $this) as $entity){
if($entity instanceof DroppedItem){ if($entity instanceof DroppedItem){
if($entity->dead !== true and $entity->getPickupDelay() <= 0){ if($entity->dead !== true and $entity->getPickupDelay() <= 0){
$item = $entity->getItem(); $item = $entity->getItem();
@ -1314,43 +1314,33 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
$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->distance($newPos) <= 0.7){
$this->forceMovement = false;
}else{
$this->setPosition($this->forceMovement);
}
}*/
/*$speed = $this->entity->getSpeedMeasure();
if($this->blocked === true or ($this->server->api->getProperty("allow-flight") !== true and (($speed > 9 and ($this->gamemode & 0x01) === 0x00) or $speed > 20 or $this->entity->distance($newPos) > 7)) or $this->server->api->handle("player.move", $this->entity) === false){
if($this->lastCorrect instanceof Vector3){
$this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false);
}
if($this->blocked !== true){
$this->server->getLogger()->warning($this->username." moved too quickly!");
}
}else{*/
$dy = $newPos->y - $this->y;
if(($this->onGround and $dy != 0) or (!$this->onGround and $dy <= 0)){
if(count($this->getLevel()->getCollisionBlocks($this->boundingBox->getOffsetBoundingBox(0, $dy - 0.1, 0))) > 0){
$isColliding = true;
}else{
$isColliding = false;
}
$this->onGround = ($dy <= 0 and $isColliding);
}
$this->updateFallState($dy, $this->onGround);
$revert = false; $revert = false;
if($this->chunk === null or !$this->chunk->isGenerated()){ if($newPos->distance($this) > 100){
$chunk = $this->getLevel()->getChunkAt($newPos->x >> 4, $newPos->z >> 4); $this->server->getLogger()->warning($this->username." moved too quickly!");
if(!($chunk instanceof FullChunk) or !$chunk->isGenerated()){ $revert = true;
$revert = true; }else{
$dy = $newPos->y - $this->y;
if(($this->onGround and $dy != 0) or (!$this->onGround and $dy <= 0)){
if(count($this->getLevel()->getCollisionBlocks($this->boundingBox->getOffsetBoundingBox(0, $dy - 0.1, 0))) > 0){
$isColliding = true;
}else{
$isColliding = false;
}
$this->onGround = ($dy <= 0 and $isColliding);
}
$this->updateFallState($dy, $this->onGround);
if($this->chunk === null or !$this->chunk->isGenerated()){
$chunk = $this->getLevel()->getChunkAt($newPos->x >> 4, $newPos->z >> 4);
if(!($chunk instanceof FullChunk) or !$chunk->isGenerated()){
$revert = true;
}
} }
} }

View File

@ -2011,6 +2011,7 @@ class Server{
return; return;
} }
} }
echo "Sending usage\n";
$plist = ""; $plist = "";
foreach($this->getPluginManager()->getPlugins() as $p){ foreach($this->getPluginManager()->getPlugins() as $p){
$d = $p->getDescription(); $d = $p->getDescription();

View File

@ -158,7 +158,7 @@ abstract class Entity extends Position implements Metadatable{
$this->justCreated = true; $this->justCreated = true;
$this->namedtag = $nbt; $this->namedtag = $nbt;
$this->chunk = $chunk; $this->chunk = $chunk;
$this->setLevel($chunk->getProvider()->getLevel()); //Create a hard reference $this->setLevel($chunk->getProvider()->getLevel());
$this->server = $chunk->getProvider()->getLevel()->getServer(); $this->server = $chunk->getProvider()->getLevel()->getServer();
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
@ -1014,8 +1014,6 @@ abstract class Entity extends Position implements Metadatable{
$this->chunk->addEntity($this); $this->chunk->addEntity($this);
} }
$this->scheduleUpdate();
return true; return true;
} }

View File

@ -666,10 +666,8 @@ class Level implements ChunkManager, Metadatable{
for($z = $minZ; $z < $maxZ; ++$z){ for($z = $minZ; $z < $maxZ; ++$z){
for($x = $minX; $x < $maxX; ++$x){ for($x = $minX; $x < $maxX; ++$x){
if($this->isChunkLoaded($x >> 4, $z >> 4)){ for($y = $minY - 1; $y < $maxY; ++$y){
for($y = $minY - 1; $y < $maxY; ++$y){ $this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
}
} }
} }
} }
@ -707,15 +705,13 @@ class Level implements ChunkManager, Metadatable{
//TODO: optimize this loop, check collision cube boundaries //TODO: optimize this loop, check collision cube boundaries
for($z = $minZ; $z < $maxZ; ++$z){ for($z = $minZ; $z < $maxZ; ++$z){
for($x = $minX; $x < $maxX; ++$x){ for($x = $minX; $x < $maxX; ++$x){
if($this->isChunkLoaded($x >> 4, $z >> 4)){ for($y = $minY - 1; $y < $maxY; ++$y){
for($y = $minY - 1; $y < $maxY; ++$y){ $this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
}
} }
} }
} }
foreach($this->getCollidingEntities($bb->expand(0.25, 0.25, 0.25), $entity) as $ent){ foreach($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent){
$collides[] = clone $ent->boundingBox; $collides[] = clone $ent->boundingBox;
} }
@ -1096,11 +1092,9 @@ class Level implements ChunkManager, Metadatable{
for($x = $minX; $x <= $maxX; ++$x){ for($x = $minX; $x <= $maxX; ++$x){
for($z = $minZ; $z <= $maxZ; ++$z){ for($z = $minZ; $z <= $maxZ; ++$z){
if($this->isChunkLoaded($x, $z)){ foreach($this->getChunkEntities($x, $z) as $ent){
foreach($this->getChunkEntities($x, $z) as $ent){ if($ent !== $entity and ($entity === null or ($ent->canCollideWith($entity) and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){
if($ent !== $entity and ($entity === null or ($ent->canCollideWith($entity) and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){ $nearby[] = $ent;
$nearby[] = $ent;
}
} }
} }
} }
@ -1199,7 +1193,7 @@ class Level implements ChunkManager, Metadatable{
* @return Entity[] * @return Entity[]
*/ */
public function getChunkEntities($X, $Z){ public function getChunkEntities($X, $Z){
return $this->getChunkAt($X, $Z, true)->getEntities(); return ($chunk = $this->getChunkAt($X, $Z)) instanceof FullChunk ? $chunk->getEntities() : [];
} }
/** /**
@ -1211,7 +1205,7 @@ class Level implements ChunkManager, Metadatable{
* @return Tile[] * @return Tile[]
*/ */
public function getChunkTiles($X, $Z){ public function getChunkTiles($X, $Z){
return $this->getChunkAt($X, $Z, true)->getTiles(); return ($chunk = $this->getChunkAt($X, $Z)) instanceof FullChunk ? $chunk->getTiles() : [];
} }
/** /**