Powered Belts


Belts now need power. All of them. Including all the modded ones. Unmaintained.

Content
2 years ago
0.17 - 1.1
775
Logistics

b [Fixed in 0.4] items on belts get deleted if you lose power

4 years ago

items on belts get deleted if you lose power

4 years ago

I already know about this, but it is pretty much the same problem as splitters losing set filter (something to do with how vanilla handles belts) so it's propably unfixable. I did try to fix these problems before, but nothing worked yet.

4 years ago

Would it maybe possible instead of replacing the entities, to just disable them like red/green wires do?

4 years ago

Not possible as far as I know.

4 years ago
(updated 4 years ago)

Something new on this one? I really like to turn unused parts of the factory off. But i also like the powered belts. :'(

4 years ago

Unfortunately no.

4 years ago

OK. Thanks nevertheless. ;)

4 years ago

A workaround suggestion:

If belts delete carried items if they have no power, then try altering the belts so they each PRODUCE a miniscule fraction of the power they need so that they ALWAYS have at least a little power even all alone in the middle of nowhere.

IE: If a belt length requires 1 watt of power to run, then have the belt itself produce 0.01 watts of power so that it can keep itself running. The belt will have power and not delete items, but theoretically it's speed being 1 percent of its rated speed will result in it being more or less at a standstill. And you don't have to worry about it being a cumulative free power generator because their power consumption will ALWAYS out-number their production.

4 years ago

Sadly you can't change the speed of the belt mid-game, it always goes at its set speed. The only way to change the speed of the belt is to replace it with a belt of different speed and when doing it from the mod, the items get removed. The only solution I can think of is to save the contents of the belt when removing it and then insert it back on the new one.

4 years ago

So I did some testing and when I put entity.die(nil) instead of entity.destroy() when replacing the belt, items won't get removed. However the belt won't replace back when I provide it with electricity and game crashes when I mine it... not perfect, but may lead you to some solution maybe?

3 years ago

I really would like to see this fixed. This is a great mod, but this one thing is a deal breaker, along with the filter bug. I know a bit of coding myself, but I would have to learn both lua and the Factorio API to know how to fix this.

3 years ago
(updated 3 years ago)

Why does this mod use destruction of the belt entities rather than https://wiki.factorio.com/Prototype/Entity#fast_replaceable_group ?

Specifically, the fast_replace argument of https://lua-api.factorio.com/latest/LuaSurface.html#LuaSurface.create_entity can be used to swap between powered and unpowered belts.

3 years ago
(updated 3 years ago)

Modified part of control.lua, doesn't fix all the issues (smart belt dragging (automatic undergrounds) doesn't work properly if building without power coverage) but does prevent items on belts from being deleted.

---- ON TICK ----
script.on_event(defines.events.on_tick, function(event)
    if power_entities ~= nil and entities ~= nil and next(power_entities) and next(entities) then
        for _ = 1, settings.global["powered-belts-operations-per-tick"].value do
            if next(power_entities) ~= nil and next(entities) ~= nil then
                if next(power_entities, k) == nil then k,_ = next(power_entities, nil) else k,_ = next(power_entities, k) end
                if entities[k] ~= nil and entities[k].valid then
                    if string.match(entities[k].name, "unpowered-") and power_entities[k].energy > 0 then
                        local entity_data = {surface = entities[k].surface, name = entities[k].name, position = entities[k].position, force = entities[k].force, direction = entities[k].direction}
                        if entities[k].type == "underground-belt" then entity_data.belt_to_ground_type = entities[k].belt_to_ground_type end
                        if entities[k].valid then
                            entities[k] = entity_data.surface.create_entity{
                                name = string.sub(entity_data.name, 11),
                                position = entity_data.position,
                                force = entity_data.force,
                                direction = entity_data.direction,
                                type = entity_data.belt_to_ground_type,
                                fast_replace = true,
                                spill = false
                            }
                        end
                    elseif (not string.match(entities[k].name, "unpowered-")) and power_entities[k].energy <= 0 then
                        local entity_data = {surface = entities[k].surface, name = entities[k].name, position = entities[k].position, force = entities[k].force, direction = entities[k].direction}
                        if entities[k].type == "underground-belt" then entity_data.belt_to_ground_type = entities[k].belt_to_ground_type end
                        if entities[k].valid then
                            entities[k] = entity_data.surface.create_entity{
                                name = "unpowered-" .. entity_data.name,
                                position = entity_data.position,
                                force = entity_data.force,
                                direction = entity_data.direction,
                                type = entity_data.belt_to_ground_type,
                                fast_replace = true,
                                spill = false
                            }
                        end
                    end
                end
            end
        end
    end
end)
3 years ago

Just tested it out, and it works! Going to update the mod now, thanks for fixing it.
I didn't use fast_replace, because I didn't know it was even a thing when I made the mod.

New response