Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect if chest has content? #538

Open
johalun opened this issue Oct 6, 2020 · 8 comments
Open

Detect if chest has content? #538

johalun opened this issue Oct 6, 2020 · 8 comments

Comments

@johalun
Copy link
Contributor

johalun commented Oct 6, 2020

Are there any plans to create a node that can sense the content of a chest (and possibly other kinds of containers). Either one node that is configured in its GUI or 3 different nodes that output signals on "has items", "is empty" and "is full". If not, I might start working on this, either as a PR to mesecons, or a stand alone mod.

I'm already looking into adding a digilines "get" command to the digiline chest to get how many items it contains but it would also be nice not having to use lua for this and instead build a physical circuit with mesecons. I'm actually quite surprised this functionality hasn't been implemented yet, or am I missing something (I'm new to MTG)? Detecting the amount of contents in a chest seems like the one of the first things you'd want for automation. At least, that's what my MC brain is telling me, maybe there are existing different solutions for MTG?

@auouymous
Copy link
Contributor

I agree.

The "is full" state is tricky because a slot could hold more, but not more of another item. Instead of those three states, it could count slots that have at least one item, and have two text fields to enter the minimum and maximum number of slots, both inclusive. It could also support percentages in addition to exact slot counts, so the player doesn't have to count slots.

0 to 0 = signal if empty
1 to 100% = signal if at least one slot, upto 100% of the slots (has items)
100% to 100% = signal if full

Those cover your initial goals.

Use 0 to 75% to fill a chest from a slow machine whose output trickles in after turned off. And 80% to 100% to export items when you have a lot but want to keep a minimum amount.

The exact slot count is needed to allow the "has items" mode because 1% might be more than one for a chest with more than 100 slots. It also gives precise control over the number of slots that a signal should be active for. And some might find it easier than figuring out percentages.

@johalun
Copy link
Contributor Author

johalun commented Oct 7, 2020

There's also unstackable items too, right? Like batteries? But, maybe there's not so many of them so we could have a static list of unstackables to use when summing up how many items are required to "fill" an item stack. Another option could be to try to add a dummy node of the same kind to the item stack but that might be wasteful in terms of cpu cycles..

@johalun
Copy link
Contributor Author

johalun commented Oct 7, 2020

Working WIP here (based on switch for now)

https://github.com/johalun/mesecons/compare/master..scanner

@auouymous
Copy link
Contributor

There is no need to check for stack size, just count the number of slots that have an item, ignoring the quantity of each stack. A chest with 1 stick in each slot will register as full but that isn't really possible to do with automation. Unless those sticks are shrinking the chest so it only holds a few of the item you actually want to go into the chest, in which case this method still works as intended.

local count = 0
for i = 1, inv:get_size(inv_name) do
  if not inv:get_stack(inv_name, i):is_empty() then count = count + 1 end
end

It would also be nice to have an inventory name field for inventories with names other than "main", or multiple inventories. It could default to "main" if blank.

@johalun
Copy link
Contributor Author

johalun commented Oct 7, 2020

That's true. Usually with automation you have one or just a few different kinds of items in a chest so maybe that's not a big deal.

Yeah, I've been thinking about inventory name as well and that's a good idea. I know for example Pipework's autocrafter has a temporary inventory for uncrafted items as well as the inventory for crafted items.

I wonder, would it be possible to fetch a list of all inventories from the chest/node behind the scanner and populate a drop down list? Sounds like it should be...

@auouymous
Copy link
Contributor

https://dev.minetest.net/InvRef -- inv:get_lists() returns a table of list names.

As for percentages, it might be good to store the actual values in min/max fields and if value is a percentage, store in min_pct and max_pct or set them to zero if 0% or not a percentage. That way the code uses fast min/max values instead of checking and calculating percentage each tick. Opening formspec and saving could recalculate or use on_punch to do it.

@johalun
Copy link
Contributor Author

johalun commented Oct 9, 2020

PR here #540

@ingvart
Copy link

ingvart commented Mar 16, 2024

I would like to see some way to request items to a chest or container.
Ideally, something oposite of an injector.
The simplest way would be to have a craftable block (let's call it an inserter) which similar to the filter injector has a direction, but detects the content of the block with inventory in front of it, which could be a chest or a machine. Then, in the inserter, one could define a set of desired content, and the inserter would send out a mesecon signal if the content was failing.

Ideally, as Factorio handles it, the mesecons would handle different signals with "IDs" or "types", and the signal could be linked to the desired/missing content of the object in from of the inserter, and therefore on the other end a decision could be bade based on what signal was sent and what items were missing.

But even if only one signal could be sent when something was missing in the chest, one could use several "inserters" to detect the status of several types items in a chest.

This could be used in a lot of ways. One could detect whether there are sufficient solar panels in a chest and when not, send a signal to an autocrafter. Another "inserter" could check whether the autocrafter has what it needs to make a solar panel, and so forth.
Perhaps a "requester" is a better name than an "inserter".

Another option is to make machine and chest inventories able to send a signal when they do not have a certain item. The "inserters" or "requesters" would then not be needed. Machines and chests could send a "request" signal when they do not have the configured amount of items (which could be multiple combinations of quantities and types).

This is rather similar to Factorio, where huge manufacturing chains can easily be setup and automated, and is pretty much the only missing item in the puzzle for Minetest to allow for automated factories.

Or is there any other way to do this, which I haven't found?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants