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
153 changes: 153 additions & 0 deletions mcproto/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,156 @@
"red",
"black",
]

SLOTS: TypeAlias = Literal[
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bitte Einzahl verwenden, also SLOT statt SLOTS.

"armor.head",
"armor.chest",
"armor.legs",
"armor.feet",
"container.0",
"container.1",
"container.2",
"container.3",
"container.4",
"container.5",
"container.6",
"container.7",
"container.8",
"container.9",
"container.10",
"container.11",
"container.12",
"container.13",
"container.14",
"container.15",
"container.16",
"container.17",
"container.18",
"container.19",
"container.20",
"container.21",
"container.22",
"container.23",
"container.24",
"container.25",
"container.26",
"container.27",
"container.28",
"container.29",
"container.30",
"container.31",
"container.32",
"container.33",
"container.34",
"container.35",
"container.36",
"container.37",
"container.38",
"container.39",
"container.40",
"container.41",
"container.42",
"container.43",
"container.44",
"container.45",
"container.46",
"container.47",
"container.48",
"container.49",
"container.50",
"container.51",
"container.52",
"container.53",
"enderchest.0",
"enderchest.1",
"enderchest.2",
"enderchest.3",
"enderchest.4",
"enderchest.5",
"enderchest.6",
"enderchest.7",
"enderchest.8",
"enderchest.9",
"enderchest.10",
"enderchest.11",
"enderchest.12",
"enderchest.13",
"enderchest.14",
"enderchest.15",
"enderchest.16",
"enderchest.17",
"enderchest.18",
"enderchest.19",
"enderchest.20",
"enderchest.21",
"enderchest.22",
"enderchest.23",
"enderchest.24",
"enderchest.25",
"enderchest.26",
"horse.0",
"horse.1",
"horse.2",
"horse.3",
"horse.4",
"horse.5",
"horse.6",
"horse.7",
"horse.8",
"horse.9",
"horse.10",
"horse.11",
"horse.12",
"horse.13",
"horse.14",
"horse.armor",
"horse.chest",
"horse.saddle",
"hotbar.0",
"hotbar.1",
"hotbar.2",
"hotbar.3",
"hotbar.4",
"hotbar.5",
"hotbar.6",
"hotbar.7",
"hotbar.8",
"inventory.0",
"inventory.1",
"inventory.2",
"inventory.3",
"inventory.4",
"inventory.5",
"inventory.6",
"inventory.7",
"inventory.8",
"inventory.9",
"inventory.10",
"inventory.11",
"inventory.12",
"inventory.13",
"inventory.14",
"inventory.15",
"inventory.16",
"inventory.17",
"inventory.18",
"inventory.19",
"inventory.20",
"inventory.21",
"inventory.22",
"inventory.23",
"inventory.24",
"inventory.25",
"inventory.26",
"villager.0",
"villager.1",
"villager.2",
"villager.3",
"villager.4",
"villager.5",
"villager.6",
"villager.7",
"weapon",
"weapon.mainhand",
"weapon.offhand"
]
4 changes: 2 additions & 2 deletions mcproto/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from functools import partial

from ._base import HasStub, _EntityProvider
from ._types import COLOR
from ._types import COLOR, SLOTS
from ._util import ThreadSafeCachedKeyBasedFactory
from .colors import color_codes
from .exception import raise_on_error
Expand Down Expand Up @@ -126,7 +126,7 @@ def giveEffect(
pbool = str(not bool(particles)).lower()
self.runCommand(f"effect give @s {effect} {int(seconds)} {amplifier} {pbool}")

def replaceItem(self, where: str, item: str, amount: int = 1, nbt: NBT | None = None) -> None:
def replaceItem(self, where: SLOTS, item: str, amount: int = 1, nbt: NBT | None = None) -> None:
if nbt is None:
self.runCommand(f"item replace entity @s {where} with {item} {amount}")
else:
Expand Down
9 changes: 8 additions & 1 deletion mcproto/world.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from .nbt import NBT
from . import entity
from ._base import HasStub, _EntityProvider
from ._types import CARDINAL, COLOR, DIRECTION
from ._types import CARDINAL, COLOR, DIRECTION, SLOTS
from .exception import raise_on_error
from .mcpb import MinecraftStub
from .mcpb import minecraft_pb2 as pb
Expand Down Expand Up @@ -97,6 +98,12 @@ def setBlockCube(self, blocktype: str, pos1: Vec3, pos2: Vec3) -> None:
)
)
raise_on_error(response)

def replaceItem(self, pos: Vec3, slot: SLOTS, item: str, amount: int = 1, nbt: NBT | None = None) -> None:
if nbt is None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bitte hier nur kurz die position abrunden, falls jemand keine Ganzzahlige Position hineinreicht.
(also, vor dem if ein pos = pos.floor() oder so, sollte meistens keine Rolle spielen, aber war eine Idee, die ich gerade hatte

self.runCommand(f"item replace block {pos.x} {pos.y} {pos.z} {slot} with {item} {amount}")
else:
self.runCommand(f"item replace block {pos.x} {pos.y} {pos.z} {slot} with {item}{nbt} {amount}")

def __getitem__(
self,
Expand Down