13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
28 public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_MAP_ITEM_DATA_PACKET;
30 public const BITFLAG_TEXTURE_UPDATE = 0x02;
31 public const BITFLAG_DECORATION_UPDATE = 0x04;
32 public const BITFLAG_MAP_CREATION = 0x08;
36 public int $dimensionId = DimensionIds::OVERWORLD;
37 public bool $isLocked =
false;
41 public array $parentMapIds = [];
45 public array $trackedEntities = [];
47 public array $decorations = [];
49 public int $xOffset = 0;
50 public int $yOffset = 0;
54 $this->mapId = $in->getActorUniqueId();
56 $this->dimensionId = $in->
getByte();
57 $this->isLocked = $in->
getBool();
60 if(($this->type & self::BITFLAG_MAP_CREATION) !== 0){
62 for($i = 0; $i < $count; ++$i){
67 if(($this->type & (self::BITFLAG_MAP_CREATION | self::BITFLAG_DECORATION_UPDATE | self::BITFLAG_TEXTURE_UPDATE)) !== 0){
71 if(($this->type & self::BITFLAG_DECORATION_UPDATE) !== 0){
73 $object =
new MapTrackedObject();
75 if($object->type === MapTrackedObject::TYPE_BLOCK){
77 }elseif($object->type === MapTrackedObject::TYPE_ENTITY){
80 throw new PacketDecodeException(
"Unknown map object type $object->type");
82 $this->trackedEntities[] = $object;
92 $this->decorations[] =
new MapDecoration($icon, $rotation, $xOffset, $yOffset, $label, $color);
96 if(($this->type & self::BITFLAG_TEXTURE_UPDATE) !== 0){
103 if($count !== $width * $height){
104 throw new PacketDecodeException(
"Expected colour count of " . ($height * $width) .
" (height $height * width $width), got $count");
112 $out->putActorUniqueId($this->mapId);
115 if(($parentMapIdsCount = count($this->parentMapIds)) > 0){
116 $type |= self::BITFLAG_MAP_CREATION;
118 if(($decorationCount = count($this->decorations)) > 0){
119 $type |= self::BITFLAG_DECORATION_UPDATE;
121 if($this->colors !==
null){
122 $type |= self::BITFLAG_TEXTURE_UPDATE;
126 $out->putByte($this->dimensionId);
127 $out->putBool($this->isLocked);
130 if(($type & self::BITFLAG_MAP_CREATION) !== 0){
132 foreach($this->parentMapIds as $parentMapId){
133 $out->putActorUniqueId($parentMapId);
137 if(($type & (self::BITFLAG_MAP_CREATION | self::BITFLAG_TEXTURE_UPDATE | self::BITFLAG_DECORATION_UPDATE)) !== 0){
138 $out->putByte($this->scale);
141 if(($type & self::BITFLAG_DECORATION_UPDATE) !== 0){
143 foreach($this->trackedEntities as $object){
144 $out->putLInt($object->type);
145 if($object->type === MapTrackedObject::TYPE_BLOCK){
147 }elseif($object->type === MapTrackedObject::TYPE_ENTITY){
148 $out->putActorUniqueId($object->actorUniqueId);
150 throw new \InvalidArgumentException(
"Unknown map object type $object->type");
155 foreach($this->decorations as $decoration){
156 $out->putByte($decoration->getIcon());
157 $out->putByte($decoration->getRotation());
158 $out->putByte($decoration->getXOffset());
159 $out->putByte($decoration->getYOffset());
160 $out->putString($decoration->getLabel());
161 $out->
putUnsignedVarInt(Binary::flipIntEndianness($decoration->getColor()->toRGBA()));
165 if($this->colors !==
null){
166 $out->
putVarInt($this->colors->getWidth());
167 $out->
putVarInt($this->colors->getHeight());
173 $this->colors->encode($out);
178 return $handler->handleClientboundMapItemData($this);
static fromRGBA(int $code)
handle(PacketHandlerInterface $handler)
decodePayload(PacketSerializer $in)
encodePayload(PacketSerializer $out)
putSignedBlockPosition(BlockPosition $blockPosition)
putBlockPosition(BlockPosition $blockPosition)
static decode(BinaryStream $input, int $height, int $width)
putUnsignedVarInt(int $v)