| 25 | } // namespace |
| 26 | |
| 27 | void init_level(py::module_ &m, py::class_<Level> &level, py::class_<Dimension> &dimension, |
| 28 | py::class_<Location> &location) |
| 29 | { |
| 30 | py::class_<Chunk>(m, "Chunk", "Represents a chunk of blocks.") |
| 31 | .def_property_readonly("x", &Chunk::getX, "Gets the X-coordinate of this chunk") |
| 32 | .def_property_readonly("z", &Chunk::getZ, "Gets the Z-coordinate of this chunk") |
| 33 | .def_property_readonly("level", &Chunk::getLevel, "Gets the level containing this chunk", |
| 34 | py::return_value_policy::reference) |
| 35 | .def_property_readonly("dimension", &Chunk::getDimension, "Gets the dimension containing this chunk", |
| 36 | py::return_value_policy::reference) |
| 37 | .def("__repr__", [](const Chunk &self) { return fmt::format("{}", self); }) |
| 38 | .def("__str__", [](const Chunk &self) { return fmt::format("{}", self); }); |
| 39 | |
| 40 | py::native_enum<Dimension::Type>(dimension, "Type", "enum.Enum", "Represents various dimension types.") |
| 41 | .value("OVERWORLD", Dimension::Type::Overworld) |
| 42 | .value("NETHER", Dimension::Type::Nether) |
| 43 | .value("THE_END", Dimension::Type::TheEnd) |
| 44 | .value("CUSTOM", Dimension::Type::Custom) |
| 45 | .export_values() |
| 46 | .finalize(); |
| 47 | |
| 48 | dimension.def_property_readonly("name", &Dimension::getName, "Gets the name of this dimension") |
| 49 | .def_property_readonly("type", &Dimension::getType, "Gets the type of this dimension") |
| 50 | .def_property_readonly("level", &Dimension::getLevel, "Gets the level to which this dimension belongs", |
| 51 | py::return_value_policy::reference) |
| 52 | .def("get_block_at", py::overload_cast<Location>(&Dimension::getBlockAt, py::const_), |
| 53 | py::arg("location").noconvert(), "Gets the Block at the given Location") |
| 54 | .def("get_block_at", py::overload_cast<int, int, int>(&Dimension::getBlockAt, py::const_), py::arg("x"), |
| 55 | py::arg("y"), py::arg("z"), "Gets the Block at the given coordinates") |
| 56 | .def("get_highest_block_y_at", &Dimension::getHighestBlockYAt, py::arg("x"), py::arg("z"), |
| 57 | "Gets the highest non-empty (impassable) coordinate at the given coordinates.") |
| 58 | .def("get_highest_block_at", py::overload_cast<Location>(&Dimension::getHighestBlockAt, py::const_), |
| 59 | py::arg("location").noconvert(), "Gets the highest non-empty (impassable) block at the given Location.") |
| 60 | .def("get_highest_block_at", py::overload_cast<int, int>(&Dimension::getHighestBlockAt, py::const_), |
| 61 | py::arg("x"), py::arg("z"), "Gets the highest non-empty (impassable) block at the given coordinates.") |
| 62 | .def_property_readonly("loaded_chunks", &Dimension::getLoadedChunks, "Gets a list of all loaded Chunks") |
| 63 | .def("drop_item", &Dimension::dropItem, py::arg("location"), py::arg("item"), |
| 64 | py::return_value_policy::reference, "Drops an item at the specified Location") |
| 65 | .def("spawn_actor", &Dimension::spawnActor, py::arg("location"), py::arg("type"), |
| 66 | py::return_value_policy::reference, "Creates an actor at the given Location") |
| 67 | .def_property_readonly("actors", &Dimension::getActors, py::return_value_policy::reference_internal, |
| 68 | "Get a list of all actors in this dimension"); |
| 69 | |
| 70 | level.def_property_readonly("name", &Level::getName, "Gets the unique name of this level") |
| 71 | .def_property_readonly("actors", &Level::getActors, "Get a list of all actors in this level", |
| 72 | py::return_value_policy::reference_internal) |
| 73 | .def_property("time", &Level::getTime, &Level::setTime, "Gets and sets the relative in-game time on the server") |
| 74 | .def_property_readonly("dimensions", &Level::getDimensions, "Gets a list of all dimensions within this level.", |
| 75 | py::return_value_policy::reference_internal) |
| 76 | .def("get_dimension", &Level::getDimension, py::arg("name"), "Gets the dimension with the given name.", |
| 77 | py::return_value_policy::reference) |
| 78 | .def_property_readonly("seed", &Level::getSeed, "Gets the Seed for this level."); |
| 79 | |
| 80 | location |
| 81 | .def(py::init(&create_location), py::arg("dimension"), py::arg("x"), py::arg("y"), py::arg("z"), |
| 82 | py::arg("pitch") = 0.0, py::arg("yaw") = 0.0) |
| 83 | .def_property("dimension", &Location::getDimension, &Location::setDimension, py::return_value_policy::reference, |
| 84 | "The Dimension that contains this position") |