@@ -175,6 +175,18 @@ function core.strip_param2_color(param2, paramtype2)
175175 return param2
176176end
177177
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+
178190function core .get_node_drops (node , toolname )
179191 -- Compatibility, if node is string
180192 local nodename = node
@@ -214,7 +226,7 @@ function core.get_node_drops(node, toolname)
214226 if item .rarity ~= nil then
215227 good_rarity = item .rarity < 1 or math.random (item .rarity ) == 1
216228 end
217- if item .tools ~= nil then
229+ if item .tools ~= nil or item . tool_groups ~= nil then
218230 good_tool = false
219231 end
220232 if item .tools ~= nil and toolname then
@@ -229,6 +241,27 @@ function core.get_node_drops(node, toolname)
229241 end
230242 end
231243 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
232265 if good_rarity and good_tool then
233266 got_count = got_count + 1
234267 for _ , add_item in ipairs (item .items ) do
0 commit comments