diff --git a/mcproto/minecraft.py b/mcproto/minecraft.py index 150e9c9..2bbd5d2 100644 --- a/mcproto/minecraft.py +++ b/mcproto/minecraft.py @@ -5,6 +5,7 @@ import grpc +from ._types import COLOR from ._base import HasStub from .entity import _EntityCache from .events import _EventHandler @@ -13,6 +14,7 @@ from .mcpb import minecraft_pb2 as pb from .player import _PlayerCache from .world import _DefaultWorld, _WorldHub +from typing import Literal __all__ = ["Minecraft"] @@ -54,3 +56,10 @@ def port(self) -> int: def postToChat(self, *args, sep: str = " ") -> None: response = self._stub.postToChat(pb.ChatPostRequest(message=sep.join(map(str, args)))) raise_on_error(response) + + def showTitle(self, text: str, typ: Literal["actionbar", "subtitle", "title"] = "title", color: COLOR = "gray", bold: bool = "false", italic: bool = "false", strikethrough: bool = "false", underlined: bool = "false", obfuscated: bool = "false", duration: int = 3, fade_in: int = 1, fade_out: int = 1) -> None: + HasStub.runCommand(self, f'title @a times {fade_in}s {duration}s {fade_out}s') + HasStub.runCommand(self, f'title @a {typ} ' + '{' + f'"text":"{text}","color":"{color}","bold":{bold},"italic":{italic},"strikethrough":{strikethrough},"underlined":{underlined},"obfuscated":{obfuscated}' + '}') + + def clearTitle(self): + HasStub.runCommand(self, 'title @a clear') diff --git a/mcproto/player.py b/mcproto/player.py index b3bc22a..a9ee0a2 100644 --- a/mcproto/player.py +++ b/mcproto/player.py @@ -4,6 +4,7 @@ from functools import partial from typing import Literal +from ._types import COLOR from ._base import HasStub, _PlayerProvider from ._util import ThreadSafeCachedKeyBasedFactory from .entity import Entity @@ -118,6 +119,13 @@ def op(self) -> None: def deop(self) -> None: HasStub.runCommand(self, f"deop {self.name}") + def showTitle(self, text: str, typ: Literal["actionbar", "subtitle", "title"] = "title", color: COLOR = "gray", bold: bool = "false", italic: bool = "false", strikethrough: bool = "false", underlined: bool = "false", obfuscated: bool = "false", duration: int = 3, fade_in: int = 1, fade_out: int = 1) -> None: + HasStub.runCommand(self, f'title {self.name} times {fade_in}s {duration}s {fade_out}s') + HasStub.runCommand(self, f'title {self.name} {typ} ' + '{' + f'"text":"{text}","color":"{color}","bold":{bold},"italic":{italic},"strikethrough":{strikethrough},"underlined":{underlined},"obfuscated":{obfuscated}' + '}') + + def clearTitle(self): + self.runCommand("title @s clear") + # properties that have different stub entpoints than entity @property def pos(self) -> Vec3: