mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 06:51:51 +00:00
add data argument to inventory.set & add inventory.get_all_data
This commit is contained in:
parent
8837542561
commit
d25180406b
1 changed files with 11 additions and 2 deletions
|
|
@ -63,13 +63,17 @@ static int l_get(lua::State* L, ItemStack& item) {
|
||||||
static int l_set(lua::State* L, ItemStack& item) {
|
static int l_set(lua::State* L, ItemStack& item) {
|
||||||
auto itemid = lua::tointeger(L, 3);
|
auto itemid = lua::tointeger(L, 3);
|
||||||
auto count = lua::tointeger(L, 4);
|
auto count = lua::tointeger(L, 4);
|
||||||
item.set(ItemStack(itemid, count));
|
auto data = lua::tovalue(L, 5);
|
||||||
|
if (!data.isObject() && data != nullptr) {
|
||||||
|
throw std::runtime_error("invalid data argument type (table expected)");
|
||||||
|
}
|
||||||
|
item.set(ItemStack(itemid, count, std::move(data)));
|
||||||
return 0;
|
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);
|
||||||
auto& inv = get_inventory(invid);
|
const auto& inv = get_inventory(invid);
|
||||||
return lua::pushinteger(L, inv.size());
|
return lua::pushinteger(L, inv.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,6 +198,10 @@ static int l_get_data(lua::State* L, ItemStack& stack) {
|
||||||
return lua::pushvalue(L, *value);
|
return lua::pushvalue(L, *value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_all_data(lua::State* L, ItemStack& stack) {
|
||||||
|
return lua::pushvalue(L, stack.getFields());
|
||||||
|
}
|
||||||
|
|
||||||
static int l_has_data(lua::State* L, ItemStack& stack) {
|
static int l_has_data(lua::State* L, ItemStack& stack) {
|
||||||
auto key = lua::require_string(L, 3);
|
auto key = lua::require_string(L, 3);
|
||||||
return lua::pushboolean(L, stack.getField(key) != nullptr);
|
return lua::pushboolean(L, stack.getField(key) != nullptr);
|
||||||
|
|
@ -220,6 +228,7 @@ const luaL_Reg inventorylib[] = {
|
||||||
{"unbind_block", lua::wrap<l_unbind_block>},
|
{"unbind_block", lua::wrap<l_unbind_block>},
|
||||||
{"get_data", wrap_slot<l_get_data>},
|
{"get_data", wrap_slot<l_get_data>},
|
||||||
{"set_data", wrap_slot<l_set_data>},
|
{"set_data", wrap_slot<l_set_data>},
|
||||||
|
{"get_all_data", wrap_slot<l_get_all_data>},
|
||||||
{"has_data", wrap_slot<l_has_data>},
|
{"has_data", wrap_slot<l_has_data>},
|
||||||
{"create", lua::wrap<l_create>},
|
{"create", lua::wrap<l_create>},
|
||||||
{"remove", lua::wrap<l_remove>},
|
{"remove", lua::wrap<l_remove>},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue