Merge branch 'master' into 0.10

This commit is contained in:
Shoghi Cervantes 2014-11-06 18:56:47 +01:00
commit 1818e64c8e
6 changed files with 44 additions and 16 deletions

View File

@ -874,7 +874,7 @@ abstract class Entity extends Location implements Metadatable{
//TODO: big messy loop //TODO: big messy loop
}*/ }*/
$list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false); $list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz));
foreach($list as $bb){ foreach($list as $bb){

View File

@ -197,15 +197,18 @@ abstract class Living extends Entity implements Damageable{
} }
$blocks = []; $blocks = [];
$nextIndex = 0;
$itr = new BlockIterator($this->level, $this->getPosition(), $this->getDirectionVector(), $this->getEyeHeight(), $maxDistance); $itr = new BlockIterator($this->level, $this->getPosition(), $this->getDirectionVector(), $this->getEyeHeight(), $maxDistance);
while($itr->valid()){ while($itr->valid()){
$itr->next(); $itr->next();
$block = $itr->current(); $block = $itr->current();
$blocks[] = $block; $blocks[$nextIndex++] = $block;
if($maxLength !== 0 and count($blocks) > $maxLength){ if($maxLength !== 0 and count($blocks) > $maxLength){
array_shift($blocks); array_shift($blocks);
--$nextIndex;
} }
$id = $block->getID(); $id = $block->getID();

View File

@ -1366,13 +1366,10 @@ class Level implements ChunkManager, Metadatable{
if($pos instanceof Position and $pos->getLevel() !== $this){ if($pos instanceof Position and $pos->getLevel() !== $this){
return null; return null;
} }
$tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4); $chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4);
if(count($tiles) > 0){
foreach($tiles as $tile){ if($chunk instanceof FullChunk){
if($tile->x === (int) $pos->x and $tile->y === (int) $pos->y and $tile->z === (int) $pos->z){ return $chunk->getTile($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f);
return $tile;
}
}
} }
return null; return null;

View File

@ -226,6 +226,13 @@ interface FullChunk{
*/ */
public function getTiles(); public function getTiles();
/**
* @param int $x 0-15
* @param int $y 0-127
* @param int $z 0-15
*/
public function getTile($x, $y, $z);
/** /**
* @return bool * @return bool
*/ */

View File

@ -37,6 +37,9 @@ abstract class BaseFullChunk implements FullChunk{
/** @var Tile[] */ /** @var Tile[] */
protected $tiles = []; protected $tiles = [];
/** @var Tile[] */
protected $tileList = [];
/** @var string */ /** @var string */
protected $biomeIds; protected $biomeIds;
@ -234,11 +237,13 @@ abstract class BaseFullChunk implements FullChunk{
public function addTile(Tile $tile){ public function addTile(Tile $tile){
$this->tiles[$tile->getID()] = $tile; $this->tiles[$tile->getID()] = $tile;
$this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)] = $tile;
$this->hasChanged = true; $this->hasChanged = true;
} }
public function removeTile(Tile $tile){ public function removeTile(Tile $tile){
unset($this->tiles[$tile->getID()]); unset($this->tiles[$tile->getID()]);
unset($this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)]);
$this->hasChanged = true; $this->hasChanged = true;
} }
@ -250,6 +255,11 @@ abstract class BaseFullChunk implements FullChunk{
return $this->tiles; return $this->tiles;
} }
public function getTile($x, $y, $z){
$index = ($z << 8) | ($x << 4) | $y;
return isset($this->tileList[$index]) ? $this->tileList[$index] : null;
}
public function isLoaded(){ public function isLoaded(){
return $this->getProvider() === null ? false : $this->getProvider()->isChunkLoaded($this->getX(), $this->getZ()); return $this->getProvider() === null ? false : $this->getProvider()->isChunkLoaded($this->getX(), $this->getZ());
} }

View File

@ -38,9 +38,11 @@ class BlockIterator implements \Iterator{
private $end = false; private $end = false;
/** @var Block[] */ /** @var \SplFixedArray<Block>[3] */
private $blockQueue = [null, null, null]; private $blockQueue;
private $currentBlock = 0; private $currentBlock = 0;
/** @var Block */
private $currentBlockObject = null;
private $currentDistance = 0; private $currentDistance = 0;
private $maxDistanceInt = 0; private $maxDistanceInt = 0;
@ -57,6 +59,7 @@ class BlockIterator implements \Iterator{
public function __construct(Level $level, Vector3 $start, Vector3 $direction, $yOffset = 0, $maxDistance = 0){ public function __construct(Level $level, Vector3 $start, Vector3 $direction, $yOffset = 0, $maxDistance = 0){
$this->level = $level; $this->level = $level;
$this->maxDistance = (int) $maxDistance; $this->maxDistance = (int) $maxDistance;
$this->blockQueue = new \SplFixedArray(3);
$startClone = new Vector3($start->x, $start->y, $start->z); $startClone = new Vector3($start->x, $start->y, $start->z);
$startClone->y += $yOffset; $startClone->y += $yOffset;
@ -163,7 +166,7 @@ class BlockIterator implements \Iterator{
} }
if(!$startBlockFound){ if(!$startBlockFound){
throw new \RuntimeException("Start block missed in BlockIterator"); throw new \InvalidStateException("Start block missed in BlockIterator");
} }
$this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection)); $this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection));
@ -219,20 +222,28 @@ class BlockIterator implements \Iterator{
if($this->currentBlock <= -1){ if($this->currentBlock <= -1){
throw new \OutOfBoundsException; throw new \OutOfBoundsException;
}else{ }else{
--$this->currentBlock; $this->currentBlockObject = $this->blockQueue[$this->currentBlock--];
} }
} }
/**
* @return Block
*
* @throws \OutOfBoundsException
*/
public function current(){ public function current(){
return $this->blockQueue[$this->currentBlock]; if($this->currentBlockObject === null){
throw new \OutOfBoundsException;
}
return $this->currentBlockObject;
} }
public function rewind(){ public function rewind(){
throw new \InvalidStateException("BlockIterator doesn't support rewind()");
} }
public function key(){ public function key(){
return $this->currentBlock; return $this->currentBlock - 1;
} }
public function valid(){ public function valid(){