Skip to content

Commit 4cd9000

Browse files
committed
Make the assemblers arm eachother
1 parent 44b4c43 commit 4cd9000

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

mods_2.0/053_greedy-inserter/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Date: ????
1313
- Setup the required hidden entities on the surface
1414
- Insert the initial blueprint
1515
- Remove pingpong mechanic for inconsistent behaviour
16+
- Make the assemblers arm eachother
1617
---------------------------------------------------------------------------------------------------
1718
Version: 0.0.1
1819
Date: 2025. 01. 11

mods_2.0/053_greedy-inserter/control.lua

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ local function new_struct(table, struct)
1717
return struct
1818
end
1919

20+
local function arm_struct(struct)
21+
struct.state = not struct.state
22+
local input_itemstack = struct.state and struct.input_itemstack_1 or struct.input_itemstack_2
23+
24+
input_itemstack.set_stack({name = "deconstruction-planner", count = 1})
25+
storage.deathrattles[script.register_on_object_destroyed(input_itemstack.item)] = {
26+
struct_id = struct.id,
27+
state = struct.state,
28+
}
29+
end
30+
2031
function Handler.on_created_entity(event)
2132
local entity = event.entity or event.destination -- todo: handle cloning
2233

@@ -35,6 +46,8 @@ function Handler.on_created_entity(event)
3546

3647
input_itemstack_1 = nil,
3748
input_itemstack_2 = nil,
49+
50+
state = true, -- assembling machine 1 will still be active in the tick it got placed, so we will give the item to assembling machine 2 first
3851
})
3952

4053
struct.children["assembling-machine-1"] = storage.surface.create_entity{
@@ -82,13 +95,9 @@ function Handler.on_created_entity(event)
8295
struct.input_itemstack_1 = struct.children["assembling-machine-1"].get_inventory(defines.inventory.assembling_machine_input)[1]
8396
struct.input_itemstack_2 = struct.children["assembling-machine-2"].get_inventory(defines.inventory.assembling_machine_input)[1]
8497

85-
-- assembling machine 1 will still be active in the tick it got placed, so we will give the item to assembling machine 2 first.
86-
struct.input_itemstack_2.set_stack({name = "deconstruction-planner", count = 1})
87-
storage.deathrattles[script.register_on_object_destroyed(struct.input_itemstack_2.item)] = {
88-
struct_id = struct.id,
89-
}
90-
9198
storage.next_x_offset = storage.next_x_offset + 3
99+
100+
arm_struct(struct)
92101
end
93102

94103
for _, event in ipairs({
@@ -109,7 +118,7 @@ script.on_event(defines.events.on_object_destroyed, function(event)
109118
if deathrattle then storage.deathrattles[event.registration_number] = nil
110119

111120
local struct = assert(storage.greedy_inserters[deathrattle.struct_id])
112-
game.print("owo")
113-
121+
arm_struct(struct)
122+
game.print(serpent.line({hand_empty = struct.state}))
114123
end
115124
end)

0 commit comments

Comments
 (0)