Ore Unlimited

by No0Vad

Adds the Ore Unlimited item which allows you to change the ore fields to unlimted, or back to normal with fixed amounts by holding SHIFT instead. IMPORTANT! Be sure to restore the ore fields to normal first if you want to remove this mod!

Content
a month ago
0.17 - 2.0
11.6K
Cheats

i Not touching the yield/resources left.

a month ago
(updated a month ago)

Some players may like it better if the yield and resource left is left intact as is, example is me. This way applying the unlimited ore, using it for a long while, then unapplying it will leave it as if it had never been used.

What i changed:
control.lua: set amount of newly created entity to use entity.amount instead of the random function (that actually isn't random, uses the config values instead)
prototypes/resources.lua: removed unlimitedOre.normal to avoid crude oil yield being multiplied by 300. this also sets yield of ores like iron ore to be 100x in percent, but i don't think it affects gameplay.

Edit: once again thank you for your efforts, my edits is only possible because you laid the foundations for me to edit rather painlessly

a month ago

Hi,

It was random at one point in time, but I changed it to settings value, but never changed the function name.
I'm unsure what you here, if I change it to entity.amount and when I undo a unlimited ore to normal ore the amount is 100?
If this is what you want, you could change the setting instead, Normal from 10000 to 100.

I added a setting Multiply the fluid result (If enabled, the fluid result get will be larger).
Basically if that one is true unlimitedOre.normal = 100 will be use.

a month ago
(updated a month ago)

I think it's best described with a video because it seems we are not on the same page.
https://youtu.be/IX7HKC1NmNQ

I'm not sure if you get exactly what I changed in control.lua, but it's this:

if set_unlimted then
  if not string.match(entity.name, "unlimited-") then
    player.surface.create_entity({
      name="unlimited-" .. entity.name,
      position=entity.position,
      amount=entity.amount
    })

    entity.destroy()
  end
else 
  if string.match(entity.name, "unlimited-") then
    player.surface.create_entity({
      name=cleanName,
      position=entity.position,
      amount=entity.amount
    })

    entity.destroy()
  end
end
a month ago

Ahh, I see now (a video is always more helpful than just text πŸ˜…)

I've removed the old setting I mentioned earlier and change it to Alternative mode, when true the effect is as you shown in the video.
The new version is now available.

a month ago
(updated a month ago)

Oh wait man, i just played with it today and yield on ores apparently does have effect. I'll have to fix it πŸ˜… otherwise a single mining cycle yields thousands of ores.

a month ago
(updated a month ago)

Oh wait man, i just played with it today and yield on ores apparently does have effect. I'll have to fix it πŸ˜… otherwise a single mining cycle yields thousands of ores. So sorry for assuming ChatGPT didn't lie to me and not testing it further.

Edit: sorry for duplicate, i fucked up.

a month ago
(updated a month ago)
-- 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)

a month ago

Also I hope you don't mind if i host a fork on my personal github just to make sure I don't lose my edited version

a month ago
(updated a month ago)

Hi,

I've just release another version that should do what you suggested, I did not copy your code 100% but took the initial_amount idea.

Also I hope you don't mind if i host a fork on my personal github just to make sure I don't lose my edited version

Not at all, you link back to original in your README too😊

New response