mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Genericize find_node_near and find_node_in implementations in C++
This commit is contained in:
parent
20b10b5691
commit
62629939ff
2 changed files with 157 additions and 99 deletions
|
@ -23,7 +23,38 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "serverenvironment.h"
|
||||
#include "raycast.h"
|
||||
|
||||
class ModApiEnvMod : public ModApiBase {
|
||||
// base class containing helpers
|
||||
class ModApiEnvBase : public ModApiBase {
|
||||
protected:
|
||||
|
||||
static void collectNodeIds(lua_State *L, int idx,
|
||||
const NodeDefManager *ndef, std::vector<content_t> &filter);
|
||||
|
||||
static void checkArea(v3s16 &minp, v3s16 &maxp);
|
||||
|
||||
// F must be (v3s16 pos) -> MapNode
|
||||
template <typename F>
|
||||
static int findNodeNear(lua_State *L, v3s16 pos, int radius,
|
||||
const std::vector<content_t> &filter, int start_radius, F &&getNode);
|
||||
|
||||
// F must be (G callback) -> void
|
||||
// with G being (v3s16 p, MapNode n) -> bool
|
||||
// and behave like Map::forEachNodeInArea
|
||||
template <typename F>
|
||||
static int findNodesInArea(lua_State *L, const NodeDefManager *ndef,
|
||||
const std::vector<content_t> &filter, bool grouped, F &&iterate);
|
||||
|
||||
// F must be (v3s16 pos) -> MapNode
|
||||
template <typename F>
|
||||
static int findNodesInAreaUnderAir(lua_State *L, v3s16 minp, v3s16 maxp,
|
||||
const std::vector<content_t> &filter, F &&getNode);
|
||||
|
||||
static const EnumString es_ClearObjectsMode[];
|
||||
static const EnumString es_BlockStatusType[];
|
||||
|
||||
};
|
||||
|
||||
class ModApiEnvMod : public ModApiEnvBase {
|
||||
private:
|
||||
// set_node(pos, node)
|
||||
// pos = {x=num, y=num, z=num}
|
||||
|
@ -198,20 +229,12 @@ private:
|
|||
// compare_block_status(nodepos)
|
||||
static int l_compare_block_status(lua_State *L);
|
||||
|
||||
// Get a string translated server side
|
||||
// get_translated_string(lang_code, string)
|
||||
static int l_get_translated_string(lua_State * L);
|
||||
|
||||
/* Helpers */
|
||||
|
||||
static void collectNodeIds(lua_State *L, int idx,
|
||||
const NodeDefManager *ndef, std::vector<content_t> &filter);
|
||||
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
static void InitializeClient(lua_State *L, int top);
|
||||
|
||||
static const EnumString es_ClearObjectsMode[];
|
||||
static const EnumString es_BlockStatusType[];
|
||||
};
|
||||
|
||||
class LuaABM : public ActiveBlockModifier {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue