Created
August 30, 2016 23:43
-
-
Save justarandomgeek/e43427bf3dc92c543984e64dc8f8bec3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function accepts_outside_entity(outside_entity, factory, interior, conn_specs) | |
local inside_entity = nil | |
local txControl, rxEntity | |
if outside_entity.name == "relay-combinator" then | |
inside_entity = interior.create_entity{ | |
name = "small-lamp", position = conn_specs.inside_pos, | |
force = factory.force, direction = outside_entity.direction} | |
outside_entity.direction = conn_specs.direction_out | |
rxEntity = inside_entity | |
txControl = outside_entity.get_or_create_control_behavior() | |
elseif outside_entity.name == "small-lamp" then | |
inside_entity = interior.create_entity{ | |
name = "relay-combinator", position = conn_specs.inside_pos, | |
force = factory.force, direction = conn_specs.direction_in} | |
txControl = inside_entity.get_or_create_control_behavior() | |
rxEntity = outside_entity | |
end | |
if not inside_entity then return nil end | |
outside_entity.rotatable = false | |
outside_entity.destructible = false | |
inside_entity.rotatable = false | |
inside_entity.minable = false | |
inside_entity.destructible = false | |
local data = { | |
outside = outside_entity, inside = inside_entity, | |
txControl = txControl, rxEntity = rxEntity, | |
} | |
return data | |
end | |
local function on_update(data) | |
if data.inside.valid and data.outside.valid | |
then | |
game.players[1].print("valid connection") | |
return 60 | |
else | |
game.players[1].print("invalid connection") | |
return nil | |
end | |
end | |
local function on_destroy(data) | |
if data.inside.valid then | |
data.inside.destroy() | |
end | |
end | |
remote.add_interface("factorissimo_circuits", | |
{ | |
accepts_outside_entity = accepts_outside_entity, | |
on_update = on_update, | |
on_destroy = on_destroy, | |
} | |
) | |
remote.call( | |
"factorissimo_connections", | |
"register_connection_type", | |
"relay-combinator", "factorissimo_circuits") | |
remote.call( | |
"factorissimo_connections", | |
"register_connection_type", | |
"small-lamp", "factorissimo_circuits") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment