Heap of bugfixes, cleanup and PHP 7 upgrades

This commit is contained in:
Dylan K. Taylor
2017-07-13 19:18:56 +01:00
parent c2a7c2c6cd
commit 2a7b736f18
49 changed files with 114 additions and 148 deletions

View File

@ -71,7 +71,7 @@ class Explosion{
$vector = new Vector3(0, 0, 0);
$vBlock = new Vector3(0, 0, 0);
$mRays = intval($this->rays - 1);
$mRays = (int) ($this->rays - 1);
for($i = 0; $i < $this->rays; ++$i){
for($j = 0; $j < $this->rays; ++$j){
for($k = 0; $k < $this->rays; ++$k){

View File

@ -819,7 +819,7 @@ class Level implements ChunkManager, Metadatable{
$pk->z = $z + 0.5;
$pk->data = ($data << 8) | $id;
$this->server->broadcastPacket($targets === null ? $this->getChunkPlayers($x >> 4, $z >> 4) : $targets, $pk);
$this->server->broadcastPacket($targets ?? $this->getChunkPlayers($x >> 4, $z >> 4), $pk);
}
/**
@ -1533,7 +1533,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $delay
*/
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10){
$motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
$motion = $motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1);
$itemTag = $item->nbtSerialize();
$itemTag->setName("Item");
@ -1582,7 +1582,7 @@ class Level implements ChunkManager, Metadatable{
}
if($player !== null){
$ev = new BlockBreakEvent($player, $target, $item, ($player->isCreative() or $player->allowInstaBreak()));
$ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() or $player->allowInstaBreak());
if(($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) or $player->isSpectator()){
$ev->setCancelled();
@ -1633,7 +1633,7 @@ class Level implements ChunkManager, Metadatable{
$breakTime -= 1; //1 tick compensation
if(!$ev->getInstaBreak() and ((ceil($player->lastBreak * 20)) + $breakTime) > ceil(microtime(true) * 20)){
if(!$ev->getInstaBreak() and (ceil($player->lastBreak * 20) + $breakTime) > ceil(microtime(true) * 20)){
return false;
}
@ -2590,7 +2590,7 @@ class Level implements ChunkManager, Metadatable{
}
public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = true) : bool{
if(($safe === true and $this->isChunkInUse($x, $z))){
if($safe === true and $this->isChunkInUse($x, $z)){
return false;
}

View File

@ -90,8 +90,9 @@ class Chunk{
* @param CompoundTag[] $tiles
* @param string $biomeIds
* @param int[] $heightMap
* @param int[] $extraData
*/
public function __construct(int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], string $biomeIds = "", array $heightMap = []){
public function __construct(int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], string $biomeIds = "", array $heightMap = [], array $extraData = []){
$this->x = $chunkX;
$this->z = $chunkZ;
@ -127,10 +128,12 @@ class Chunk{
if(strlen($biomeIds) === 256){
$this->biomeIds = $biomeIds;
}else{
assert(strlen($biomeIds) === 0, "Wrong BiomeIds value count, expected 256, got " . strlen($biomeIds));
assert($biomeIds === "", "Wrong BiomeIds value count, expected 256, got " . strlen($biomeIds));
$this->biomeIds = str_repeat("\x00", 256);
}
$this->extraData = $extraData;
$this->NBTtiles = $tiles;
$this->NBTentities = $entities;
}

View File

@ -173,19 +173,19 @@ class SubChunk implements SubChunkInterface{
}
public function getBlockIdColumn(int $x, int $z) : string{
return substr($this->ids, (($x << 8) | ($z << 4)), 16);
return substr($this->ids, ($x << 8) | ($z << 4), 16);
}
public function getBlockDataColumn(int $x, int $z) : string{
return substr($this->data, (($x << 7) | ($z << 3)), 8);
return substr($this->data, ($x << 7) | ($z << 3), 8);
}
public function getBlockLightColumn(int $x, int $z) : string{
return substr($this->blockLight, (($x << 7) | ($z << 3)), 8);
return substr($this->blockLight, ($x << 7) | ($z << 3), 8);
}
public function getBlockSkyLightColumn(int $x, int $z) : string{
return substr($this->skyLight, (($x << 7) | ($z << 3)), 8);
return substr($this->skyLight, ($x << 7) | ($z << 3), 8);
}
public function getBlockIdArray() : string{

View File

@ -436,7 +436,8 @@ class LevelDB extends BaseLevelProvider{
$entities,
$tiles,
$biomeIds,
$heightMap
$heightMap,
$extraData
);
//TODO: tile ticks, biome states (?)

View File

@ -134,9 +134,9 @@ class McRegion extends BaseLevelProvider{
$subChunks = [];
$fullIds = isset($chunk->Blocks) ? $chunk->Blocks->getValue() : str_repeat("\x00", 32768);
$fullData = isset($chunk->Data) ? $chunk->Data->getValue() : (str_repeat("\x00", 16384));
$fullData = isset($chunk->Data) ? $chunk->Data->getValue() : str_repeat("\x00", 16384);
$fullSkyLight = isset($chunk->SkyLight) ? $chunk->SkyLight->getValue() : str_repeat("\xff", 16384);
$fullBlockLight = isset($chunk->BlockLight) ? $chunk->BlockLight->getValue() : (str_repeat("\x00", 16384));
$fullBlockLight = isset($chunk->BlockLight) ? $chunk->BlockLight->getValue() : str_repeat("\x00", 16384);
for($y = 0; $y < 8; ++$y){
$offset = ($y << 4);
@ -262,7 +262,7 @@ class McRegion extends BaseLevelProvider{
new LongTag("SizeOnDisk", 0),
new LongTag("Time", 0),
new StringTag("generatorName", Generator::getGeneratorName($generator)),
new StringTag("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
new StringTag("generatorOptions", $options["preset"] ?? ""),
new StringTag("LevelName", $name),
new CompoundTag("GameRules", [])
]);

View File

@ -292,7 +292,7 @@ class RegionLoader{
$index = $data[$i + 1];
$offset = $index >> 8;
if($offset !== 0){
fseek($this->filePointer, ($offset << 12));
fseek($this->filePointer, $offset << 12);
if(fgetc($this->filePointer) === false){ //Try and read from the location
throw new CorruptedRegionException("Region file location offset points to invalid location");
}elseif(isset($usedOffsets[$offset])){

View File

@ -90,7 +90,7 @@ class Flat extends Generator{
$y = 0;
foreach($matches[3] as $i => $b){
$b = Item::fromString($b . $matches[4][$i]);
$cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
$cnt = $matches[2][$i] === "" ? 1 : (int) ($matches[2][$i]);
for($cY = $y, $y += $cnt; $cY < $y; ++$cY){
$result[$cY] = [$b->getId(), $b->getDamage()];
}