Skip to content

Instantly share code, notes, and snippets.

@tburrows13
Last active January 26, 2025 15:59
Show Gist options
  • Save tburrows13/687f7dc86da1840624575ba437e86cfa to your computer and use it in GitHub Desktop.
Save tburrows13/687f7dc86da1840624575ba437e86cfa to your computer and use it in GitHub Desktop.
Factorio 2.0 mod porting guide
@anonhostpi
Copy link

anonhostpi commented Oct 22, 2024

That's where I'm at. I figured out that issue. Recipe results needs to be a list of tables, and not a singular table, so if you have only 1 result, you need to wrap it in an additional set of curly brackets

@anonhostpi
Copy link

Another thing I would point out is that if your mod worked with in-game sprites for v1.1.110, but your having issues with 2.0, you can download a legacy linux version, and compare the in game assets with the current version, by extracting the linux tar ball

@tburrows13
Copy link
Author

Thanks for the comments. I’d ask that in the future, please don’t post porting help requests here. Use the forums or #mod-dev-help on the official discord. And yes please follow step 1 (disable quality mod) at least before asking for help!

@anonhostpi not sure the advantage of that vs the following which is already in the guide

I've also found the 1.1 data files useful when porting - you can download them from the factorio-data repo.

@renoth
Copy link

renoth commented Oct 22, 2024

Any idea how to replace the get_request_slot() and set_request_slot() methods?

@tburrows13
Copy link
Author

Any idea how to replace the get_request_slot() and set_request_slot() methods?

Yes, see https://gist.github.com/tburrows13/687f7dc86da1840624575ba437e86cfa#logistic-points and the linked docs. You’ll need to do it through a logistic section.

@anonhostpi
Copy link

Thanks for the comments. I’d ask that in the future, please don’t post porting help requests here. Use the forums or #mod-dev-help on the official discord. And yes please follow step 1 (disable quality mod) at least before asking for help!

@anonhostpi not sure the advantage of that vs the following which is already in the guide

I've also found the 1.1 data files useful when porting - you can download them from the factorio-data repo.

Oh apologies. I missed that.

@anonhostpi
Copy link

Also, capitalized KW is no longer a valid electrical unit. kW is

@anonhostpi
Copy link

anonhostpi commented Oct 22, 2024

If anyone wants to see some more example changes, here is a (draft PR) changes for moon logic: mk-fg/games@master...anonhostpi:mk-fg-games:master

EDIT: mk-fg no longer plans to maintain moon-logic 😔

@anonhostpi
Copy link

anonhostpi commented Oct 22, 2024

Not mentioned in the change logs: virtual_signal_prototypes has been removed from LuaGameScript

I believe it has been moved to the virtual_signal field of LuaPrototypes

@tburrows13
Copy link
Author

Not mentioned in the change logs: virtual_signal_prototypes has been removed from LuaGameScript

It is in the changelog, albeit not very searchable.

Moved prototypes access from LuaGameScript::X_prototypes to LuaPrototypes::X.

@anonhostpi
Copy link

Couldn't find in the change logs, but ItemPrototypeFilter has also changed. The flag and filter fields appear to have been merged ('hidden' flag is now a filter)

@anonhostpi
Copy link

It also appears that entity.connect_neighbour has been replaced with some other method

@anonhostpi
Copy link

Here is an example of how to do programmatic circuit connections from my Moon Logic patch:

https://github.com/anonhostpi/mk-fg-games/blob/0778c1a9e0dfae86f561c571d78629258541ac64/factorio/Moon_Logic/control.lua#L321-L357

local Terminals = {
	red = {
		output = defines.wire_connector_id.combinator_output_red,
		input = defines.wire_connector_id.combinator_input_red
	},
	green = {
		output = defines.wire_connector_id.combinator_output_green,
		input = defines.wire_connector_id.combinator_input_green
	}
}

-- Create/connect/remove invisible constant-combinator entities for wire outputs
local function out_wire_connect(e, color)
	local core = e.surface.create_entity{
		name='mlc-core', position=e.position,
		force=e.force, create_build_effect_smoke=false }

	local terminals = Terminals[color]
	local connectors = {
		transmitter = e.get_wire_connector( terminals.output ),
		receiver = core.get_wire_connector( terminals.input )
	}

	local success = connectors.transmitter.connect_to( connectors.receiver, false, defines.wire_origin.script )

	if not success then
		error(('Failed to connect %s wire outputs to core'):format(color))
	end

	core.destructible = false
	return core
end
local function out_wire_connect_both(e)
	return
		out_wire_connect(e, "red"),
		out_wire_connect(e, "green")
end

NOTE: the core entity is a mod item from Moon Logic. I would recommend replacing it and adding an additional argument for these objects so that the receiver can be arbitrary

@jamuspsi
Copy link

Not mentioned in the change logs: virtual_signal_prototypes has been removed from LuaGameScript

It is in the changelog, albeit not very searchable.

Moved prototypes access from LuaGameScript::X_prototypes to LuaPrototypes::X.

If anyone else is losing their mind, because the current docs are incorrect, the old "game.item_prototypes" is now "prototypes.item".

I think there used to be a game.virtual_signal_prototypes, which is now prototypes.virtual_signal.

I'd guess that it's a relatively common thing to fetch stack sizes at runtime, so I hope they fix the docs. (They currently have a dead link from ItemPrototypeFilter to the game object.) I found the name by guessing!

@jocker-il
Copy link

no mention of the 'working_sound' changes and how the new system works - from the changelog:

Added support for sound accents for entities' working_sound. These are short sounds which play at a specific moment in the entity's animation.

Now in my 'KnightRider mod' theme music also plays if the player is in the car and opens the car GUI (BTW - the extension sounds that I add for KITT greeting Michel also sound for the tank and IDK how to remove that, because a 'tank' is also a 'car'...)

Please add a section about how main sounds work now (like why there are multiples defined for the 'car' 'working_sound' and how they are used) and help me fix the issue I mentioned above

@tburrows13
Copy link
Author

@jocker-il I have no idea how sounds work. If the docs aren’t explaining them adequately then please make a documentation improvement request in the official forums.

@PlexPt
Copy link

PlexPt commented Oct 29, 2024

@jocker-il
Copy link

@jocker-il I have no idea how sounds work. If the docs aren’t explaining them adequately then please make a documentation improvement request in the official forums.

A. thank you for the reply, as you are the second to propose this, it seems I will do that as a first step,
B. I owe you an apology as I (mistakenly?) thought you were part of the development team and I might have come-on too strong here - so please forgive any bad feeling, if I caused any (to anyone else, as well) - I tend to come on strong sometime as I'm a passionate person

@PlexPt
Copy link

PlexPt commented Oct 30, 2024

It is recommended to open a separate GitHub repository for better maintenance and collaboration with everyone

@tburrows13
Copy link
Author

tburrows13 commented Oct 31, 2024

Thanks for all your comments everyone. The guide has now been moved to a repository and gained some additional guidance for new 2.0 features: https://github.com/tburrows13/factorio-2.0-mod-porting-guide

@PlexPt
Copy link

PlexPt commented Oct 31, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment