[Solved] Help changing entity image for custom arithmetic combinator

Place to get help with not working mods / modding interface.
Post Reply
KuroiRoy
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 07, 2014 3:49 pm
Contact:

[Solved] Help changing entity image for custom arithmetic combinator

Post by KuroiRoy »

I'm working on my first mod for Factorio and I have most of it working in game now. It's a new combinator that takes the first item signal it finds from an attached circuit wire and outputs the stack size of that item.

The only thing left before submitting to the mod portal is the sprite of the entity in-game. I have made a new image to differentiate it from other combinators but I don't have a clue how to get the game to use my image instead of the default arithmetic combinator sprite. Here is the code for the item, entity and recipe.

Code: Select all

function copyPrototype(type, name, newName)
    if not data.raw[type][name] then
        error("type " .. type .. " " .. name .. " doesn't exist")
    end
    local p = table.deepcopy(data.raw[type][name])
    p.name = newName
    if p.minable and p.minable.result then
        p.minable.result = newName
    end
    if p.place_result then
        p.place_result = newName
    end
    if p.result then
        p.result = newName
    end
    if p.results then
        for _, result in pairs(p.results) do
            if result.name == name then
                result.name = newName
            end
        end
    end
    return p
end

local item = copyPrototype("item", "arithmetic-combinator", "stack-size-combinator")

item.icon = "__StackSizeCombinator__/graphics/icons/stack-size-combinator.png"
item.order = "c[combinators]-d[stack-size-combinator]"

local entity = copyPrototype("arithmetic-combinator", "arithmetic-combinator", "stack-size-combinator")

entity.icon = "__StackSizeCombinator__/graphics/icons/stack-size-combinator.png"
entity.sprites.north.filename = "__StackSizeCombinator__/graphics/entity/stack-size-combinator.png"
entity.sprites.east.filename = "__StackSizeCombinator__/graphics/entity/stack-size-combinator.png"
entity.sprites.south.filename = "__StackSizeCombinator__/graphics/entity/stack-size-combinator.png"
entity.sprites.west.filename = "__StackSizeCombinator__/graphics/entity/stack-size-combinator.png"

local recipe = copyPrototype("recipe", "arithmetic-combinator", "stack-size-combinator")

recipe.enabled = true

data:extend(
    {
        item,
        entity,
        recipe
    }
)
I hope someone can give me some insight into this issue.
Last edited by KuroiRoy on Wed Apr 18, 2018 9:17 am, edited 1 time in total.

mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Help changing entity image for custom arithmetic combinator

Post by mrvn »

When I tried copying a arithmetic combinator it required sprites for all the arithmetic functions it can do.

I don't think an arithmetic combinator is the entity you should be using. You should probably use a lamp for input and constant combinator for output like most other mods use.

KuroiRoy
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 07, 2014 3:49 pm
Contact:

Re: Help changing entity image for custom arithmetic combinator

Post by KuroiRoy »

Thanks to darkfrei for pointing me to his excellent Info mod viewtopic.php?f=135&t=45107
that made it really easy to see which image files still needed to be overridden to get it working.
mrvn wrote:When I tried copying a arithmetic combinator it required sprites for all the arithmetic functions it can do.

I don't think an arithmetic combinator is the entity you should be using. You should probably use a lamp for input and constant combinator for output like most other mods use.
The combinator is working just the way I want it right now, it only sets the filters on the combinator so the other functionality is actually really nice since the input is multiplied by the correct stack size. Which might save another combinator and I only had to write code to set the filters. Thanks for pointing out how mods usually do it though.

I'm going to put the mod up on the portal tomorrow

KuroiRoy
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 07, 2014 3:49 pm
Contact:

Re: Help changing entity image for custom arithmetic combinator

Post by KuroiRoy »

As promised the mod is now up on the mod portal here https://mods.factorio.com/mod/StackSizeCombinator

mrvn
Smart Inserter
Smart Inserter
Posts: 5709
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [Solved] Help changing entity image for custom arithmetic combinator

Post by mrvn »

Can you give a choice between * stack and / stack?

KuroiRoy
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 07, 2014 3:49 pm
Contact:

Re: [Solved] Help changing entity image for custom arithmetic combinator

Post by KuroiRoy »

mrvn wrote:Can you give a choice between * stack and / stack?
Sorry for the late reply, I just uploaded a new version that allows you to set whichever operation you want. Maybe I should have done it this way from the start cause it was simple to fix.

Post Reply

Return to “Modding help”