[2.1.8] How do you read research pack in the lab with new behavior ?

Place to get help with not working mods / modding interface.
vinaghost
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Sep 08, 2025 4:10 am
Contact:

[2.1.8] How do you read research pack in the lab with new behavior ?

Post by vinaghost »

This mod draws the number into the entity to show how long the machine last.
In 2.0, I can read the durability of research pack to calculate the time, but in 2.1.7, I cannot do that
TechnologyPrototype and LabPrototype now accept any item type as research ingredients. Changed all science packs to be plain items
I search new property added to lab, item, etc but found nothing (maybe I'm blind)
So how do I read the progression of active science pack ?
06-30-2026, 16-22-17.png
06-30-2026, 16-22-17.png (31 KiB) Viewed 163 times

Code: Select all

    local inventory = entity.get_inventory(defines.inventory.lab_input)
    if inventory == nil or research == nil then return end
    local count = 9999
    for i = 1, #research_ingredients do
        local research_ingredients_name = research_ingredients[i].name
        local stack = inventory[research_stack_names[research_ingredients_name]]--inventory.find_item_stack(research_ingredients_name)
        if stack and stack.valid_for_read then
            local new_count = (stack.count - 1 + stack.durability) / research_ingredients[i].amount
            count = new_count < count and new_count or count
        end

        if count == 0 then break end
    end

    if count == 9999 then count = 0 end

    if not researching_speed then researching_speed = entity.prototype.get_researching_speed() end
    local time = count * research_unit_energy / researching_speed
    local text = time <= storage.settings.lab_yellow_swap and math.floor(time) or math.floor(time/60)
    local color = time > storage.settings.lab_yellow_swap and WHITE or time <= storage.settings.lab_red_swap and RED or YELLOW
    if not node.bottom_left then
        node.bottom_left = {
            text = text,
            color = color,
            id = rendering.draw_text{
                text = text,
                surface = entity.surface,
                target = {x = entity.bounding_box.left_top.x, y = entity.bounding_box.right_bottom.y -0.5}, --left bottom
                color = color,
            },
        }
    else
        set_text(node.bottom_left, text)
        set_color(node.bottom_left, color)
    end
vinaghost
Burner Inserter
Burner Inserter
Posts: 11
Joined: Mon Sep 08, 2025 4:10 am
Contact:

Re: [2.1.8] How do you read research pack in the lab with new behavior ?

Post by vinaghost »

boskid wrote: Tue Jun 30, 2026 9:26 am LuaEntity::get_stored_durability
it didn't have lab in its name so I didn't find it in changelog, my bad
Post Reply

Return to “Modding help”