From 883754256142d57dc34c167fb484ba15565d25e0 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 16 Feb 2025 02:27:21 +0300 Subject: [PATCH] add inventory.has_data --- src/logic/scripting/lua/libs/libinventory.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/logic/scripting/lua/libs/libinventory.cpp b/src/logic/scripting/lua/libs/libinventory.cpp index 4b4511fc..855b8eca 100644 --- a/src/logic/scripting/lua/libs/libinventory.cpp +++ b/src/logic/scripting/lua/libs/libinventory.cpp @@ -194,6 +194,11 @@ static int l_get_data(lua::State* L, ItemStack& stack) { return lua::pushvalue(L, *value); } +static int l_has_data(lua::State* L, ItemStack& stack) { + auto key = lua::require_string(L, 3); + return lua::pushboolean(L, stack.getField(key) != nullptr); +} + static int l_set_data(lua::State* L, ItemStack& stack) { auto key = lua::require_string(L, 3); auto value = lua::tovalue(L, 4); @@ -215,6 +220,7 @@ const luaL_Reg inventorylib[] = { {"unbind_block", lua::wrap}, {"get_data", wrap_slot}, {"set_data", wrap_slot}, + {"has_data", wrap_slot}, {"create", lua::wrap}, {"remove", lua::wrap}, {"clone", lua::wrap},