Inventory Trash Slot


A trash slot for easy deletion of unwanted items.

Utilities
14 days ago
2.0
2.47K
Character Storage Cheats

i Trash Item in Cursor -> Trash Item at Cursor

16 days ago
(updated 16 days ago)

Hello again,

Hopefully I am not spamming, but I was getting to using the mod and got pretty confused for a second as I assumed "Trash Item in Cursor" worked like shift clicking an item in your inventory when you have another inventory open and just moving the whole stack over (What I will delineate as "Trash Item at Cursor"). Instead I have to individually click on each item I want to delete and then hit the key combination to delete it, or manually move it to the garbage icon which is not my style.

I think it would be more factorio-esk (opinion) if it operated as "Trash Item at Cursor" where it operated more like moving items between inventories. I think this would make it a more seamless integration when cleaning your inventory. As a plus it decreases the chance of an accidental key stroke from deleting items as now it would only work in inventory menus. It would require said cat to not only hit a key sequence but move the mouse as well in the area of the screen where it would be a valid delete action.

That is just my two cents. At the end of the day this mod resolves the issue I have though I will probably only use it for the one delete necessary to clear space in my inventory for an infinity chest and then dump all the items in there to be auto deleted since it is less clicks. Again thanks for the mod and have a good one.

16 days ago

Honetly I'm not sure how feasable that is, the other trash mod I looked at was only able to use this system. I agree it would be much better tho, I'll take a look at if it's possible.

16 days ago

Yeah I do not know the feasibility myself, but let me have a look around the mods and see if I can find anything that looks like it does something similar. Again appreciate it!

16 days ago

So looking through the modding api this looks promising:
- https://lua-api.factorio.com/latest/events.html#on_gui_hover

Though it really depends on what triggers these events as well as what you have access to in LuaGuiElement which tbh is the first time I have actually looked at the factorio mod api docs so lots of assumptions on my part here.

If you get an actual reference back from the on_hover event that is the explicit item in the inventory that makes things easier for what you are acting on. Otherwise you would have to sift through the whole characters inventory and delete the first reference that matches item idea and item count. which depending on how that was coded might add latency.

Another option is this api event:
- https://lua-api.factorio.com/latest/events.html#on_gui_click

It seems to give you the item specifically though it is very limited in key strokes it will capture (mouse buttons, ctrl, alt, shift)

If you wanted one that was more customizable to not just the keys available in on_giu_click you might have to implement your own version of:
- https://lua-api.factorio.com/latest/events.html#CustomInputEvent

Though that might be a bit overboard as I do not know your level of comfort programming

I did find a very minimal post about something like this:
- https://forums.factorio.com/viewtopic.php?t=109641

Again all of this is speculation as I do not know the factorio api mod scene that well but just attempting to give the best info I can to help.

16 days ago

The event only exposes the element that's hovered but the vanilla inventory slots work on a custom system and I can't get the specific item stack from the gui element, so I don't think it's possible.

15 days ago
(updated 15 days ago)

Here's something I whipped up quickly:

local function cleanupMassDeleteChest(index)
    if storage.massDeleteChest and storage.massDeleteChest[index] then
        local chest = storage.massDeleteChest[index]
        if chest.valid then
            chest.destroy()
        end
        storage.massDeleteChest[index] = nil
    end
end

local function massDeleteError(player)
    player.create_local_flying_text{
        -- REPLACE this with a LocalisedString
        text = "Couldn't create/open chest, try switching Editor tabs",
        create_at_cursor = true,
    }
    player.play_sound{path = "utility/cannot_build"}
end

script.on_event("inventory-trash-slot-mass-delete", function(e)
    local player = game.get_player(e.player_index)
    if player.controller_type ~= defines.controllers.editor then
        return
    end

    -- In case a previous one got left behind
    cleanupMassDeleteChest(e.player_index)

    -- This will even work on top of existing buildings and water!
    local chest = player.surface.create_entity{
        name = "infinity-chest",
        position = e.cursor_position,
        create_build_effect_smoke = false,
        preserve_ghosts_and_corpses = true,
    }
    if not chest then
        massDeleteError(player)
        return
    end

    -- Try to open the chest's GUI
    player.opened = chest
    storage.massDeleteChest = storage.massDeleteChest or {}
    storage.massDeleteChest[e.player_index] = chest

    -- User is in an Editor mode that doesn't support opening entity GUIs
    if not player.opened then
        massDeleteError(player)
        cleanupMassDeleteChest(e.player_index)
    end
end)

script.on_event(defines.events.on_gui_closed, function(e)
    -- Put this in your existing GUI closed handler
    cleanupMassDeleteChest(e.player_index)
end)

Basically, you make a new unbound keybind called inventory-trash-slot-mass-delete that only works in Editor mode. It will spawn and try to open an infinity chest at the player's cursor, and delete itself when you close it.

If you're feeling up to it, you could try prototyping your own invisible chest to use with this function.

14 days ago

Yeah I guess you could do that, I'm not sure you would really need to delete that many items tho.

New response