1
1
from __future__ import annotations
2
2
3
+ from enum import IntEnum
3
4
from typing import final
4
- from attrs import define
5
5
6
+ from attrs import define
6
7
from typing_extensions import override
7
8
8
9
from mcproto .buffer import Buffer
9
10
from mcproto .protocol import StructFormat
10
- from mcproto .types .identifier import Identifier
11
+ from mcproto .types .abc import MCType
11
12
from mcproto .types .chat import TextComponent
13
+ from mcproto .types .identifier import Identifier
12
14
from mcproto .types .slot import Slot
13
- from mcproto .types .abc import MCType
14
15
15
16
16
17
@final
17
18
@define
18
19
class Advancement (MCType ):
19
20
"""Represents an advancement in the game.
20
21
21
- https://wiki.vg/Protocol#Update_Advancements
22
+ Non-standard type, see: `< https://wiki.vg/Protocol#Update_Advancements>`
22
23
23
24
:param parent: The parent advancement.
24
25
:type parent: :class:`~mcproto.types.identifier.Identifier`, optional
@@ -56,6 +57,14 @@ def deserialize(cls, buf: Buffer) -> Advancement:
56
57
return cls (parent = parent , display = display , requirements = requirements , telemetry = telemetry )
57
58
58
59
60
+ class AdvancementFrame (IntEnum ):
61
+ """Represents the shape of the frame of an advancement in the GUI."""
62
+
63
+ TASK = 0
64
+ CHALLENGE = 1
65
+ GOAL = 2
66
+
67
+
59
68
@final
60
69
@define
61
70
class AdvancementDisplay (MCType ):
@@ -67,7 +76,8 @@ class AdvancementDisplay(MCType):
67
76
:type description: :class:`~mcproto.types.chat.TextComponent`
68
77
:param icon: The icon of the advancement.
69
78
:type icon: :class:`~mcproto.types.slot.Slot`
70
- :param frame: The frame of the advancement (0: task, 1: challenge, 2: goal).
79
+ :param frame: The frame of the advancement.
80
+ :type frame: :class:`AdvancementFrame`
71
81
:param background: The background texture of the advancement.
72
82
:type background: :class:`~mcproto.types.identifier.Identifier`, optional
73
83
:param show_toast: Whether to show a toast notification.
@@ -83,7 +93,7 @@ class AdvancementDisplay(MCType):
83
93
title : TextComponent
84
94
description : TextComponent
85
95
icon : Slot
86
- frame : int
96
+ frame : AdvancementFrame
87
97
background : Identifier | None
88
98
show_toast : bool
89
99
hidden : bool
@@ -95,7 +105,7 @@ def serialize_to(self, buf: Buffer) -> None:
95
105
self .title .serialize_to (buf )
96
106
self .description .serialize_to (buf )
97
107
self .icon .serialize_to (buf )
98
- buf .write_varint (self .frame )
108
+ buf .write_varint (self .frame . value )
99
109
100
110
flags = (self .background is not None ) << 0 | self .show_toast << 1 | self .hidden << 2
101
111
buf .write_value (StructFormat .BYTE , flags )
@@ -110,7 +120,7 @@ def deserialize(cls, buf: Buffer) -> AdvancementDisplay:
110
120
title = TextComponent .deserialize (buf )
111
121
description = TextComponent .deserialize (buf )
112
122
icon = Slot .deserialize (buf )
113
- frame = buf .read_varint ()
123
+ frame = AdvancementFrame ( buf .read_varint () )
114
124
flags = buf .read_value (StructFormat .BYTE )
115
125
background = Identifier .deserialize (buf ) if flags & 0x1 else None
116
126
show_toast = bool (flags & 0x2 )
@@ -166,7 +176,7 @@ class AdvancementCriterion(MCType):
166
176
:type date: int, optional
167
177
"""
168
178
169
- date : int | None
179
+ date : int | None = None
170
180
171
181
@override
172
182
def serialize_to (self , buf : Buffer ) -> None :
0 commit comments