Disable "Logistic connection" for belt prototype

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
kizrak
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Thu Jul 19, 2018 1:27 am
Contact:

Disable "Logistic connection" for belt prototype

Post by kizrak »

I making a modded belt that is inferior to the yellow belts. I've been able to make them move items slower, and prevent red/green wires from attaching. Screenshot:
showing prototype disabling red/green wires
showing prototype disabling red/green wires
AUe5IJBXML.png (514.26 KiB) Viewed 2758 times

This seems like the magic for disabling red/green wires in data.lua prototype code:

Code: Select all

grey_belt_entity.circuit_connector_sprites = nil
grey_belt_entity.circuit_wire_connection_points = nil
grey_belt_entity.circuit_wire_max_distance = nil

However, I'd also like to be able to disable logistic connections for my belt prototype. For example:
Belt logistic connections
Belt logistic connections
cfU1WV4b1f.png (998.79 KiB) Viewed 2758 times

I would prefer doing this via data.lua prototype code.

I talked with Klonan a little about this on Discord and he suggested setting each belt entity operable=false (LuaEntity.operable) but I would like to avoid that because I don't want to catch all of the edge cases for players/robots/map-editors/biters/trees/other-mods trying to place/build/materialize/grow/spawn my new type of belt.

I would also like the players to be able to interact with the belts in all the other normal ways, like picking items off belts (F), hand placing items (Z), etc.

I would like something in Prototype/TransportBelt such as setting connector_frame_sprites to nil, or some Boolean flag that would indicate that player should not be able to connect the belts to logistic networks.

I also see a future where modders might want a similar functionality for inserters, so if this could be be applicable to all logistic connectable devices, that would definitely be a massive bonus! 8-)

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by DaveMcW »

Just prevent the player from opening the gui in control.lua.

Code: Select all

script.on_event(defines.events.on_gui_opened, function(event)
  local entity = event.entity
  if not entity or not entity.valid then return end
  if entity.name == "grey_belt_entity" then 
    local player = game.players[event.player_index]
    player.opened = nil
  end
end)

User avatar
kizrak
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Thu Jul 19, 2018 1:27 am
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by kizrak »

DaveMcW wrote:
Sun Dec 01, 2019 5:17 am
Just prevent the player from opening the gui in control.lua.
What if they take a yellow belt and add a logistic connection to it, then use upgrade planner to switch it for my modded belt? control.lua has to cover too many edge cases that I would rather avoid.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by DaveMcW »

Code: Select all

function on_built(event)
  local entity = event.created_entity or event.entity or event.destination
  if not entity or not entity.valid then return end
  if entity.name == "grey_belt_entity" then
    local behavior = entity.get_control_behavior()
    if behavior then
      behavior.connect_to_logistic_network = false
    end
  end
end  
  
script.on_event(defines.events.on_built_entity, on_built)
script.on_event(defines.events.on_robot_built_entity, on_built)
script.on_event(defines.events.script_raised_built, on_built)
script.on_event(defines.events.script_raised_revive, on_built)
script.on_event(defines.events.on_entity_cloned, on_built)
What is your next edge case?

User avatar
kizrak
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Thu Jul 19, 2018 1:27 am
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by kizrak »

DaveMcW wrote:
Sun Dec 01, 2019 9:13 am
What is your next edge case?
What if I still want red/green wire connections?
What if I want this to apply to inserters, with the ability to set stack size, but not logistic network?
What if there is a mod that has a GUI attached to the belt GUI, but that code disables it entirely?

BTW it also appears you edited the code??? It use to close the GUI, but now only clears connection behavior? Is that a thing? But it only clears it when you open? not when you close the GUI? so they can open it, set Logistic connection behavior then close it, and as long as they don't open it again, it would still have behavior, right?

User avatar
kizrak
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Thu Jul 19, 2018 1:27 am
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by kizrak »

DaveMcW wrote:
Sun Dec 01, 2019 9:13 am

Code: Select all

function on_built(event)
  local entity = event.created_entity or event.entity or event.destination
  if not entity or not entity.valid then return end
  if entity.name == "grey_belt_entity" then
    local behavior = entity.get_control_behavior()
    if behavior then
      behavior.connect_to_logistic_network = false
    end
  end
end  
  
script.on_event(defines.events.on_built_entity, on_built)
script.on_event(defines.events.on_robot_built_entity, on_built)
script.on_event(defines.events.script_raised_built, on_built)
script.on_event(defines.events.script_raised_revive, on_built)
script.on_event(defines.events.on_entity_cloned, on_built)
What is your next edge case?
I've tried this code, and it doesn't seem to do as expected. It does trigger when built (which clears the behavior), but if the player sets it *after* it is built, nothing stops them, or clears it afterwards. It would probably work for robots making blueprints with logistic networks, but not for the normal case of a player using the GUI to make a connection.

I also tried the event on_selected_entity_changed but that only clears the behavior if the user mouses-over the belt after they setup the GUI.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by DaveMcW »

You are supposed to disable the gui using the code in my first post.

User avatar
kizrak
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Thu Jul 19, 2018 1:27 am
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by kizrak »

DaveMcW wrote:
Fri Dec 13, 2019 7:52 am
You are supposed to disable the gui using the code in my first post.
So there probably isn't a good way to enable red/green wire conditionals and simultaneously disabling logistic network conditionals (without a change to the modding API)?

If that is the case, this request could be tweaked to:
1) a request at the prototype to disable/prevent logistic network conditionals,
**OR**
2) a run-time flag that could be set (when the belt/inserter/drill/etc is placed, per DaveMcW's code) to disable/prevent logistic network conditionals.

Thanks :D

User avatar
QGamer
Fast Inserter
Fast Inserter
Posts: 213
Joined: Fri Apr 14, 2017 9:27 pm
Contact:

Re: Disable "Logistic connection" for belt prototype

Post by QGamer »

I just saw this and realized this is what I need.
I would like to specify in the entity prototype of any entity I want that it CANNOT connect to the logistic network...
But it seems the API doesn't yet support this feature.
Can we have it, please?
"Adam fell that men might be; and men are, that they might have joy."

Post Reply

Return to “Modding interface requests”