60 $this->type = VarInt::readUnsignedInt($in);
61 $this->dimensionId = Byte::readUnsigned($in);
62 $this->isLocked = CommonTypes::getBool($in);
63 $this->origin = CommonTypes::getSignedBlockPosition($in);
65 if(($this->type & self::BITFLAG_MAP_CREATION) !== 0){
66 $count = VarInt::readUnsignedInt($in);
67 for($i = 0; $i < $count; ++$i){
68 $this->parentMapIds[] = CommonTypes::getActorUniqueId($in);
72 if(($this->type & (self::BITFLAG_MAP_CREATION | self::BITFLAG_DECORATION_UPDATE | self::BITFLAG_TEXTURE_UPDATE)) !== 0){
73 $this->scale = Byte::readUnsigned($in);
76 if(($this->type & self::BITFLAG_DECORATION_UPDATE) !== 0){
77 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
78 $object =
new MapTrackedObject();
79 $object->type = LE::readUnsignedInt($in);
80 if($object->type === MapTrackedObject::TYPE_BLOCK){
81 $object->blockPosition = CommonTypes::getBlockPosition($in);
82 }elseif($object->type === MapTrackedObject::TYPE_ENTITY){
83 $object->actorUniqueId = CommonTypes::getActorUniqueId($in);
85 throw new PacketDecodeException(
"Unknown map object type $object->type");
87 $this->trackedEntities[] = $object;
90 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
91 $icon = Byte::readUnsigned($in);
92 $rotation = Byte::readUnsigned($in);
93 $xOffset = Byte::readUnsigned($in);
94 $yOffset = Byte::readUnsigned($in);
95 $label = CommonTypes::getString($in);
96 $color = Color::fromRGBA(Binary::flipIntEndianness(VarInt::readUnsignedInt($in)));
97 $this->decorations[] =
new MapDecoration($icon, $rotation, $xOffset, $yOffset, $label, $color);
101 if(($this->type & self::BITFLAG_TEXTURE_UPDATE) !== 0){
102 $width = VarInt::readSignedInt($in);
103 $height = VarInt::readSignedInt($in);
104 $this->xOffset = VarInt::readSignedInt($in);
105 $this->yOffset = VarInt::readSignedInt($in);
107 $count = VarInt::readUnsignedInt($in);
108 if($count !== $width * $height){
109 throw new PacketDecodeException(
"Expected colour count of " . ($height * $width) .
" (height $height * width $width), got $count");
112 $this->colors = MapImage::decode($in, $height, $width);
120 if(($parentMapIdsCount = count($this->parentMapIds)) > 0){
121 $type |= self::BITFLAG_MAP_CREATION;
123 if(($decorationCount = count($this->decorations)) > 0){
124 $type |= self::BITFLAG_DECORATION_UPDATE;
126 if($this->colors !==
null){
127 $type |= self::BITFLAG_TEXTURE_UPDATE;
130 VarInt::writeUnsignedInt($out, $type);
131 Byte::writeUnsigned($out, $this->dimensionId);
132 CommonTypes::putBool($out, $this->isLocked);
133 CommonTypes::putSignedBlockPosition($out, $this->origin);
135 if(($type & self::BITFLAG_MAP_CREATION) !== 0){
136 VarInt::writeUnsignedInt($out, $parentMapIdsCount);
137 foreach($this->parentMapIds as $parentMapId){
138 CommonTypes::putActorUniqueId($out, $parentMapId);
142 if(($type & (self::BITFLAG_MAP_CREATION | self::BITFLAG_TEXTURE_UPDATE | self::BITFLAG_DECORATION_UPDATE)) !== 0){
143 Byte::writeUnsigned($out, $this->scale);
146 if(($type & self::BITFLAG_DECORATION_UPDATE) !== 0){
147 VarInt::writeUnsignedInt($out, count($this->trackedEntities));
148 foreach($this->trackedEntities as $object){
149 LE::writeUnsignedInt($out, $object->type);
150 if($object->type === MapTrackedObject::TYPE_BLOCK){
151 CommonTypes::putBlockPosition($out, $object->blockPosition);
152 }elseif($object->type === MapTrackedObject::TYPE_ENTITY){
153 CommonTypes::putActorUniqueId($out, $object->actorUniqueId);
155 throw new \InvalidArgumentException(
"Unknown map object type $object->type");
159 VarInt::writeUnsignedInt($out, $decorationCount);
160 foreach($this->decorations as $decoration){
161 Byte::writeUnsigned($out, $decoration->getIcon());
162 Byte::writeUnsigned($out, $decoration->getRotation());
163 Byte::writeUnsigned($out, $decoration->getXOffset());
164 Byte::writeUnsigned($out, $decoration->getYOffset());
165 CommonTypes::putString($out, $decoration->getLabel());
166 VarInt::writeUnsignedInt($out, Binary::flipIntEndianness($decoration->getColor()->toRGBA()));
170 if($this->colors !==
null){
171 VarInt::writeSignedInt($out, $this->colors->getWidth());
172 VarInt::writeSignedInt($out, $this->colors->getHeight());
173 VarInt::writeSignedInt($out, $this->xOffset);
174 VarInt::writeSignedInt($out, $this->yOffset);
176 VarInt::writeUnsignedInt($out, $this->colors->getWidth() * $this->colors->getHeight());
178 $this->colors->encode($out);