Merge branch 'master' into tools-refactor

This commit is contained in:
Dylan K. Taylor 2017-12-13 11:26:24 +00:00
commit 015cde2169
2 changed files with 14 additions and 9 deletions

View File

@ -75,7 +75,7 @@ class ItemFrame extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_DOWN or $face === Vector3::SIDE_UP){ if($face === Vector3::SIDE_DOWN or $face === Vector3::SIDE_UP or !$blockClicked->isSolid()){
return false; return false;
} }

View File

@ -1456,8 +1456,13 @@ class Level implements ChunkManager, Metadatable{
$index = Level::blockHash($x, $y, $z); $index = Level::blockHash($x, $y, $z);
if($cached and isset($this->blockCache[$index])){ if($cached and isset($this->blockCache[$index])){
return $this->blockCache[$index]; return $this->blockCache[$index];
}elseif(isset($this->chunks[$chunkIndex = Level::chunkHash($x >> 4, $z >> 4)])){ }
$fullState = $this->chunks[$chunkIndex]->getFullBlock($x & 0x0f, $y, $z & 0x0f);
$chunk = $this->chunks[$chunkIndex = Level::chunkHash($x >> 4, $z >> 4)] ?? null;
if($chunk !== null){
$fullState = $chunk->getFullBlock($x & 0x0f, $y, $z & 0x0f);
}else{
$addToCache = false;
} }
} }
@ -1607,7 +1612,7 @@ class Level implements ChunkManager, Metadatable{
$block->position($pos); $block->position($pos);
$block->clearCaches(); $block->clearCaches();
unset($this->blockCache[Level::blockHash($pos->x, $pos->y, $pos->z)]); unset($this->blockCache[$blockHash = Level::blockHash($pos->x, $pos->y, $pos->z)]);
$index = Level::chunkHash($pos->x >> 4, $pos->z >> 4); $index = Level::chunkHash($pos->x >> 4, $pos->z >> 4);
@ -1619,7 +1624,7 @@ class Level implements ChunkManager, Metadatable{
$this->changedBlocks[$index] = []; $this->changedBlocks[$index] = [];
} }
$this->changedBlocks[$index][Level::blockHash($block->x, $block->y, $block->z)] = clone $block; $this->changedBlocks[$index][$blockHash] = clone $block;
} }
foreach($this->getChunkLoaders($pos->x >> 4, $pos->z >> 4) as $loader){ foreach($this->getChunkLoaders($pos->x >> 4, $pos->z >> 4) as $loader){
@ -2141,13 +2146,13 @@ class Level implements ChunkManager, Metadatable{
* @param int $id 0-255 * @param int $id 0-255
*/ */
public function setBlockIdAt(int $x, int $y, int $z, int $id){ public function setBlockIdAt(int $x, int $y, int $z, int $id){
unset($this->blockCache[Level::blockHash($x, $y, $z)]); unset($this->blockCache[$blockHash = Level::blockHash($x, $y, $z)]);
$this->getChunk($x >> 4, $z >> 4, true)->setBlockId($x & 0x0f, $y, $z & 0x0f, $id & 0xff); $this->getChunk($x >> 4, $z >> 4, true)->setBlockId($x & 0x0f, $y, $z & 0x0f, $id & 0xff);
if(!isset($this->changedBlocks[$index = Level::chunkHash($x >> 4, $z >> 4)])){ if(!isset($this->changedBlocks[$index = Level::chunkHash($x >> 4, $z >> 4)])){
$this->changedBlocks[$index] = []; $this->changedBlocks[$index] = [];
} }
$this->changedBlocks[$index][Level::blockHash($x, $y, $z)] = $v = new Vector3($x, $y, $z); $this->changedBlocks[$index][$blockHash] = $v = new Vector3($x, $y, $z);
foreach($this->getChunkLoaders($x >> 4, $z >> 4) as $loader){ foreach($this->getChunkLoaders($x >> 4, $z >> 4) as $loader){
$loader->onBlockChanged($v); $loader->onBlockChanged($v);
} }
@ -2203,13 +2208,13 @@ class Level implements ChunkManager, Metadatable{
* @param int $data 0-15 * @param int $data 0-15
*/ */
public function setBlockDataAt(int $x, int $y, int $z, int $data){ public function setBlockDataAt(int $x, int $y, int $z, int $data){
unset($this->blockCache[Level::blockHash($x, $y, $z)]); unset($this->blockCache[$blockHash = Level::blockHash($x, $y, $z)]);
$this->getChunk($x >> 4, $z >> 4, true)->setBlockData($x & 0x0f, $y, $z & 0x0f, $data & 0x0f); $this->getChunk($x >> 4, $z >> 4, true)->setBlockData($x & 0x0f, $y, $z & 0x0f, $data & 0x0f);
if(!isset($this->changedBlocks[$index = Level::chunkHash($x >> 4, $z >> 4)])){ if(!isset($this->changedBlocks[$index = Level::chunkHash($x >> 4, $z >> 4)])){
$this->changedBlocks[$index] = []; $this->changedBlocks[$index] = [];
} }
$this->changedBlocks[$index][Level::blockHash($x, $y, $z)] = $v = new Vector3($x, $y, $z); $this->changedBlocks[$index][$blockHash] = $v = new Vector3($x, $y, $z);
foreach($this->getChunkLoaders($x >> 4, $z >> 4) as $loader){ foreach($this->getChunkLoaders($x >> 4, $z >> 4) as $loader){
$loader->onBlockChanged($v); $loader->onBlockChanged($v);
} }