-- control.lua
local function logic_on_player_selected_area(event, set_unlimited)
local player = game.players[event.player_index]
local item = event.item
local entities = event.entities
if not item == "ore-unlimited" then
return
end
for _, entity in pairs(entities) do
local function loop_body()
if (not entity.valid) or not (entity.type == "resource") then
return
end
-- Cannot figure out these ones
if string.find(entity.name, "se-core-fragment", 1, true) then
return
end
if set_unlimited and string.match(entity.name, "unlimited-") then
return
end
if (not set_unlimited) and (not string.match(entity.name, "unlimited-")) then
return
end
local cleanName = string.gsub(entity.name, "unlimited%-", "")
local amount
local initial_amount
player.print(cleanName .. " - Processed!")
if cleanName == "crude-oil" or cleanName == "sulfuric-acid-geyser" or cleanName == "fluorine-vent" then
amount = entity.amount
initial_amount = entity.initial_amount
else
if set_unlimited then
-- Why one? because by default normal is 1, so amount 1 means 100% yield
-- Wtf is initial_amount? A hack so we can store the real amount left without fucking up yield.
amount = 1
initial_amount = entity.amount
else
amount = entity.initial_amount
initial_amount = nil
end
end
local name
if set_unlimited then
name = "unlimited-" .. entity.name
else
name = cleanName
end
player.print(name)
player.print(tostring(initial_amount))
local new_entity = player.surface.create_entity({
name = name,
position = entity.position,
amount = amount,
})
-- Why here? because create_entity does not respect us setting initial_amount
if not (initial_amount == nil) then
new_entity.initial_amount = initial_amount
end
entity.destroy()
end
loop_body()
end
end
script.on_event(defines.events.on_player_selected_area, function(event)
logic_on_player_selected_area(event, true)
end)
script.on_event(defines.events.on_player_alt_selected_area, function(event)
logic_on_player_selected_area(event, false)
end)
script.on_event(defines.events.on_player_dropped_item, function(event)
if event.entity ~= nil then
if event.entity.stack ~= nil then
if event.entity.stack.name == "ore-unlimited" then
event.entity.stack.clear()
end
end
end
end)
-- prototypes/resources.lua
local oreNames = {}
for key, name in pairs(data.raw.resource) do
table.insert(oreNames, key)
end
for i, name in ipairs(oreNames) do
local unlimitedOre = table.deepcopy(data.raw.resource[name])
unlimitedOre.name = "unlimited-" .. name
unlimitedOre.localised_name =
{
"resource-name.unlimited",
{
"entity-name." .. name
}
}
unlimitedOre.infinite = true
unlimitedOre.infinite_depletion_amount = 0
if unlimitedOre.minimum == 0 then
unlimitedOre.minimum = 1
end
unlimitedOre.autoplace = nil
if unlimitedOre.stage_counts then
-- #foo is like foo.length
for i = 1, #unlimitedOre.stage_counts do
unlimitedOre.stage_counts[i] = 0
end
end
if mods["Krastorio2"] and name == "crude-oil" then
unlimitedOre.collision_box = { { -1.4, -1.4 }, { 1.4, 1.4 } }
unlimitedOre.selection_box = { { -1, -1 }, { 1, 1 } }
unlimitedOre.category = "oil"
end
data:extend({unlimitedOre})
end
There you go. It's quite a bit of change, and honestly I made it the way I wanted it to look like so it might not fit your tastes. Hope this helps though.
(Also please don't be in a hurry to implement this, I'm not asking for a feature request just a suggestion, and I haven't really tested it all that much)