Item added by mod has unexpected "Yield" property in UI

Place to get help with not working mods / modding interface.
radmin96
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Oct 29, 2024 10:47 am
Contact:

Item added by mod has unexpected "Yield" property in UI

Post by radmin96 »

For training purposes, I just created a simple mod that adds a new lamp recipe, item, and entity with modified energy requirements.

All added prototypes are exact deep copies of the original small-lamp. Everything works as expected, only:

My modded item, when crafted, shows an additional "Yield" attribute in the inventory UI on mouse over, however the original small-lamp doesn't show "Yield" in the UI.

I even logged the item prototype (both the original and my cloned and modified one) using serpent to compare them. I can't really see any differences apart from the expected ones, like place_result and name. The modding API docs also don't show a dedicated yield property at the code level, so it must come from something else in the UI.

The only idea I have left is that I'm cloning the wrong base prototype for the lamp, maybe? I used table.deepcopy on data.raw["item"]["small-lamp"] - is this maybe the wrong item?

This is my specific code:

Code: Select all

local prototype = table.deepcopy(data.raw['item']['small-lamp'])
prototype.name = "solar-appliances-solar-lamp-item"
prototype.place_result = "solar-appliances-solar-lamp-entity"

log(serpent.block(prototype))
log(serpent.block(data.raw['item']['small-lamp']))

data: extend({prototype})
If it helps, here's the recipe and entity as well:

Code: Select all

local prototype = table.deepcopy(data.raw['recipe']['small-lamp'])
prototype.name = "solar-appliances-solar-lamp-recipe"
prototype.localised_name = { "recipe-name.solar-appliances-solar-lamp" }
prototype.enabled = true
prototype.results = {
    { type = "item", name = "solar-appliances-solar-lamp-item", amount = 1 },
}

prototype.main_product = nil
prototype.result_count = nil

table.insert(prototype.ingredients, { type = "item", name = "solar-panel", amount = 1 })
table.insert(prototype.ingredients, { type = "item", name = "battery", amount = 2 })

log(serpent.block(prototype))
log(serpent.block(data.raw['recipe']['small-lamp']))

data:extend({ prototype })

Code: Select all

local prototype = table.deepcopy(data.raw['lamp']['small-lamp'])
prototype.name = "solar-appliances-solar-lamp-entity"
prototype.energy_source = { type = "void" }
prototype.localised_name = { "entity-name.solar-appliances-solar-lamp" }

if prototype.minable then
    prototype.minable.result = "solar-appliances-solar-lamp-item"
end

log(serpent.block(prototype))
log(serpent.block(data.raw['lamp']['small-lamp']))

data:extend({ prototype })
Can someone who's experienced with modding factorio give me a pointer on where this "Yield" property is coming from? My thinking is: I just cloned the item, which doesn't have "Yield". So why would my clone suddenly have it?

Thanks in advance!
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3860
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Item added by mod has unexpected "Yield" property in UI

Post by boskid »

"Yield" description comes from MinableProperties. This field is hidden when 3 conditions are all met at the same time:
- products specifies exactly 1 item (this is true in your case)
- product is simple (has count_min == count_max, probability of 1 and is not using extra_count_fraction, also true in your case)
- product item has exactly the same name as the entity to be mined.

Since you have suffixes `-entity` and `-item`, the entity and item are seen as having a different name and as such Yield is shown.
radmin96
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue Oct 29, 2024 10:47 am
Contact:

Re: Item added by mod has unexpected "Yield" property in UI

Post by radmin96 »

Okay, that explains it. As long as it doesn't cause unexpected side-effects (as your reply would support), I can live with it. Is it good practice to name them all the same, though?

Thank you so much for clearing that up for me. Is this documented somewhere? I looked, but couldn't find anything.
Post Reply

Return to “Modding help”