Skip to content

Commit e298699

Browse files
committed
Fixed AxisAlignedBB infinite expansion
1 parent 9fb46d8 commit e298699

4 files changed

Lines changed: 34 additions & 51 deletions

File tree

src/pocketmine/Player.php

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ public function onUpdate(){
10651065
return true;
10661066
}
10671067
$hasUpdate = $this->entityBaseTick();
1068-
foreach($this->getLevel()->getNearbyEntities($this->boundingBox->expand(1, 1, 1), $this) as $entity){
1068+
foreach($this->getLevel()->getNearbyEntities($this->boundingBox->grow(1, 1, 1), $this) as $entity){
10691069
if($entity instanceof DroppedItem){
10701070
if($entity->dead !== true and $entity->getPickupDelay() <= 0){
10711071
$item = $entity->getItem();
@@ -1314,43 +1314,33 @@ public function handleDataPacket(DataPacket $packet){
13141314
}
13151315

13161316
$newPos = new Vector3($packet->x, $packet->y, $packet->z);
1317-
/*if($this->forceMovement instanceof Vector3){
1318-
if($this->forceMovement->distance($newPos) <= 0.7){
1319-
$this->forceMovement = false;
1320-
}else{
1321-
$this->setPosition($this->forceMovement);
1322-
}
1323-
}*/
1324-
/*$speed = $this->entity->getSpeedMeasure();
1325-
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){
1326-
if($this->lastCorrect instanceof Vector3){
1327-
$this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false);
1328-
}
1329-
if($this->blocked !== true){
1330-
$this->server->getLogger()->warning($this->username." moved too quickly!");
1331-
}
1332-
}else{*/
13331317

1334-
$dy = $newPos->y - $this->y;
1318+
$revert = false;
13351319

1336-
if(($this->onGround and $dy != 0) or (!$this->onGround and $dy <= 0)){
1337-
if(count($this->getLevel()->getCollisionBlocks($this->boundingBox->getOffsetBoundingBox(0, $dy - 0.1, 0))) > 0){
1338-
$isColliding = true;
1339-
}else{
1340-
$isColliding = false;
1341-
}
1320+
if($newPos->distance($this) > 100){
1321+
$this->server->getLogger()->warning($this->username." moved too quickly!");
1322+
$revert = true;
1323+
}else{
1324+
$dy = $newPos->y - $this->y;
13421325

1343-
$this->onGround = ($dy <= 0 and $isColliding);
1344-
}
1326+
if(($this->onGround and $dy != 0) or (!$this->onGround and $dy <= 0)){
1327+
if(count($this->getLevel()->getCollisionBlocks($this->boundingBox->getOffsetBoundingBox(0, $dy - 0.1, 0))) > 0){
1328+
$isColliding = true;
1329+
}else{
1330+
$isColliding = false;
1331+
}
13451332

1346-
$this->updateFallState($dy, $this->onGround);
1333+
$this->onGround = ($dy <= 0 and $isColliding);
1334+
}
1335+
1336+
$this->updateFallState($dy, $this->onGround);
13471337

1348-
$revert = false;
13491338

1350-
if($this->chunk === null or !$this->chunk->isGenerated()){
1351-
$chunk = $this->getLevel()->getChunkAt($newPos->x >> 4, $newPos->z >> 4);
1352-
if(!($chunk instanceof FullChunk) or !$chunk->isGenerated()){
1353-
$revert = true;
1339+
if($this->chunk === null or !$this->chunk->isGenerated()){
1340+
$chunk = $this->getLevel()->getChunkAt($newPos->x >> 4, $newPos->z >> 4);
1341+
if(!($chunk instanceof FullChunk) or !$chunk->isGenerated()){
1342+
$revert = true;
1343+
}
13541344
}
13551345
}
13561346

src/pocketmine/Server.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,7 @@ public function sendUsage(){
20112011
return;
20122012
}
20132013
}
2014+
echo "Sending usage\n";
20142015
$plist = "";
20152016
foreach($this->getPluginManager()->getPlugins() as $p){
20162017
$d = $p->getDescription();

src/pocketmine/entity/Entity.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function __construct(FullChunk $chunk, Compound $nbt){
158158
$this->justCreated = true;
159159
$this->namedtag = $nbt;
160160
$this->chunk = $chunk;
161-
$this->setLevel($chunk->getProvider()->getLevel()); //Create a hard reference
161+
$this->setLevel($chunk->getProvider()->getLevel());
162162
$this->server = $chunk->getProvider()->getLevel()->getServer();
163163

164164
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
@@ -1014,8 +1014,6 @@ public function setPosition(Vector3 $pos, $force = false){
10141014
$this->chunk->addEntity($this);
10151015
}
10161016

1017-
$this->scheduleUpdate();
1018-
10191017
return true;
10201018
}
10211019

src/pocketmine/level/Level.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -666,10 +666,8 @@ public function getCollisionBlocks(AxisAlignedBB $bb){
666666

667667
for($z = $minZ; $z < $maxZ; ++$z){
668668
for($x = $minX; $x < $maxX; ++$x){
669-
if($this->isChunkLoaded($x >> 4, $z >> 4)){
670-
for($y = $minY - 1; $y < $maxY; ++$y){
671-
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
672-
}
669+
for($y = $minY - 1; $y < $maxY; ++$y){
670+
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
673671
}
674672
}
675673
}
@@ -707,15 +705,13 @@ public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb){
707705
//TODO: optimize this loop, check collision cube boundaries
708706
for($z = $minZ; $z < $maxZ; ++$z){
709707
for($x = $minX; $x < $maxX; ++$x){
710-
if($this->isChunkLoaded($x >> 4, $z >> 4)){
711-
for($y = $minY - 1; $y < $maxY; ++$y){
712-
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
713-
}
708+
for($y = $minY - 1; $y < $maxY; ++$y){
709+
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
714710
}
715711
}
716712
}
717713

718-
foreach($this->getCollidingEntities($bb->expand(0.25, 0.25, 0.25), $entity) as $ent){
714+
foreach($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent){
719715
$collides[] = clone $ent->boundingBox;
720716
}
721717

@@ -1096,11 +1092,9 @@ public function getCollidingEntities(AxisAlignedBB $bb, Entity $entity = null){
10961092

10971093
for($x = $minX; $x <= $maxX; ++$x){
10981094
for($z = $minZ; $z <= $maxZ; ++$z){
1099-
if($this->isChunkLoaded($x, $z)){
1100-
foreach($this->getChunkEntities($x, $z) as $ent){
1101-
if($ent !== $entity and ($entity === null or ($ent->canCollideWith($entity) and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){
1102-
$nearby[] = $ent;
1103-
}
1095+
foreach($this->getChunkEntities($x, $z) as $ent){
1096+
if($ent !== $entity and ($entity === null or ($ent->canCollideWith($entity) and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){
1097+
$nearby[] = $ent;
11041098
}
11051099
}
11061100
}
@@ -1199,7 +1193,7 @@ public function getTile(Vector3 $pos){
11991193
* @return Entity[]
12001194
*/
12011195
public function getChunkEntities($X, $Z){
1202-
return $this->getChunkAt($X, $Z, true)->getEntities();
1196+
return ($chunk = $this->getChunkAt($X, $Z)) instanceof FullChunk ? $chunk->getEntities() : [];
12031197
}
12041198

12051199
/**
@@ -1211,7 +1205,7 @@ public function getChunkEntities($X, $Z){
12111205
* @return Tile[]
12121206
*/
12131207
public function getChunkTiles($X, $Z){
1214-
return $this->getChunkAt($X, $Z, true)->getTiles();
1208+
return ($chunk = $this->getChunkAt($X, $Z)) instanceof FullChunk ? $chunk->getTiles() : [];
12151209
}
12161210

12171211
/**

0 commit comments

Comments
 (0)