aboutsummaryrefslogtreecommitdiff
path: root/src/scriptapi_node.cpp
blob: 2fea50fa1823cfab49e39b9f10e432e76a77e982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "scriptapi.h"
#include "scriptapi_node.h"
#include "util/pointedthing.h"
#include "script.h"
#include "scriptapi_common.h"
#include "scriptapi_types.h"
#include "scriptapi_item.h"
#include "scriptapi_object.h"


struct EnumString es_DrawType[] =
{
	{NDT_NORMAL, "normal"},
	{NDT_AIRLIKE, "airlike"},
	{NDT_LIQUID, "liquid"},
	{NDT_FLOWINGLIQUID, "flowingliquid"},
	{NDT_GLASSLIKE, "glasslike"},
	{NDT_GLASSLIKE_FRAMED, "glasslike_framed"},
	{NDT_ALLFACES, "allfaces"},
	{NDT_ALLFACES_OPTIONAL, "allfaces_optional"},
	{NDT_TORCHLIKE, "torchlike"},
	{NDT_SIGNLIKE, "signlike"},
	{NDT_PLANTLIKE, "plantlike"},
	{NDT_FENCELIKE, "fencelike"},
	{NDT_RAILLIKE, "raillike"},
	{NDT_NODEBOX, "nodebox"},
	{0, NULL},
};

struct EnumString es_ContentParamType[] =
{
	{CPT_NONE, "none"},
	{CPT_LIGHT, "light"},
	{0, NULL},
};

struct EnumString es_ContentParamType2[] =
{
	{CPT2_NONE, "none"},
	{CPT2_FULL, "full"},
	{CPT2_FLOWINGLIQUID, "flowingliquid"},
	{CPT2_FACEDIR, "facedir"},
	{CPT2_WALLMOUNTED, "wallmounted"},
	{0, NULL},
};

struct EnumString es_LiquidType[] =
{
	{LIQUID_NONE, "none"},
	{LIQUID_FLOWING, "flowing"},
	{LIQUID_SOURCE, "source"},
	{0, NULL},
};

struct EnumString es_NodeBoxType[] =
{
	{NODEBOX_REGULAR, "regular"},
	{NODEBOX_FIXED, "fixed"},
	{NODEBOX_WALLMOUNTED, "wallmounted"},
	{0, NULL},
};


