diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index fa8aea85b..e7e924e76 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -392,21 +392,38 @@ abstract class Entity extends Location implements Metadatable{ public function setNameTagAlwaysVisible($value = true){ $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value); } - + /** * @return float */ - public function getScale(): float{ + public function getScale() : float{ return $this->getDataProperty(self::DATA_SCALE); } - + /** * @param float $value */ public function setScale(float $value){ + $multiplier = $value / $this->getScale(); + + $this->width *= $multiplier; + $this->height *= $multiplier; + $halfWidth = $this->width / 2; + + $this->boundingBox->setBounds( + $this->x - $halfWidth, + $this->y, + $this->z - $halfWidth, + $this->x + $halfWidth, + $this->y + $this->height, + $this->z + $halfWidth + ); + $this->setDataProperty(self::DATA_SCALE, self::DATA_TYPE_FLOAT, $value); + $this->setDataProperty(self::DATA_BOUNDING_BOX_WIDTH, self::DATA_TYPE_FLOAT, $this->width); + $this->setDataProperty(self::DATA_BOUNDING_BOX_HEIGHT, self::DATA_TYPE_FLOAT, $this->height); } - + public function isSneaking(){ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING); } diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 7e793d55e..7cc94878c 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -46,12 +46,22 @@ class Item implements ItemIds, \JsonSerializable{ private static $cachedParser = null; private static function parseCompoundTag(string $tag) : CompoundTag{ + if(strlen($tag) === 0){ + throw new \InvalidArgumentException("No NBT data found in supplied string"); + } + if(self::$cachedParser === null){ self::$cachedParser = new NBT(NBT::LITTLE_ENDIAN); } self::$cachedParser->read($tag); - return self::$cachedParser->getData(); + $data = self::$cachedParser->getData(); + + if(!($data instanceof CompoundTag)){ + throw new \InvalidArgumentException("Invalid item NBT string given, it could not be deserialized"); + } + + return $data; } private static function writeCompoundTag(CompoundTag $tag) : string{ diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 52684896c..9f47296cf 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -307,7 +307,7 @@ class Chunk{ * @param int $level 0-15 */ public function setBlockSkyLight(int $x, int $y, int $z, int $level){ - if($this->getSubChunk($y >> 4)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){ + if($this->getSubChunk($y >> 4, true)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){ $this->hasChanged = true; } } @@ -334,7 +334,7 @@ class Chunk{ * @param int $level 0-15 */ public function setBlockLight(int $x, int $y, int $z, int $level){ - if($this->getSubChunk($y >> 4)->setBlockLight($x, $y & 0x0f, $z, $level)){ + if($this->getSubChunk($y >> 4, true)->setBlockLight($x, $y & 0x0f, $z, $level)){ $this->hasChanged = true; } } diff --git a/src/pocketmine/level/format/SubChunk.php b/src/pocketmine/level/format/SubChunk.php index 38cb57194..8a5cc5be6 100644 --- a/src/pocketmine/level/format/SubChunk.php +++ b/src/pocketmine/level/format/SubChunk.php @@ -47,8 +47,11 @@ class SubChunk{ } public function isEmpty() : bool{ - assert(strlen($this->ids) === 4096, "Wrong length of ID array, expecting 4096 bytes, got " . strlen($this->ids)); - return substr_count($this->ids, "\x00") === 4096; + return ( + substr_count($this->ids, "\x00") === 4096 and + substr_count($this->skyLight, "\xff") === 2048 and + substr_count($this->blockLight, "\x00") === 2048 + ); } public function getBlockId(int $x, int $y, int $z) : int{ diff --git a/src/pocketmine/nbt/tag/CompoundTag.php b/src/pocketmine/nbt/tag/CompoundTag.php index 99f384a4e..45ab5bf6d 100644 --- a/src/pocketmine/nbt/tag/CompoundTag.php +++ b/src/pocketmine/nbt/tag/CompoundTag.php @@ -111,4 +111,12 @@ class CompoundTag extends NamedTag implements \ArrayAccess{ } return $str . "}"; } + + public function __clone(){ + foreach($this as $key => $tag){ + if($tag instanceof Tag){ + $this->{$key} = clone $tag; + } + } + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/ListTag.php b/src/pocketmine/nbt/tag/ListTag.php index 3fed630be..361db14d6 100644 --- a/src/pocketmine/nbt/tag/ListTag.php +++ b/src/pocketmine/nbt/tag/ListTag.php @@ -220,4 +220,12 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{ } return $str . "}"; } + + public function __clone(){ + foreach($this as $key => $tag){ + if($tag instanceof Tag){ + $this->{$key} = clone $tag; + } + } + } } diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index 132890293..8efe10809 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -183,7 +183,7 @@ auto-updater: timings: #Choose the host to use for viewing your timings results. - host: mcpetimings.com + host: timings.pmmp.io console: #Choose whether to enable server stats reporting on the console title.