From 259f0425a9657befcc8ef5f474ecc24ec78042fa Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 30 Jan 2020 20:05:11 +0000 Subject: [PATCH] ClientboundMapItemDataPacket: replace assoc array with MapDecoration class I thought I'd done this already, but it appears not. --- .../protocol/ClientboundMapItemDataPacket.php | 31 ++++---- .../mcpe/protocol/types/MapDecoration.php | 74 +++++++++++++++++++ 2 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/types/MapDecoration.php diff --git a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php index 3a35cf1dd..ec9b0c532 100644 --- a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\protocol\types\DimensionIds; +use pocketmine\network\mcpe\protocol\types\MapDecoration; use pocketmine\network\mcpe\protocol\types\MapTrackedObject; use pocketmine\utils\Color; use function assert; @@ -54,7 +55,7 @@ class ClientboundMapItemDataPacket extends DataPacket{ /** @var MapTrackedObject[] */ public $trackedEntities = []; - /** @var array */ + /** @var MapDecoration[] */ public $decorations = []; /** @var int */ @@ -100,13 +101,13 @@ class ClientboundMapItemDataPacket extends DataPacket{ } for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ - $this->decorations[$i]["img"] = $this->getByte(); - $this->decorations[$i]["rot"] = $this->getByte(); - $this->decorations[$i]["xOffset"] = $this->getByte(); - $this->decorations[$i]["yOffset"] = $this->getByte(); - $this->decorations[$i]["label"] = $this->getString(); - - $this->decorations[$i]["color"] = Color::fromABGR($this->getUnsignedVarInt()); + $icon = $this->getByte(); + $rotation = $this->getByte(); + $xOffset = $this->getByte(); + $yOffset = $this->getByte(); + $label = $this->getString(); + $color = Color::fromABGR($this->getUnsignedVarInt()); + $this->decorations[] = new MapDecoration($icon, $rotation, $xOffset, $yOffset, $label, $color); } } @@ -173,14 +174,12 @@ class ClientboundMapItemDataPacket extends DataPacket{ $this->putUnsignedVarInt($decorationCount); foreach($this->decorations as $decoration){ - $this->putByte($decoration["img"]); - $this->putByte($decoration["rot"]); - $this->putByte($decoration["xOffset"]); - $this->putByte($decoration["yOffset"]); - $this->putString($decoration["label"]); - - assert($decoration["color"] instanceof Color); - $this->putUnsignedVarInt($decoration["color"]->toABGR()); + $this->putByte($decoration->getIcon()); + $this->putByte($decoration->getRotation()); + $this->putByte($decoration->getXOffset()); + $this->putByte($decoration->getYOffset()); + $this->putString($decoration->getLabel()); + $this->putUnsignedVarInt($decoration->getColor()->toABGR()); } } diff --git a/src/pocketmine/network/mcpe/protocol/types/MapDecoration.php b/src/pocketmine/network/mcpe/protocol/types/MapDecoration.php new file mode 100644 index 000000000..564cdf4bf --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/MapDecoration.php @@ -0,0 +1,74 @@ +icon = $icon; + $this->rotation = $rotation; + $this->xOffset = $xOffset; + $this->yOffset = $yOffset; + $this->label = $label; + $this->color = $color; + } + + public function getIcon() : int{ + return $this->icon; + } + + public function getRotation() : int{ + return $this->rotation; + } + + public function getXOffset() : int{ + return $this->xOffset; + } + + public function getYOffset() : int{ + return $this->yOffset; + } + + public function getLabel() : string{ + return $this->label; + } + + public function getColor() : Color{ + return $this->color; + } +}