You are viewing a potentially older version of this package. View all versions.
LJIndustries-CollectionChest-1.0.0 icon

CollectionChest

A switch in the chest menu makes a chest pull in items dropped right beside it. Put one under a smelter, kiln or windmill and the output stores itself.

Date uploaded 2 weeks ago
Version 1.0.0
Download link LJIndustries-CollectionChest-1.0.0.zip
Downloads 290
Dependency string LJIndustries-CollectionChest-1.0.0

This mod requires the following mods to function

denikson-BepInExPack_Valheim-5.4.2350 icon
denikson-BepInExPack_Valheim

BepInEx pack for Valheim. Preconfigured with the correct entry point for mods and preferred defaults for the community.

Preferred version: 5.4.2350

README

CollectionChest

A switch inside the chest's menu that allows you to enable auto collection! No more wandering around smelters, furnaces, windmills and other appliances manually collecting random stuff.

Every chest you build gets the switch. Turn it on, and the chest pulls in any item dropped right beside it. Put a chest where a smelter spits out its bars and the bars store themselves.

How it works

Open a chest. Just below the chest's panel, on the left, there is a new button: Auto-collect: OFF. Click it to turn it ON.

From then on the chest checks once a second for dropped items within 1 metre of it, and moves them in. That covers anything that ends up on the ground: bars from a smelter or blast furnace, coal from a charcoal kiln, flour from a windmill, thread from a spinning wheel, eitr from a refinery, honey from a beehive, and things you drop yourself.

The switch is saved with the chest, in the world. It stays on through restarts, every player sees the same setting, and hovering over a collecting chest says so:

  • Auto-collect on: collecting.
  • Auto-collect on - full: no empty slots left. It still tops up stacks it already has, but anything else stays on the ground.

It will not overfill a chest

A chest only ever takes what it has room for. It fills stacks of the same item first, then empty slots, and stops there:

  • If only part of a stack fits, it takes that part and leaves the rest on the ground, still one pickup, for you or another chest.
  • A full chest leaves items where they are and does not keep grabbing at them.
  • The drop on the floor is reduced by exactly what the chest gained, counted after the move rather than assumed, so an item cannot end up both in the chest and on the ground.

Range, and tightly packed bases

The 1 metre is measured from the chest's sides and lid, not its centre. An item resting on the chest is at 0, and a long chest reaches no further past its ends than a small one does.

It is tight on purpose. A chest under one smelter should catch that smelter's bars, not the next one along the wall. If your layout needs more reach, raise Range a little at a time; it goes up to 4 metres.

What it leaves alone

  • Storage that is not a chest you built: carts, ship storage, gravestones and loot bags get no switch.
  • The obliterator. It has an inventory too, but a self-filling obliterator is one lever pull from destroying whatever wandered into it.
  • Food set out on a table, fish still in the water, items stuck in tar, quest items, and anything the game only lets you pick up by hand (the same items your own auto-pickup ignores).
  • Items that have only just dropped: like your own auto-pickup, it waits half a second.

Configuration

BepInEx/config/com.ljindustries.valheim.collectionchest.cfg, written on first run.

Setting Default What it does
Enabled true Master switch. While off, no chest collects and the button is hidden. Chests you switched on remember it and resume when you turn this back on.
Range 1 How far from the chest's sides and lid an item can be and still get pulled in, in metres. 0.25–4.
ScanInterval 1 Seconds between checks. Machines produce every 30 seconds or more, so there is little to gain below 1. 0.25–10.
ShowHoverStatus true The "Auto-collect on" line on a collecting chest's hover text.
VerboseLogging false Log every item collected, and when a chest runs out of room, to the BepInEx console.

BepInEx only reads the file at startup, so edit it with the game closed or use a configuration manager in game.

Multiplayer

Install it on every player's game. The server does not need it.

Valheim gives each chest to one player's game to run, normally whoever got near it first, and only that game is allowed to change what is in the chest. That game is the one that does the collecting, which is what keeps two players from each storing the same bar. If the player running a chest does not have the mod, that chest simply pauses until someone who does takes it over. It does not break, and nothing is lost.

Works alongside MultiUserChest. With it, a second player can have a chest open at the same time, and flipping the switch from their menu asks the player running the chest to do it.

Install

Through a mod manager (r2modman, Thunderstore Mod Manager), or by hand: drop CollectionChest.dll into BepInEx/plugins/.

Requires BepInExPack Valheim.

CHANGELOG

Changelog

1.0.0

First release.

  • An auto-collect switch in every built chest's menu. A copy of the menu's own Take all button, hung below the chest panel's bottom-left corner. The panel's header already holds Take all, the chest name and Place stacks, and everything below the header is the item grid. The switch is a flag in the chest's ZDO, so it is saved with the world and every player sees the same setting.
  • A switched-on chest pulls in items dropped within 1 metre of it, checked once a second. The distance is to the chest's own colliders, not its pivot, so an item on the lid is at 0 and a long chest reaches no further past its ends than a short one.
  • It never takes more than it has room for. Room is counted the way Inventory.AddItem counts it: matching stacks by name, quality and world level first, then empty slots. CanAddItem ignores quality and can promise room AddItem will not give. Items go in at most one stack per call, since AddItem puts its whole remainder into a single new slot. Whatever does not fit stays on the ground as a smaller stack, and a full chest leaves drops alone instead of repeatedly claiming them.
  • An item cannot end up in the chest and on the ground at once. The drop is shrunk by what the chest actually gained, counted afterwards, not by what the code expected to move. The chest only takes a drop once this client owns it, since ZNetScene.Destroy on anyone else's copy leaves the ZDO behind and the item would reappear.
  • Only the chest's owner collects. That is the one peer allowed to write its inventory. It reloads the chest from its ZDO first, in case another player changed it within the last second. Built with MultiUserChest in mind: the menu switch asks the owner by RPC rather than writing the flag itself.
  • Leaves alone: carts, ship storage, gravestones, loot bags, the obliterator, food set out on a table, fish still in the water, items in tar, quest items, and anything whose prefab opts out of auto-pickup.