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;
86 $icon = $in->getByte();
87 $rotation = $in->getByte();
88 $xOffset = $in->getByte();
89 $yOffset = $in->getByte();
90 $label = $in->getString();
91 $color = Color::fromRGBA(Binary::flipIntEndianness($in->getUnsignedVarInt()));
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");
107 $this->colors = MapImage::decode($in, $height, $width);
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);