aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-04-11 00:09:11 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2020-04-11 13:12:51 +0200
commit1292bdbbcec45613c95aff9f2ea88aa49af25011 (patch)
tree382e24bba4da9699809e1fd8088dcd4ad92de0fa /src
parent5f3a17eb65c1ad9259f03bde346a8d69fe0c1069 (diff)
downloadminetest-1292bdbbcec45613c95aff9f2ea88aa49af25011.tar.gz
minetest-1292bdbbcec45613c95aff9f2ea88aa49af25011.tar.bz2
minetest-1292bdbbcec45613c95aff9f2ea88aa49af25011.zip
Various features and fixes
Diffstat (limited to 'src')
-rw-r--r--src/script/lua_api/l_client.cpp26
-rw-r--r--src/script/lua_api/l_localplayer.cpp74
-rw-r--r--src/script/lua_api/l_localplayer.h21
3 files changed, 92 insertions, 29 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index e30c05260..aaced7cd0 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -29,7 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cpp_api/s_base.h"
#include "gettext.h"
#include "l_internal.h"
-#include "lua_api/l_item.h"
#include "lua_api/l_nodemeta.h"
#include "gui/mainmenumanager.h"
#include "map.h"
@@ -245,25 +244,18 @@ int ModApiClient::l_get_language(lua_State *L)
return 2;
}
-// get_wielded_item()
-int ModApiClient::l_get_wielded_item(lua_State *L)
-{
- Client *client = getClient(L);
- LocalPlayer *player = client->getEnv().getLocalPlayer();
- if (!player)
- return 0;
-
- ItemStack selected_item;
- player->getWieldedItem(&selected_item, nullptr);
- LuaItemStack::create(L, selected_item);
- return 1;
-}
-
// get_meta(pos)
int ModApiClient::l_get_meta(lua_State *L)
{
v3s16 p = read_v3s16(L, 1);
- NodeMetadata *meta = getClient(L)->getEnv().getMap().getNodeMetadata(p);
+
+ // check restrictions first
+ bool pos_ok;
+ getClient(L)->CSMGetNode(p, &pos_ok);
+ if (!pos_ok)
+ return 0;
+
+ NodeMetadata *meta = getEnv(L)->getMap().getNodeMetadata(p);
NodeMetaRef::createClient(L, meta);
return 1;
}
@@ -390,6 +382,7 @@ int ModApiClient::l_get_node_def(lua_State *L)
return 1;
}
+// get_privilege_list()
int ModApiClient::l_get_privilege_list(lua_State *L)
{
const Client *client = getClient(L);
@@ -436,7 +429,6 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(send_respawn);
API_FCT(gettext);
API_FCT(get_node_or_nil);
- API_FCT(get_wielded_item);
API_FCT(disconnect);
API_FCT(get_meta);
API_FCT(sound_play);
diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp
index 821b1cb66..851ede535 100644
--- a/src/script/lua_api/l_localplayer.cpp
+++ b/src/script/lua_api/l_localplayer.cpp
@@ -19,10 +19,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "l_localplayer.h"
#include "l_internal.h"
+#include "lua_api/l_item.h"
#include "script/common/c_converter.h"
#include "client/localplayer.h"
#include "hud.h"
#include "common/c_content.h"
+#include "client/content_cao.h"
LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m)
{
@@ -74,6 +76,26 @@ int LuaLocalPlayer::l_get_name(lua_State *L)
return 1;
}
+// get_wield_index(self)
+int LuaLocalPlayer::l_get_wield_index(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+
+ lua_pushinteger(L, player->getWieldIndex());
+ return 1;
+}
+
+// get_wielded_item(self)
+int LuaLocalPlayer::l_get_wielded_item(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+
+ ItemStack selected_item;
+ player->getWieldedItem(&selected_item, nullptr);
+ LuaItemStack::create(L, selected_item);
+ return 1;
+}
+
int LuaLocalPlayer::l_is_attached(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -130,6 +152,7 @@ int LuaLocalPlayer::l_swimming_vertical(lua_State *L)
return 1;
}
+// get_physics_override(self)
int LuaLocalPlayer::l_get_physics_override(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -150,14 +173,9 @@ int LuaLocalPlayer::l_get_physics_override(lua_State *L)
lua_pushboolean(L, player->physics_override_sneak_glitch);
lua_setfield(L, -2, "sneak_glitch");
- return 1;
-}
-
-int LuaLocalPlayer::l_get_override_pos(lua_State *L)
-{
- LocalPlayer *player = getobject(L, 1);
+ lua_pushboolean(L, player->physics_override_new_move);
+ lua_setfield(L, -2, "new_move");
- push_v3f(L, player->getPosition());
return 1;
}
@@ -193,14 +211,33 @@ int LuaLocalPlayer::l_get_last_look_horizontal(lua_State *L)
return 1;
}
-int LuaLocalPlayer::l_get_key_pressed(lua_State *L)
+// get_control(self)
+int LuaLocalPlayer::l_get_control(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
+ const PlayerControl &c = player->getPlayerControl();
+
+ auto set = [L] (const char *name, bool value) {
+ lua_pushboolean(L, value);
+ lua_setfield(L, -2, name);
+ };
+
+ lua_createtable(L, 0, 12);
+ set("up", c.up);
+ set("down", c.down);
+ set("left", c.left);
+ set("right", c.right);
+ set("jump", c.jump);
+ set("aux1", c.aux1);
+ set("sneak", c.sneak);
+ set("zoom", c.zoom);
+ set("LMB", c.LMB);
+ set("RMB", c.RMB);
- lua_pushinteger(L, player->last_keyPressed);
return 1;
}
+// get_breath(self)
int LuaLocalPlayer::l_get_breath(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -209,6 +246,7 @@ int LuaLocalPlayer::l_get_breath(lua_State *L)
return 1;
}
+// get_pos(self)
int LuaLocalPlayer::l_get_pos(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -217,6 +255,7 @@ int LuaLocalPlayer::l_get_pos(lua_State *L)
return 1;
}
+// get_movement_acceleration(self)
int LuaLocalPlayer::l_get_movement_acceleration(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -234,6 +273,7 @@ int LuaLocalPlayer::l_get_movement_acceleration(lua_State *L)
return 1;
}
+// get_movement_speed(self)
int LuaLocalPlayer::l_get_movement_speed(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -257,6 +297,7 @@ int LuaLocalPlayer::l_get_movement_speed(lua_State *L)
return 1;
}
+// get_movement(self)
int LuaLocalPlayer::l_get_movement(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
@@ -278,6 +319,13 @@ int LuaLocalPlayer::l_get_movement(lua_State *L)
return 1;
}
+// get_armor_groups(self)
+int LuaLocalPlayer::l_get_armor_groups(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+ push_groups(L, player->getCAO()->getGroups());
+ return 1;
+}
// hud_add(self, form)
int LuaLocalPlayer::l_hud_add(lua_State *L)
@@ -407,6 +455,8 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
luamethod(LuaLocalPlayer, get_velocity),
luamethod(LuaLocalPlayer, get_hp),
luamethod(LuaLocalPlayer, get_name),
+ luamethod(LuaLocalPlayer, get_wield_index),
+ luamethod(LuaLocalPlayer, get_wielded_item),
luamethod(LuaLocalPlayer, is_attached),
luamethod(LuaLocalPlayer, is_touching_ground),
luamethod(LuaLocalPlayer, is_in_liquid),
@@ -415,17 +465,19 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
luamethod(LuaLocalPlayer, is_climbing),
luamethod(LuaLocalPlayer, swimming_vertical),
luamethod(LuaLocalPlayer, get_physics_override),
- luamethod(LuaLocalPlayer, get_override_pos),
+ // TODO: figure our if these are useful in any way
luamethod(LuaLocalPlayer, get_last_pos),
luamethod(LuaLocalPlayer, get_last_velocity),
luamethod(LuaLocalPlayer, get_last_look_horizontal),
luamethod(LuaLocalPlayer, get_last_look_vertical),
- luamethod(LuaLocalPlayer, get_key_pressed),
+ //
+ luamethod(LuaLocalPlayer, get_control),
luamethod(LuaLocalPlayer, get_breath),
luamethod(LuaLocalPlayer, get_pos),
luamethod(LuaLocalPlayer, get_movement_acceleration),
luamethod(LuaLocalPlayer, get_movement_speed),
luamethod(LuaLocalPlayer, get_movement),
+ luamethod(LuaLocalPlayer, get_armor_groups),
luamethod(LuaLocalPlayer, hud_add),
luamethod(LuaLocalPlayer, hud_remove),
luamethod(LuaLocalPlayer, hud_change),
diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h
index 01de2ed4e..4413f2bdb 100644
--- a/src/script/lua_api/l_localplayer.h
+++ b/src/script/lua_api/l_localplayer.h
@@ -32,12 +32,21 @@ private:
// garbage collector
static int gc_object(lua_State *L);
+ // get_velocity(self)
static int l_get_velocity(lua_State *L);
+ // get_hp(self)
static int l_get_hp(lua_State *L);
+ // get_name(self)
static int l_get_name(lua_State *L);
+ // get_wield_index(self)
+ static int l_get_wield_index(lua_State *L);
+
+ // get_wielded_item(self)
+ static int l_get_wielded_item(lua_State *L);
+
static int l_is_attached(lua_State *L);
static int l_is_touching_ground(lua_State *L);
static int l_is_in_liquid(lua_State *L);
@@ -54,18 +63,28 @@ private:
static int l_get_last_velocity(lua_State *L);
static int l_get_last_look_vertical(lua_State *L);
static int l_get_last_look_horizontal(lua_State *L);
- static int l_get_key_pressed(lua_State *L);
+ // get_control(self)
+ static int l_get_control(lua_State *L);
+
+ // get_breath(self)
static int l_get_breath(lua_State *L);
+ // get_pos(self)
static int l_get_pos(lua_State *L);
+ // get_movement_acceleration(self)
static int l_get_movement_acceleration(lua_State *L);
+ // get_movement_speed(self)
static int l_get_movement_speed(lua_State *L);
+ // get_movement(self)
static int l_get_movement(lua_State *L);
+ // get_armor_groups(self)
+ static int l_get_armor_groups(lua_State *L);
+
// hud_add(self, id, form)
static int l_hud_add(lua_State *L);