From d20344cac10b9d91ee6115926047139f77031dcd Mon Sep 17 00:00:00 2001 From: Zachy Date: Sun, 12 Aug 2018 10:39:11 +0100 Subject: [PATCH 01/10] Implement clientbound.play.RespawnPacket --- .../packets/clientbound/play/__init__.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index dc4364e..5bf64b7 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -34,6 +34,7 @@ def get_packets(context): SpawnObjectPacket, BlockChangePacket, MultiBlockChangePacket, + RespawnPacket, PluginMessagePacket, } if context.protocol_version <= 47: @@ -184,6 +185,27 @@ class UpdateHealthPacket(Packet): ]) +class RespawnPacket(Packet): + @staticmethod + def get_id(context): + return 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}, + {'game_mode': UnsignedByte}, + {'level_type': String} + ]) + + class PluginMessagePacket(AbstractPluginMessagePacket): @staticmethod def get_id(context): From 1a114c1b95704decc591ea223bb3ca3874229155 Mon Sep 17 00:00:00 2001 From: Zachy Date: Sun, 12 Aug 2018 10:47:50 +0100 Subject: [PATCH 02/10] Implement clientbound.play.ServerDifficultyPacket --- .../packets/clientbound/play/__init__.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index 5bf64b7..5a3cdad 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -21,6 +21,7 @@ def get_packets(context): packets = { KeepAlivePacket, JoinGamePacket, + ServerDifficultyPacket, ChatMessagePacket, PlayerPositionAndLookPacket, MapPacket, @@ -73,7 +74,21 @@ class JoinGamePacket(Packet): {'difficulty': UnsignedByte}, {'max_players': UnsignedByte}, {'level_type': String}, - {'reduced_debug_info': Boolean}]) + {'reduced_debug_info': Boolean} + ]) + + +class ServerDifficultyPacket(Packet): + def get_id(context): + return 0x0D if context.protocol_version >= 332 else \ + 0x0E if context.protocol_version >= 318 else \ + 0x0D if context.protocol_version >= 67 else \ + 0x41 + + packet_name = 'server difficulty' + get_definition = staticmethod(lambda context: [ + {'difficulty': UnsignedByte} + ]) class ChatMessagePacket(Packet): From e840fab26700e43fd89688ae7004c562dfaa6bf8 Mon Sep 17 00:00:00 2001 From: Zachy Date: Sun, 12 Aug 2018 11:04:40 +0100 Subject: [PATCH 03/10] Update __init__.py --- minecraft/networking/packets/clientbound/play/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index 5a3cdad..ba24110 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -79,6 +79,7 @@ class JoinGamePacket(Packet): class ServerDifficultyPacket(Packet): + @staticmethod def get_id(context): return 0x0D if context.protocol_version >= 332 else \ 0x0E if context.protocol_version >= 318 else \ From 0198476fa97c803a86987a954f96e40d9784b215 Mon Sep 17 00:00:00 2001 From: Zachy Date: Sun, 12 Aug 2018 22:56:16 +0100 Subject: [PATCH 04/10] Fix packet id for protocol versions 47 and 69. --- minecraft/networking/packets/clientbound/play/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index ba24110..27e5378 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -83,7 +83,7 @@ class ServerDifficultyPacket(Packet): def get_id(context): return 0x0D if context.protocol_version >= 332 else \ 0x0E if context.protocol_version >= 318 else \ - 0x0D if context.protocol_version >= 67 else \ + 0x0D if context.protocol_version >= 70 else \ 0x41 packet_name = 'server difficulty' From ed85cb793a775a3e68a8075e8527c34ed42b9a1e Mon Sep 17 00:00:00 2001 From: Zachy Date: Sun, 12 Aug 2018 23:07:07 +0100 Subject: [PATCH 05/10] Implement Enums for Difficulty/Dimension/Gamemode --- minecraft/networking/types/enum.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/minecraft/networking/types/enum.py b/minecraft/networking/types/enum.py index 089b586..8336739 100644 --- a/minecraft/networking/types/enum.py +++ b/minecraft/networking/types/enum.py @@ -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 From aeaf7b5bcb3e0f4bd9af289b3eee4f18cdb192c7 Mon Sep 17 00:00:00 2001 From: Zachy Date: Sun, 12 Aug 2018 23:12:45 +0100 Subject: [PATCH 06/10] Import new enums into Packet Definition --- minecraft/networking/packets/clientbound/play/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index 27e5378..f074e24 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -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 From 4ba6a40df62729004323737e91635665221a2070 Mon Sep 17 00:00:00 2001 From: Zachy24 Date: Mon, 13 Aug 2018 00:41:21 +0100 Subject: [PATCH 07/10] Add aliases for Enums in Packet Definitions --- .../packets/clientbound/play/__init__.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index f074e24..5269217 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -77,6 +77,15 @@ class JoinGamePacket(Packet): {'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 @@ -88,9 +97,12 @@ class ServerDifficultyPacket(Packet): packet_name = 'server difficulty' get_definition = staticmethod(lambda context: [ - {'difficulty': UnsignedByte} + {'difficulty_enum': UnsignedByte} ]) + # ServerDifficultyPacket.Difficulty is an alias for Difficulty + Difficulty = Difficulty + class ChatMessagePacket(Packet): @staticmethod @@ -221,6 +233,15 @@ class RespawnPacket(Packet): {'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 From da103c6d3cdc438f1b99bb4a95597f4ae8e1925a Mon Sep 17 00:00:00 2001 From: Zachy24 Date: Mon, 13 Aug 2018 00:42:24 +0100 Subject: [PATCH 08/10] Oops --- minecraft/networking/packets/clientbound/play/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index 5269217..e417a86 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -97,7 +97,7 @@ class ServerDifficultyPacket(Packet): packet_name = 'server difficulty' get_definition = staticmethod(lambda context: [ - {'difficulty_enum': UnsignedByte} + {'difficulty': UnsignedByte} ]) # ServerDifficultyPacket.Difficulty is an alias for Difficulty From 103b53a97a28cac44996f3e8afce8380795aacf0 Mon Sep 17 00:00:00 2001 From: Zachy24 Date: Wed, 15 Aug 2018 22:29:18 +0100 Subject: [PATCH 09/10] Change case on GameMode --- minecraft/networking/packets/clientbound/play/__init__.py | 6 +++--- minecraft/networking/types/enum.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index e417a86..286cc40 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -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, Difficulty, Dimension, Gamemode + VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode ) from .combat_event_packet import CombatEventPacket @@ -81,7 +81,7 @@ class JoinGamePacket(Packet): Difficulty = Difficulty # JoinGamePacket.Gamemode is an alias for Gamemode - Gamemode = Gamemode + GameMode = GameMode # JoinGamePacket.Dimension is an alias for Dimension Dimension = Dimension @@ -240,7 +240,7 @@ class RespawnPacket(Packet): Dimension = Dimension # RespawnPacket.Gamemode is an alias for Gamemode. - Gamemode = Gamemode + GameMode = GameMode class PluginMessagePacket(AbstractPluginMessagePacket): diff --git a/minecraft/networking/types/enum.py b/minecraft/networking/types/enum.py index 8336739..8d43374 100644 --- a/minecraft/networking/types/enum.py +++ b/minecraft/networking/types/enum.py @@ -12,7 +12,7 @@ from .utility import Vector __all__ = ( 'Enum', 'BitFieldEnum', 'AbsoluteHand', 'RelativeHand', 'BlockFace', - 'Difficulty', 'Dimension', 'Gamemode' + 'Difficulty', 'Dimension', 'GameMode' ) @@ -101,7 +101,7 @@ class Dimension(Enum): # Designation of a player's gamemode. -class Gamemode(Enum): +class GameMode(Enum): SURVIVAL = 0 CREATIVE = 1 ADVENTURE = 2 From bf719611ec11c0175c429b63d9ca3b2878f605e7 Mon Sep 17 00:00:00 2001 From: joodicator Date: Mon, 13 May 2019 18:22:53 +0200 Subject: [PATCH 10/10] Update RespawnPacket and ServerDifficultyPacket to 1.14. --- .../networking/packets/clientbound/play/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index 1c612f1..b13a576 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -100,7 +100,8 @@ class ServerDifficultyPacket(Packet): packet_name = 'server difficulty' get_definition = staticmethod(lambda context: [ - {'difficulty': UnsignedByte} + {'difficulty': UnsignedByte}, + {'is_locked': Boolean} if context.protocol_version >= 464 else {}, ]) # ServerDifficultyPacket.Difficulty is an alias for Difficulty @@ -226,7 +227,10 @@ class UpdateHealthPacket(Packet): class RespawnPacket(Packet): @staticmethod def get_id(context): - return 0x38 if context.protocol_version >= 389 else \ + 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 \ @@ -238,9 +242,9 @@ class RespawnPacket(Packet): packet_name = 'respawn' get_definition = staticmethod(lambda context: [ {'dimension': Integer}, - {'difficulty': UnsignedByte}, + {'difficulty': UnsignedByte} if context.protocol_version < 464 else {}, {'game_mode': UnsignedByte}, - {'level_type': String} + {'level_type': String}, ]) # RespawnPacket.Difficulty is an alias for Difficulty.