@@ -175,6 +175,18 @@ function core.strip_param2_color(param2, paramtype2)
175
175
return param2
176
176
end
177
177
178
+ local function has_all_groups (tbl , required_groups )
179
+ if type (required_groups ) == " string" then
180
+ return (tbl [required_groups ] or 0 ) ~= 0
181
+ end
182
+ for _ , group in ipairs (required_groups ) do
183
+ if (tbl [group ] or 0 ) == 0 then
184
+ return false
185
+ end
186
+ end
187
+ return true
188
+ end
189
+
178
190
function core .get_node_drops (node , toolname )
179
191
-- Compatibility, if node is string
180
192
local nodename = node
@@ -214,7 +226,7 @@ function core.get_node_drops(node, toolname)
214
226
if item .rarity ~= nil then
215
227
good_rarity = item .rarity < 1 or math.random (item .rarity ) == 1
216
228
end
217
- if item .tools ~= nil then
229
+ if item .tools ~= nil or item . tool_groups ~= nil then
218
230
good_tool = false
219
231
end
220
232
if item .tools ~= nil and toolname then
@@ -229,6 +241,27 @@ function core.get_node_drops(node, toolname)
229
241
end
230
242
end
231
243
end
244
+ if item .tool_groups ~= nil and toolname then
245
+ local tooldef = core .registered_items [toolname ]
246
+ if tooldef ~= nil and type (tooldef .groups ) == " table" then
247
+ if type (item .tool_groups ) == " string" then
248
+ -- tool_groups can be a string which specifies the required group
249
+ good_tool = core .get_item_group (toolname , item .tool_groups ) ~= 0
250
+ else
251
+ -- tool_groups can be a list of sufficient requirements.
252
+ -- i.e. if any item in the list can be satisfied then the tool is good
253
+ assert (type (item .tool_groups ) == " table" )
254
+ for _ , required_groups in ipairs (item .tool_groups ) do
255
+ -- required_groups can be either a string (a single group),
256
+ -- or an array of strings where all must be in tooldef.groups
257
+ good_tool = has_all_groups (tooldef .groups , required_groups )
258
+ if good_tool then
259
+ break
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end
232
265
if good_rarity and good_tool then
233
266
got_count = got_count + 1
234
267
for _ , add_item in ipairs (item .items ) do
0 commit comments