How to make a custom arithmetic/decider combinator?

Place to get help with not working mods / modding interface.
Griffork
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Aug 05, 2017 2:17 am
Contact:

How to make a custom arithmetic/decider combinator?

Post by Griffork »

Hey all!

I want to make an entity in my mod that has two input wires and two output wires and does some logic on them in the middle. I've been poking my head around the source code of other mods, tutorials and the modding API but I can't seem to get this to work. Whenever I set the type of the data to "arithmetic-combinator" the built-in arithmetic combinator UI and code takes over the entity. When I set the type to "constant-combinator" I can no longer define input and output wire locations.

What I'd like to do is be able to define my own UI and output based on inputted wires (two input wires are necessary).

Any help is appreciated,
Griffork.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3715
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: How to make a custom arithmetic/decider combinator?

Post by DaveMcW »

You need to use 2 entities, one for input and one for output. Listen for the built_entity events and create a second entity when your primary entity is built.
cyfrov
Inserter
Inserter
Posts: 25
Joined: Thu May 03, 2018 7:09 pm
Contact:

Re: How to make a custom arithmetic/decider combinator?

Post by cyfrov »

So is there any way to override the built-in UI for a custom arithmetic combinator?

I see https://lua-api.factorio.com/latest/eve ... tem_opened, but when setting "can_be_mod_opened=1" in either the entity or item definition to data.raw, nothing seems to happen later on


I can't use a custom type when populating the data.raw table, and it seems that whatever happens, I can't override the game attempting to process the circuit network.
i.e. it seems that the built-in on_tick() for the arithmetic combinator looks at the type, rather than the name of the entity
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to make a custom arithmetic/decider combinator?

Post by eradicator »

cyfrov wrote:So is there any way to override the built-in UI for a custom arithmetic combinator?
Roughtly something like:

Code: Select all

script.on_event(defines.events.on_gui_opened, function(event)
  local player =  game.players[event.player_index]
  if player.opened and (player.opened.name == 'yourcombinator') do
    player.opened = nil
    local gui = player.center.add{'type=frame'} --etcpp, create your custom gui
    player.opened = gui
    end end)
You can stop a combinator with LuaEntity.active = false. But processing circuit signals in lua has abysmal performance.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
CyberWizard2261
Inserter
Inserter
Posts: 26
Joined: Tue Jun 26, 2018 11:01 am
Contact:

Re: How to make a custom arithmetic/decider combinator?

Post by CyberWizard2261 »

I don't recommend modify data.raw table, it's better to make your entity apart from vanilla ones, you'll have much more freedom with the definitions

Vanilla combinators have too much code written in C for performance reasons, make combinator logic in LUA is not recommended unless it's really critical for your mod and you don't need to update information every tick

I already made a custom combinator, "https://mods.factorio.com/mod/CW-power-combinator". You can look at its code, I almost made the main entity from scratch and used invisible vanilla combinators for internal processing

You can ask additional questions about my mod at any time (reading other people's code is not easy at all)
Post Reply

Return to “Modding help”