mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2025-02-16 11:51:52 +01:00
Update SoundEffectPacket and UseItemPacket to 1.14; misc improvements
This commit is contained in:
parent
faf02acf62
commit
d24b6eaded
@ -4,7 +4,7 @@ from minecraft.networking.packets import (
|
|||||||
|
|
||||||
from minecraft.networking.types import (
|
from minecraft.networking.types import (
|
||||||
Integer, FixedPointInteger, UnsignedByte, Byte, Boolean, UUID, Short,
|
Integer, FixedPointInteger, UnsignedByte, Byte, Boolean, UUID, Short,
|
||||||
VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode
|
VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .combat_event_packet import CombatEventPacket
|
from .combat_event_packet import CombatEventPacket
|
||||||
@ -14,6 +14,7 @@ from .player_position_and_look_packet import PlayerPositionAndLookPacket
|
|||||||
from .spawn_object_packet import SpawnObjectPacket
|
from .spawn_object_packet import SpawnObjectPacket
|
||||||
from .block_change_packet import BlockChangePacket, MultiBlockChangePacket
|
from .block_change_packet import BlockChangePacket, MultiBlockChangePacket
|
||||||
from .explosion_packet import ExplosionPacket
|
from .explosion_packet import ExplosionPacket
|
||||||
|
from .sound_effect_packet import SoundEffectPacket
|
||||||
|
|
||||||
|
|
||||||
# Formerly known as state_playing_clientbound.
|
# Formerly known as state_playing_clientbound.
|
||||||
@ -38,12 +39,15 @@ def get_packets(context):
|
|||||||
RespawnPacket,
|
RespawnPacket,
|
||||||
PluginMessagePacket,
|
PluginMessagePacket,
|
||||||
PlayerListHeaderAndFooterPacket,
|
PlayerListHeaderAndFooterPacket,
|
||||||
SoundEffectPacket,
|
|
||||||
}
|
}
|
||||||
if context.protocol_version <= 47:
|
if context.protocol_version <= 47:
|
||||||
packets |= {
|
packets |= {
|
||||||
SetCompressionPacket,
|
SetCompressionPacket,
|
||||||
}
|
}
|
||||||
|
if context.protocol_version >= 94:
|
||||||
|
packets |= {
|
||||||
|
SoundEffectPacket,
|
||||||
|
}
|
||||||
return packets
|
return packets
|
||||||
|
|
||||||
|
|
||||||
@ -287,40 +291,3 @@ class PlayerListHeaderAndFooterPacket(Packet):
|
|||||||
definition = [
|
definition = [
|
||||||
{'header': String},
|
{'header': String},
|
||||||
{'footer': String}]
|
{'footer': String}]
|
||||||
|
|
||||||
|
|
||||||
class SoundEffectPacket(Packet):
|
|
||||||
@staticmethod
|
|
||||||
def get_id(context):
|
|
||||||
return 0x4E if context.protocol_version >= 451 else \
|
|
||||||
0x4D if context.protocol_version >= 389 else \
|
|
||||||
0x4C if context.protocol_version >= 352 else \
|
|
||||||
0x4B if context.protocol_version >= 345 else \
|
|
||||||
0x4A if context.protocol_version >= 343 else \
|
|
||||||
0x49 if context.protocol_version >= 336 else \
|
|
||||||
0x48 if context.protocol_version >= 318 else \
|
|
||||||
0x46 if context.protocol_version >= 110 else \
|
|
||||||
0x47 if context.protocol_version >= 94 else \
|
|
||||||
0x23 if context.protocol_version >= 72 else \
|
|
||||||
0x29 if context.protocol_version >= 0 else \
|
|
||||||
0x2C
|
|
||||||
|
|
||||||
packet_name = 'sound effect'
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_definition(context):
|
|
||||||
definition = [
|
|
||||||
{'sound_id': VarInt},
|
|
||||||
{'sound_category': VarInt} if context.protocol_version >= 95 else {},
|
|
||||||
{'parrotted_entity_type': String} if 326 > context.protocol_version >= 321 else {},
|
|
||||||
{'effect_position_x': Integer},
|
|
||||||
{'effect_position_y': Integer},
|
|
||||||
{'effect_position_z': Integer},
|
|
||||||
{'volume': Float},
|
|
||||||
{'pitch': Float if context.protocol_version >= 201 else UnsignedByte}
|
|
||||||
]
|
|
||||||
|
|
||||||
if 326 > context.protocol_version >= 321:
|
|
||||||
# Swaps the position of sound category and -id
|
|
||||||
definition[0], definition[1] = definition[1], definition[0]
|
|
||||||
return definition
|
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
from minecraft.networking.packets import Packet
|
||||||
|
from minecraft.networking.types import (
|
||||||
|
VarInt, String, Float, Byte, Type, Integer, Vector, Enum,
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = 'SoundEffectPacket',
|
||||||
|
|
||||||
|
|
||||||
|
class SoundEffectPacket(Packet):
|
||||||
|
@staticmethod
|
||||||
|
def get_id(context):
|
||||||
|
return 0x51 if context.protocol_version >= 471 else \
|
||||||
|
0x4D if context.protocol_version >= 461 else \
|
||||||
|
0x4E if context.protocol_version >= 451 else \
|
||||||
|
0x4E if context.protocol_version >= 451 else \
|
||||||
|
0x4D if context.protocol_version >= 389 else \
|
||||||
|
0x4C if context.protocol_version >= 352 else \
|
||||||
|
0x4B if context.protocol_version >= 345 else \
|
||||||
|
0x4A if context.protocol_version >= 343 else \
|
||||||
|
0x49 if context.protocol_version >= 336 else \
|
||||||
|
0x48 if context.protocol_version >= 318 else \
|
||||||
|
0x46 if context.protocol_version >= 110 else \
|
||||||
|
0x47
|
||||||
|
|
||||||
|
packet_name = 'sound effect'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_definition(context):
|
||||||
|
return [
|
||||||
|
({'sound_category': VarInt}
|
||||||
|
if 326 > context.protocol_version >= 321 else {}),
|
||||||
|
{'sound_id': VarInt},
|
||||||
|
({'sound_category': VarInt}
|
||||||
|
if 95 <= context.protocol_version < 321
|
||||||
|
or context.protocol_version >= 326 else {}),
|
||||||
|
({'parroted_entity_type': String}
|
||||||
|
if 326 > context.protocol_version >= 321 else {}),
|
||||||
|
{'effect_position': SoundEffectPacket.EffectPosition},
|
||||||
|
{'volume': Float},
|
||||||
|
{'pitch': SoundEffectPacket.Pitch},
|
||||||
|
]
|
||||||
|
|
||||||
|
class SoundCategory(Enum):
|
||||||
|
MASTER = 0
|
||||||
|
MUSIC = 1
|
||||||
|
RECORDS = 2
|
||||||
|
WEATHER = 3
|
||||||
|
BLOCKS = 4
|
||||||
|
HOSTILE = 5
|
||||||
|
NEUTRAL = 6
|
||||||
|
PLAYERS = 7
|
||||||
|
AMBIENT = 8
|
||||||
|
VOICE = 9
|
||||||
|
|
||||||
|
class EffectPosition(Type):
|
||||||
|
@classmethod
|
||||||
|
def read(cls, file_object):
|
||||||
|
return Vector(*(Integer.read(file_object) / 8.0 for i in range(3)))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def send(cls, value, socket):
|
||||||
|
for coordinate in value:
|
||||||
|
Integer.send(int(coordinate * 8), socket)
|
||||||
|
|
||||||
|
class Pitch(Type):
|
||||||
|
@staticmethod
|
||||||
|
def read_with_context(file_object, context):
|
||||||
|
if context.protocol_version >= 201:
|
||||||
|
value = Float.read(file_object)
|
||||||
|
else:
|
||||||
|
value = Byte.read(file_object) / 63.5
|
||||||
|
if context.protocol_version < 204:
|
||||||
|
value /= 63.5
|
||||||
|
return value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def send_with_context(value, socket, context):
|
||||||
|
if context.protocol_version < 204:
|
||||||
|
value *= 63.5
|
||||||
|
if context.protocol_version >= 201:
|
||||||
|
Float.send(value, socket)
|
||||||
|
else:
|
||||||
|
Byte.send(int(value), socket)
|
@ -21,8 +21,11 @@ def get_packets(context):
|
|||||||
ClientSettingsPacket,
|
ClientSettingsPacket,
|
||||||
PluginMessagePacket,
|
PluginMessagePacket,
|
||||||
PlayerBlockPlacementPacket,
|
PlayerBlockPlacementPacket,
|
||||||
UseItemPacket,
|
|
||||||
}
|
}
|
||||||
|
if context.protocol_version >= 69:
|
||||||
|
packets |= {
|
||||||
|
UseItemPacket,
|
||||||
|
}
|
||||||
if context.protocol_version >= 107:
|
if context.protocol_version >= 107:
|
||||||
packets |= {
|
packets |= {
|
||||||
TeleportConfirmPacket,
|
TeleportConfirmPacket,
|
||||||
@ -217,7 +220,9 @@ class PlayerBlockPlacementPacket(Packet):
|
|||||||
class UseItemPacket(Packet):
|
class UseItemPacket(Packet):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_id(context):
|
def get_id(context):
|
||||||
return 0x2A if context.protocol_version >= 389 else \
|
return 0x2D if context.protocol_version >= 468 else \
|
||||||
|
0x2C if context.protocol_version >= 464 else \
|
||||||
|
0x2A if context.protocol_version >= 389 else \
|
||||||
0x28 if context.protocol_version >= 386 else \
|
0x28 if context.protocol_version >= 386 else \
|
||||||
0x20 if context.protocol_version >= 345 else \
|
0x20 if context.protocol_version >= 345 else \
|
||||||
0x1F if context.protocol_version >= 343 else \
|
0x1F if context.protocol_version >= 343 else \
|
||||||
@ -232,4 +237,3 @@ class UseItemPacket(Packet):
|
|||||||
{'hand': VarInt}])
|
{'hand': VarInt}])
|
||||||
|
|
||||||
Hand = RelativeHand
|
Hand = RelativeHand
|
||||||
HAND_MAIN, HAND_OFF = Hand.MAIN, Hand.OFF # For backward compatibility.
|
|
||||||
|
@ -6,7 +6,7 @@ from collections import namedtuple
|
|||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Vector', 'MutableRecord', 'descriptor',
|
'Vector', 'MutableRecord', 'PositionAndLook', 'descriptor',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,6 +221,13 @@ class TestReadWritePackets(unittest.TestCase):
|
|||||||
self._test_read_write_packet(packet)
|
self._test_read_write_packet(packet)
|
||||||
self._test_read_write_packet(packet2)
|
self._test_read_write_packet(packet2)
|
||||||
|
|
||||||
|
def test_sound_effect_packet(self):
|
||||||
|
SoundCategory = clientbound.play.SoundEffectPacket.SoundCategory
|
||||||
|
packet = clientbound.play.SoundEffectPacket(
|
||||||
|
sound_category=SoundCategory.NEUTRAL, sound_id=545,
|
||||||
|
effect_position=Vector(0.125, 300.0, 50.5), volume=0.75, pitch=1.5)
|
||||||
|
self._test_read_write_packet(packet)
|
||||||
|
|
||||||
def _test_read_write_packet(self, packet_in):
|
def _test_read_write_packet(self, packet_in):
|
||||||
packet_in.context = self.context
|
packet_in.context = self.context
|
||||||
packet_buffer = PacketBuffer()
|
packet_buffer = PacketBuffer()
|
||||||
|
Loading…
Reference in New Issue
Block a user