feat: support items data in base pack
This commit is contained in:
@@ -57,6 +57,9 @@ void ItemStack::setField(std::string_view name, dv::value value) {
|
||||
}
|
||||
if (value == nullptr) {
|
||||
fields.erase(std::string(name));
|
||||
if (fields.empty()) {
|
||||
fields = nullptr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
fields[std::string(name)] = std::move(value);
|
||||
|
||||
@@ -54,4 +54,8 @@ public:
|
||||
const dv::value& getFields() const {
|
||||
return fields;
|
||||
}
|
||||
|
||||
bool hasFields() const {
|
||||
return fields != nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -208,7 +208,10 @@ static int l_get_all_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::tostring(L, 3);
|
||||
if (key == nullptr) {
|
||||
return lua::pushboolean(L, stack.hasFields());
|
||||
}
|
||||
return lua::pushboolean(L, stack.getField(key) != nullptr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user