Commits

Pierre-Marie de Rodat  committed a481974

Client: added *BlockChange packets handling.

  • Participants
  • Parent commits 321f3b5

Comments (0)

Files changed (1)

             PlayerPositionLookServer.packet_id: self.handle_playerpositionlook,
             PreChunk.packet_id: self.handle_prechunk,
             MapChunk.packet_id: self.handle_mapchunk,
+            MultiBlockChange.packet_id: self.handle_multiblockchange,
+            BlockChange.packet_id: self.handle_blockchange,
             ChatMessage.packet_id: self.handle_chat,
         })
         self.connected = False
                 )
             )
             first_half = not first_half
+
+    def handle_multiblockchange(self, packet):
+        chunk = self.map.get((packet.x, packet.z))
+        if chunk is None:
+            return
+        for coordinates, type, metadata in zip(*packet.data):
+            coordinates = (
+                coordinates & 0xFF,
+                (coordinates >> 8) & 0xFF,
+                coordinates >> 12
+            )
+            chunk.put(
+                coordinates,
+                # TODO: handle metadata.
+                chunk.get(coordinates)._replace(type=type)
+            )
+
+    def handle_blockchange(self, packet):
+        chunk = self.map.get((packet.x >> 4, packet.z >> 4))
+        if chunk is None:
+            return
+        coordinates = (packet.x & 0xF, packet.y, packet.z & 0xF)
+        chunk.put(
+            coordinates,
+            # TODO: handle metadata.
+            chunk.get(coordinates)._replace(type=packet.block_type)
+        )