Skip to content

Commit 185f75b

Browse files
committed
fixed inserting into 2x2 machines, rocket silo
1 parent e663b70 commit 185f75b

File tree

3 files changed

+85
-89
lines changed

3 files changed

+85
-89
lines changed

control.lua

+83-88
Original file line numberDiff line numberDiff line change
@@ -97,115 +97,110 @@ script.on_event(defines.events.on_marked_for_deconstruction, function(event)
9797

9898
local config = global["config"][player.name]
9999

100-
if entity.type ~= "rocket-silo" then
101-
102-
-- Check if player has space for proxy item
103-
--/c game.player.print(serpent.dump(game.player.get_inventory(defines.inventory.player_main).can_insert{name="module-inserter-proxy", count=1} or game.player.get_inventory(defines.inventory.player_quickbar).can_insert{name="module-inserter-proxy", count=1}))
104-
105-
local proxy = {name="module-inserter-proxy", count=1}
106-
107-
--if player.get_inventory(defines.inventory.player_main).can_insert(proxy) or player.get_inventory(defines.inventory.player_quickbar).can_insert(proxy) then
108-
-- Check if entity is valid and stored in config as a source.
109-
local index = 0
110-
for i = 1, #config do
111-
if config[i].from == entity.name then
112-
index = i
113-
break
114-
end
100+
-- Check if player has space for proxy item
101+
--/c game.player.print(serpent.dump(game.player.get_inventory(defines.inventory.player_main).can_insert{name="module-inserter-proxy", count=1} or game.player.get_inventory(defines.inventory.player_quickbar).can_insert{name="module-inserter-proxy", count=1}))
102+
103+
local proxy = {name="module-inserter-proxy", count=1}
104+
105+
--if player.get_inventory(defines.inventory.player_main).can_insert(proxy) or player.get_inventory(defines.inventory.player_quickbar).can_insert(proxy) then
106+
-- Check if entity is valid and stored in config as a source.
107+
local index = 0
108+
for i = 1, #config do
109+
if config[i].from == entity.name then
110+
index = i
111+
break
112+
end
113+
end
114+
if index == 0 then
115+
entity.cancel_deconstruction(entity.force)
116+
return
117+
end
118+
local freeSlots = 0
119+
for i=1,#player.get_inventory(defines.inventory.player_quickbar) do
120+
if not player.get_inventory(defines.inventory.player_quickbar)[i].valid_for_read then
121+
freeSlots = freeSlots + 1
115122
end
116-
if index == 0 then
123+
end
124+
125+
if player.get_inventory(defines.inventory.player_main).can_insert(proxy) or
126+
(freeSlots > 1 and player.cursor_stack.valid_for_read) or
127+
(freeSlots > 0 and not player.cursor_stack.valid_for_read) then
128+
if entity.type == "assembling-machine" and not entity.recipe then
129+
player.print("Can't insert modules in assembler without recipe")
117130
entity.cancel_deconstruction(entity.force)
118131
return
119132
end
120-
local freeSlots = 0
121-
for i=1,#player.get_inventory(defines.inventory.player_quickbar) do
122-
if not player.get_inventory(defines.inventory.player_quickbar)[i].valid_for_read then
123-
freeSlots = freeSlots + 1
124-
end
125-
end
126-
127-
if player.get_inventory(defines.inventory.player_main).can_insert(proxy) or
128-
(freeSlots > 1 and player.cursor_stack.valid_for_read) or
129-
(freeSlots > 0 and not player.cursor_stack.valid_for_read) then
130-
if entity.type == "assembling-machine" and not entity.recipe then
131-
player.print("Can't insert modules in assembler without recipe")
132-
entity.cancel_deconstruction(entity.force)
133-
return
133+
local modules = util.table.deepcopy(config[index].to)
134+
local cTable = {}
135+
for i, module in pairs(modules) do
136+
if module then
137+
if not cTable[module] then
138+
cTable[module] = 1
139+
else
140+
cTable[module] = cTable[module] + 1
141+
end
134142
end
135-
local modules = util.table.deepcopy(config[index].to)
136-
local cTable = {}
137-
for i, module in pairs(modules) do
138-
if module then
139-
if not cTable[module] then
140-
cTable[module] = 1
141-
else
142-
cTable[module] = cTable[module] + 1
143+
local prototype = game.item_prototypes[module]
144+
if module and prototype.module_effects and prototype.module_effects["productivity"] then
145+
if prototype.module_effects["productivity"] ~= 0 then
146+
if entity.type == "beacon" then
147+
player.print("Can't insert "..module.." in "..entity.name)
148+
entity.cancel_deconstruction(entity.force)
149+
return
143150
end
144-
end
145-
local prototype = game.item_prototypes[module]
146-
if module and prototype.module_effects and prototype.module_effects["productivity"] then
147-
if prototype.module_effects["productivity"] ~= 0 then
148-
if entity.type == "beacon" then
149-
player.print("Can't insert "..module.." in "..entity.name)
151+
if global.productivityAllowed and entity.type == "assembling-machine" then
152+
if entity.recipe and not global.productivityAllowed[entity.recipe.name] == true then
153+
player.print("Can't use "..module.." with recipe: " .. entity.recipe.name)
150154
entity.cancel_deconstruction(entity.force)
151155
return
152156
end
153-
if global.productivityAllowed and entity.type == "assembling-machine" then
154-
if entity.recipe and not global.productivityAllowed[entity.recipe.name] == true then
155-
player.print("Can't use "..module.." with recipe: " .. entity.recipe.name)
156-
entity.cancel_deconstruction(entity.force)
157-
return
158-
end
159-
end
160157
end
161158
end
162159
end
163-
local inventory = entity.get_inventory(typeToSlot[entity.type])
164-
local contents = inventory.get_contents()
165-
if not util.table.compare(cTable,contents) then
166-
-- proxy entity that the robots fly to
167-
local new_entity = {
168-
name = "entity-ghost",
169-
inner_name = "module-inserter-proxy",
170-
position = entity.position,
171-
direction = entity.direction,
172-
force = entity.force
173-
}
174-
if string.find(entity.name, "replicator%-%d") then
175-
new_entity.position = subPos(new_entity.position, {x=0.5,y=0.5})
160+
end
161+
local inventory = entity.get_inventory(typeToSlot[entity.type])
162+
local contents = inventory.get_contents()
163+
if not util.table.compare(cTable,contents) then
164+
-- proxy entity that the robots fly to
165+
local new_entity = {
166+
name = "entity-ghost",
167+
inner_name = "module-inserter-proxy",
168+
position = entity.position,
169+
direction = entity.direction,
170+
force = entity.force
171+
}
172+
173+
local key = entityKey(new_entity)
174+
if global.entitiesToInsert[key] then
175+
global.entitiesToInsert[key] = nil
176+
if player.get_item_count("module-inserter-proxy") > 0 then
177+
player.remove_item(proxy)
176178
end
177-
local key = entityKey(new_entity)
178-
if global.entitiesToInsert[key] then
179-
global.entitiesToInsert[key] = nil
180-
if player.get_item_count("module-inserter-proxy") > 0 then
181-
player.remove_item(proxy)
182-
end
183-
local toDelete = false
184-
for tick, t in pairs(global.removeTicks) do
185-
for k, g in pairs(t) do
186-
if g.key == key then
187-
toDelete = {t=tick, k=k}
188-
break
189-
end
190-
end
191-
if toDelete then
179+
local toDelete = false
180+
for tick, t in pairs(global.removeTicks) do
181+
for k, g in pairs(t) do
182+
if g.key == key then
183+
toDelete = {t=tick, k=k}
192184
break
193185
end
194186
end
195187
if toDelete then
196-
global.removeTicks[toDelete.t][toDelete.k] = nil
188+
break
197189
end
198190
end
199-
if not global.entitiesToInsert[key] then -- or (global.entitiesToInsert[key].ghost and not global.entitiesToInsert[key].ghost.valid) then
200-
local ghost = entity.surface.create_entity(new_entity)
201-
global.entitiesToInsert[key] = {entity = entity, player = player, modules = modules, ghost = ghost}
202-
--ghost.time_to_live = 60*30
203-
local delTick = game.tick + ghost.time_to_live + 2
204-
global.removeTicks[delTick] = global.removeTicks[delTick] or {}
205-
table.insert(global.removeTicks[delTick], {p=player,g=ghost, key = key})
206-
player.insert{name="module-inserter-proxy", count=1}
191+
if toDelete then
192+
global.removeTicks[toDelete.t][toDelete.k] = nil
207193
end
208194
end
195+
if not global.entitiesToInsert[key] then -- or (global.entitiesToInsert[key].ghost and not global.entitiesToInsert[key].ghost.valid) then
196+
local ghost = entity.surface.create_entity(new_entity)
197+
global.entitiesToInsert[key] = {entity = entity, player = player, modules = modules, ghost = ghost}
198+
--ghost.time_to_live = 60*30
199+
local delTick = game.tick + ghost.time_to_live + 2
200+
global.removeTicks[delTick] = global.removeTicks[delTick] or {}
201+
table.insert(global.removeTicks[delTick], {p=player,g=ghost, key = key})
202+
player.insert{name="module-inserter-proxy", count=1}
203+
end
209204
end
210205
end
211206
entity.cancel_deconstruction(entity.force)

info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ModuleInserter",
3-
"version": "0.1.31",
3+
"version": "0.1.32",
44
"title": "Module Inserter",
55
"author": "Choumiko",
66
"homepage": "",

prototypes/item.lua

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mi_planner.icon = "__ModuleInserter__/graphics/module-inserter-icon.png"
55

66
local mi_proxy = copyPrototype("container","wooden-chest","module-inserter-proxy")
77
mi_proxy.icon = "__ModuleInserter__/graphics/module-inserter-icon.png"
8+
table.insert(mi_proxy.flags, "placeable-off-grid")
89
mi_proxy.collision_box = {{-0.1,-0.1},{0.1,0.1}}
910
mi_proxy.collision_mask = {"doodad-layer", "not-colliding-with-itself"}
1011

0 commit comments

Comments
 (0)