bool scriptapi_node_on_punch(lua_State *L, v3s16 p, MapNode node,
		ServerActiveObject *puncher)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	INodeDefManager *ndef = get_server(L)->ndef();

	// Push callback function on stack
	if(!get_item_callback(L, ndef->get(node).name.c_str(), "on_punch"))
		return false;

	// Call function
	push_v3s16(L, p);
	pushnode(L, node, ndef);
	objectref_get_or_create(L, puncher);
	if(lua_pcall(L, 3, 0, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	return true;
}

bool scriptapi_node_on_dig(lua_State *L, v3s16 p, MapNode node,
		ServerActiveObject *digger)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	INodeDefManager *ndef = get_server(L)->ndef();

	// Push callback function on stack
	if(!get_item_callback(L, ndef->get(node).name.c_str(), "on_dig"))
		return false;

	// Call function
	push_v3s16(L, p);
	pushnode(L, node, ndef);
	objectref_get_or_create(L, digger);
	if(lua_pcall(L, 3, 0, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	return true;
}

void scriptapi_node_on_construct(lua_State *L, v3s16 p, MapNode node)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	INodeDefManager *ndef = get_server(L)->ndef();

	// Push callback function on stack
	if(!get_item_callback(L, ndef->get(node).name.c_str(), "on_construct"))
		return;

	// Call function
	push_v3s16(L, p);
	if(lua_pcall(L, 1, 0, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
}

void scriptapi_node_on_destruct(lua_State *L, v3s16 p, MapNode node)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	INodeDefManager *ndef = get_server(L)->ndef();

	// Push callback function on stack
	if(!get_item_callback(L, ndef->get(node).name.c_str(), "on_destruct"))
		return;

	// Call function
	push_v3s16(L, p);
	if(lua_pcall(L, 1, 0, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
}

void scriptapi_node_after_destruct(lua_State *L, v3s16 p, MapNode node)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	INodeDefManager *ndef = get_server(L)->ndef();

	// Push callback function on stack
	if(!get_item_callback(L, ndef->get(node).name.c_str(), "after_destruct"))
		return;

	// Call function
	push_v3s16(L, p);
	pushnode(L, node, ndef);
	if(lua_pcall(L, 2, 0, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
}

bool scriptapi_node_on_timer(lua_State *L, v3s16 p, MapNode node, f32 dtime)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	INodeDefManager *ndef = get_server(L)->ndef();

	// Push callback function on stack
	if(!get_item_callback(L, ndef->get(node).name.c_str(), "on_timer"))
		return false;

	// Call function
	push_v3s16(L, p);
	lua_pushnumber(L,dtime);
	if(lua_pcall(L, 2, 1, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
	if((bool)lua_isboolean(L,-1) && (bool)lua_toboolean(L,-1) == true)
		return true;

	return false;
}

void scriptapi_node_on_receive_fields(lua_State *L, v3s16 p,
		const std::string &formname,
		const std::map<std::string, std::string> &fields,
		ServerActiveObject *sender)
{
	realitycheck(L);
	assert(lua_checkstack(L, 20));
	StackUnroller stack_unroller(L);

	INodeDefManager *ndef = get_server(L)->ndef();

	// If node doesn't exist, we don't know what callback to call
	MapNode node = get_env(L)->getMap().getNodeNoEx(p);
	if(node.getContent() == CONTENT_IGNORE)
		return;

	// Push callback function on stack
	if(!get_item_callback(L, ndef->get(node).name.c_str(), "on_receive_fields"))
		return;

	// Call function
	// param 1
	push_v3s16(L, p);
	// param 2
	lua_pushstring(L, formname.c_str());
	// param 3
	lua_newtable(L);
	for(std::map<std::string, std::string>::const_iterator
			i = fields.begin(); i != fields.end(); i++){
		const std::string &name = i->first;
		const std::string &value = i->second;
		lua_pushstring(L, name.c_str());
		lua_pushlstring(L, value.c_str(), value.size());
		lua_settable(L, -3);
	}
	// param 4
	objectref_get_or_create(L, sender);
	if(lua_pcall(L, 4, 0, 0))
		script_error(L, "error: %s", lua_tostring(L, -1));
}
ot; #: src/guiMainMenu.cpp:623 msgid "3D Clouds" msgstr "Nubes 3D" #: src/guiMainMenu.cpp:629 msgid "Opaque water" msgstr "Agua opaca" #: src/guiMainMenu.cpp:639 msgid "Mip-Mapping" msgstr "" #: src/guiMainMenu.cpp:646 msgid "Anisotropic Filtering" msgstr "" #: src/guiMainMenu.cpp:653 msgid "Bi-Linear Filtering" msgstr "" #: src/guiMainMenu.cpp:660 msgid "Tri-Linear Filtering" msgstr "" #: src/guiMainMenu.cpp:668 msgid "Shaders" msgstr "Shader" #: src/guiMainMenu.cpp:675 msgid "Preload item visuals" msgstr "Precarga elementos visuales" #: src/guiMainMenu.cpp:682 msgid "Enable Particles" msgstr "Permitir las partículas" #: src/guiMainMenu.cpp:692 msgid "Change keys" msgstr "Configurar Teclas" #: src/guiMainMenu.cpp:977 msgid "Address required." msgstr "Requiere una dirección." #: src/guiMainMenu.cpp:995 msgid "Cannot delete world: Nothing selected" msgstr "No se puede eliminar el mundo: nada seleccionado" #: src/guiMainMenu.cpp:1010 msgid "Files to be deleted" msgstr "Archivos que se eliminarán" #: src/guiMainMenu.cpp:1026 msgid "Cannot create world: No games found" msgstr "" #: src/guiMainMenu.cpp:1042 msgid "Cannot configure world: Nothing selected" msgstr "" #: src/guiMainMenu.cpp:1146 msgid "Failed to delete all world files" msgstr "No se pudo eliminar todos los archivos del mundo" #: src/guiPasswordChange.cpp:108 msgid "Old Password" msgstr "Contraseña anterior" #: src/guiPasswordChange.cpp:125 msgid "New Password" msgstr "Nueva contraseña" #: src/guiPasswordChange.cpp:141 msgid "Confirm Password" msgstr "Confirmar contraseña" #: src/guiPasswordChange.cpp:158 msgid "Change" msgstr "Cambiar" #: src/guiPasswordChange.cpp:167 msgid "Passwords do not match!" msgstr "Las contraseñas no coinciden!" #: src/guiPauseMenu.cpp:118 msgid "Continue" msgstr "Continuar" #: src/guiPauseMenu.cpp:127 msgid "Change Password" msgstr "Modificar contraseña" #: src/guiPauseMenu.cpp:135 msgid "Exit to Menu" msgstr "Salir al menú" #: src/guiPauseMenu.cpp:142 msgid "Exit to OS" msgstr "Salir al sistema operatio" #: src/guiPauseMenu.cpp:149 msgid "" "Default Controls:\n" "- WASD: Walk\n" "- Mouse left: dig/hit\n" "- Mouse right: place/use\n" "- Mouse wheel: select item\n" "- 0...9: select item\n" "- Shift: sneak\n" "- R: Toggle viewing all loaded chunks\n" "- I: Inventory menu\n" "- ESC: This menu\n" "- T: Chat\n" msgstr "" "Controles predeterminados:\n" "- WASD: Caminar \n" "- ratón izquierda: Cavar/Golpear\n" "- ratón derecho: lugar o usar\n" "- rueda de ratón: seleccionar cuadro menu objectos\n" "- 0... 9: seleccionar cuadro menu objectos\n" "- Shift: caminar despacio\n" "- R: Visibilidad mayor o menor distancia\n" "- menú I: inventario \n" "- ESC: Ir al Menu\n" "- T: Chat\n" #: src/keycode.cpp:223 msgid "Left Button" msgstr "Boton izquierdo" #: src/keycode.cpp:223 msgid "Middle Button" msgstr "Botón central" #: src/keycode.cpp:223 msgid "Right Button" msgstr "Botón derecho" #: src/keycode.cpp:223 msgid "X Button 1" msgstr "" #: src/keycode.cpp:224 msgid "Back" msgstr "Atras" #: src/keycode.cpp:224 msgid "Clear" msgstr "" #: src/keycode.cpp:224 msgid "Return" msgstr "Intro" #: src/keycode.cpp:224 msgid "Tab" msgstr "Tabulador" #: src/keycode.cpp:224 msgid "X Button 2" msgstr "" #: src/keycode.cpp:225 msgid "Capital" msgstr "" #: src/keycode.cpp:225 msgid "Control" msgstr "" #: src/keycode.cpp:225 msgid "Kana" msgstr "" #: src/keycode.cpp:225 msgid "Menu" msgstr "Menú" #: src/keycode.cpp:225 msgid "Pause" msgstr "Pausa" #: src/keycode.cpp:225 msgid "Shift" msgstr "Shift" #: src/keycode.cpp:226 msgid "Convert" msgstr "Convertir" #: src/keycode.cpp:226 msgid "Escape" msgstr "Escape" #: src/keycode.cpp:226 msgid "Final" msgstr "Final" #: src/keycode.cpp:226 msgid "Junja" msgstr "" #: src/keycode.cpp:226 msgid "Kanji" msgstr "" #: src/keycode.cpp:226 msgid "Nonconvert" msgstr "" #: src/keycode.cpp:227 msgid "Accept" msgstr "Aceptar" #: src/keycode.cpp:227 msgid "End" msgstr "Fin" #: src/keycode.cpp:227 msgid "Home" msgstr "Inicio" #: src/keycode.cpp:227 msgid "Mode Change" msgstr "Cambio de modo" #: src/keycode.cpp:227 msgid "Next" msgstr "Continuar" #: src/keycode.cpp:227 msgid "Prior" msgstr "" #: src/keycode.cpp:227 msgid "Space" msgstr "Espacio" #: src/keycode.cpp:228 msgid "Down" msgstr "Abajo" #: src/keycode.cpp:228 msgid "Execute" msgstr "Ejecutar" #: src/keycode.cpp:228 msgid "Left" msgstr "Izquierda" #: src/keycode.cpp:228 msgid "Print" msgstr "Captura" #: src/keycode.cpp:228 msgid "Right" msgstr "Derecha" #: src/keycode.cpp:228 msgid "Select" msgstr "Seleccionar" #: src/keycode.cpp:228 msgid "Up" msgstr "Arriba" #: src/keycode.cpp:229 msgid "Help" msgstr "Ayuda" #: src/keycode.cpp:229 msgid "Insert" msgstr "Introducir" #: src/keycode.cpp:229 msgid "Snapshot" msgstr "Captura de pantalla" #: src/keycode.cpp:232 msgid "Left Windows" msgstr "" #: src/keycode.cpp:233 msgid "Apps" msgstr "Aplicaciones" #: src/keycode.cpp:233 msgid "Numpad 0" msgstr "Teclado numérico 0" #: src/keycode.cpp:233 msgid "Numpad 1" msgstr "1 (Teclado numérico)" #: src/keycode.cpp:233 msgid "Right Windows" msgstr "" #: src/keycode.cpp:233 msgid "Sleep" msgstr "Sueño" #: src/keycode.cpp:234 msgid "Numpad 2" msgstr "2 (Teclado numérico)" #: src/keycode.cpp:234 msgid "Numpad 3" msgstr "3 (Teclado numérico)" #: src/keycode.cpp:234 msgid "Numpad 4" msgstr "4 (Teclado numérico)" #: src/keycode.cpp:234 msgid "Numpad 5" msgstr "5 (Teclado numérico)" #: src/keycode.cpp:234 msgid "Numpad 6" msgstr "6 (Teclado numérico)" #: src/keycode.cpp:234 msgid "Numpad 7" msgstr "7 (Teclado numérico)" #: src/keycode.cpp:235 msgid "Numpad *" msgstr "* (Teclado numérico)" #: src/keycode.cpp:235 msgid "Numpad +" msgstr "+ (Teclado numérico)" #: src/keycode.cpp:235 msgid "Numpad -" msgstr "- (Teclado numérico)" #: src/keycode.cpp:235 msgid "Numpad /" msgstr "/ (Teclado numérico)" #: src/keycode.cpp:235 msgid "Numpad 8" msgstr "8 (Teclado numérico)" #: src/keycode.cpp:235 msgid "Numpad 9" msgstr "9 (Teclado numérico)" #: src/keycode.cpp:239 msgid "Num Lock" msgstr "Bloq Núm" #: src/keycode.cpp:239 msgid "Scroll Lock" msgstr "Bloq Despl" #: src/keycode.cpp:240 msgid "Left Shift" msgstr "Desplazamiento a la izquierda" #: src/keycode.cpp:240 msgid "Right Shift" msgstr "Desplazamiento a la derecha" #: src/keycode.cpp:241 msgid "Left Control" msgstr "Control izquierdo" #: src/keycode.cpp:241 msgid "Left Menu" msgstr "Menú de la izquierda" #: src/keycode.cpp:241 msgid "Right Control" msgstr "Control derecho" #: src/keycode.cpp:241 msgid "Right Menu" msgstr "Menú de la derecha" #: src/keycode.cpp:243 msgid "Comma" msgstr "Coma" #: src/keycode.cpp:243 msgid "Minus" msgstr "Signos más y menos" #: src/keycode.cpp:243 msgid "Period" msgstr "" #: src/keycode.cpp:243 msgid "Plus" msgstr "Más" #: src/keycode.cpp:247 msgid "Attn" msgstr "" #: src/keycode.cpp:247 msgid "CrSel" msgstr "" #: src/keycode.cpp:248 msgid "Erase OEF" msgstr "" #: src/keycode.cpp:248 msgid "ExSel" msgstr "" #: src/keycode.cpp:248 msgid "OEM Clear" msgstr "" #: src/keycode.cpp:248 msgid "PA1" msgstr "" #: src/keycode.cpp:248 msgid "Zoom" msgstr "" #: src/main.cpp:1384 msgid "Main Menu" msgstr "Menú Principal" #: src/main.cpp:1633 msgid "Failed to initialize world" msgstr "Fallo al iniciar el mundo" #: src/main.cpp:1645 msgid "No world selected and no address provided. Nothing to do." msgstr "" #: src/main.cpp:1653 msgid "Could not find or load game \"" msgstr "No se puede encontrar o cargar el juego\"" #: src/main.cpp:1667 msgid "Invalid gamespec." msgstr "Juego especificado no válido." #: src/main.cpp:1707 msgid "Connection error (timed out?)" msgstr "¿Error de conexión (agotado tiempo)?" #: src/main.cpp:1718 msgid "" "\n" "Check debug.txt for details." msgstr "" "\n" "Consulta debug.txt para obtener más detalles."