Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
s_item.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include "cpp_api/s_base.h"
23#include "irr_v3d.h"
24#include <optional>
25
26struct PointedThing;
27struct ItemStack;
29struct ItemDefinition;
30class LuaItemStack;
31class ModApiItem;
32class InventoryList;
34
36: virtual public ScriptApiBase
37{
38public:
39 /*
40 * Functions with std::optional<ItemStack> are for callbacks where Lua may
41 * want to prevent the engine from modifying the inventory after it's done.
42 * This has a longer backstory where on_use may need to empty the player's
43 * inventory without the engine interfering (see issue #6546).
44 */
45
46 bool item_OnDrop(ItemStack &item,
47 ServerActiveObject *dropper, v3f pos);
48 bool item_OnPlace(std::optional<ItemStack> &item,
49 ServerActiveObject *placer, const PointedThing &pointed);
50 bool item_OnUse(std::optional<ItemStack> &item,
51 ServerActiveObject *user, const PointedThing &pointed);
52 bool item_OnSecondaryUse(std::optional<ItemStack> &item,
53 ServerActiveObject *user, const PointedThing &pointed);
55 const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);
57 const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);
58
59protected:
60 friend class LuaItemStack;
61 friend class ModApiItem;
62
63 bool getItemCallback(const char *name, const char *callbackname, const v3s16 *p = nullptr);
68 void pushPointedThing(const PointedThing &pointed, bool hitpoint = false);
69
70};
Definition: inventory.h:209
Definition: l_item.h:26
Definition: l_item.h:171
Definition: s_base.h:79
Definition: s_item.h:37
bool item_OnUse(std::optional< ItemStack > &item, ServerActiveObject *user, const PointedThing &pointed)
Definition: s_item.cpp:98
bool item_OnCraft(ItemStack &item, ServerActiveObject *user, const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
Definition: s_item.cpp:156
void pushPointedThing(const PointedThing &pointed, bool hitpoint=false)
Definition: s_item.cpp:270
bool item_OnDrop(ItemStack &item, ServerActiveObject *dropper, v3f pos)
Definition: s_item.cpp:36
bool getItemCallback(const char *name, const char *callbackname, const v3s16 *p=nullptr)
Definition: s_item.cpp:226
bool item_OnSecondaryUse(std::optional< ItemStack > &item, ServerActiveObject *user, const PointedThing &pointed)
Definition: s_item.cpp:128
bool item_CraftPredict(ItemStack &item, ServerActiveObject *user, const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
Definition: s_item.cpp:188
bool item_OnPlace(std::optional< ItemStack > &item, ServerActiveObject *placer, const PointedThing &pointed)
Definition: s_item.cpp:63
Definition: serveractiveobject.h:55
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
Definition: inventorymanager.h:33
Definition: itemdef.h:80
Definition: inventory.h:34
An active object or node which is selected by a ray on the map.
Definition: pointedthing.h:37
static std::string p(std::string path)
Definition: test_filesys.cpp:64