Merge pull request #102 from SirGhostal/patch-1

Add RespawnPacket and ServerDifficultyPacket.
This commit is contained in:
joo 2019-05-13 18:39:20 +02:00 committed by GitHub
commit 7ae6d599fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 2 deletions

View File

@ -4,7 +4,7 @@ from minecraft.networking.packets import (
from minecraft.networking.types import (
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
@ -21,6 +21,7 @@ def get_packets(context):
packets = {
KeepAlivePacket,
JoinGamePacket,
ServerDifficultyPacket,
ChatMessagePacket,
PlayerPositionAndLookPacket,
MapPacket,
@ -34,6 +35,7 @@ def get_packets(context):
SpawnObjectPacket,
BlockChangePacket,
MultiBlockChangePacket,
RespawnPacket,
PluginMessagePacket,
PlayerListHeaderAndFooterPacket,
}
@ -75,7 +77,35 @@ class JoinGamePacket(Packet):
{'max_players': UnsignedByte},
{'level_type': String},
{'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):
@ -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):
@staticmethod
def get_id(context):

View File

@ -12,6 +12,7 @@ from .utility import Vector
__all__ = (
'Enum', 'BitFieldEnum', 'AbsoluteHand', 'RelativeHand', 'BlockFace',
'Difficulty', 'Dimension', 'GameMode'
)
@ -82,3 +83,26 @@ class BlockFace(Enum):
# >>> BlockFace.to_vector[BlockFace.NORTH]
# Position(x=0, y=0, z=-1)
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