forked from pyanodon/pyhightech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
83 lines (65 loc) · 1.88 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require("__core__/lualib/util")
script.on_init(function()
global.blackhole =
{
{
counter = 0,
generator =
{
name="a",
pos={0,0}
},
furnace =
{
name="b",
pos={0,0}
}
}
}
global.gencounter = 1
end)
script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event)
local E = event.created_entity
if E.name == "blackhole" then
local Furn = game.surfaces["nauvis"].create_entity{name="magic-furnace",position={E.position.x,E.position.y},force=E.force}
local newgen = util.table.deepcopy(global.blackhole[1])
--log(serpent.block(newgen))
newgen.counter=global.gencounter
newgen.generator.name = E.name
newgen.generator.pos=E.position
newgen.furnace.name=Furn.name
newgen.furnace.pos=Furn.position
table.insert(global.blackhole, newgen)
--log(serpent.block(newgen))
--log(serpent.block(global.blackhole))
global.gencounter = global.gencounter+1
end
end)
script.on_nth_tick(30,function()
for _,e in pairs(global.blackhole) do
--log(serpent.block(e))
--log(serpent.block(e.generator.pos))
local curgen = game.surfaces["nauvis"].find_entity("blackhole",e.generator.pos)
local curfurn = game.surfaces["nauvis"].find_entity("magic-furnace",e.furnace.pos)
if curgen ~= nil then
--log(serpent.block(curgen.name))
--log(serpent.block(curfurn.name))
if curgen.get_fuel_inventory().get_item_count() <= 5 then
--log("low fuel")
local fuel = curfurn.get_output_inventory().get_item_count()
if fuel >= 1 then
curgen.get_fuel_inventory().insert({name="blackhole-fuel",count=fuel})
curfurn.get_output_inventory().clear()
end
end
end
end
end)
script.on_event({defines.events.on_player_mined_entity, defines.events.on_robot_mined_entity}, function(event)
if event.entity.name == "blackhole" then
local f = game.surfaces["nauvis"].find_entity("magic-furnace",event.entity.position)
if f ~= nil then
f.destroy()
end
end
end)