Skip to content

Commit 41993ef

Browse files
committed
fix productivity modules being restricted/allowed incorrectly
hide metatech again
1 parent 3788014 commit 41993ef

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

control.lua

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ for i, ent in pairs(metaitem) do
2525
nameToSlots[ent.name] = ent.amount
2626
end
2727

28+
game.forces.player.technologies["mi-meta-productivityRecipes"].reload()
2829
productivityRecipes = game.forces.player.technologies["mi-meta-productivityRecipes"].effects
29-
productivityAllowed = {}
30+
productivityAllowed = #productivityRecipes > 0 and {} or false
3031
for _, recipe in pairs(productivityRecipes) do
3132
productivityAllowed[recipe.recipe] = true
3233
end
@@ -139,6 +140,11 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
139140
if player.get_inventory(defines.inventory.player_main).can_insert(proxy) or
140141
(freeSlots > 1 and player.cursor_stack.valid_for_read) or
141142
(freeSlots > 0 and not player.cursor_stack.valid_for_read) then
143+
if entity.type == "assembling-machine" and not entity.recipe then
144+
player.print("Can't insert modules in assembler without recipe")
145+
entity.cancel_deconstruction(entity.force)
146+
return
147+
end
142148
local modules = util.table.deepcopy(config[index].to)
143149
local cTable = {}
144150
for i, module in pairs(modules) do
@@ -149,15 +155,16 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
149155
cTable[module] = cTable[module] + 1
150156
end
151157
end
152-
if module and game.item_prototypes[module].module_effects and game.item_prototypes[module].module_effects["productivity"] then
153-
if game.item_prototypes[module].module_effects["productivity"] ~= 0 then
158+
local prototype = game.item_prototypes[module]
159+
if module and prototype.module_effects and prototype.module_effects["productivity"] then
160+
if prototype.module_effects["productivity"] ~= 0 then
154161
if entity.type == "beacon" then
155162
player.print("Can't insert "..module.." in "..entity.name)
156163
entity.cancel_deconstruction(entity.force)
157164
return
158165
end
159-
if entity.type == "assembling-machine" then
160-
if entity.recipe and not productivityAllowed[entity.recipe.name] then
166+
if productivityAllowed and entity.type == "assembling-machine" then
167+
if entity.recipe and not productivityAllowed[entity.recipe.name] == true then
161168
player.print("Can't use "..module.." with recipe: " .. entity.recipe.name)
162169
entity.cancel_deconstruction(entity.force)
163170
return
@@ -166,11 +173,6 @@ game.on_event(defines.events.on_marked_for_deconstruction, function(event)
166173
end
167174
end
168175
end
169-
if entity.type == "assembling-machine" and not entity.recipe then
170-
player.print("Can't insert modules in assembler without recipe")
171-
entity.cancel_deconstruction(entity.force)
172-
return
173-
end
174176
local inventory = entity.get_inventory(typeToSlot[entity.type])
175177
local contents = inventory.get_contents()
176178
if not util.table.compare(cTable,contents) then
@@ -263,7 +265,7 @@ local function initGlob()
263265
if p[i].from ~= "" and not items[p[i].from] then
264266
global.config[name][i].from = ""
265267
global.config[name][i].to = ""
266-
debugDump(p[i].from,true)
268+
debugDump(p[i].from,true)
267269
end
268270
if type(p[i].to) == "table" then
269271
for k, m in pairs(p[i].to) do
@@ -399,20 +401,13 @@ game.on_event(defines.events.on_robot_built_entity, function(event)
399401
end
400402
if type(modules) == "table" then
401403
local logisticsNetwork = origEntity.surface.find_logistic_network_by_position(origEntity.position, origEntity.force.name)
402-
-- if not logisticsNetwork then
403-
-- for _, network in pairs(player.force.logistic_networks[origEntity.surface.name]) do
404-
-- local cell = network.find_cell_closest_to(origEntity.position)
405-
-- if cell and not cell.mobile and cell.is_in_construction_range(origEntity.position) and cell.logistic_network then
406-
-- logisticsNetwork = cell.logistic_network
407-
-- end
408-
-- end
409-
-- end
410404
for i,module in pairs(modules) do
411405
if module then
412406
if inventory.can_insert{name = module, count = 1} then
413407
if player.get_item_count(module) > 0 then
414408
inventory.insert{name = module, count = 1}
415409
player.remove_item{name = module, count = 1}
410+
--inventory.insert{name = module, count = player.remove_item{name= module, count = 1}}
416411
else
417412
--check logisticsnetwork
418413
if logisticsNetwork and logisticsNetwork.get_item_count(module) > 0 then
@@ -515,5 +510,9 @@ remote.add_interface("mi",
515510
{
516511
saveVar = function(name)
517512
saveVar(global, name)
518-
end
513+
end,
514+
limits = function()
515+
debugDump(productivityAllowed,true)
516+
debugDump(productivityRecipes,true)
517+
end,
519518
})

data-final-fixes.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ metarecipe.hidden = true
1111
local metaProductivityRecipesR = copyPrototype("technology", "automated-construction", "mi-meta-productivityRecipes")
1212
metaProductivityRecipesR.ingredients = {}
1313
metaProductivityRecipesR.enabled = false
14-
metaProductivityRecipesR.hidden = false
14+
metaProductivityRecipesR.hidden = true
1515
metaProductivityRecipesR.effects = {}
1616

1717

0 commit comments

Comments
 (0)