Event on_pre_player_crafted_item doesn't trigger on free crafts

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Tixout
Burner Inserter
Burner Inserter
Posts: 9
Joined: Tue Jun 28, 2016 4:59 pm
Contact:

Event on_pre_player_crafted_item doesn't trigger on free crafts

Post by Tixout »

I am currently on the mod Instant Crafting which basically makes crafting instant but not free. To do so, i catch the "on_pre_player_crafted_item" event, insert desired item in the inventory, cancel the craft, and removes the items added back on the craft cancel.

However, when using free recipes, which are recipes without ingredients, the event doesn't seem to be triggered. Which is a bit silly in my case, as I am unable to catch those crafts. On great example is the foraging recipe in sea block.

So I would like to know if this behavior is normal, and if it would be possible to add the free recipes to the event. You should also note that crafts with cheat mode activated will not trigger this event either.

Thanks ! :)

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Event on_pre_player_crafted_item doesn't trigger on free crafts

Post by Rseding91 »

This seems like trying to solve a broken mod hack instead of what seems like the correct solution: asking to allow crafting times of 0.
If you want to get ahold of me I'm almost always on Discord.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Event on_pre_player_crafted_item doesn't trigger on free crafts

Post by bobingabout »

Although I Agree with Rseding here.... I presume you're talking about hand crafting?

Would it be possible to make the hand craft time 0, but the machine craft time still whatever it is normally?


Alternate solution to try: change the player entity's crafting speed to INSANE to make all items take 1 tick to craft. I'm fairly sure the player entity itself doesn't accept the line crafting_speed, so it's always set to 1, but I'm unsure, however, you could still do this by setting the player's (controller, not entity) crafting speed bonus to, like... I dunno, what's the slowest craft, about 45 seconds? set it to a bonus of about 3000, and it should make ALL hand craft recipes (unless there are modded recipes with even longer craft times) be a single tick.


Which brings me back to another issue... you setting the hand crafting speed bonus to 3000 on the player would break if the player was also using a mod with some sort of skill tree that modifies the crafting speed multiplier of the player, as there is no real way for it to work independently per mod...
Depending how the other mod was written, either every time you spend a skill point, it sets the value to whatever, and you've just dropped 3000 bonus, or if they go for an addition system, say, adding 0.1 to it every time they spend a point, what if there's a respec button that resets it to zero? oh no, you've lost your 3000 bonus too.

Maybe some form of Technology (I'm fairly sure there is a hook for that, try character-crafting-speed) that you use a script (on_init, on_configuration_changed, and anything that monitors the creation of a new force) to unlock it automatically.



On the point of the player and entity crafting speed bonus thing (and all bonuses really), ideally if you're making some sort of bonus system, like a skill tree, there could be a mod that handles all this for you automatically. So Mod A sets a crafting speed multiplier of 3000, Mod B adds 0.1 per point, and when a reset button is pressed, sets it back to zero. The two don't interfere, There should be a 3rd party mod that controls it, so instead of setting it directly, Mod A would send a remote call to the control mod to set it to 3000, then assuming mod B plays along, it could then use the same remote call to add 0.1, and reset it to zero as it likes, but the actual value set by mod A wouldn't be effected.

Now, I can write a mod like this myself, but unfortunately it wouldn't carry much weight, so there's no real incentive for anyone to actually use it. it would be more appropriate if such a thing was in the base game.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding interface requests”