Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
l_env.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "lua_api/l_base.h"
8#include "raycast.h"
9
10class ServerScripting;
11
12// base class containing helpers
13class ModApiEnvBase : public ModApiBase {
14protected:
15
16 static void collectNodeIds(lua_State *L, int idx,
17 const NodeDefManager *ndef, std::vector<content_t> &filter);
18
19 static void checkArea(v3s16 &minp, v3s16 &maxp);
20
21 // F must be (v3s16 pos) -> MapNode
22 template <typename F>
23 static int findNodeNear(lua_State *L, v3s16 pos, int radius,
24 const std::vector<content_t> &filter, int start_radius, F &&getNode);
25
26 // F must be (G callback) -> void
27 // with G being (v3s16 p, MapNode n) -> bool
28 // and behave like Map::forEachNodeInArea
29 template <typename F>
30 static int findNodesInArea(lua_State *L, const NodeDefManager *ndef,
31 const std::vector<content_t> &filter, bool grouped, F &&iterate);
32
33 // F must be (v3s16 pos) -> MapNode
34 template <typename F>
35 static int findNodesInAreaUnderAir(lua_State *L, v3s16 minp, v3s16 maxp,
36 const std::vector<content_t> &filter, F &&getNode);
37
38 static const EnumString es_ClearObjectsMode[];
39 static const EnumString es_BlockStatusType[];
40
41};
43class ModApiEnv : public ModApiEnvBase {
44private:
45 // set_node(pos, node)
46 // pos = {x=num, y=num, z=num}
47 static int l_set_node(lua_State *L);
48
49 // bulk_set_node([pos1, pos2, ...], node)
50 // pos = {x=num, y=num, z=num}
51 static int l_bulk_set_node(lua_State *L);
52
53 // bulk_swap_node([pos1, pos2, ...], node)
54 // pos = {x=num, y=num, z=num}
55 static int l_bulk_swap_node(lua_State *L);
56
57 static int l_add_node(lua_State *L);
58
59 // remove_node(pos)
60 // pos = {x=num, y=num, z=num}
61 static int l_remove_node(lua_State *L);
62
63 // swap_node(pos, node)
64 // pos = {x=num, y=num, z=num}
65 static int l_swap_node(lua_State *L);
66
67 // get_node_raw(x, y, z) -> content, param1, param2, pos_ok
68 // Used to implement get_node and get_node_or_nil in lua.
69 // This is still faster than doing it from C++ even with optimized pushnode.
70 static int l_get_node_raw(lua_State *L);
71
72 // get_node_light(pos, timeofday)
73 // pos = {x=num, y=num, z=num}
74 // timeofday: nil = current time, 0 = night, 0.5 = day
75 static int l_get_node_light(lua_State *L);
76
77 // get_natural_light(pos, timeofday)
78 // pos = {x=num, y=num, z=num}
79 // timeofday: nil = current time, 0 = night, 0.5 = day
80 static int l_get_natural_light(lua_State *L);
81
82 // place_node(pos, node, [placer])
83 // pos = {x=num, y=num, z=num}
84 static int l_place_node(lua_State *L);
85
86 // dig_node(pos, [digger])
87 // pos = {x=num, y=num, z=num}
88 static int l_dig_node(lua_State *L);
89
90 // punch_node(pos, [puncher])
91 // pos = {x=num, y=num, z=num}
92 static int l_punch_node(lua_State *L);
93
94 // get_node_max_level(pos)
95 // pos = {x=num, y=num, z=num}
96 static int l_get_node_max_level(lua_State *L);
97
98 // get_node_level(pos)
99 // pos = {x=num, y=num, z=num}
100 static int l_get_node_level(lua_State *L);
101
102 // set_node_level(pos)
103 // pos = {x=num, y=num, z=num}
104 static int l_set_node_level(lua_State *L);
105
106 // add_node_level(pos)
107 // pos = {x=num, y=num, z=num}
108 static int l_add_node_level(lua_State *L);
109
110 // get_node_boxes(box_type, pos, [node]) -> table
111 // box_type = string
112 // pos = {x=num, y=num, z=num}
113 // node = {name=string, param1=num, param2=num} or nil
114 static int l_get_node_boxes(lua_State *L);
115
116 // find_nodes_with_meta(pos1, pos2)
117 static int l_find_nodes_with_meta(lua_State *L);
118
119 // get_meta(pos)
120 static int l_get_meta(lua_State *L);
121
122 // get_node_timer(pos)
123 static int l_get_node_timer(lua_State *L);
124
125 // add_entity(pos, entityname) -> ObjectRef or nil
126 // pos = {x=num, y=num, z=num}
127 static int l_add_entity(lua_State *L);
128
129 // add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
130 // pos = {x=num, y=num, z=num}
131 static int l_add_item(lua_State *L);
132
133 // get_connected_players()
134 static int l_get_connected_players(lua_State *L);
135
136 // get_player_by_name(name)
137 static int l_get_player_by_name(lua_State *L);
138
139 // get_objects_inside_radius(pos, radius)
140 static int l_get_objects_inside_radius(lua_State *L);
141
142 // get_objects_in_area(pos, minp, maxp)
143 static int l_get_objects_in_area(lua_State *L);
144
145 // set_timeofday(val)
146 // val = 0...1
147 static int l_set_timeofday(lua_State *L);
148
149 // get_timeofday() -> 0...1
150 static int l_get_timeofday(lua_State *L);
151
152 // get_gametime()
153 static int l_get_gametime(lua_State *L);
154
155 // get_day_count() -> int
156 static int l_get_day_count(lua_State *L);
157
158 // find_node_near(pos, radius, nodenames, search_center) -> pos or nil
159 // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
160 static int l_find_node_near(lua_State *L);
161
162 // find_nodes_in_area(minp, maxp, nodenames) -> list of positions
163 // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
164 static int l_find_nodes_in_area(lua_State *L);
165
166 // find_surface_nodes_in_area(minp, maxp, nodenames) -> list of positions
167 // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
168 static int l_find_nodes_in_area_under_air(lua_State *L);
169
170 // fix_light(p1, p2) -> true/false
171 static int l_fix_light(lua_State *L);
172
173 // load_area(p1)
174 static int l_load_area(lua_State *L);
175
176 // emerge_area(p1, p2)
177 static int l_emerge_area(lua_State *L);
178
179 // delete_area(p1, p2) -> true/false
180 static int l_delete_area(lua_State *L);
181
182 // get_perlin(seeddiff, octaves, persistence, scale)
183 // returns world-specific PerlinNoise
184 static int l_get_perlin(lua_State *L);
185
186 // get_perlin_map(noiseparams, size)
187 // returns world-specific PerlinNoiseMap
188 static int l_get_perlin_map(lua_State *L);
189
190 // get_voxel_manip()
191 // returns world-specific voxel manipulator
192 static int l_get_voxel_manip(lua_State *L);
193
194 // clear_objects()
195 // clear all objects in the environment
196 static int l_clear_objects(lua_State *L);
197
198 // spawn_tree(pos, treedef)
199 static int l_spawn_tree(lua_State *L);
200
201 // line_of_sight(pos1, pos2) -> true/false
202 static int l_line_of_sight(lua_State *L);
203
204 // raycast(pos1, pos2, objects, liquids) -> Raycast
205 static int l_raycast(lua_State *L);
206
207 // find_path(pos1, pos2, searchdistance,
208 // max_jump, max_drop, algorithm) -> table containing path
209 static int l_find_path(lua_State *L);
210
211 // transforming_liquid_add(pos)
212 static int l_transforming_liquid_add(lua_State *L);
213
214 // forceload_block(blockpos)
215 // forceloads a block
216 static int l_forceload_block(lua_State *L);
217
218 // forceload_free_block(blockpos)
219 // stops forceloading a position
220 static int l_forceload_free_block(lua_State *L);
221
222 // compare_block_status(nodepos)
223 static int l_compare_block_status(lua_State *L);
224
225 // get_translated_string(lang_code, string)
226 static int l_get_translated_string(lua_State * L);
227
228public:
229 static void Initialize(lua_State *L, int top);
230 static void InitializeClient(lua_State *L, int top);
231};
232
233/*
234 * Duplicates of certain env APIs that operate not on the global
235 * map but on a VoxelManipulator. This is for emerge scripting.
236 */
238private:
239
240 // get_node_or_nil(pos)
241 static int l_get_node_or_nil(lua_State *L);
242
243 // get_node_max_level(pos)
244 static int l_get_node_max_level(lua_State *L);
245
246 // get_node_level(pos)
247 static int l_get_node_level(lua_State *L);
248
249 // set_node_level(pos)
250 static int l_set_node_level(lua_State *L);
251
252 // add_node_level(pos)
253 static int l_add_node_level(lua_State *L);
254
255 // find_node_near(pos, radius, nodenames, [search_center])
256 static int l_find_node_near(lua_State *L);
257
258 // find_nodes_in_area(minp, maxp, nodenames, [grouped])
259 static int l_find_nodes_in_area(lua_State *L);
260
261 // find_surface_nodes_in_area(minp, maxp, nodenames)
262 static int l_find_nodes_in_area_under_air(lua_State *L);
263
264 // spawn_tree(pos, treedef)
265 static int l_spawn_tree(lua_State *L);
266
267 // Helper: get the vmanip we're operating on
268 static MMVManip *getVManip(lua_State *L);
269
270public:
271 static void InitializeEmerge(lua_State *L, int top);
272};
273
275class LuaRaycast : public ModApiBase
276{
277private:
278 static const luaL_Reg methods[];
281
282 // Exported functions
283
284 // garbage collector
285 static int gc_object(lua_State *L);
286
291 static int l_next(lua_State *L);
292public:
295 const core::line3d<f32> &shootline,
296 bool objects_pointable,
297 bool liquids_pointable,
298 const std::optional<Pointabilities> &pointabilities) :
299 state(shootline, objects_pointable, liquids_pointable, pointabilities)
300 {}
301
303 static int create_object(lua_State *L);
304
306 static void Register(lua_State *L);
307
308 static const char className[];
309};
310
Lua wrapper for RaycastState objects.
Definition l_env.h:276
LuaRaycast(const core::line3d< f32 > &shootline, bool objects_pointable, bool liquids_pointable, const std::optional< Pointabilities > &pointabilities)
Constructor with the same arguments as RaycastState.
Definition l_env.h:294
static int l_next(lua_State *L)
Definition l_env.cpp:53
static const char className[]
Definition l_env.h:308
static const luaL_Reg methods[]
Definition l_env.h:133
static int gc_object(lua_State *L)
Definition l_env.cpp:113
RaycastState state
Inner state.
Definition l_env.h:280
static int create_object(lua_State *L)
Creates a LuaRaycast and leaves it on top of the stack.
Definition l_env.cpp:84
Definition map.h:305
Definition l_base.h:28
Definition l_env.h:13
static int findNodesInArea(lua_State *L, const NodeDefManager *ndef, const std::vector< content_t > &filter, bool grouped, F &&iterate)
Definition l_env.cpp:863
static const EnumString es_ClearObjectsMode[]
Definition l_env.h:35
static void collectNodeIds(lua_State *L, int idx, const NodeDefManager *ndef, std::vector< content_t > &filter)
Definition l_env.cpp:784
static void checkArea(v3s16 &minp, v3s16 &maxp)
Definition l_env.cpp:847
static int findNodeNear(lua_State *L, v3s16 pos, int radius, const std::vector< content_t > &filter, int start_radius, F &&getNode)
Definition l_env.cpp:802
static int findNodesInAreaUnderAir(lua_State *L, v3s16 minp, v3s16 maxp, const std::vector< content_t > &filter, F &&getNode)
Definition l_env.cpp:968
static const EnumString es_BlockStatusType[]
Definition l_env.h:42
Definition l_env.h:237
static int l_get_node_or_nil(lua_State *L)
Definition l_env.cpp:1458
static int l_spawn_tree(lua_State *L)
Definition l_env.cpp:1603
static void InitializeEmerge(lua_State *L, int top)
Definition l_env.cpp:1636
static int l_add_node_level(lua_State *L)
Definition l_env.cpp:1508
static int l_find_node_near(lua_State *L)
Definition l_env.cpp:1523
static int l_find_nodes_in_area(lua_State *L)
Definition l_env.cpp:1542
static int l_get_node_max_level(lua_State *L)
Definition l_env.cpp:1471
static int l_set_node_level(lua_State *L)
Definition l_env.cpp:1493
static int l_find_nodes_in_area_under_air(lua_State *L)
Definition l_env.cpp:1582
static MMVManip * getVManip(lua_State *L)
Definition l_env.cpp:1628
static int l_get_node_level(lua_State *L)
Definition l_env.cpp:1482
Definition l_env.h:43
static int l_bulk_set_node(lua_State *L)
Definition l_env.cpp:177
static int l_forceload_block(lua_State *L)
Definition l_env.cpp:1333
static int l_find_nodes_in_area_under_air(lua_State *L)
Definition l_env.cpp:994
static int l_fix_light(lua_State *L)
Definition l_env.cpp:1118
static int l_raycast(lua_State *L)
Definition l_env.cpp:1145
static int l_set_timeofday(lua_State *L)
Definition l_env.cpp:740
static int l_get_translated_string(lua_State *L)
Definition l_env.cpp:1372
static int l_swap_node(lua_State *L)
Definition l_env.cpp:228
static int l_add_node(lua_State *L)
Definition l_env.cpp:207
static int l_get_voxel_manip(lua_State *L)
Definition l_env.cpp:1074
static int l_find_nodes_with_meta(lua_State *L)
Definition l_env.cpp:555
static int l_get_node_max_level(lua_State *L)
Definition l_env.cpp:464
static int l_spawn_tree(lua_State *L)
Definition l_env.cpp:1295
static int l_bulk_swap_node(lua_State *L)
Definition l_env.cpp:243
static int l_get_node_level(lua_State *L)
Definition l_env.cpp:476
static int l_emerge_area(lua_State *L)
Definition l_env.cpp:1176
static int l_get_objects_inside_radius(lua_State *L)
Definition l_env.cpp:690
static int l_get_node_light(lua_State *L)
Definition l_env.cpp:291
static int l_get_connected_players(lua_State *L)
Definition l_env.cpp:649
static int l_forceload_free_block(lua_State *L)
Definition l_env.cpp:1362
static int l_set_node(lua_State *L)
Definition l_env.cpp:162
static int l_get_player_by_name(lua_State *L)
Definition l_env.cpp:672
static int l_load_area(lua_State *L)
Definition l_env.cpp:1152
static int l_get_timeofday(lua_State *L)
Definition l_env.cpp:758
static int l_get_gametime(lua_State *L)
Definition l_env.cpp:776
static int l_find_nodes_in_area(lua_State *L)
Definition l_env.cpp:936
static int l_set_node_level(lua_State *L)
Definition l_env.cpp:489
static int l_get_node_raw(lua_State *L)
Definition l_env.cpp:267
static int l_line_of_sight(lua_State *L)
Definition l_env.cpp:1097
static int l_find_node_near(lua_State *L)
Definition l_env.cpp:821
static void Initialize(lua_State *L, int top)
Definition l_env.cpp:1384
static int l_get_perlin(lua_State *L)
Definition l_env.cpp:1029
static int l_add_entity(lua_State *L)
Definition l_env.cpp:595
static int l_get_meta(lua_State *L)
Definition l_env.cpp:572
static int l_get_node_timer(lua_State *L)
Definition l_env.cpp:583
static int l_clear_objects(lua_State *L)
Definition l_env.cpp:1082
static int l_add_node_level(lua_State *L)
Definition l_env.cpp:506
static int l_get_day_count(lua_State *L)
Definition l_env.cpp:767
static int l_punch_node(lua_State *L)
Definition l_env.cpp:431
static int l_add_item(lua_State *L)
Definition l_env.cpp:620
static int l_get_natural_light(lua_State *L)
Definition l_env.cpp:318
static int l_get_node_boxes(lua_State *L)
Definition l_env.cpp:524
static int l_dig_node(lua_State *L)
Definition l_env.cpp:399
static int l_transforming_liquid_add(lua_State *L)
Definition l_env.cpp:1322
static int l_get_objects_in_area(lua_State *L)
Definition l_env.cpp:714
static void InitializeClient(lua_State *L, int top)
Definition l_env.cpp:1438
static int l_find_path(lua_State *L)
Definition l_env.cpp:1255
static int l_compare_block_status(lua_State *L)
Definition l_env.cpp:1343
static int l_delete_area(lua_State *L)
Definition l_env.cpp:1222
static int l_place_node(lua_State *L)
Definition l_env.cpp:356
static int l_remove_node(lua_State *L)
Definition l_env.cpp:214
static int l_get_perlin_map(lua_State *L)
Definition l_env.cpp:1055
This class is for getting the actual properties of nodes from their content ID.
Definition nodedef.h:540
Describes the state of a raycast.
Definition raycast.h:18
Definition scripting_server.h:33
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
#define idx(x, y)
Definition noise.cpp:490
Definition c_types.h:16
Definition l_env.h:311
int args_ref
Definition l_env.h:314
std::string origin
Definition l_env.h:316
ServerScripting * script
Definition l_env.h:312
int callback_ref
Definition l_env.h:313
unsigned int refcount
Definition l_env.h:315