summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp271
1 files changed, 208 insertions, 63 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 2a8b8a64e..aaab0d98e 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_sao.h"
#include "server.h"
#include "hud.h"
-#include "scripting_game.h"
+#include "scripting_server.h"
struct EnumString es_HudElementType[] =
{
@@ -137,8 +137,8 @@ int ObjectRef::l_remove(lua_State *L)
if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
return 0;
- UNORDERED_SET<int> child_ids = co->getAttachmentChildIds();
- UNORDERED_SET<int>::iterator it;
+ const UNORDERED_SET<int> &child_ids = co->getAttachmentChildIds();
+ UNORDERED_SET<int>::const_iterator it;
for (it = child_ids.begin(); it != child_ids.end(); ++it) {
// Child can be NULL if it was deleted earlier
if (ServerActiveObject *child = env->getActiveObject(*it))
@@ -150,9 +150,9 @@ int ObjectRef::l_remove(lua_State *L)
return 0;
}
-// getpos(self)
+// get_pos(self)
// returns: {x=num, y=num, z=num}
-int ObjectRef::l_getpos(lua_State *L)
+int ObjectRef::l_get_pos(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -169,8 +169,8 @@ int ObjectRef::l_getpos(lua_State *L)
return 1;
}
-// setpos(self, pos)
-int ObjectRef::l_setpos(lua_State *L)
+// set_pos(self, pos)
+int ObjectRef::l_set_pos(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -184,8 +184,8 @@ int ObjectRef::l_setpos(lua_State *L)
return 0;
}
-// moveto(self, pos, continuous=false)
-int ObjectRef::l_moveto(lua_State *L)
+// move_to(self, pos, continuous=false)
+int ObjectRef::l_move_to(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -364,7 +364,7 @@ int ObjectRef::l_set_wielded_item(lua_State *L)
ServerActiveObject *co = getobject(ref);
if (co == NULL) return 0;
// Do it
- ItemStack item = read_item(L, 2, getServer(L));
+ ItemStack item = read_item(L, 2, getServer(L)->idef());
bool success = co->setWieldedItem(item);
if (success && co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
getServer(L)->SendInventory(((PlayerSAO*)co));
@@ -396,13 +396,12 @@ int ObjectRef::l_get_armor_groups(lua_State *L)
if (co == NULL)
return 0;
// Do it
- ItemGroupList groups = co->getArmorGroups();
- push_groups(L, groups);
+ push_groups(L, co->getArmorGroups());
return 1;
}
// set_physics_override(self, physics_override_speed, physics_override_jump,
-// physics_override_gravity, sneak, sneak_glitch)
+// physics_override_gravity, sneak, sneak_glitch, new_move)
int ObjectRef::l_set_physics_override(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
@@ -411,11 +410,18 @@ int ObjectRef::l_set_physics_override(lua_State *L)
if (co == NULL) return 0;
// Do it
if (lua_istable(L, 2)) {
- co->m_physics_override_speed = getfloatfield_default(L, 2, "speed", co->m_physics_override_speed);
- co->m_physics_override_jump = getfloatfield_default(L, 2, "jump", co->m_physics_override_jump);
- co->m_physics_override_gravity = getfloatfield_default(L, 2, "gravity", co->m_physics_override_gravity);
- co->m_physics_override_sneak = getboolfield_default(L, 2, "sneak", co->m_physics_override_sneak);
- co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
+ co->m_physics_override_speed = getfloatfield_default(
+ L, 2, "speed", co->m_physics_override_speed);
+ co->m_physics_override_jump = getfloatfield_default(
+ L, 2, "jump", co->m_physics_override_jump);
+ co->m_physics_override_gravity = getfloatfield_default(
+ L, 2, "gravity", co->m_physics_override_gravity);
+ co->m_physics_override_sneak = getboolfield_default(
+ L, 2, "sneak", co->m_physics_override_sneak);
+ co->m_physics_override_sneak_glitch = getboolfield_default(
+ L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
+ co->m_physics_override_new_move = getboolfield_default(
+ L, 2, "new_move", co->m_physics_override_new_move);
co->m_physics_override_sent = false;
} else {
// old, non-table format
@@ -455,6 +461,8 @@ int ObjectRef::l_get_physics_override(lua_State *L)
lua_setfield(L, -2, "sneak");
lua_pushboolean(L, co->m_physics_override_sneak_glitch);
lua_setfield(L, -2, "sneak_glitch");
+ lua_pushboolean(L, co->m_physics_override_new_move);
+ lua_setfield(L, -2, "new_move");
return 1;
}
@@ -718,11 +726,13 @@ int ObjectRef::l_set_detach(lua_State *L)
v3f rotation;
co->getAttachment(&parent_id, &bone, &position, &rotation);
ServerActiveObject *parent = NULL;
- if (parent_id)
+ if (parent_id) {
parent = env->getActiveObject(parent_id);
-
+ co->setAttachment(0, "", position, rotation);
+ } else {
+ co->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0));
+ }
// Do it
- co->setAttachment(0, "", v3f(0,0,0), v3f(0,0,0));
if (parent != NULL)
parent->removeAttachmentChild(co->getId());
return 0;
@@ -738,7 +748,7 @@ int ObjectRef::l_set_properties(lua_State *L)
ObjectProperties *prop = co->accessObjectProperties();
if (!prop)
return 0;
- read_object_properties(L, 2, prop);
+ read_object_properties(L, 2, prop, getServer(L)->idef());
co->notifyObjectPropertiesModified();
return 0;
}
@@ -790,8 +800,7 @@ int ObjectRef::l_set_nametag_attributes(lua_State *L)
lua_pop(L, 1);
std::string nametag = getstringfield_default(L, 2, "text", "");
- if (nametag != "")
- prop->nametag = nametag;
+ prop->nametag = nametag;
co->notifyObjectPropertiesModified();
lua_pushboolean(L, true);
@@ -823,8 +832,8 @@ int ObjectRef::l_get_nametag_attributes(lua_State *L)
/* LuaEntitySAO-only */
-// setvelocity(self, {x=num, y=num, z=num})
-int ObjectRef::l_setvelocity(lua_State *L)
+// set_velocity(self, {x=num, y=num, z=num})
+int ObjectRef::l_set_velocity(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -836,8 +845,8 @@ int ObjectRef::l_setvelocity(lua_State *L)
return 0;
}
-// getvelocity(self)
-int ObjectRef::l_getvelocity(lua_State *L)
+// get_velocity(self)
+int ObjectRef::l_get_velocity(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -849,8 +858,8 @@ int ObjectRef::l_getvelocity(lua_State *L)
return 1;
}
-// setacceleration(self, {x=num, y=num, z=num})
-int ObjectRef::l_setacceleration(lua_State *L)
+// set_acceleration(self, {x=num, y=num, z=num})
+int ObjectRef::l_set_acceleration(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -863,8 +872,8 @@ int ObjectRef::l_setacceleration(lua_State *L)
return 0;
}
-// getacceleration(self)
-int ObjectRef::l_getacceleration(lua_State *L)
+// get_acceleration(self)
+int ObjectRef::l_get_acceleration(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -876,8 +885,8 @@ int ObjectRef::l_getacceleration(lua_State *L)
return 1;
}
-// setyaw(self, radians)
-int ObjectRef::l_setyaw(lua_State *L)
+// set_yaw(self, radians)
+int ObjectRef::l_set_yaw(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -889,8 +898,8 @@ int ObjectRef::l_setyaw(lua_State *L)
return 0;
}
-// getyaw(self)
-int ObjectRef::l_getyaw(lua_State *L)
+// get_yaw(self)
+int ObjectRef::l_get_yaw(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -902,8 +911,8 @@ int ObjectRef::l_getyaw(lua_State *L)
return 1;
}
-// settexturemod(self, mod)
-int ObjectRef::l_settexturemod(lua_State *L)
+// set_texture_mod(self, mod)
+int ObjectRef::l_set_texture_mod(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -915,9 +924,22 @@ int ObjectRef::l_settexturemod(lua_State *L)
return 0;
}
-// setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
+// get_texture_mod(self)
+int ObjectRef::l_get_texture_mod(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ LuaEntitySAO *co = getluaobject(ref);
+ if (co == NULL) return 0;
+ // Do it
+ std::string mod = co->getTextureMod();
+ lua_pushstring(L, mod.c_str());
+ return 1;
+}
+
+// set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
// select_horiz_by_yawpitch=false)
-int ObjectRef::l_setsprite(lua_State *L)
+int ObjectRef::l_set_sprite(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@@ -1152,13 +1174,8 @@ int ObjectRef::l_set_breath(lua_State *L)
PlayerSAO* co = getplayersao(ref);
if (co == NULL) return 0;
u16 breath = luaL_checknumber(L, 2);
- // Do it
co->setBreath(breath);
- // If the object is a player sent the breath to client
- if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
- getServer(L)->SendPlayerBreath(((PlayerSAO*)co)->getPeerID());
-
return 0;
}
@@ -1175,6 +1192,46 @@ int ObjectRef::l_get_breath(lua_State *L)
return 1;
}
+// set_attribute(self, attribute, value)
+int ObjectRef::l_set_attribute(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ PlayerSAO* co = getplayersao(ref);
+ if (co == NULL) {
+ return 0;
+ }
+
+ std::string attr = luaL_checkstring(L, 2);
+ if (lua_isnil(L, 3)) {
+ co->removeExtendedAttribute(attr);
+ } else {
+ std::string value = luaL_checkstring(L, 3);
+ co->setExtendedAttribute(attr, value);
+ }
+ return 1;
+}
+
+// get_attribute(self, attribute)
+int ObjectRef::l_get_attribute(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ PlayerSAO* co = getplayersao(ref);
+ if (co == NULL) {
+ return 0;
+ }
+
+ std::string attr = luaL_checkstring(L, 2);
+
+ std::string value = "";
+ if (co->getExtendedAttribute(attr, &value)) {
+ lua_pushstring(L, value.c_str());
+ return 1;
+ }
+
+ return 0;
+}
+
+
// set_inventory_formspec(self, formspec)
int ObjectRef::l_set_inventory_formspec(lua_State *L)
{
@@ -1606,7 +1663,7 @@ int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
return 1;
}
-// set_sky(self, bgcolor, type, list)
+// set_sky(self, bgcolor, type, list, clouds = true)
int ObjectRef::l_set_sky(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
@@ -1622,9 +1679,8 @@ int ObjectRef::l_set_sky(lua_State *L)
std::vector<std::string> params;
if (lua_istable(L, 4)) {
- int table = lua_gettop(L);
lua_pushnil(L);
- while (lua_next(L, table) != 0) {
+ while (lua_next(L, 4) != 0) {
// key at index -2 and value at index -1
if (lua_isstring(L, -1))
params.push_back(lua_tostring(L, -1));
@@ -1638,7 +1694,11 @@ int ObjectRef::l_set_sky(lua_State *L)
if (type == "skybox" && params.size() != 6)
throw LuaError("skybox expects 6 textures");
- if (!getServer(L)->setSky(player, bgcolor, type, params))
+ bool clouds = true;
+ if (lua_isboolean(L, 5))
+ clouds = lua_toboolean(L, 5);
+
+ if (!getServer(L)->setSky(player, bgcolor, type, params, clouds))
return 0;
lua_pushboolean(L, true);
@@ -1656,8 +1716,9 @@ int ObjectRef::l_get_sky(lua_State *L)
video::SColor bgcolor(255, 255, 255, 255);
std::string type;
std::vector<std::string> params;
+ bool clouds;
- player->getSky(&bgcolor, &type, &params);
+ player->getSky(&bgcolor, &type, &params, &clouds);
type = type == "" ? "regular" : type;
push_ARGB8(L, bgcolor);
@@ -1670,9 +1731,89 @@ int ObjectRef::l_get_sky(lua_State *L)
lua_rawseti(L, -2, i);
i++;
}
- return 3;
+ lua_pushboolean(L, clouds);
+ return 4;
}
+// set_clouds(self, {density=, color=, ambient=, height=, thickness=, speed=})
+int ObjectRef::l_set_clouds(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (!player)
+ return 0;
+ if (!lua_istable(L, 2))
+ return 0;
+
+ CloudParams cloud_params = player->getCloudParams();
+
+ cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density);
+
+ lua_getfield(L, 2, "color");
+ if (!lua_isnil(L, -1))
+ read_color(L, -1, &cloud_params.color_bright);
+ lua_pop(L, 1);
+ lua_getfield(L, 2, "ambient");
+ if (!lua_isnil(L, -1))
+ read_color(L, -1, &cloud_params.color_ambient);
+ lua_pop(L, 1);
+
+ cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height );
+ cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness);
+
+ lua_getfield(L, 2, "speed");
+ if (lua_istable(L, -1)) {
+ v2f new_speed;
+ new_speed.X = getfloatfield_default(L, -1, "x", 0);
+ new_speed.Y = getfloatfield_default(L, -1, "y", 0);
+ cloud_params.speed = new_speed;
+ }
+ lua_pop(L, 1);
+
+ if (!getServer(L)->setClouds(player, cloud_params.density,
+ cloud_params.color_bright, cloud_params.color_ambient,
+ cloud_params.height, cloud_params.thickness,
+ cloud_params.speed))
+ return 0;
+
+ player->setCloudParams(cloud_params);
+
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+int ObjectRef::l_get_clouds(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (!player)
+ return 0;
+ const CloudParams &cloud_params = player->getCloudParams();
+
+ lua_newtable(L);
+ lua_pushnumber(L, cloud_params.density);
+ lua_setfield(L, -2, "density");
+ push_ARGB8(L, cloud_params.color_bright);
+ lua_setfield(L, -2, "color");
+ push_ARGB8(L, cloud_params.color_ambient);
+ lua_setfield(L, -2, "ambient");
+ lua_pushnumber(L, cloud_params.height);
+ lua_setfield(L, -2, "height");
+ lua_pushnumber(L, cloud_params.thickness);
+ lua_setfield(L, -2, "thickness");
+ lua_newtable(L);
+ lua_pushnumber(L, cloud_params.speed.X);
+ lua_setfield(L, -2, "x");
+ lua_pushnumber(L, cloud_params.speed.Y);
+ lua_setfield(L, -2, "y");
+ lua_setfield(L, -2, "speed");
+
+ return 1;
+}
+
+
// override_day_night_ratio(self, brightness=0...1)
int ObjectRef::l_override_day_night_ratio(lua_State *L)
{
@@ -1778,12 +1919,12 @@ void ObjectRef::Register(lua_State *L)
}
const char ObjectRef::className[] = "ObjectRef";
-const luaL_reg ObjectRef::methods[] = {
+const luaL_Reg ObjectRef::methods[] = {
// ServerActiveObject
luamethod(ObjectRef, remove),
- luamethod(ObjectRef, getpos),
- luamethod(ObjectRef, setpos),
- luamethod(ObjectRef, moveto),
+ luamethod_aliased(ObjectRef, get_pos, getpos),
+ luamethod_aliased(ObjectRef, set_pos, setpos),
+ luamethod_aliased(ObjectRef, move_to, moveto),
luamethod(ObjectRef, punch),
luamethod(ObjectRef, right_click),
luamethod(ObjectRef, set_hp),
@@ -1807,14 +1948,14 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, set_nametag_attributes),
luamethod(ObjectRef, get_nametag_attributes),
// LuaEntitySAO-only
- luamethod(ObjectRef, setvelocity),
- luamethod(ObjectRef, getvelocity),
- luamethod(ObjectRef, setacceleration),
- luamethod(ObjectRef, getacceleration),
- luamethod(ObjectRef, setyaw),
- luamethod(ObjectRef, getyaw),
- luamethod(ObjectRef, settexturemod),
- luamethod(ObjectRef, setsprite),
+ luamethod_aliased(ObjectRef, set_velocity, setvelocity),
+ luamethod_aliased(ObjectRef, get_velocity, getvelocity),
+ luamethod_aliased(ObjectRef, set_acceleration, setacceleration),
+ luamethod_aliased(ObjectRef, get_acceleration, getacceleration),
+ luamethod_aliased(ObjectRef, set_yaw, setyaw),
+ luamethod_aliased(ObjectRef, get_yaw, getyaw),
+ luamethod_aliased(ObjectRef, set_texture_mod, settexturemod),
+ luamethod_aliased(ObjectRef, set_sprite, setsprite),
luamethod(ObjectRef, get_entity_name),
luamethod(ObjectRef, get_luaentity),
// Player-only
@@ -1833,6 +1974,8 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, set_look_pitch),
luamethod(ObjectRef, get_breath),
luamethod(ObjectRef, set_breath),
+ luamethod(ObjectRef, get_attribute),
+ luamethod(ObjectRef, set_attribute),
luamethod(ObjectRef, set_inventory_formspec),
luamethod(ObjectRef, get_inventory_formspec),
luamethod(ObjectRef, get_player_control),
@@ -1853,6 +1996,8 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, hud_get_hotbar_selected_image),
luamethod(ObjectRef, set_sky),
luamethod(ObjectRef, get_sky),
+ luamethod(ObjectRef, set_clouds),
+ luamethod(ObjectRef, get_clouds),
luamethod(ObjectRef, override_day_night_ratio),
luamethod(ObjectRef, get_day_night_ratio),
luamethod(ObjectRef, set_local_animation),