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

Function init_block

src/endstone/python/block.cpp:23–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21namespace endstone::python {
22
23void init_block(py::module_ &m, py::class_<Block> &block)
24{
25 py::native_enum<BlockFace>(m, "BlockFace", "enum.Enum")
26 .value("DOWN", BlockFace::Down)
27 .value("UP", BlockFace::Up)
28 .value("NORTH", BlockFace::North)
29 .value("SOUTH", BlockFace::South)
30 .value("WEST", BlockFace::West)
31 .value("EAST", BlockFace::East)
32 .finalize();
33
34 // register class handles up front so cross-references render as Python names in the stubs
35 auto block_type = py::class_<BlockType>(m, "BlockType", "Represents a block type.");
36 auto block_data = py::class_<BlockData>(m, "BlockData", "Represents the data related to a live block");
37 auto block_state = py::class_<BlockState>(
38 m, "BlockState", "Represents a captured state of a block, which will not update automatically.");
39
40 block_type.def_property_readonly("id", &BlockType::getId, "Return the identifier of this block type.")
41 .def_property_readonly("translation_key", &BlockType::getTranslationKey,
42 "Get the translation key, suitable for use in a translation component.")
43 .def_property_readonly("has_item_type", &BlockType::hasItemType,
44 "Returns true if this BlockType has a corresponding ItemType.")
45 .def("create_block_data", &BlockType::createBlockData,
46 "Creates a new BlockData instance for this block type, with all properties initialized to defaults.")
47 .def_static("get", &BlockType::get, py::arg("name"), "Attempts to get the BlockType with the given name.",
48 py::return_value_policy::reference)
49 .def("__str__", &BlockType::getId)
50 .def("__repr__", [](const BlockType &self) { return fmt::format("BlockType({})", self.getId()); });
51
52 block_data.def_property_readonly("type", &BlockData::getType, "Get the block type represented by this block data.")
53 .def_property_readonly("block_states", &BlockData::getBlockStates, "Gets the block states for this block.")
54 .def_property_readonly("runtime_id", &BlockData::getRuntimeId, "Gets the runtime id for this block.")
55 .def("__str__", [](const BlockData &self) { return fmt::format("{}", self); });
56
57 block_state
58 .def_property_readonly("block", &BlockState::getBlock, "Gets the block represented by this block state.")
59 .def_property("type", &BlockState::getType, &BlockState::setType, "Gets or sets the type of this block state.")
60 .def_property("data", &BlockState::getData, &BlockState::setData, "Gets or sets the data for this block state.")
61 .def_property_readonly("dimension", &BlockState::getDimension, py::return_value_policy::reference,
62 "Gets the dimension which contains the block represented by this block state.")
63 .def_property_readonly("x", &BlockState::getX, "Gets the x-coordinate of this block state.")
64 .def_property_readonly("y", &BlockState::getY, "Gets the y-coordinate of this block state.")
65 .def_property_readonly("z", &BlockState::getZ, "Gets the z-coordinate of this block state.")
66 .def_property_readonly("location", &BlockState::getLocation, "Gets the location of this block state.")
67 .def("update", py::overload_cast<bool, bool>(&BlockState::update), py::arg("force") = false,
68 py::arg("apply_physics") = true, "Attempts to update the block represented by this state.")
69 .def("__str__", [](const BlockState &self) { return fmt::format("{}", self); });
70
71 block.def_property_readonly("type", &Block::getType, "Gets or sets the type of the block.")
72 .def("set_type", py::overload_cast<std::string, bool>(&Block::setType), py::arg("type"),
73 py::arg("apply_physics") = true, "Sets the type of this block")
74 .def_property_readonly("data", &Block::getData, "Gets the complete data for this block")
75 .def("set_data", py::overload_cast<const BlockData &, bool>(&Block::setData), py::arg("data"),
76 py::arg("apply_physics") = true, "Sets the complete data for this block")
77 .def("get_relative", py::overload_cast<int, int, int>(&Block::getRelative), py::arg("offset_x"),
78 py::arg("offset_y"), py::arg("offset_z"), "Gets the block at the given offsets")
79 .def("get_relative", py::overload_cast<BlockFace, int>(&Block::getRelative), py::arg("face"),
80 py::arg("distance") = 1, "Gets the block at the given distance of the given face")

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 2

valueMethod · 0.80
getIdMethod · 0.45

Tested by

no test coverage detected