]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_env.h
Private nodemeta (#5702)
[dragonfireclient.git] / src / script / lua_api / l_env.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef L_ENV_H_
21 #define L_ENV_H_
22
23 #include "lua_api/l_base.h"
24 #include "serverenvironment.h"
25
26 class ModApiEnvMod : public ModApiBase {
27 private:
28         // set_node(pos, node)
29         // pos = {x=num, y=num, z=num}
30         static int l_set_node(lua_State *L);
31
32         static int l_add_node(lua_State *L);
33
34         // remove_node(pos)
35         // pos = {x=num, y=num, z=num}
36         static int l_remove_node(lua_State *L);
37
38         // swap_node(pos, node)
39         // pos = {x=num, y=num, z=num}
40         static int l_swap_node(lua_State *L);
41
42         // get_node(pos)
43         // pos = {x=num, y=num, z=num}
44         static int l_get_node(lua_State *L);
45
46         // get_node_or_nil(pos)
47         // pos = {x=num, y=num, z=num}
48         static int l_get_node_or_nil(lua_State *L);
49
50         // get_node_light(pos, timeofday)
51         // pos = {x=num, y=num, z=num}
52         // timeofday: nil = current time, 0 = night, 0.5 = day
53         static int l_get_node_light(lua_State *L);
54
55         // place_node(pos, node)
56         // pos = {x=num, y=num, z=num}
57         static int l_place_node(lua_State *L);
58
59         // dig_node(pos)
60         // pos = {x=num, y=num, z=num}
61         static int l_dig_node(lua_State *L);
62
63         // punch_node(pos)
64         // pos = {x=num, y=num, z=num}
65         static int l_punch_node(lua_State *L);
66
67         // get_node_max_level(pos)
68         // pos = {x=num, y=num, z=num}
69         static int l_get_node_max_level(lua_State *L);
70
71         // get_node_level(pos)
72         // pos = {x=num, y=num, z=num}
73         static int l_get_node_level(lua_State *L);
74
75         // set_node_level(pos)
76         // pos = {x=num, y=num, z=num}
77         static int l_set_node_level(lua_State *L);
78
79         // add_node_level(pos)
80         // pos = {x=num, y=num, z=num}
81         static int l_add_node_level(lua_State *L);
82
83         // find_nodes_with_meta(pos1, pos2)
84         static int l_find_nodes_with_meta(lua_State *L);
85
86         // get_meta(pos)
87         static int l_get_meta(lua_State *L);
88
89         // get_node_timer(pos)
90         static int l_get_node_timer(lua_State *L);
91
92         // add_entity(pos, entityname) -> ObjectRef or nil
93         // pos = {x=num, y=num, z=num}
94         static int l_add_entity(lua_State *L);
95
96         // add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
97         // pos = {x=num, y=num, z=num}
98         static int l_add_item(lua_State *L);
99
100         // get_player_by_name(name)
101         static int l_get_player_by_name(lua_State *L);
102
103         // get_objects_inside_radius(pos, radius)
104         static int l_get_objects_inside_radius(lua_State *L);
105
106         // set_timeofday(val)
107         // val = 0...1
108         static int l_set_timeofday(lua_State *L);
109
110         // get_timeofday() -> 0...1
111         static int l_get_timeofday(lua_State *L);
112
113         // get_gametime()
114         static int l_get_gametime(lua_State *L);
115
116         // get_day_count() -> int
117         static int l_get_day_count(lua_State *L);
118
119         // find_node_near(pos, radius, nodenames, search_center) -> pos or nil
120         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
121         static int l_find_node_near(lua_State *L);
122
123         // find_nodes_in_area(minp, maxp, nodenames) -> list of positions
124         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
125         static int l_find_nodes_in_area(lua_State *L);
126
127         // find_surface_nodes_in_area(minp, maxp, nodenames) -> list of positions
128         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
129         static int l_find_nodes_in_area_under_air(lua_State *L);
130
131         // fix_light(p1, p2) -> true/false
132         static int l_fix_light(lua_State *L);
133
134         // emerge_area(p1, p2)
135         static int l_emerge_area(lua_State *L);
136
137         // delete_area(p1, p2) -> true/false
138         static int l_delete_area(lua_State *L);
139
140         // get_perlin(seeddiff, octaves, persistence, scale)
141         // returns world-specific PerlinNoise
142         static int l_get_perlin(lua_State *L);
143
144         // get_perlin_map(noiseparams, size)
145         // returns world-specific PerlinNoiseMap
146         static int l_get_perlin_map(lua_State *L);
147
148         // get_voxel_manip()
149         // returns world-specific voxel manipulator
150         static int l_get_voxel_manip(lua_State *L);
151
152         // clear_objects()
153         // clear all objects in the environment
154         static int l_clear_objects(lua_State *L);
155
156         // spawn_tree(pos, treedef)
157         static int l_spawn_tree(lua_State *L);
158
159         // line_of_sight(pos1, pos2, stepsize) -> true/false
160         static int l_line_of_sight(lua_State *L);
161
162         // find_path(pos1, pos2, searchdistance,
163         //     max_jump, max_drop, algorithm) -> table containing path
164         static int l_find_path(lua_State *L);
165
166         // transforming_liquid_add(pos)
167         static int l_transforming_liquid_add(lua_State *L);
168
169         // forceload_block(blockpos)
170         // forceloads a block
171         static int l_forceload_block(lua_State *L);
172
173         // forceload_free_block(blockpos)
174         // stops forceloading a position
175         static int l_forceload_free_block(lua_State *L);
176
177 public:
178         static void Initialize(lua_State *L, int top);
179         static void InitializeClient(lua_State *L, int top);
180
181         static struct EnumString es_ClearObjectsMode[];
182 };
183
184 class LuaABM : public ActiveBlockModifier {
185 private:
186         int m_id;
187
188         std::set<std::string> m_trigger_contents;
189         std::set<std::string> m_required_neighbors;
190         float m_trigger_interval;
191         u32 m_trigger_chance;
192         bool m_simple_catch_up;
193 public:
194         LuaABM(lua_State *L, int id,
195                         const std::set<std::string> &trigger_contents,
196                         const std::set<std::string> &required_neighbors,
197                         float trigger_interval, u32 trigger_chance, bool simple_catch_up):
198                 m_id(id),
199                 m_trigger_contents(trigger_contents),
200                 m_required_neighbors(required_neighbors),
201                 m_trigger_interval(trigger_interval),
202                 m_trigger_chance(trigger_chance),
203                 m_simple_catch_up(simple_catch_up)
204         {
205         }
206         virtual std::set<std::string> getTriggerContents()
207         {
208                 return m_trigger_contents;
209         }
210         virtual std::set<std::string> getRequiredNeighbors()
211         {
212                 return m_required_neighbors;
213         }
214         virtual float getTriggerInterval()
215         {
216                 return m_trigger_interval;
217         }
218         virtual u32 getTriggerChance()
219         {
220                 return m_trigger_chance;
221         }
222         virtual bool getSimpleCatchUp()
223         {
224                 return m_simple_catch_up;
225         }
226         virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
227                         u32 active_object_count, u32 active_object_count_wider);
228 };
229
230 class LuaLBM : public LoadingBlockModifierDef
231 {
232 private:
233         int m_id;
234 public:
235         LuaLBM(lua_State *L, int id,
236                         const std::set<std::string> &trigger_contents,
237                         const std::string &name,
238                         bool run_at_every_load):
239                 m_id(id)
240         {
241                 this->run_at_every_load = run_at_every_load;
242                 this->trigger_contents = trigger_contents;
243                 this->name = name;
244         }
245         virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n);
246 };
247
248 struct ScriptCallbackState {
249         ServerScripting *script;
250         int callback_ref;
251         int args_ref;
252         unsigned int refcount;
253         std::string origin;
254 };
255
256 #endif /* L_ENV_H_ */