Skip to content

Commit 392494b

Browse files
committed
Add multiplier to lazyAPI.EntityWithHealth.add_item_from_mining
1 parent d10e5a3 commit 392494b

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Date: 28. 11. 2025
44
Scripting:
55
- Added lazyAPI.adapt_ItemProduct_for_LootItem(table?): table?
66
- Added lazyAPI.adapt_LootItem_for_ItemProduct(table?): table?
7-
- Added lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_product): prototype
7+
- Added lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_product, multiplier): prototype
88
- Added lazyAPI.get_valid_items(data?): string[]|table[]|table<string, any>
99
---------------------------------------------------------------------------------------------------
1010
Version: 0.17.11

experimental/lazyAPI.lua

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ lazyAPI.EntityWithHealth.set_loot(prototype, item, count_min?, count_max? percen
239239
lazyAPI.EntityWithHealth.set_valid_loot(prototype, item, count_min?, count_max? percent?, decrease?): prototype
240240
lazyAPI.EntityWithHealth.remove_loot(prototype, item): prototype
241241
lazyAPI.EntityWithHealth.remove_non_existing_loot(prototype): prototype
242-
lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_product): prototype
242+
lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_product, multiplier): prototype
243243
lazyAPI.item.find_main_recipes(item): table[]
244244
-- There are several issues still
245245
lazyAPI.recipe.set_subgroup(prototype, subgroup, order?): prototype
@@ -5787,9 +5787,11 @@ lazyAPI.EntityWithHealth.remove_non_existing_loot = lazyAPI.loot.remove_non_exis
57875787
---@param prototype table|LAPIWrappedPrototype #https://lua-api.factorio.com/latest/prototypes/EntityPrototype.html
57885788
---@param item string|table
57895789
---@param item_product table #https://wiki.factorio.com/Types/ItemProductPrototype
5790+
---@param multiplier number
57905791
---@return table|LAPIWrappedPrototype
5791-
function lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_product)
5792+
function lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_product, multiplier)
57925793
if item == nil then error("item is nil") end
5794+
if multiplier and multiplier <= 0 then multiplier = 0 end
57935795
local prot = prototype.prototype or prototype
57945796

57955797
if (item_product.amount_min == nil or item_product.amount_max == nil)
@@ -5800,14 +5802,29 @@ function lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_pro
58005802
if item_product.amount <= 0 then return prototype end
58015803
end
58025804

5805+
local amount = item_product.amount or (item_product.amount and multiplier)
5806+
if amount <= 0 then return prototype end
5807+
58035808
prot.minable = prot.minable or {}
5809+
local amount_min = item_product.amount_min or (item_product.amount_min and multiplier)
5810+
local amount_max = item_product.amount_max or (item_product.amount_max and multiplier)
5811+
if not amount_min and amount_max then
5812+
amount_min = amount
5813+
end
5814+
if amount_max and amount_max < amount_min then
5815+
amount_max = amount_min
5816+
elseif amount_max == amount_min and amount_min == amount then
5817+
amount_min = nil
5818+
amount_max = nil
5819+
end
5820+
58045821
local results = prot.minable.results
58055822
if results == nil then
58065823
prot.minable.results = {
58075824
{
58085825
type = "item", name = item,
5809-
amount = item_product.amount,
5810-
amount_min = item_product.amount_min, amount_max = item_product.amount_max,
5826+
amount = amount,
5827+
amount_min = amount_min, amount_max = amount_max,
58115828
probability = item_product.probability, ignored_by_stats = item_product.ignored_by_stats,
58125829
ignored_by_productivity = item_product.ignored_by_productivity,
58135830
show_details_in_recipe_tooltip = item_product.show_details_in_recipe_tooltip,
@@ -5823,8 +5840,8 @@ function lazyAPI.EntityWithHealth.add_item_from_mining(prototype, item, item_pro
58235840

58245841
results[#results+1] = {
58255842
type = "item", name = item,
5826-
amount = item_product.amount,
5827-
amount_min = item_product.amount_min, amount_max = item_product.amount_max,
5843+
amount = amount,
5844+
amount_min = amount_min, amount_max = amount_max,
58285845
probability = item_product.probability, ignored_by_stats = item_product.ignored_by_stats,
58295846
ignored_by_productivity = item_product.ignored_by_productivity,
58305847
show_details_in_recipe_tooltip = item_product.show_details_in_recipe_tooltip,

0 commit comments

Comments
 (0)