From caff7ce965b4728b08f5b11677b3d622e53f48c3 Mon Sep 17 00:00:00 2001 From: alemidev Date: Sat, 11 Dec 2021 06:00:09 +0100 Subject: [PATCH] util methods for BlockPos --- aiocraft/mc/definitions.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/aiocraft/mc/definitions.py b/aiocraft/mc/definitions.py index c406969..5a41161 100644 --- a/aiocraft/mc/definitions.py +++ b/aiocraft/mc/definitions.py @@ -9,6 +9,22 @@ class BlockPos: y : float z : float + def __equals__(self, other) -> bool: + if not isinstance(other, self.__class__): + return False + return self.x == other.x \ + and self.y == other.y \ + and self.z == other.z + + def __repr__(self) -> str: + return f"{self.__class__.__name__}(x={self.x},y={self.y},z={self.z})" + + def __str__(self) -> str: + return repr(self) + + def __hash__(self) -> int: + return hash(repr(self)) # TODO VERY cheap hack but Cantor pairing or hash combining is not something I want to get into now + @classmethod def from_tuple(cls, t:Tuple[float, float, float]): return cls(x=float(t[0]), y=float(t[1]), z=float(t[2]))