Merge branch 'stable'

This commit is contained in:
Dylan K. Taylor
2019-08-14 18:20:55 +01:00
12 changed files with 48 additions and 29 deletions

View File

@@ -23,40 +23,45 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types\entity;
use pocketmine\item\Item;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\TreeRoot;
use pocketmine\network\mcpe\serializer\NetworkBinaryStream;
use pocketmine\network\mcpe\serializer\NetworkNbtSerializer;
final class ItemStackMetadataProperty implements MetadataProperty{
/** @var Item */
final class CompoundTagMetadataProperty implements MetadataProperty{
/** @var CompoundTag */
private $value;
/**
* @param Item $value
* @param CompoundTag $value
*/
public function __construct(Item $value){
public function __construct(CompoundTag $value){
$this->value = clone $value;
}
/**
* @return Item
* @return CompoundTag
*/
public function getValue() : Item{
public function getValue() : CompoundTag{
return clone $this->value;
}
public static function id() : int{
return EntityMetadataTypes::SLOT;
return EntityMetadataTypes::COMPOUND_TAG;
}
public function equals(MetadataProperty $other) : bool{
return $other instanceof $this and $other->value->equalsExact($this->value);
return $other instanceof $this and $other->value->equals($this->value);
}
public static function read(NetworkBinaryStream $in) : self{
return new self($in->getSlot());
$offset = $in->getOffset();
$result = new self((new NetworkNbtSerializer())->read($in->getBuffer(), $offset, 512)->getTag());
$in->setOffset($offset);
return $result;
}
public function write(NetworkBinaryStream $out) : void{
$out->putSlot($this->value);
$out->put((new NetworkNbtSerializer())->write(new TreeRoot($this->value)));
}
}

View File

@@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types\entity;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use function get_class;
class EntityMetadataCollection{
@@ -85,12 +85,12 @@ class EntityMetadataCollection{
}
/**
* @param int $key
* @param Item $value
* @param bool $force
* @param int $key
* @param CompoundTag $value
* @param bool $force
*/
public function setItem(int $key, Item $value, bool $force = false) : void{
$this->set($key, new ItemStackMetadataProperty($value), $force);
public function setCompoundTag(int $key, CompoundTag $value, bool $force = false) : void{
$this->set($key, new CompoundTagMetadataProperty($value), $force);
}
/**

View File

@@ -34,7 +34,7 @@ final class EntityMetadataTypes{
public const INT = 2;
public const FLOAT = 3;
public const STRING = 4;
public const SLOT = 5;
public const COMPOUND_TAG = 5;
public const POS = 6;
public const LONG = 7;
public const VECTOR3F = 8;

View File

@@ -42,7 +42,7 @@ use pocketmine\network\mcpe\protocol\types\entity\ByteMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\EntityLink;
use pocketmine\network\mcpe\protocol\types\entity\FloatMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\IntMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\ItemStackMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\CompoundTagMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\LongMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\ShortMetadataProperty;
@@ -258,7 +258,7 @@ class NetworkBinaryStream extends BinaryStream{
case IntMetadataProperty::id(): return IntMetadataProperty::read($this);
case FloatMetadataProperty::id(): return FloatMetadataProperty::read($this);
case StringMetadataProperty::id(): return StringMetadataProperty::read($this);
case ItemStackMetadataProperty::id(): return ItemStackMetadataProperty::read($this);
case CompoundTagMetadataProperty::id(): return CompoundTagMetadataProperty::read($this);
case BlockPosMetadataProperty::id(): return BlockPosMetadataProperty::read($this);
case LongMetadataProperty::id(): return LongMetadataProperty::read($this);
case Vec3MetadataProperty::id(): return Vec3MetadataProperty::read($this);