Merge pull request #102 from SirGhostal/patch-1
Add RespawnPacket and ServerDifficultyPacket.
This commit is contained in:
2 files changed
+89
-2
No files matched your search
@@ -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,
|
VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode
|
||||||
)
|
)
|
||||||
|
|
||||||
from .combat_event_packet import CombatEventPacket
|
from .combat_event_packet import CombatEventPacket
|
||||||
@@ -21,6 +21,7 @@ def get_packets(context):
|
|||||||
packets = {
|
packets = {
|
||||||
KeepAlivePacket,
|
KeepAlivePacket,
|
||||||
JoinGamePacket,
|
JoinGamePacket,
|
||||||
|
ServerDifficultyPacket,
|
||||||
ChatMessagePacket,
|
ChatMessagePacket,
|
||||||
PlayerPositionAndLookPacket,
|
PlayerPositionAndLookPacket,
|
||||||
MapPacket,
|
MapPacket,
|
||||||
@@ -34,6 +35,7 @@ def get_packets(context):
|
|||||||
SpawnObjectPacket,
|
SpawnObjectPacket,
|
||||||
BlockChangePacket,
|
BlockChangePacket,
|
||||||
MultiBlockChangePacket,
|
MultiBlockChangePacket,
|
||||||
|
RespawnPacket,
|
||||||
PluginMessagePacket,
|
PluginMessagePacket,
|
||||||
PlayerListHeaderAndFooterPacket,
|
PlayerListHeaderAndFooterPacket,
|
||||||
}
|
}
|
||||||
@@ -75,7 +77,35 @@ class JoinGamePacket(Packet):
|
|||||||
{'max_players': UnsignedByte},
|
{'max_players': UnsignedByte},
|
||||||
{'level_type': String},
|
{'level_type': String},
|
||||||
{'render_distance': VarInt} if context.protocol_version >= 468 else {},
|
{'render_distance': VarInt} if context.protocol_version >= 468 else {},
|
||||||
{'reduced_debug_info': Boolean}])
|
{'reduced_debug_info': Boolean},
|
||||||
|
])
|
||||||
|
|
||||||
|
# JoinGamePacket.Difficulty is an alias for Difficulty
|
||||||
|
Difficulty = Difficulty
|
||||||
|
|
||||||
|
# JoinGamePacket.Gamemode is an alias for Gamemode
|
||||||
|
GameMode = GameMode
|
||||||
|
|
||||||
|
# JoinGamePacket.Dimension is an alias for Dimension
|
||||||
|
Dimension = Dimension
|
||||||
|
|
||||||
|
|
||||||
|
class ServerDifficultyPacket(Packet):
|
||||||
|
@staticmethod
|
||||||
|
def get_id(context):
|
||||||
|
return 0x0D if context.protocol_version >= 332 else \
|
||||||
|
0x0E if context.protocol_version >= 318 else \
|
||||||
|
0x0D if context.protocol_version >= 70 else \
|
||||||
|
0x41
|
||||||
|
|
||||||
|
packet_name = 'server difficulty'
|
||||||
|
get_definition = staticmethod(lambda context: [
|
||||||
|
{'difficulty': UnsignedByte},
|
||||||
|
{'is_locked': Boolean} if context.protocol_version >= 464 else {},
|
||||||
|
])
|
||||||
|
|
||||||
|
# ServerDifficultyPacket.Difficulty is an alias for Difficulty
|
||||||
|
Difficulty = Difficulty
|
||||||
|
|
||||||
|
|
||||||
class ChatMessagePacket(Packet):
|
class ChatMessagePacket(Packet):
|
||||||
@@ -194,6 +224,39 @@ class UpdateHealthPacket(Packet):
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class RespawnPacket(Packet):
|
||||||
|
@staticmethod
|
||||||
|
def get_id(context):
|
||||||
|
return 0x3A if context.protocol_version >= 471 else \
|
||||||
|
0x38 if context.protocol_version >= 461 else \
|
||||||
|
0x39 if context.protocol_version >= 451 else \
|
||||||
|
0x38 if context.protocol_version >= 389 else \
|
||||||
|
0x37 if context.protocol_version >= 352 else \
|
||||||
|
0x36 if context.protocol_version >= 345 else \
|
||||||
|
0x35 if context.protocol_version >= 336 else \
|
||||||
|
0x34 if context.protocol_version >= 332 else \
|
||||||
|
0x35 if context.protocol_version >= 318 else \
|
||||||
|
0x33 if context.protocol_version >= 70 else \
|
||||||
|
0x07
|
||||||
|
|
||||||
|
packet_name = 'respawn'
|
||||||
|
get_definition = staticmethod(lambda context: [
|
||||||
|
{'dimension': Integer},
|
||||||
|
{'difficulty': UnsignedByte} if context.protocol_version < 464 else {},
|
||||||
|
{'game_mode': UnsignedByte},
|
||||||
|
{'level_type': String},
|
||||||
|
])
|
||||||
|
|
||||||
|
# RespawnPacket.Difficulty is an alias for Difficulty.
|
||||||
|
Difficulty = Difficulty
|
||||||
|
|
||||||
|
# RespawnPacket.Dimension is an alias for Dimension.
|
||||||
|
Dimension = Dimension
|
||||||
|
|
||||||
|
# RespawnPacket.Gamemode is an alias for Gamemode.
|
||||||
|
GameMode = GameMode
|
||||||
|
|
||||||
|
|
||||||
class PluginMessagePacket(AbstractPluginMessagePacket):
|
class PluginMessagePacket(AbstractPluginMessagePacket):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_id(context):
|
def get_id(context):
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from .utility import Vector
|
|||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Enum', 'BitFieldEnum', 'AbsoluteHand', 'RelativeHand', 'BlockFace',
|
'Enum', 'BitFieldEnum', 'AbsoluteHand', 'RelativeHand', 'BlockFace',
|
||||||
|
'Difficulty', 'Dimension', 'GameMode'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -82,3 +83,26 @@ class BlockFace(Enum):
|
|||||||
# >>> BlockFace.to_vector[BlockFace.NORTH]
|
# >>> BlockFace.to_vector[BlockFace.NORTH]
|
||||||
# Position(x=0, y=0, z=-1)
|
# Position(x=0, y=0, z=-1)
|
||||||
to_vector = {fce: pos for (pos, fce) in from_vector.items()}
|
to_vector = {fce: pos for (pos, fce) in from_vector.items()}
|
||||||
|
|
||||||
|
|
||||||
|
# Designation of a world's difficulty.
|
||||||
|
class Difficulty(Enum):
|
||||||
|
PEACEFUL = 0
|
||||||
|
EASY = 1
|
||||||
|
NORMAL = 2
|
||||||
|
HARD = 3
|
||||||
|
|
||||||
|
|
||||||
|
# Designation of a world's dimension.
|
||||||
|
class Dimension(Enum):
|
||||||
|
NETHER = -1
|
||||||
|
OVERWORLD = 0
|
||||||
|
END = 1
|
||||||
|
|
||||||
|
|
||||||
|
# Designation of a player's gamemode.
|
||||||
|
class GameMode(Enum):
|
||||||
|
SURVIVAL = 0
|
||||||
|
CREATIVE = 1
|
||||||
|
ADVENTURE = 2
|
||||||
|
SPECTATOR = 3
|
||||||
Reference in new issue
Block a user