The Wrench mod is a simple mod that tries to cover a very specific and useful hole in the Lua API: the inexistence of a entity clicked event.
Such an event would allow you to open a totally custom GUI, and make very unique machines (or anything, actually).
With this mod, it exists -- with one drawback: the player has to click the entity with a Wrench item.
Not very fancy, for sure, but as far as I've researched, the desired behavior is simply impossible (currently).
So this seems, to me, to be the best second way. Besides, your mod structure will be ready to replace this custom event with a standard and remove the dependency, once it is added in the API.
The mod also comes with a API to help to design the GUIs.
For now it only contains one element, but it is very helpful: the item slot (a single inventory slot).
More are planned, I just don't know which.
Example
Code: Select all
-- This custom event is called whenever an entity in the world is clicked with the wrench
entity_click = remote.call("wrench.events", "entity_click")
script.on_event(entity_click, function (e)
local player = e.player -- the player who clicked
local entity = e.entity -- the entity clicked
-- Check if it is one of your mod's entities
if (entity.name == "my-modded-chest") then
-- Add your gui with
local frame = player.gui.center.add{type="frame", name="wrench", direction="vertical"}
-- Using the name "wrench" so that it will be closed automatically
-- You can do anything else if you don't have a gui, of course
-- Want to add a inventory slot? Easy:
remote.call("wrench.gui", "add_item_button", frame, id) -- id is just a number to identify your slot within the gui
-- How does a simple chest look like?
frame.add{type="label", caption="Awesome Chest", style="caption_label_style"}
local main = frame.add{type="table", colspan=4}
for i = 1,12 do
remote.call("wrench.gui", "add_item_button", main, i)
end
end
end)
Code speaks louder than words, so: https://github.com/luanpotter/factorio-wrench
Or download a zip file: https://github.com/luanpotter/factorio- ... /0.0.3.zip (just save as Wrench_0.0.3.zip and drop into the mods folder)
Versions and changelog can be found there too.
Disclaimer
This mod is still WIP! It works but is limited and has several known bugs I am already working on.
But I'm posting it right now to collect feedback to further development
Also, this only work on 12.20 (and potentially further (as of this writing 12.20 is latest)). Because of the huge renaming of the apis.
Not that there were any limitations previously, so I believe it is easily converted if needed.
How it works
TODO
Bugs
Limitations
License
Thanks