diff --git a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php index 6c716ffaa..f9a4802d2 100644 --- a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php @@ -31,6 +31,7 @@ use pocketmine\network\BadPacketException; use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\DimensionIds; use pocketmine\network\mcpe\protocol\types\MapTrackedObject; +use pocketmine\utils\Binary; use pocketmine\utils\Color; use function assert; use function count; @@ -106,7 +107,7 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack $this->decorations[$i]["yOffset"] = $this->getByte(); $this->decorations[$i]["label"] = $this->getString(); - $this->decorations[$i]["color"] = Color::fromABGR($this->getUnsignedVarInt()); + $this->decorations[$i]["color"] = Color::fromRGBA(Binary::flipIntEndianness($this->getUnsignedVarInt())); } } @@ -123,7 +124,7 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack for($y = 0; $y < $this->height; ++$y){ for($x = 0; $x < $this->width; ++$x){ - $this->colors[$y][$x] = Color::fromABGR($this->getUnsignedVarInt()); + $this->colors[$y][$x] = Color::fromRGBA(Binary::flipIntEndianness($this->getUnsignedVarInt())); } } } @@ -179,7 +180,7 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack $this->putString($decoration["label"]); assert($decoration["color"] instanceof Color); - $this->putUnsignedVarInt($decoration["color"]->toABGR()); + $this->putUnsignedVarInt(Binary::flipIntEndianness($decoration["color"]->toRGBA())); } } @@ -193,7 +194,8 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack for($y = 0; $y < $this->height; ++$y){ for($x = 0; $x < $this->width; ++$x){ - $this->putUnsignedVarInt($this->colors[$y][$x]->toABGR()); + //if mojang had any sense this would just be a regular LE int + $this->putUnsignedVarInt(Binary::flipIntEndianness($this->colors[$y][$x]->toRGBA())); } } } diff --git a/src/pocketmine/utils/Color.php b/src/pocketmine/utils/Color.php index 69a6ff852..19289f7d8 100644 --- a/src/pocketmine/utils/Color.php +++ b/src/pocketmine/utils/Color.php @@ -163,11 +163,14 @@ class Color{ } /** - * Returns a little-endian ARGB 32-bit colour value. - * @return int + * Returns a Color from the supplied RGBA colour code (32-bit) + * + * @param int $c + * + * @return Color */ - public function toBGRA() : int{ - return ($this->b << 24) | ($this->g << 16) | ($this->r << 8) | $this->a; + public static function fromRGBA(int $c) : Color{ + return new Color(($c >> 24) & 0xff, ($c >> 16) & 0xff, ($c >> 8) & 0xff, $c & 0xff); } /** @@ -177,16 +180,4 @@ class Color{ public function toRGBA() : int{ return ($this->r << 24) | ($this->g << 16) | ($this->b << 8) | $this->a; } - - /** - * Returns a little-endian RGBA colour value. - * @return int - */ - public function toABGR() : int{ - return ($this->a << 24) | ($this->b << 16) | ($this->g << 8) | $this->r; - } - - public static function fromABGR(int $code){ - return new Color($code & 0xff, ($code >> 8) & 0xff, ($code >> 16) & 0xff, ($code >> 24) & 0xff); - } }