[MOD 0.12.20] Wrench

Topics and discussion about specific mods
Post Reply
luan
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Dec 23, 2015 4:11 pm
Contact:

[MOD 0.12.20] Wrench

Post by luan »

Description

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)
Source

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

ILMTitan
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sat Dec 19, 2015 4:57 pm
Contact:

Re: [MOD 0.12.20] Wrench

Post by ILMTitan »

I was literally about to start coding this same solution for my Overflow Valve. I will try it out.

ILMTitan
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sat Dec 19, 2015 4:57 pm
Contact:

Re: [MOD 0.12.20] Wrench

Post by ILMTitan »

I created a pull request. Overflow-Valve has three entities in the same location, so your code was simply rejecting it. The given changes would fix that.

luan
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed Dec 23, 2015 4:11 pm
Contact:

Re: [MOD 0.12.20] Wrench

Post by luan »

That is an interesting request. As I said the in PR, the problem is to know which entity was clicked. So I did this: first, ignored a few useless things in the map (decorative and corpses, though I'm not sure yet if that is wise). After that, I check the amount and if more than one is found, I trigger the event and set the Entities to hold the entire array of entities. So your client code can choose how to handle them :)
Check this commit: #3ee34f3
If this fixes your problem, I can release a 0.0.4

ILMTitan
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sat Dec 19, 2015 4:57 pm
Contact:

Re: [MOD 0.12.20] Wrench

Post by ILMTitan »

That does indeed work for my purposes. Thank you.

I needed it because my entity actually has two hidden entities that are just extra flowboxes. I can ignore your event on those other entites and only trigger on the main one. I also don't see a use for your entity tracking with what I am doing.

Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: [MOD 0.12.20] Wrench

Post by Supercheese »

So, is this mod any different from the similarly-named WrenchFu? It looks to me like more than just the names are similar, they both do nearly the same thing.

Post Reply

Return to “Mods”