Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d62aa47
Add pyright dev dependency
ItsDrike Feb 28, 2022
ea7157a
Make registry typed
ItsDrike Feb 28, 2022
7dcbfa9
Improve from_list logic and fix type hints
ItsDrike Feb 28, 2022
709677b
Enum comparison should be is, not __eq__
ItsDrike Feb 28, 2022
5cae9ae
Take __getitem__ argument as positional-only
ItsDrike Feb 28, 2022
32fdff2
Use a more specific return type
ItsDrike Feb 28, 2022
af35559
Specify __getitems__ overload
ItsDrike Feb 28, 2022
cd84302
Fix overload type hint
ItsDrike Feb 28, 2022
586841f
Fix from_list fucntion
ItsDrike Feb 28, 2022
ff49d3c
Fix return type for __getitem__
ItsDrike Feb 28, 2022
4afd065
Improve error message
ItsDrike Feb 28, 2022
b913cb0
Follow black
ItsDrike Feb 28, 2022
98cb927
Actually return Buffer from write_ingredient
ItsDrike Mar 1, 2022
cceb48b
Cast some values where necessary
ItsDrike Mar 1, 2022
df6a25e
Actually return Buffer from write_slot
ItsDrike Mar 1, 2022
aa81341
Use Self as return type
ItsDrike Mar 1, 2022
ded7449
Use Optional for params defaulting to None
ItsDrike Mar 1, 2022
c8b1063
Properly define __repr__
ItsDrike Mar 1, 2022
43dc7b8
Fix typo
ItsDrike Mar 1, 2022
10c3984
Properly annotate read_optional
ItsDrike Mar 1, 2022
46bfabd
Use a dict switch instead of elif mess
ItsDrike Mar 1, 2022
de6879d
Add not-implemented write_block for refs
ItsDrike Mar 1, 2022
d5ae040
Improve docstring
ItsDrike Mar 1, 2022
251530d
Cast read('f') output as float
ItsDrike Mar 1, 2022
27617f4
Run black
ItsDrike Mar 1, 2022
c0c7404
Use Optional for params defaulting to None
ItsDrike Mar 1, 2022
5ac2eb3
Make a more specific type for json-like values
ItsDrike Mar 2, 2022
71db844
Add some TODOs to fix weird things
ItsDrike Mar 2, 2022
8b83610
Merge branch 'main' into add-pyright
ItsDrike Mar 5, 2022
c138ba2
Merge branch 'main' into add-pyright
ItsDrike Mar 17, 2022
cee02ed
Revert typing generic additions to Registry
ItsDrike Mar 17, 2022
57ff2f0
Split logic for taking sequences to a classmethod
ItsDrike Mar 17, 2022
8980e7e
Properly annotate list of tag classes
ItsDrike Mar 17, 2022
dc568a4
Fix get function annotation
ItsDrike Mar 17, 2022
c42d1a0
Don't make packet id optional
ItsDrike Mar 17, 2022
683ebe2
Adhere to pyright's strictParameterNoneValue
ItsDrike Mar 17, 2022
ae184e1
Run isort
ItsDrike Mar 17, 2022
71679e8
Allow tag names to be None
ItsDrike Mar 21, 2022
01d5eb9
Cast types from Buffer.read
ItsDrike Mar 21, 2022
933ac3d
Actually return buffer from PlayPlayerInfo.pack
ItsDrike Mar 21, 2022
9b3d0b3
Actually initialize buffer before calling instance methods
ItsDrike Mar 21, 2022
8bbbdab
Actually pass kwargs to fucntion that takes kwargs
ItsDrike Mar 21, 2022
c159328
Use correct type (ServerBoundPacket, not ClientBoundPacket)
ItsDrike Mar 21, 2022
4fa6de4
Type-ignore vars with async init set to None in constructor
ItsDrike Mar 21, 2022
7138cc4
Don't use len() on int variable
ItsDrike Mar 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pymine_net/net/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class AsyncProtocolClient(AbstractProtocolClient):
def __init__(self, host: str, port: int, protocol: Union[int, str], packet_map: PacketMap):
super().__init__(host, port, protocol, packet_map)

