aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_item.h
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-10-25 20:30:27 +0200
committerGitHub <noreply@github.com>2021-10-25 20:30:27 +0200
commit660e63dbae5901f8178b39ab40e6f770b8d7a215 (patch)
tree6b17279e1583716684b9d97bb8d56c8e7b8655f4 /src/script/cpp_api/s_item.h
parentd4b89eb106220f43838b039b13a0e356d366c259 (diff)
downloadhax-minetest-server-660e63dbae5901f8178b39ab40e6f770b8d7a215.tar.gz
hax-minetest-server-660e63dbae5901f8178b39ab40e6f770b8d7a215.zip
Fix item duplication if player dies during interact callback (alternative) (#11662)
Diffstat (limited to 'src/script/cpp_api/s_item.h')
-rw-r--r--src/script/cpp_api/s_item.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h
index 25a3501f9..5015d8bd4 100644
--- a/src/script/cpp_api/s_item.h
+++ b/src/script/cpp_api/s_item.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "cpp_api/s_base.h"
#include "irr_v3d.h"
+#include "util/Optional.h"
struct PointedThing;
struct ItemStack;
@@ -35,13 +36,20 @@ class ScriptApiItem
: virtual public ScriptApiBase
{
public:
+ /*
+ * Functions with Optional<ItemStack> are for callbacks where Lua may
+ * want to prevent the engine from modifying the inventory after it's done.
+ * This has a longer backstory where on_use may need to empty the player's
+ * inventory without the engine interfering (see issue #6546).
+ */
+
bool item_OnDrop(ItemStack &item,
ServerActiveObject *dropper, v3f pos);
- bool item_OnPlace(ItemStack &item,
+ bool item_OnPlace(Optional<ItemStack> &item,
ServerActiveObject *placer, const PointedThing &pointed);
- bool item_OnUse(ItemStack &item,
+ bool item_OnUse(Optional<ItemStack> &item,
ServerActiveObject *user, const PointedThing &pointed);
- bool item_OnSecondaryUse(ItemStack &item,
+ bool item_OnSecondaryUse(Optional<ItemStack> &item,
ServerActiveObject *user, const PointedThing &pointed);
bool item_OnCraft(ItemStack &item, ServerActiveObject *user,
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);