mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-10 15:59:39 +00:00
Clean up internal inconsistency in Color
This commit is contained in:
parent
c6a5829a92
commit
d23e32622e
@ -31,6 +31,7 @@ use pocketmine\network\BadPacketException;
|
|||||||
use pocketmine\network\mcpe\handler\SessionHandler;
|
use pocketmine\network\mcpe\handler\SessionHandler;
|
||||||
use pocketmine\network\mcpe\protocol\types\DimensionIds;
|
use pocketmine\network\mcpe\protocol\types\DimensionIds;
|
||||||
use pocketmine\network\mcpe\protocol\types\MapTrackedObject;
|
use pocketmine\network\mcpe\protocol\types\MapTrackedObject;
|
||||||
|
use pocketmine\utils\Binary;
|
||||||
use pocketmine\utils\Color;
|
use pocketmine\utils\Color;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function count;
|
use function count;
|
||||||
@ -106,7 +107,7 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack
|
|||||||
$this->decorations[$i]["yOffset"] = $this->getByte();
|
$this->decorations[$i]["yOffset"] = $this->getByte();
|
||||||
$this->decorations[$i]["label"] = $this->getString();
|
$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($y = 0; $y < $this->height; ++$y){
|
||||||
for($x = 0; $x < $this->width; ++$x){
|
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"]);
|
$this->putString($decoration["label"]);
|
||||||
|
|
||||||
assert($decoration["color"] instanceof Color);
|
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($y = 0; $y < $this->height; ++$y){
|
||||||
for($x = 0; $x < $this->width; ++$x){
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,11 +163,14 @@ class Color{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a little-endian ARGB 32-bit colour value.
|
* Returns a Color from the supplied RGBA colour code (32-bit)
|
||||||
* @return int
|
*
|
||||||
|
* @param int $c
|
||||||
|
*
|
||||||
|
* @return Color
|
||||||
*/
|
*/
|
||||||
public function toBGRA() : int{
|
public static function fromRGBA(int $c) : Color{
|
||||||
return ($this->b << 24) | ($this->g << 16) | ($this->r << 8) | $this->a;
|
return new Color(($c >> 24) & 0xff, ($c >> 16) & 0xff, ($c >> 8) & 0xff, $c & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,16 +180,4 @@ class Color{
|
|||||||
public function toRGBA() : int{
|
public function toRGBA() : int{
|
||||||
return ($this->r << 24) | ($this->g << 16) | ($this->b << 8) | $this->a;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user