self.stream: AsyncTCPStream = None
# We type-ignore this assignment since we don't expect it to stay as None
# it should be set in connect function which is expected to be ran after init
# this avoids further type-ignores or casts whenever it'd be used, to tell
# type checker that it won't actually be None.
self.stream: AsyncTCPStream = None # type: ignore

async def connect(self) -> None:
_, writer = await asyncio.open_connection(self.host, self.port)
Expand Down
6 changes: 5 additions & 1 deletion pymine_net/net/asyncio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def __init__(self, host: str, port: int, protocol: Union[int, str], packet_map:

self.connected_clients: Dict[Tuple[str, int], AsyncProtocolServerClient] = {}

self.server: asyncio.AbstractServer = None
# We type-ignore this assignment since we don't expect it to stay as None
# it should be set in run function which is expected to be ran after init
# this avoids further type-ignores or casts whenever it'd be used, to tell
# type checker that it won't actually be None.
self.server: asyncio.AbstractServer = None # type: ignore

async def run(self) -> None:
self.server = await asyncio.start_server(self._client_connected_cb, self.host, self.port)
Expand Down
2 changes: 1 addition & 1 deletion pymine_net/net/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _decode_packet(self, buf: Buffer) -> ServerBoundPacket:

# attempt to get packet class from given state and packet id
try:
packet_class: Type[ClientBoundPacket] = self.packet_map[
packet_class: Type[ServerBoundPacket] = self.packet_map[
PacketDirection.SERVERBOUND, self.state, packet_id
]
except KeyError:
Expand Down
3 changes: 2 additions & 1 deletion pymine_net/packets/v_1_18_1/login/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from typing import Optional
from uuid import UUID

from pymine_net.types.buffer import Buffer
Expand Down Expand Up @@ -190,7 +191,7 @@ class LoginPluginResponse(ServerBoundPacket):

id = 0x02

def __init__(self, message_id: int, data: bytes = None):
def __init__(self, message_id: int, data: Optional[bytes] = None):
self.message_id = message_id
self.data = data

Expand Down
2 changes: 1 addition & 1 deletion pymine_net/packets/v_1_18_1/play/advancement.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PlaySelectAdvancementTab(ClientBoundPacket):

id = 0x40

def __init__(self, identifier: str = None):
def __init__(self, identifier: Optional[str] = None):
super().__init__()

self.identifier = identifier
Expand Down
2 changes: 1 addition & 1 deletion pymine_net/packets/v_1_18_1/play/boss.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, uuid: UUID, action: int, **data: dict):
self.data = data

def pack(self) -> Buffer:
buf = Buffer.write_uuid(self.uuid).write_varint(self.action)
buf = Buffer().write_uuid(self.uuid).write_varint(self.action)

if self.action == 0:
buf.write_chat(self.data["title"]).write("f", self.data["health"]).write_varint(
Expand Down
4 changes: 2 additions & 2 deletions pymine_net/packets/v_1_18_1/play/crafting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Dict, List
from typing import Dict, List, Optional

from pymine_net.types.buffer import Buffer
from pymine_net.types.packet import ClientBoundPacket, ServerBoundPacket
Expand Down Expand Up @@ -177,7 +177,7 @@ def __init__(
smoker_book_open: bool,
smoker_book_filter_active: bool,
recipe_ids_1: List[str],
recipe_ids_2: List[list] = None,
recipe_ids_2: Optional[List[list]] = None,
):
super().__init__()

Expand Down
10 changes: 5 additions & 5 deletions pymine_net/packets/v_1_18_1/play/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def __init__(
tracking_pos: bool,
icons: List[Tuple[int, int, int, int, bool, Optional[Chat]]],
columns: int,
rows: int = None,
x: int = None,
z: int = None,
data: bytes = None,
rows: Optional[int] = None,
x: Optional[int] = None,
z: Optional[int] = None,
data: Optional[bytes] = None,
):
super().__init__()

Expand Down Expand Up @@ -86,7 +86,7 @@ def pack(self) -> Buffer:

buf.write("B", self.columns)

if len(self.columns) < 1:
if self.columns < 1:
return buf

return (
Expand Down
2 changes: 1 addition & 1 deletion pymine_net/packets/v_1_18_1/play/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ def pack(self) -> Buffer:
.write("f", self.offset_z)
.write("f", self.particle_data)
.write("i", self.particle_count)
.write_particle(self.data)
.write_particle(**self.data)
)
48 changes: 31 additions & 17 deletions pymine_net/packets/v_1_18_1/play/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import List
from typing import List, Optional, cast
from uuid import UUID

import pymine_net.types.nbt as nbt
Expand Down Expand Up @@ -314,7 +314,12 @@ def __init__(self, x: float, feet_y: float, z: float, on_ground: bool):

@classmethod
def unpack(cls, buf: Buffer) -> PlayPlayerPositionServerBound:
return cls(buf.read("d"), buf.read("d"), buf.read("d"), buf.read("?"))
return cls(
cast(int, buf.read("d")),
cast(int, buf.read("d")),
cast(int, buf.read("d")),
cast(bool, buf.read("?"))
)


class PlayPlayerPositionAndRotationServerBound(ServerBoundPacket):
Expand Down Expand Up @@ -352,12 +357,12 @@ def __init__(
@classmethod
def unpack(cls, buf: Buffer) -> PlayPlayerPositionAndRotationServerBound:
return cls(
buf.read("d"),
buf.read("d"),
buf.read("d"),
buf.read("f"),
buf.read("f"),
buf.read("?"),
cast(int, buf.read("d")),
cast(int, buf.read("d")),
cast(int, buf.read("d")),
cast(float, buf.read("f")),
cast(float, buf.read("f")),
cast(bool, buf.read("?")),
)


Expand Down Expand Up @@ -416,7 +421,11 @@ def __init__(self, yaw: float, pitch: float, on_ground: bool):

@classmethod
def unpack(cls, buf: Buffer) -> PlayPlayerRotation:
return cls(buf.read("f"), buf.read("f"), buf.read("?"))
return cls(
cast(float, buf.read("f")),
cast(float, buf.read("f")),
cast(bool, buf.read("?"))
)


class PlayPlayerMovement(ServerBoundPacket):
Expand All @@ -436,7 +445,7 @@ def __init__(self, on_ground: bool):

@classmethod
def unpack(cls, buf: Buffer) -> PlayPlayerMovement:
return cls(buf.read("?"))
return cls(cast(bool, buf.read("?")))


class PlayTeleportConfirm(ServerBoundPacket):
Expand Down Expand Up @@ -530,11 +539,11 @@ def unpack(cls, buf: Buffer) -> PlayClientSettings:
buf.read_string(),
buf.read_byte(),
buf.read_varint(),
buf.read("?"),
buf.read("B"),
cast(bool, buf.read("?")),
cast(int, buf.read("B")),
buf.read_varint(),
buf.read("?"),
buf.read("?"),
cast(bool, buf.read("?")),
cast(bool, buf.read("?")),
)


Expand All @@ -558,7 +567,10 @@ def __init__(self, slot_id: int, slot: dict):

@classmethod
def unpack(cls, buf: Buffer) -> PlayCreativeInventoryAction:
return cls(buf.read("h"), buf.read_slot())
return cls(
cast(int, buf.read("h")),
buf.read_slot(), # TODO: This is missing a Registry parameter?
)


class PlaySpectate(ServerBoundPacket):
Expand Down Expand Up @@ -775,6 +787,8 @@ def pack(self) -> Buffer:
for player in self.players:
buf.write_uuid(player.uuid)

return buf


class PlayFacePlayer(ClientBoundPacket):
"""Used by the server to rotate the client player to face the given location or entity. (Server -> Client)
Expand Down Expand Up @@ -804,8 +818,8 @@ def __init__(
target_y: float,
target_z: float,
is_entity: bool,
entity_id: int = None,
entity_feet_or_eyes: int = None,
entity_id: Optional[int] = None,
entity_feet_or_eyes: Optional[int] = None,
):
super().__init__()

Expand Down
3 changes: 2 additions & 1 deletion pymine_net/types/block_palette.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import abstractmethod
from typing import Optional

from strict_abc import StrictABC

Expand All @@ -17,7 +18,7 @@ def get_bits_per_block(self) -> int:
pass

@abstractmethod
def encode(self, block: str, props: dict = None) -> int:
def encode(self, block: str, props: Optional[dict] = None) -> int:
pass

@abstractmethod
Expand Down
Loading