-
Notifications
You must be signed in to change notification settings - Fork 5
More types #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
More types #297
Changes from all commits
8335d7d
2214c20
12369fa
9f4063d
d465bb2
3ed5833
4c48a14
ddd8428
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
- Added more types to the implementation: | ||
|
||
- `Angle`: Represents an angle. | ||
- `BitSet`: Represents a set of bits of variable length. | ||
- `FixedBitSet`: Represents a set of bits of fixed length. | ||
- `TextComponent`: Represents a Minecraft text component. | ||
- Renamed `ChatMessage` to `JSONTextComponent`. | ||
- `Identifier`: Represents a Minecraft identifier. | ||
- `Quaternion`: Represents a quaternion. | ||
- `Slot`: Represents an item slot. | ||
- `Vec3`: Represents a 3D vector. | ||
- `Position`: Represents a position with packed integers. | ||
- `EntityMetadata`: Represents metadata for an entity. | ||
> There are **A LOT** of different entity metadata types, so I'm not going to list them all here. | ||
|
||
- Removed the `validate` method from most `Serializable` classes. | ||
- Make use of validators and convertors from the `attrs` library instead. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Entity Metadata | ||
====================== | ||
|
||
This is the documentation for the Entity Metadata types used in Minecraft's network protocol. | ||
|
||
|
||
|
||
|
||
.. automodule:: mcproto.types.entity | ||
:no-undoc-members: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
General Types | ||
====================== | ||
|
||
Here are documented the general types used throughout the Minecraft protocol. | ||
|
||
.. automodule:: mcproto.types | ||
:no-undoc-members: | ||
:exclude-members: NBTag, StringNBT, CompoundNBT, EndNBT, EntityMetadata, UUID | ||
|
||
.. autoclass:: mcproto.types.UUID | ||
:class-doc-from: class |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
.. api/types documentation master file | ||
.. Types Documentation | ||
|
||
======================= | ||
API Types Documentation | ||
======================= | ||
Types Documentation | ||
================================== | ||
|
||
Welcome to the API Types documentation! This documentation provides information about the various types used in the API. | ||
This folder contains the documentation for various types used in the project. | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
general.rst | ||
nbt.rst | ||
entity_metadata.rst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
NBT Format | ||
========== | ||
|
||
This is the documentation for the NBT type used in Minecraft's network protocol. | ||
|
||
|
||
.. automodule:: mcproto.types.nbt | ||
:members: | ||
:show-inheritance: |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,15 +2,15 @@ | |||||||||
|
||||||||||
from typing import ClassVar, cast, final | ||||||||||
|
||||||||||
from attrs import define | ||||||||||
from attrs import define, field | ||||||||||
from cryptography.hazmat.backends import default_backend | ||||||||||
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey | ||||||||||
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat, load_der_public_key | ||||||||||
from typing_extensions import Self, override | ||||||||||
|
||||||||||
from mcproto.buffer import Buffer | ||||||||||
from mcproto.packets.packet import ClientBoundPacket, GameState, ServerBoundPacket | ||||||||||
from mcproto.types.chat import ChatMessage | ||||||||||
from mcproto.types.chat import JSONTextComponent | ||||||||||
from mcproto.types.uuid import UUID | ||||||||||
|
||||||||||
__all__ = [ | ||||||||||
|
@@ -33,7 +33,8 @@ class LoginStart(ServerBoundPacket): | |||||||||
Initialize the LoginStart packet. | ||||||||||
|
||||||||||
:param username: Username of the client who sent the request. | ||||||||||
:param uuid: UUID of the player logging in (if the player doesn't have a UUID, this can be ``None``) | ||||||||||
:param uuid: UUID of the player logging in (unused by the server) | ||||||||||
:type uuid: :class:`~mcproto.types.UUID` | ||||||||||
""" | ||||||||||
|
||||||||||
PACKET_ID: ClassVar[int] = 0x00 | ||||||||||
|
@@ -70,16 +71,9 @@ class LoginEncryptionRequest(ClientBoundPacket): | |||||||||
PACKET_ID: ClassVar[int] = 0x01 | ||||||||||
GAME_STATE: ClassVar[GameState] = GameState.LOGIN | ||||||||||
|
||||||||||
public_key: RSAPublicKey | ||||||||||
verify_token: bytes | ||||||||||
server_id: str | None = None | ||||||||||
|
||||||||||
@override | ||||||||||
def __attrs_post_init__(self) -> None: | ||||||||||
if self.server_id is None: | ||||||||||
self.server_id = " " * 20 | ||||||||||
|
||||||||||
super().__attrs_post_init__() | ||||||||||
public_key: RSAPublicKey = field() | ||||||||||
verify_token: bytes = field() | ||||||||||
server_id: str | None = field(default=" " * 20) | ||||||||||
|
||||||||||
@override | ||||||||||
def serialize_to(self, buf: Buffer) -> None: | ||||||||||
|
@@ -143,7 +137,9 @@ class LoginSuccess(ClientBoundPacket): | |||||||||
Initialize the LoginSuccess packet. | ||||||||||
|
||||||||||
:param uuid: The UUID of the connecting player/client. | ||||||||||
:type uuid: :class:`~mcproto.types.UUID` | ||||||||||
:param username: The username of the connecting player/client. | ||||||||||
:type username: str | ||||||||||
Comment on lines
+140
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type should be picked up from the type-hint by sphinx autodoc, it shouldn't be necessary to doc it manually. There's a lot of these in the code, this suggestion applies to all such instances.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They add the type between parenthesis (and links to the actual type) along with saying if it is optional : Without Parameters:
With it : Parameters:
Also these type informations only appear on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I think this might be configurable with autosphinx, will need to check though |
||||||||||
""" | ||||||||||
|
||||||||||
PACKET_ID: ClassVar[int] = 0x02 | ||||||||||
|
@@ -178,7 +174,7 @@ class LoginDisconnect(ClientBoundPacket): | |||||||||
PACKET_ID: ClassVar[int] = 0x00 | ||||||||||
GAME_STATE: ClassVar[GameState] = GameState.LOGIN | ||||||||||
|
||||||||||
reason: ChatMessage | ||||||||||
reason: JSONTextComponent | ||||||||||
|
||||||||||
@override | ||||||||||
def serialize_to(self, buf: Buffer) -> None: | ||||||||||
|
@@ -187,7 +183,7 @@ def serialize_to(self, buf: Buffer) -> None: | |||||||||
@override | ||||||||||
@classmethod | ||||||||||
def _deserialize(cls, buf: Buffer, /) -> Self: | ||||||||||
reason = ChatMessage.deserialize(buf) | ||||||||||
reason = JSONTextComponent.deserialize(buf) | ||||||||||
return cls(reason) | ||||||||||
|
||||||||||
|
||||||||||
|
@@ -240,7 +236,7 @@ class LoginPluginResponse(ServerBoundPacket): | |||||||||
GAME_STATE: ClassVar[GameState] = GameState.LOGIN | ||||||||||
|
||||||||||
message_id: int | ||||||||||
data: bytes | None | ||||||||||
data: bytes | None = None | ||||||||||
|
||||||||||
@override | ||||||||||
def serialize_to(self, buf: Buffer) -> None: | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.