Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions mcproto/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import grpc

from ._types import COLOR
from ._base import HasStub
from .entity import _EntityCache
from .events import _EventHandler
Expand All @@ -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"]

Expand Down Expand Up @@ -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 = 5, fade_in: int = 1, fade_out: int = 1) -> None:
self.runCommand(self, f'title @a times {fade_in}s {duration}s {fade_out}s')
self.runCommand(self, f'title @a {typ} ' + '{' + f'"text":"{text}","color":"{color}","bold":{bold},"italic":{italic},"strikethrough":{strikethrough},"underlined":{underlined},"obfuscated":{obfuscated}' + '}')

def clearTitle(self):
self.runCommand(self, 'title @a clear')
8 changes: 8 additions & 0 deletions mcproto/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = 5, fade_in: int = 1, fade_out: int = 1) -> None:
self.runCommand(self, f'title {self.name} times {fade_in}s {duration}s {fade_out}s')
self.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:
Expand Down