From 9ea39ea3d7a89ec93b4e286145a98ed2133642f3 Mon Sep 17 00:00:00 2001 From: xFlare Date: Thu, 31 Aug 2017 16:14:18 -0400 Subject: [PATCH 1/4] Stop clearing chunk cache after 768 batched packets are cached. (#1320) --- src/pocketmine/level/Level.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index ad11f6356..f8607c6cc 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -836,21 +836,15 @@ class Level implements ChunkManager, Metadatable{ $this->server->batchPackets($target, $packets, false, false); } - public function clearCache(bool $full = false){ - if($full){ + public function clearCache(bool $force = false){ + if($force){ $this->chunkCache = []; $this->blockCache = []; }else{ - if(count($this->chunkCache) > 768){ - $this->chunkCache = []; - } - if(count($this->blockCache) > 2048){ $this->blockCache = []; } - } - } public function clearChunkCache(int $chunkX, int $chunkZ){ From 297cfcf1686ca9d06447c40deeb8c0263d303050 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 31 Aug 2017 21:04:36 +0100 Subject: [PATCH 2/4] Check for existence of ChunkUtils extension --- src/pocketmine/level/format/io/ChunkUtils.php | 142 +++++++++--------- 1 file changed, 72 insertions(+), 70 deletions(-) diff --git a/src/pocketmine/level/format/io/ChunkUtils.php b/src/pocketmine/level/format/io/ChunkUtils.php index e9e35e8ce..3a02ba04f 100644 --- a/src/pocketmine/level/format/io/ChunkUtils.php +++ b/src/pocketmine/level/format/io/ChunkUtils.php @@ -23,84 +23,86 @@ declare(strict_types=1); namespace pocketmine\level\format\io; -class ChunkUtils{ +if(!extension_loaded('pocketmine_chunkutils')){ + class ChunkUtils{ - /** - * Re-orders a byte array (YZX -> XZY and vice versa) - * - * @param string $array length 4096 - * - * @return string length 4096 - */ - final public static function reorderByteArray(string $array) : string{ - $result = str_repeat("\x00", 4096); - if($array !== $result){ - $i = 0; - for($x = 0; $x < 16; ++$x){ - $zM = $x + 256; - for($z = $x; $z < $zM; $z += 16){ - $yM = $z + 4096; - for($y = $z; $y < $yM; $y += 256){ - $result{$i} = $array{$y}; - ++$i; - } - } - } - } - - return $result; - } - - /** - * Re-orders a nibble array (YZX -> XZY and vice versa) - * - * @param string $array length 2048 - * @param string $commonValue length 1 common value to fill the default array with and to expect, may improve sort time - * - * @return string length 2048 - */ - final public static function reorderNibbleArray(string $array, string $commonValue = "\x00") : string{ - $result = str_repeat($commonValue, 2048); - - if($array !== $result){ - $i = 0; - for($x = 0; $x < 8; ++$x){ - for($z = 0; $z < 16; ++$z){ - $zx = (($z << 3) | $x); - for($y = 0; $y < 8; ++$y){ - $j = (($y << 8) | $zx); - $j80 = ($j | 0x80); - if($array{$j} === $commonValue and $array{$j80} === $commonValue){ - //values are already filled - }else{ - $i1 = ord($array{$j}); - $i2 = ord($array{$j80}); - $result{$i} = chr(($i2 << 4) | ($i1 & 0x0f)); - $result{$i | 0x80} = chr(($i1 >> 4) | ($i2 & 0xf0)); + /** + * Re-orders a byte array (YZX -> XZY and vice versa) + * + * @param string $array length 4096 + * + * @return string length 4096 + */ + final public static function reorderByteArray(string $array) : string{ + $result = str_repeat("\x00", 4096); + if($array !== $result){ + $i = 0; + for($x = 0; $x < 16; ++$x){ + $zM = $x + 256; + for($z = $x; $z < $zM; $z += 16){ + $yM = $z + 4096; + for($y = $z; $y < $yM; $y += 256){ + $result{$i} = $array{$y}; + ++$i; } - $i++; } } - $i += 128; } + + return $result; } - return $result; - } + /** + * Re-orders a nibble array (YZX -> XZY and vice versa) + * + * @param string $array length 2048 + * @param string $commonValue length 1 common value to fill the default array with and to expect, may improve sort time + * + * @return string length 2048 + */ + final public static function reorderNibbleArray(string $array, string $commonValue = "\x00") : string{ + $result = str_repeat($commonValue, 2048); - /** - * Converts pre-MCPE-1.0 biome color array to biome ID array. - * - * @param int[] $array of biome color values - * - * @return string - */ - public static function convertBiomeColors(array $array) : string{ - $result = str_repeat("\x00", 256); - foreach($array as $i => $color){ - $result{$i} = chr(($color >> 24) & 0xff); + if($array !== $result){ + $i = 0; + for($x = 0; $x < 8; ++$x){ + for($z = 0; $z < 16; ++$z){ + $zx = (($z << 3) | $x); + for($y = 0; $y < 8; ++$y){ + $j = (($y << 8) | $zx); + $j80 = ($j | 0x80); + if($array{$j} === $commonValue and $array{$j80} === $commonValue){ + //values are already filled + }else{ + $i1 = ord($array{$j}); + $i2 = ord($array{$j80}); + $result{$i} = chr(($i2 << 4) | ($i1 & 0x0f)); + $result{$i | 0x80} = chr(($i1 >> 4) | ($i2 & 0xf0)); + } + $i++; + } + } + $i += 128; + } + } + + return $result; } - return $result; - } + /** + * Converts pre-MCPE-1.0 biome color array to biome ID array. + * + * @param int[] $array of biome color values + * + * @return string + */ + public static function convertBiomeColors(array $array) : string{ + $result = str_repeat("\x00", 256); + foreach($array as $i => $color){ + $result{$i} = chr(($color >> 24) & 0xff); + } + return $result; + } + + } } \ No newline at end of file From 226175f96156c216f1380c160d29a36f3ec3b073 Mon Sep 17 00:00:00 2001 From: "Tim (robske_110)" Date: Fri, 1 Sep 2017 09:34:40 +0200 Subject: [PATCH 3/4] setText now nullable instead of overwriting with empty lines (#1204) --- src/pocketmine/tile/Sign.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index 49688588a..fc90ed2ed 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -54,11 +54,30 @@ class Sign extends Spawnable{ unset($this->namedtag->Creator); } + /** + * Changes contents of the specific lines to the string provided. + * Leaves contents of the specifc lines as is if null is provided. + * + * @param null|string $line1 + * @param null|string $line2 + * @param null|string $line3 + * @param null|string $line4 + * + * @return bool + */ public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){ - $this->namedtag->Text1->setValue($line1); - $this->namedtag->Text2->setValue($line2); - $this->namedtag->Text3->setValue($line3); - $this->namedtag->Text4->setValue($line4); + if($line1 !== null){ + $this->namedtag->Text1->setValue("Text1", $line1); + } + if($line2 !== null){ + $this->namedtag->Text2->setValue("Text2", $line2); + } + if($line3 !== null){ + $this->namedtag->Text3->setValue("Text3", $line3); + } + if($line4 !== null){ + $this->namedtag->Text4->setValue("Text4", $line4); + } $this->onChanged(); } From 138d85307beb4d74cb131406524bcd957faf2d1f Mon Sep 17 00:00:00 2001 From: Muqsit Date: Fri, 1 Sep 2017 16:50:55 +0100 Subject: [PATCH 4/4] Fixed double chests being openable when the other half has a solid block above it, close #1165 --- src/pocketmine/block/Chest.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 31640b3ee..eca854726 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -136,10 +136,6 @@ class Chest extends Transparent{ public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ - $top = $this->getSide(Vector3::SIDE_UP); - if($top->isTransparent() !== true){ - return true; - } $t = $this->getLevel()->getTile($this); $chest = null; @@ -157,10 +153,12 @@ class Chest extends Transparent{ $chest = Tile::createTile("Chest", $this->getLevel(), $nbt); } - if(isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag){ - if($chest->namedtag->Lock->getValue() !== $item->getCustomName()){ - return true; - } + if( + !$this->getSide(Vector3::SIDE_UP)->isTransparent() or + ($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Vector3::SIDE_UP)->isTransparent()) or + (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag and $chest->namedtag->Lock->getValue() !== $item->getCustomName()) + ){ + return true; } $player->addWindow($chest->getInventory());