aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2020-10-05 22:33:32 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2020-10-05 22:33:32 +0200
commitcb1915efa780292c7221bb14f38976967d7bcdab (patch)
tree8c0e87d77198aaa50ab03d74d3d3041800707cb8
parent43ee069dbf0dc805277fcee9f1ac8925da2a4061 (diff)
downloaddragonfireclient-cb1915efa780292c7221bb14f38976967d7bcdab.tar.xz
Added minetest.drop_selected_item(), Improved AutoEject
-rw-r--r--clientmods/dragonfire/inventory/autoeject.lua19
-rw-r--r--doc/client_lua_api.txt2
-rw-r--r--src/script/lua_api/l_client.cpp8
-rw-r--r--src/script/lua_api/l_client.h5
4 files changed, 19 insertions, 15 deletions
diff --git a/clientmods/dragonfire/inventory/autoeject.lua b/clientmods/dragonfire/inventory/autoeject.lua
index bd2eb0d47..5e61b1ef9 100644
--- a/clientmods/dragonfire/inventory/autoeject.lua
+++ b/clientmods/dragonfire/inventory/autoeject.lua
@@ -1,23 +1,14 @@
-local old_index
-
minetest.register_globalstep(function()
- if inventory_mod.nodrop then
- inventory_mod.nodrop = false
- return
- end
- local player = minetest.localplayer
- if old_index then
- player:set_wield_index(old_index)
- minetest.set_keypress("drop", false)
- old_index = nil
- elseif minetest.settings:get_bool("autoeject") then
+ if minetest.settings:get_bool("autoeject") then
+ local player = minetest.localplayer
local list = (minetest.settings:get("eject_items") or ""):split(",")
local inventory = minetest.get_inventory("current_player")
for index, stack in pairs(inventory.main) do
if table.indexof(list, stack:get_name()) ~= -1 then
- old_index = player:get_wield_index()
+ local old_index = player:get_wield_index()
player:set_wield_index(index - 1)
- minetest.set_keypress("drop", true) -- causes to drop tools selected using autotool sometimes, just
+ minetest.drop_selected_item()
+ player:set_wield_index(old_index)
return
end
end
diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt
index 636fc63c7..85fe1005d 100644
--- a/doc/client_lua_api.txt
+++ b/doc/client_lua_api.txt
@@ -876,6 +876,8 @@ Call these functions only at load time!
* Alias for `minetest.send_chat_message("/" .. cmd .. " " .. param)`
* `minetest.clear_out_chat_queue()`
* Clears the out chat queue
+* `minetest.drop_selected_item()`
+ * Drops the selected item
* `minetest.localplayer`
* Reference to the LocalPlayer object. See [`LocalPlayer`](#localplayer) class reference for methods.
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index b9a8f77a8..56ce6471c 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -496,6 +496,13 @@ int ModApiClient::l_set_keypress(lua_State *L)
return 1;
}
+// drop_selected_item()
+int ModApiClient::l_drop_selected_item(lua_State *L)
+{
+ g_game->dropSelectedItem();
+ return 0;
+}
+
void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
@@ -528,4 +535,5 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(dig_node);
API_FCT(get_inventory);
API_FCT(set_keypress);
+ API_FCT(drop_selected_item);
}
diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h
index 1ea57f9ee..ebce7c02a 100644
--- a/src/script/lua_api/l_client.h
+++ b/src/script/lua_api/l_client.h
@@ -117,8 +117,11 @@ private:
// get_inventory(location)
static int l_get_inventory(lua_State *L);
- // l_set_keypress(key_setting, pressed)
+ // set_keypress(key_setting, pressed)
static int l_set_keypress(lua_State *L);
+
+ // drop_selected_item()
+ static int l_drop_selected_item(lua_State *L);
public:
static void Initialize(lua_State *L, int top);
};