]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_env.h
Add minetest.swap_node
[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 "environment.h"
25
26 class ModApiEnvMod : public ModApiBase {
27 private:
28         // minetest.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         // minetest.remove_node(pos)
35         // pos = {x=num, y=num, z=num}
36         static int l_remove_node(lua_State *L);
37         
38         // minetest.swap_node(pos, node)
39         // pos = {x=num, y=num, z=num}
40         static int l_swap_node(lua_State *L);
41
42         // minetest.get_node(pos)
43         // pos = {x=num, y=num, z=num}
44         static int l_get_node(lua_State *L);
45
46         // minetest.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         // minetest.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         // minetest.place_node(pos, node)
56         // pos = {x=num, y=num, z=num}
57         static int l_place_node(lua_State *L);
58
59         // minetest.dig_node(pos)
60         // pos = {x=num, y=num, z=num}
61         static int l_dig_node(lua_State *L);
62
63         // minetest.punch_node(pos)
64         // pos = {x=num, y=num, z=num}
65         static int l_punch_node(lua_State *L);
66
67
68         // minetest.get_node_max_level(pos)
69         // pos = {x=num, y=num, z=num}
70         static int l_get_node_max_level(lua_State *L);
71
72         // minetest.get_node_level(pos)
73         // pos = {x=num, y=num, z=num}
74         static int l_get_node_level(lua_State *L);
75
76         // minetest.set_node_level(pos)
77         // pos = {x=num, y=num, z=num}
78         static int l_set_node_level(lua_State *L);
79
80         // minetest.add_node_level(pos)
81         // pos = {x=num, y=num, z=num}
82         static int l_add_node_level(lua_State *L);
83
84         // minetest.get_meta(pos)
85         static int l_get_meta(lua_State *L);
86
87         // minetest.get_node_timer(pos)
88         static int l_get_node_timer(lua_State *L);
89
90         // minetest.add_entity(pos, entityname) -> ObjectRef or nil
91         // pos = {x=num, y=num, z=num}
92         static int l_add_entity(lua_State *L);
93
94         // minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
95         // pos = {x=num, y=num, z=num}
96         static int l_add_item(lua_State *L);
97
98         // minetest.get_player_by_name(name)
99         static int l_get_player_by_name(lua_State *L);
100
101         // minetest.get_objects_inside_radius(pos, radius)
102         static int l_get_objects_inside_radius(lua_State *L);
103
104         // minetest.set_timeofday(val)
105         // val = 0...1
106         static int l_set_timeofday(lua_State *L);
107
108         // minetest.get_timeofday() -> 0...1
109         static int l_get_timeofday(lua_State *L);
110
111         // minetest.get_gametime()
112         static int l_get_gametime(lua_State *L);
113
114         // minetest.find_node_near(pos, radius, nodenames) -> pos or nil
115         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
116         static int l_find_node_near(lua_State *L);
117
118         // minetest.find_nodes_in_area(minp, maxp, nodenames) -> list of positions
119         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
120         static int l_find_nodes_in_area(lua_State *L);
121
122         // minetest.get_perlin(seeddiff, octaves, persistence, scale)
123         // returns world-specific PerlinNoise
124         static int l_get_perlin(lua_State *L);
125
126         // minetest.get_perlin_map(noiseparams, size)
127         // returns world-specific PerlinNoiseMap
128         static int l_get_perlin_map(lua_State *L);
129         
130         // minetest.get_voxel_manip()
131         // returns world-specific voxel manipulator
132         static int l_get_voxel_manip(lua_State *L);
133         
134         // minetest.clear_objects()
135         // clear all objects in the environment
136         static int l_clear_objects(lua_State *L);
137
138         // minetest.spawn_tree(pos, treedef)
139         static int l_spawn_tree(lua_State *L);
140
141         // minetest.line_of_sight(pos1, pos2, stepsize) -> true/false
142         static int l_line_of_sight(lua_State *L);
143
144         // minetest.find_path(pos1, pos2, searchdistance,
145         //     max_jump, max_drop, algorithm) -> table containing path
146         static int l_find_path(lua_State *L);
147
148         // minetest.transforming_liquid_add(pos)
149         static int l_transforming_liquid_add(lua_State *L);
150
151         static int l_get_heat(lua_State *L);
152         static int l_get_humidity(lua_State *L);
153         
154 public:
155         static void Initialize(lua_State *L, int top);
156 };
157
158 class LuaABM : public ActiveBlockModifier
159 {
160 private:
161         int m_id;
162
163         std::set<std::string> m_trigger_contents;
164         std::set<std::string> m_required_neighbors;
165         float m_trigger_interval;
166         u32 m_trigger_chance;
167 public:
168         LuaABM(lua_State *L, int id,
169                         const std::set<std::string> &trigger_contents,
170                         const std::set<std::string> &required_neighbors,
171                         float trigger_interval, u32 trigger_chance):
172                 m_id(id),
173                 m_trigger_contents(trigger_contents),
174                 m_required_neighbors(required_neighbors),
175                 m_trigger_interval(trigger_interval),
176                 m_trigger_chance(trigger_chance)
177         {
178         }
179         virtual std::set<std::string> getTriggerContents()
180         {
181                 return m_trigger_contents;
182         }
183         virtual std::set<std::string> getRequiredNeighbors()
184         {
185                 return m_required_neighbors;
186         }
187         virtual float getTriggerInterval()
188         {
189                 return m_trigger_interval;
190         }
191         virtual u32 getTriggerChance()
192         {
193                 return m_trigger_chance;
194         }
195         virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
196                         u32 active_object_count, u32 active_object_count_wider);
197 };
198
199 #endif /* L_ENV_H_ */