Implement New Type. FixedPointInteger. (#93)

Fix: SpawnPlayerPacket coordinates read wrongly before protocol 100. Add types.FixedPointInteger.
This commit is contained in:
Zachy authored and joo committed 2018-06-20 05:32:35 +01:00
1 parent 0a1776f97a
commit d3a8cc8dfb
3 files changed
+27 -9

No files matched your search

@@ -3,8 +3,8 @@ from minecraft.networking.packets import (
)
from minecraft.networking.types import (
Integer, UnsignedByte, Byte, Boolean, UUID, Short, VarInt, Double, Float,
String, Enum,
Integer, FixedPointInteger, UnsignedByte, Byte, Boolean, UUID, Short,
VarInt, Double, Float, String, Enum,
)
from .combat_event_packet import CombatEventPacket
@@ -126,9 +126,12 @@ class SpawnPlayerPacket(Packet):
get_definition = staticmethod(lambda context: [
{'entity_id': VarInt},
{'player_UUID': UUID},
{'x': Double} if context.protocol_version >= 100 else {'x': Integer},
{'y': Double} if context.protocol_version >= 100 else {'y': Integer},
{'z': Double} if context.protocol_version >= 100 else {'z': Integer},
{'x': Double} if context.protocol_version >= 100
else {'x': FixedPointInteger},
{'y': Double} if context.protocol_version >= 100
else {'y': FixedPointInteger},
{'z': Double} if context.protocol_version >= 100
else {'z': FixedPointInteger},
{'yaw': Float},
{'pitch': Float},
# TODO: read entity metadata
+11
View File
@@ -2,6 +2,7 @@
Each type has a method which is used to read and write it.
These definitions and methods are used by the packet definitions
"""
from __future__ import division
import struct
import uuid
from collections import namedtuple
@@ -120,6 +121,16 @@ class Integer(Type):
socket.send(struct.pack('>i', value))
class FixedPointInteger(Type):
@staticmethod
def read(file_object):
return Integer.read(file_object) / 32
@staticmethod
def send(value, socket):
Integer.send(int(value * 32), socket)
class VarInt(Type):
@staticmethod
def read(file_object):