mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-20 18:06:40 +00:00
Merge branch 'master' into 0.10
This commit is contained in:
commit
1818e64c8e
@ -874,7 +874,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
//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){
|
||||
|
@ -197,15 +197,18 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
|
||||
$blocks = [];
|
||||
$nextIndex = 0;
|
||||
|
||||
$itr = new BlockIterator($this->level, $this->getPosition(), $this->getDirectionVector(), $this->getEyeHeight(), $maxDistance);
|
||||
|
||||
while($itr->valid()){
|
||||
$itr->next();
|
||||
$block = $itr->current();
|
||||
$blocks[] = $block;
|
||||
$blocks[$nextIndex++] = $block;
|
||||
|
||||
if($maxLength !== 0 and count($blocks) > $maxLength){
|
||||
array_shift($blocks);
|
||||
--$nextIndex;
|
||||
}
|
||||
|
||||
$id = $block->getID();
|
||||
|
@ -1366,13 +1366,10 @@ class Level implements ChunkManager, Metadatable{
|
||||
if($pos instanceof Position and $pos->getLevel() !== $this){
|
||||
return null;
|
||||
}
|
||||
$tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4);
|
||||
if(count($tiles) > 0){
|
||||
foreach($tiles as $tile){
|
||||
if($tile->x === (int) $pos->x and $tile->y === (int) $pos->y and $tile->z === (int) $pos->z){
|
||||
return $tile;
|
||||
}
|
||||
}
|
||||
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4);
|
||||
|
||||
if($chunk instanceof FullChunk){
|
||||
return $chunk->getTile($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -226,6 +226,13 @@ interface FullChunk{
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -37,6 +37,9 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
/** @var Tile[] */
|
||||
protected $tiles = [];
|
||||
|
||||
/** @var Tile[] */
|
||||
protected $tileList = [];
|
||||
|
||||
/** @var string */
|
||||
protected $biomeIds;
|
||||
|
||||
@ -234,11 +237,13 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
|
||||
public function addTile(Tile $tile){
|
||||
$this->tiles[$tile->getID()] = $tile;
|
||||
$this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)] = $tile;
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
public function removeTile(Tile $tile){
|
||||
unset($this->tiles[$tile->getID()]);
|
||||
unset($this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)]);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -250,6 +255,11 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
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(){
|
||||
return $this->getProvider() === null ? false : $this->getProvider()->isChunkLoaded($this->getX(), $this->getZ());
|
||||
}
|
||||
|
@ -38,9 +38,11 @@ class BlockIterator implements \Iterator{
|
||||
|
||||
private $end = false;
|
||||
|
||||
/** @var Block[] */
|
||||
private $blockQueue = [null, null, null];
|
||||
/** @var \SplFixedArray<Block>[3] */
|
||||
private $blockQueue;
|
||||
private $currentBlock = 0;
|
||||
/** @var Block */
|
||||
private $currentBlockObject = null;
|
||||
private $currentDistance = 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){
|
||||
$this->level = $level;
|
||||
$this->maxDistance = (int) $maxDistance;
|
||||
$this->blockQueue = new \SplFixedArray(3);
|
||||
|
||||
$startClone = new Vector3($start->x, $start->y, $start->z);
|
||||
$startClone->y += $yOffset;
|
||||
@ -163,7 +166,7 @@ class BlockIterator implements \Iterator{
|
||||
}
|
||||
|
||||
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));
|
||||
@ -219,20 +222,28 @@ class BlockIterator implements \Iterator{
|
||||
if($this->currentBlock <= -1){
|
||||
throw new \OutOfBoundsException;
|
||||
}else{
|
||||
--$this->currentBlock;
|
||||
$this->currentBlockObject = $this->blockQueue[$this->currentBlock--];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block
|
||||
*
|
||||
* @throws \OutOfBoundsException
|
||||
*/
|
||||
public function current(){
|
||||
return $this->blockQueue[$this->currentBlock];
|
||||
if($this->currentBlockObject === null){
|
||||
throw new \OutOfBoundsException;
|
||||
}
|
||||
return $this->currentBlockObject;
|
||||
}
|
||||
|
||||
public function rewind(){
|
||||
|
||||
throw new \InvalidStateException("BlockIterator doesn't support rewind()");
|
||||
}
|
||||
|
||||
public function key(){
|
||||
return $this->currentBlock;
|
||||
return $this->currentBlock - 1;
|
||||
}
|
||||
|
||||
public function valid(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user