Improved safe spawn calculation, fixes #3094

This commit is contained in:
Shoghi Cervantes 2015-06-13 14:43:14 +02:00
parent f490ff8074
commit 2ac27bd382
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89

View File

@ -1061,6 +1061,9 @@ class Level implements ChunkManager, Metadatable{
*/ */
public function isFullBlock(Vector3 $pos){ public function isFullBlock(Vector3 $pos){
if($pos instanceof Block){ if($pos instanceof Block){
if($pos->isSolid()){
return true;
}
$bb = $pos->getBoundingBox(); $bb = $pos->getBoundingBox();
}else{ }else{
$bb = $this->getBlock($pos)->getBoundingBox(); $bb = $this->getBlock($pos)->getBoundingBox();
@ -2513,26 +2516,36 @@ class Level implements ChunkManager, Metadatable{
$spawn = $this->getSpawnLocation(); $spawn = $this->getSpawnLocation();
} }
if($spawn instanceof Vector3){ if($spawn instanceof Vector3){
$v = $spawn->round(); $v = $spawn->floor();
$chunk = $this->getChunk($v->x >> 4, $v->z >> 4, false); $chunk = $this->getChunk($v->x >> 4, $v->z >> 4, false);
$x = $v->x & 0x0f; $x = $v->x & 0x0f;
$z = $v->z & 0x0f; $z = $v->z & 0x0f;
if($chunk !== null){ if($chunk !== null){
for(; $v->y > 0; --$v->y){ $y = (int) min(127, $v->y);
if($v->y < 127 and Block::$solid[$chunk->getBlockId($x, $v->y & 0x7f, $z)]){ for(; $y > 0; --$y){
$v->y++; $b = $chunk->getFullBlock($x, $y, $z);
$block = Block::get($b >> 4, $b & 0x0f);
if($this->isFullBlock($block)){
$y++;
break; break;
} }
} }
for(; $v->y >= 0 and $v->y < 128; ++$v->y){
if(!Block::$solid[$chunk->getBlockId($x, $v->y + 1, $z)]){ for(; $y >= 0 and $y < 128; ++$y){
if(!Block::$solid[$chunk->getBlockId($x, $v->y, $z)]){ $b = $chunk->getFullBlock($x, $y + 1, $z);
return new Position($spawn->x, $v->y === (int) $spawn->y ? $spawn->y : $v->y, $spawn->z, $this); $block = Block::get($b >> 4, $b & 0x0f);
if(!$this->isFullBlock($block)){
$b = $chunk->getFullBlock($x, $y, $z);
$block = Block::get($b >> 4, $b & 0x0f);
if(!$this->isFullBlock($block)){
return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this);
} }
}else{ }else{
++$v->y; ++$y;
} }
} }
$v->y = $y;
} }
return new Position($spawn->x, $v->y, $spawn->z, $this); return new Position($spawn->x, $v->y, $spawn->z, $this);