add inventory.decrement, inventory.set_count
This commit is contained in:
parent
12105c2933
commit
8fecc70e05
@ -102,7 +102,6 @@ function inventory.get_uses(invid, slot)
|
|||||||
return uses
|
return uses
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function inventory.use(invid, slot)
|
function inventory.use(invid, slot)
|
||||||
local itemid, count = inventory.get(invid, slot)
|
local itemid, count = inventory.get(invid, slot)
|
||||||
if itemid == nil then
|
if itemid == nil then
|
||||||
@ -119,6 +118,16 @@ function inventory.use(invid, slot)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function inventory.decrement(invid, slot, count)
|
||||||
|
count = count or 1
|
||||||
|
local itemid, itemcount = inventory.get(invid, slot)
|
||||||
|
if itemcount <= count then
|
||||||
|
inventory.set(invid, slot, 0)
|
||||||
|
else
|
||||||
|
inventory.set_count(invid, slot, itemcount - count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
------------------- Events ---------------------
|
------------------- Events ---------------------
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|||||||
@ -71,6 +71,15 @@ static int l_set(lua::State* L, ItemStack& item) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_set_count(lua::State* L, ItemStack& item) {
|
||||||
|
auto count = lua::tointeger(L, 3);
|
||||||
|
if (item.getItemId() == ITEM_EMPTY) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
item.setCount(count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_size(lua::State* L) {
|
static int l_size(lua::State* L) {
|
||||||
auto invid = lua::tointeger(L, 1);
|
auto invid = lua::tointeger(L, 1);
|
||||||
const auto& inv = get_inventory(invid);
|
const auto& inv = get_inventory(invid);
|
||||||
@ -226,6 +235,7 @@ static int l_set_data(lua::State* L, ItemStack& stack) {
|
|||||||
const luaL_Reg inventorylib[] = {
|
const luaL_Reg inventorylib[] = {
|
||||||
{"get", wrap_slot<l_get>},
|
{"get", wrap_slot<l_get>},
|
||||||
{"set", wrap_slot<l_set>},
|
{"set", wrap_slot<l_set>},
|
||||||
|
{"set_count", wrap_slot<l_set_count>},
|
||||||
{"size", lua::wrap<l_size>},
|
{"size", lua::wrap<l_size>},
|
||||||
{"add", lua::wrap<l_add>},
|
{"add", lua::wrap<l_add>},
|
||||||
{"move", lua::wrap<l_move>},
|
{"move", lua::wrap<l_move>},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user