Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by Linver »

Hi, I noticed from many mod user reports, that Vehicle and BurnerGenerator prototypes, have a glitch about the burnt result.
When a vehicle or a burner generator consume an item, and they use as a fuel an item that should return a burnt result item, if they are mined before they complete the consumption of the fuel item the burnt result item will be lost.
An option to solve this problem will be; introduce a check that when a vehicle or a burner generator (but this can be extended to other entities) are mined, if is expected that from the current consumption process would have been produced a burnt result item, give it with the entity item (vehicle or burner generator).

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2384
Joined: Fri Nov 06, 2015 7:41 pm

Re: Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by Deadlock989 »

There are (admittedly obscure) situations where that could be abused. Essentially you could get instant burnt results just by repeatedly mining a car, instead of the seconds/minutes/hours it would normally take to exhaust the fuel item. The fuel hasn't been consumed yet so there is no completed result yet. I had plans for a process (now abandoned however) that would have been ruined by such a change, where the burnt result was the only way of obtaining a particular item but you had to burn and consume energy to get it.

I would be fine if it was in the game but controllable with a flag that defaulted to off - a bit like the return_ingredients_on_change property on crafting machines.
"If Stalin had a good writeup on programming, would linking that be dangerous?"

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by Linver »

I agree too that a flag like return_ingredients_on_change/return_ingredients_on_mining (maybe default true? I dunno if this is equal to ingredients better leave this decision to devs) will be the best solution, in any case both problems that we are discussing are glitches, specially in the actual state where items are mandatory voided.
Last edited by Linver on Mon Nov 23, 2020 5:58 pm, edited 1 time in total.

PFQNiet
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by PFQNiet »

I definitely feel like this is something that should be "opted in" to, if added. As it is, you should be able to add a relatively cheap control script for mined events, check if a burner exists, check if the burning fuel has a burnt_result, and add it to the event buffer if so.

A similar idea can be done to refund the currently burning fuel if it hasn't been used much. You could even combine both and have it return the un-burnt fuel if it's 50% remaining or higher, or the burnt result if less than 50% remains. Might have interesting applications. It depends on how you want your mod's energy economy to work, and how much it matters that a determined player could "cheat" extra stuff if they really want to.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by Linver »

Cheap?

Code: Select all

-Each time an entity is mined ->
--Check if have a get_burnt_result_inventory() valid, if true->
---Check if the current energy is greater than 0->
----Give the burnt result of the last consumed item 
Excluding that "give the burnt result of the last consumed item" I'm not sure how can be impelemented but, do this on each entity that is subclass of crafting machine or vehicle, is not cheap

This or become something from the main code or from the modding point is something of very not UPS friendly.

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

Re: Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by Rseding91 »

Linver wrote:
Mon Nov 23, 2020 5:53 pm
Cheap?

Code: Select all

-Each time an entity is mined ->
--Check if have a get_burnt_result_inventory() valid, if true->
---Check if the current energy is greater than 0->
----Give the burnt result of the last consumed item 
Excluding that "give the burnt result of the last consumed item" I'm not sure how can be impelemented but, do this on each entity that is subclass of crafting machine or vehicle, is not cheap

This or become something from the main code or from the modding point is something of very not UPS friendly.
That is cheap. You're only running code on-mined-event and the code is all O(1) cost.
If you want to get ahold of me I'm almost always on Discord.

PFQNiet
Fast Inserter
Fast Inserter
Posts: 236
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by PFQNiet »

Code: Select all

if event.buffer then
  local burner = entity.burner
  if burner then
    local burning = burner.currently_burning
    if burning then
      local burnt = burning.burnt_result
      if burnt then
        event.buffer.insert{name=burnt.name,count=1}
      end
    end
  end
end
Seems fine to me.

User avatar
Linver
Fast Inserter
Fast Inserter
Posts: 158
Joined: Wed Jan 09, 2019 2:28 pm
Contact:

Re: Get BurntResult on Vehicle and BurnerGenerator while mined interrupting a consumption process

Post by Linver »

Rseding91 wrote:
Mon Nov 23, 2020 6:35 pm
Linver wrote:
Mon Nov 23, 2020 5:53 pm
Cheap?

Code: Select all

-Each time an entity is mined ->
--Check if have a get_burnt_result_inventory() valid, if true->
---Check if the current energy is greater than 0->
----Give the burnt result of the last consumed item 
Excluding that "give the burnt result of the last consumed item" I'm not sure how can be impelemented but, do this on each entity that is subclass of crafting machine or vehicle, is not cheap

This or become something from the main code or from the modding point is something of very not UPS friendly.
That is cheap. You're only running code on-mined-event and the code is all O(1) cost.
No LuaPlayerMinedEntityEventFilters can filter the exact entity wanted, but if we analize cost of all callbacks, if n is the number of callback triggered by the on_player_mined_entity event, that will exit instatly because no entity match the wanted class (a special case to this example), and that if-block cost 1 operation, the cost is O(n), and this cost cannot be reduced, what can be reduced is the cost of the whole callback, if was implemented in C/C++ instead of Lua.

And this must be checked on on_player_mined_entity and on_robot_mined.

Post Reply

Return to “Modding interface requests”