Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
l_item.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "lua_api/l_base.h"
8#include "inventory.h" // ItemStack
9#include "util/pointer.h"
10
12private:
14
15 LuaItemStack(const ItemStack &item);
16 ~LuaItemStack() = default;
17
18 static const luaL_Reg methods[];
19
20 // Exported functions
21
22 // garbage collector
23 static int gc_object(lua_State *L);
24
25 // __tostring metamethod
26 static int mt_tostring(lua_State *L);
27
28 // is_empty(self) -> true/false
29 static int l_is_empty(lua_State *L);
30
31 // get_name(self) -> string
32 static int l_get_name(lua_State *L);
33
34 // set_name(self, name)
35 static int l_set_name(lua_State *L);
36
37 // get_count(self) -> number
38 static int l_get_count(lua_State *L);
39
40 // set_count(self, number)
41 static int l_set_count(lua_State *L);
42
43 // get_wear(self) -> number
44 static int l_get_wear(lua_State *L);
45
46 // set_wear(self, number)
47 static int l_set_wear(lua_State *L);
48
49 // get_meta(self) -> string
50 static int l_get_meta(lua_State *L);
51
52 // DEPRECATED
53 // get_metadata(self) -> string
54 static int l_get_metadata(lua_State *L);
55
56 // DEPRECATED
57 // set_metadata(self, string)
58 static int l_set_metadata(lua_State *L);
59
60 // get_description(self)
61 static int l_get_description(lua_State *L);
62
63 // get_short_description(self)
64 static int l_get_short_description(lua_State *L);
65
66 // clear(self) -> true
67 static int l_clear(lua_State *L);
68
69 // replace(self, itemstack or itemstring or table or nil) -> true
70 static int l_replace(lua_State *L);
71
72 // to_string(self) -> string
73 static int l_to_string(lua_State *L);
74
75 // to_table(self) -> table or nil
76 static int l_to_table(lua_State *L);
77
78 // get_stack_max(self) -> number
79 static int l_get_stack_max(lua_State *L);
80
81 // get_free_space(self) -> number
82 static int l_get_free_space(lua_State *L);
83
84 // is_known(self) -> true/false
85 // Checks if the item is defined.
86 static int l_is_known(lua_State *L);
87
88 // get_definition(self) -> table
89 // Returns the item definition table from core.registered_items,
90 // or a fallback one (name="unknown")
91 static int l_get_definition(lua_State *L);
92
93 // get_tool_capabilities(self) -> table
94 // Returns the effective tool digging properties.
95 // Returns those of the hand ("") if this item has none associated.
96 static int l_get_tool_capabilities(lua_State *L);
97
98 // add_wear(self, amount) -> true/false
99 // The range for "amount" is [0,65536]. Wear is only added if the item
100 // is a tool. Adding wear might destroy the item.
101 // Returns true if the item is (or was) a tool.
102 static int l_add_wear(lua_State *L);
103
104 // add_wear_by_uses(self, max_uses) -> true/false
105 // The range for "max_uses" is [0,65536].
106 // Adds wear to the item in such a way that, if
107 // only this function is called to add wear, the item
108 // will be destroyed exactly after `max_uses` times of calling it.
109 // No-op if `max_uses` is 0 or item is not a tool.
110 // Returns true if the item is (or was) a tool.
111 static int l_add_wear_by_uses(lua_State *L);
112
113 // get_wear_bar_params(self) -> table
114 // Returns the effective wear bar parameters.
115 // Returns nil if this item has none associated.
116 static int l_get_wear_bar_params(lua_State *L);
117
118 // add_item(self, itemstack or itemstring or table or nil) -> itemstack
119 // Returns leftover item stack
120 static int l_add_item(lua_State *L);
121
122 // item_fits(self, itemstack or itemstring or table or nil) -> true/false, itemstack
123 // First return value is true iff the new item fits fully into the stack
124 // Second return value is the would-be-left-over item stack
125 static int l_item_fits(lua_State *L);
126
127 // take_item(self, takecount=1) -> itemstack
128 static int l_take_item(lua_State *L);
129
130 // peek_item(self, peekcount=1) -> itemstack
131 static int l_peek_item(lua_State *L);
132
133 // equals(self, other) -> bool
134 static int l_equals(lua_State *L);
135
136public:
138
139 inline const ItemStack& getItem() const { return m_stack; }
140 inline ItemStack& getItem() { return m_stack; }
141
142 // LuaItemStack(itemstack or itemstring or table or nil)
143 // Creates an LuaItemStack and leaves it on top of stack
144 static int create_object(lua_State *L);
145 // Not callable from Lua
146 static int create(lua_State *L, const ItemStack &item);
147
148 static void *packIn(lua_State *L, int idx);
149 static void packOut(lua_State *L, void *ptr);
150
151 static void Register(lua_State *L);
152
153 static const char className[];
154};
155
156class ModApiItem : public ModApiBase {
157private:
158 static int l_register_item_raw(lua_State *L);
159 static int l_unregister_item_raw(lua_State *L);
160 static int l_register_alias_raw(lua_State *L);
161 static int l_get_content_id(lua_State *L);
162 static int l_get_name_from_content_id(lua_State *L);
163
164public:
165 static void Initialize(lua_State *L, int top);
166 static void InitializeAsync(lua_State *L, int top);
167 static void InitializeClient(lua_State *L, int top);
168};
#define DISABLE_CLASS_COPY(C)
Definition basic_macros.h:26
Definition pointer.h:254
Definition l_item.h:11
static int l_set_wear(lua_State *L)
Definition l_item.cpp:115
static const char className[]
Definition l_item.h:153
~LuaItemStack()=default
const ItemStack & getItem() const
Definition l_item.h:139
static int l_add_wear(lua_State *L)
Definition l_item.cpp:339
LuaItemStack(const ItemStack &item)
Definition l_item.cpp:474
static int l_take_item(lua_State *L)
Definition l_item.cpp:415
static int l_get_free_space(lua_State *L)
Definition l_item.cpp:278
static int gc_object(lua_State *L)
Definition l_item.cpp:19
static int l_add_item(lua_State *L)
Definition l_item.cpp:387
ItemStack m_stack
Definition l_item.h:13
static int l_equals(lua_State *L)
Definition l_item.cpp:443
static int create(lua_State *L, const ItemStack &item)
Definition l_item.cpp:495
static int l_set_name(lua_State *L)
Definition l_item.cpp:56
static int l_set_count(lua_State *L)
Definition l_item.cpp:84
static int l_item_fits(lua_State *L)
Definition l_item.cpp:401
static int l_get_tool_capabilities(lua_State *L)
Definition l_item.cpp:324
static int l_add_wear_by_uses(lua_State *L)
Definition l_item.cpp:357
static int l_to_string(lua_State *L)
Definition l_item.cpp:218
static int l_get_short_description(lua_State *L)
Definition l_item.cpp:188
ItemStack & getItem()
Definition l_item.h:140
static void packOut(lua_State *L, void *ptr)
Definition l_item.cpp:511
static int create_object(lua_State *L)
Definition l_item.cpp:481
static int l_set_metadata(lua_State *L)
Definition l_item.cpp:161
static int mt_tostring(lua_State *L)
Definition l_item.cpp:27
static int l_get_name(lua_State *L)
Definition l_item.cpp:46
static int l_clear(lua_State *L)
Definition l_item.cpp:198
static int l_is_empty(lua_State *L)
Definition l_item.cpp:36
static int l_replace(lua_State *L)
Definition l_item.cpp:208
static int l_get_wear(lua_State *L)
Definition l_item.cpp:105
static int l_get_count(lua_State *L)
Definition l_item.cpp:74
static const luaL_Reg methods[]
Definition l_item.h:536
static int l_get_definition(lua_State *L)
Definition l_item.cpp:302
static int l_get_stack_max(lua_State *L)
Definition l_item.cpp:268
static int l_get_description(lua_State *L)
Definition l_item.cpp:178
static int l_to_table(lua_State *L)
Definition l_item.cpp:228
static void * packIn(lua_State *L, int idx)
Definition l_item.cpp:505
static int l_get_wear_bar_params(lua_State *L)
Definition l_item.cpp:372
static int l_get_metadata(lua_State *L)
Definition l_item.cpp:146
static int l_get_meta(lua_State *L)
Definition l_item.cpp:136
static int l_is_known(lua_State *L)
Definition l_item.cpp:289
static int l_peek_item(lua_State *L)
Definition l_item.cpp:429
Definition l_base.h:28
Definition l_item.h:156
static int l_register_alias_raw(lua_State *L)
Definition l_item.cpp:662
static void InitializeAsync(lua_State *L, int top)
Definition l_item.cpp:725
static int l_unregister_item_raw(lua_State *L)
Definition l_item.cpp:641
static int l_register_item_raw(lua_State *L)
Definition l_item.cpp:574
static void InitializeClient(lua_State *L, int top)
Definition l_item.cpp:732
static int l_get_content_id(lua_State *L)
Definition l_item.cpp:678
static void Initialize(lua_State *L, int top)
Definition l_item.cpp:716
static int l_get_name_from_content_id(lua_State *L)
Definition l_item.cpp:704
#define idx(x, y)
Definition noise.cpp:490
Definition inventory.h:19