Skip to content

Commit

Permalink
fix(python): correct binding for overloaded Dimension::getBlockAt f…
Browse files Browse the repository at this point in the history
…unction
  • Loading branch information
wu-vincent committed Sep 9, 2024
1 parent fa9d66e commit ede1674
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
23 changes: 19 additions & 4 deletions python/src/endstone/_internal/endstone_python.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -840,14 +840,14 @@ class Dimension:
OVERWORLD: typing.ClassVar[Dimension.Type] # value = <Type.OVERWORLD: 0>
THE_END: typing.ClassVar[Dimension.Type] # value = <Type.THE_END: 2>
@typing.overload
def get_block_at(self, x: int, y: int, z: int) -> Block:
def get_block_at(self, location: Location) -> Block:
"""
Gets the Block at the given coordinates
Gets the Block at the given Location
"""
@typing.overload
def get_block_at(self, location: Location) -> Block:
def get_block_at(self, x: int, y: int, z: int) -> Block:
"""
Gets the Block at the given Location
Gets the Block at the given coordinates
"""
@property
def level(self) -> Level:
Expand Down Expand Up @@ -2391,6 +2391,21 @@ class Position(Vector):
def __str__(self) -> str:
...
@property
def block_x(self) -> int:
"""
Gets the floored value of the X component, indicating the block that this location is contained with.
"""
@property
def block_y(self) -> int:
"""
Gets the floored value of the Y component, indicating the block that this location is contained with.
"""
@property
def block_z(self) -> int:
"""
Gets the floored value of the Z component, indicating the block that this location is contained with.
"""
@property
def dimension(self) -> Dimension:
"""
The Dimension that contains this position
Expand Down
15 changes: 12 additions & 3 deletions src/endstone_python/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ void init_level(py::module_ &m)
py::arg("z"))
.def_property("dimension", &Position::getDimension, &Position::setDimension, py::return_value_policy::reference,
"The Dimension that contains this position")
.def_property_readonly(
"block_x", &Position::getBlockX,
"Gets the floored value of the X component, indicating the block that this location is contained with.")
.def_property_readonly(
"block_y", &Position::getBlockY,
"Gets the floored value of the Y component, indicating the block that this location is contained with.")
.def_property_readonly(
"block_z", &Position::getBlockZ,
"Gets the floored value of the Z component, indicating the block that this location is contained with.")
.def("__repr__", position_to_string)
.def("__str__", position_to_string);

Expand Down Expand Up @@ -68,10 +77,10 @@ void init_level(py::module_ &m)
.def_property_readonly("type", &Dimension::getType, "Gets the type of this dimension")
.def_property_readonly("level", &Dimension::getLevel, "Gets the level to which this dimension belongs",
py::return_value_policy::reference)
.def("get_block_at", py::overload_cast<Location>(&Dimension::getBlockAt), py::arg("location").noconvert(),
"Gets the Block at the given Location")
.def("get_block_at", py::overload_cast<int, int, int>(&Dimension::getBlockAt), py::arg("x"), py::arg("y"),
py::arg("z"), "Gets the Block at the given coordinates")
.def("get_block_at", py::overload_cast<Location>(&Dimension::getBlockAt), py::arg("location"),
"Gets the Block at the given Location");
py::arg("z"), "Gets the Block at the given coordinates");

level.def_property_readonly("name", &Level::getName, "Gets the unique name of this level")
.def_property_readonly("actors", &Level::getActors, "Get a list of all actors in this level",
Expand Down

0 comments on commit ede1674

Please sign in to comment.