don't try to serialize optional fields

This commit is contained in:
əlemi 2021-11-24 11:23:56 +01:00
parent d1d1eb5ca1
commit 5cc4c8d844

View file

@ -38,7 +38,8 @@ class Packet:
buf = io.BytesIO() buf = io.BytesIO()
VarInt.write(self.id, buf) VarInt.write(self.id, buf)
for name, t in self.definition: for name, t in self.definition:
t.write(getattr(self, name, None), buf) if getattr(self, name, None) is not None: # minecraft proto has no null type: this is an optional field left unset
t.write(getattr(self, name, None), buf)
buf.seek(0) buf.seek(0)
return buf return buf