2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-11-11 19:33:17 +02:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2011-11-11 19:33:17 +02:00
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
#include "cpp_api/s_base.h"
|
|
|
|
#include "irr_v3d.h"
|
2023-06-11 22:55:36 +02:00
|
|
|
#include <optional>
|
2011-12-02 22:49:54 +02:00
|
|
|
|
2013-06-06 22:57:38 +02:00
|
|
|
struct PointedThing;
|
|
|
|
struct ItemStack;
|
2013-05-25 00:51:02 +02:00
|
|
|
class ServerActiveObject;
|
2013-06-06 22:57:38 +02:00
|
|
|
struct ItemDefinition;
|
2013-05-25 00:51:02 +02:00
|
|
|
class LuaItemStack;
|
2023-06-17 16:07:45 +02:00
|
|
|
class ModApiItem;
|
2013-10-26 11:25:28 +02:00
|
|
|
class InventoryList;
|
2014-04-15 19:49:32 +02:00
|
|
|
struct InventoryLocation;
|
2011-12-03 02:45:55 +02:00
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
class ScriptApiItem
|
|
|
|
: virtual public ScriptApiBase
|
2011-12-02 22:49:54 +02:00
|
|
|
{
|
|
|
|
public:
|
2021-10-25 20:30:27 +02:00
|
|
|
/*
|
2023-06-11 22:55:36 +02:00
|
|
|
* Functions with std::optional<ItemStack> are for callbacks where Lua may
|
2021-10-25 20:30:27 +02:00
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
bool item_OnDrop(ItemStack &item,
|
|
|
|
ServerActiveObject *dropper, v3f pos);
|
2023-06-11 22:55:36 +02:00
|
|
|
bool item_OnPlace(std::optional<ItemStack> &item,
|
2013-05-25 00:51:02 +02:00
|
|
|
ServerActiveObject *placer, const PointedThing &pointed);
|
2023-06-11 22:55:36 +02:00
|
|
|
bool item_OnUse(std::optional<ItemStack> &item,
|
2013-05-25 00:51:02 +02:00
|
|
|
ServerActiveObject *user, const PointedThing &pointed);
|
2023-06-11 22:55:36 +02:00
|
|
|
bool item_OnSecondaryUse(std::optional<ItemStack> &item,
|
2019-11-10 00:36:29 +01:00
|
|
|
ServerActiveObject *user, const PointedThing &pointed);
|
2013-10-26 11:25:28 +02:00
|
|
|
bool item_OnCraft(ItemStack &item, ServerActiveObject *user,
|
|
|
|
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);
|
|
|
|
bool item_CraftPredict(ItemStack &item, ServerActiveObject *user,
|
|
|
|
const InventoryList *old_craft_grid, const InventoryLocation &craft_inv);
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class LuaItemStack;
|
2023-06-17 16:07:45 +02:00
|
|
|
friend class ModApiItem;
|
2011-12-02 22:49:54 +02:00
|
|
|
|
2017-10-07 15:11:07 +02:00
|
|
|
bool getItemCallback(const char *name, const char *callbackname, const v3s16 *p = nullptr);
|
2018-08-16 20:10:08 +02:00
|
|
|
/*!
|
|
|
|
* Pushes a `pointed_thing` tabe to the stack.
|
|
|
|
* \param hitpoint If true, the exact pointing location is also pushed
|
|
|
|
*/
|
|
|
|
void pushPointedThing(const PointedThing &pointed, bool hitpoint = false);
|
2013-05-25 00:51:02 +02:00
|
|
|
|
|
|
|
};
|