MCPcopy Create free account
hub / github.com/EndstoneMC/endstone / init_util

Function init_util

src/endstone/python/util.cpp:22–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21namespace endstone::python {
22void init_util(py::module &m, py::class_<Vector> &vector)
23{
24 py::class_<SocketAddress>(m, "SocketAddress", "Represents an IP Socket Address (hostname + port number).")
25 .def(py::init<>())
26 .def(py::init<std::string, std::uint32_t>(), py::arg("hostname"), py::arg("port"))
27 .def_property_readonly("hostname", &SocketAddress::getHostname, "Gets the hostname.")
28 .def_property_readonly("port", &SocketAddress::getPort, "Gets the port number.")
29 .def("__repr__",
30 [](const SocketAddress &self) {
31 return fmt::format("SocketAddress(hostname='{}', port={})", self.getHostname(), self.getPort());
32 })
33 .def("__str__",
34 [](const SocketAddress &self) { return self.getHostname() + ":" + std::to_string(self.getPort()); });
35
36 vector.def(py::init<>())
37 .def(py::init<float, float, float>(), py::arg("x"), py::arg("y"), py::arg("z"))
38 .def_property(
39 "x", &Vector::getX, [](Vector &self, float x) { self.setX(x); }, "The X component of the vector")
40 .def_property(
41 "y", &Vector::getY, [](Vector &self, float y) { self.setY(y); }, "The Y component of the vector")
42 .def_property(
43 "z", &Vector::getZ, [](Vector &self, float z) { self.setZ(z); }, "The Z component of the vector")
44 .def_property_readonly(
45 "block_x", &Vector::getBlockX,
46 "Gets the floored value of the X component, indicating the block that this vector is contained with.")
47 .def_property_readonly(
48 "block_y", &Vector::getBlockY,
49 "Gets the floored value of the Y component, indicating the block that this vector is contained with.")
50 .def_property_readonly(
51 "block_z", &Vector::getBlockZ,
52 "Gets the floored value of the Z component, indicating the block that this vector is contained with.")
53 .def(py::self + py::self)
54 .def(py::self - py::self)
55 .def(py::self * py::self)
56 .def(py::self / py::self)
57 .def(py::self += py::self)
58 .def(py::self -= py::self)
59 .def(py::self *= py::self)
60 .def(py::self /= py::self)
61 .def(py::self + float())
62 .def(py::self - float())
63 .def(py::self * float())
64 .def(py::self / float())
65 .def(float() + py::self)
66 .def(float() - py::self)
67 .def(float() * py::self)
68 .def(float() / py::self)
69 .def(py::self == py::self)
70 .def(py::self != py::self)
71 .def_property_readonly("length", &Vector::length, "The magnitude of the Vector")
72 .def_property_readonly("length_squared", &Vector::lengthSquared, "The squared magnitude of the Vector")
73 .def("distance", &Vector::distance, py::arg("other"), "The distance between this Vector and another")
74 .def("distance_squared", &Vector::distanceSquared, py::arg("other"),
75 "The squared distance between this Vector and another")
76 .def("angle", &Vector::angle, py::arg("other"), "Gets the angle between this vector and another in radians.")
77 .def("midpoint", &Vector::getMidpoint, py::arg("other"),
78 "Gets a new midpoint vector between this vector and another.")
79 .def("dot", &Vector::dot, py::arg("other"), "Calculates the dot product of this vector with another.")

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 9

VectorClass · 0.85
setZMethod · 0.80
isNormalizedMethod · 0.80
getPortMethod · 0.45
setXMethod · 0.45
setYMethod · 0.45
getXMethod · 0.45
getYMethod · 0.45
getZMethod · 0.45

Tested by

no test coverage detected