mojira.dev
MC-6165

Comparators cannot determine if a container is empty

What I expected to happen was:
As comparators can now be used to guage the contents of containers, I expected a single item to be adequate to output a signal, allowing us to determine when a container has become empty

What actually happened was:
The container must be over 6.666...% full before any output is created. For chests, this means 116 items must be inside before a signal is produced. For hoppers, this means 22 items must be inside.

This essentially makes it impossible to check for emptiness, restricting us to a fullness test. The fix would be simple enough: output floor( (contents/capacity) * 14) + ceil((contents/capacity)), instead of floor( (contents/capacity) * 15). This would still allow checking if a container is at its capacity, while also allowing you to check if it's completely empty.

Steps to reproduce:
1. Place a comparator, with a container as its input, and a 15-long wire of redstone dust as its output.
2. Insert an item into the container. If it does not exceed 6.666...% of the container's capacity, there will be no output.
3. Bring the container to above 6.666...% of its capacity. Observe an output of 1.
4. Bring the container to near full capacity. Observe that its output is 14.
5. Bring the container to full capacity. Observe that its output is 15.

I don't see this as a feature request, but rather a bug in the newly added system (remember, the snapshot came out just today). It seems unreasonable (and likely accidental) to have no way of determining a container is completely empty, when you can determine the container is completely full. Both of these features are far more useful than determining a container's percent content in increments of 6.666...% instead of 7.142857...%.

In fact, this change would have an added benefit (unintentional by my equation, but still): an output of 8 would indicate a container is precisely at 50% or higher. In the current system, 7 indicates you're 3.333% higher or lower than 50%, which is again a failure to provide a useful threshold for calculations.

Finally, an example usage case of why you would want to determine a container is empty: you could have an automated storage minecart unloading station, using a hopper to unload the carts. When the hopper contains zero items, you know the cart is empty, and you can send it on its way.

Comments 15

You know, I have a feeling a mod here will be tempted to close this as "Invalid". I've seen this happen many times. At the very least, if you're going to close this, have the courtesy to acknowledge that it's a bug report, not a feature request. Thus, if you feel this behavior is intended, mark it "Works as Intended", not "Invalid". It would also be nice to see evidence it's intended (Hi Dinnerbone! 😃), not the opinions of somebody who does not actually work at Mojang.

The heart of the report is "comparators don't give an output if their input container has at least one item". There is no way to interpret that as a 'feature request'; it is a factual statement, which is either intentional or unintentional. If you must close this, close it based on the issue I am reporting, not based on the fact that I suggested a fix.

Of course, if you don't think this is intentional, then there's no need to close it. I'm not asking for it to be closed; I'm just saying that if you are closing it, don't cop-out and say it was never a bug report to begin with.

PLEASE FIX THIS DINNERBONE! Everybody else, VOTE THIS UP SO HE CAN SEE

I found this behavior to be undesirable as well.

Personally for me it would be more useful to have a system that showed how many slots where free, ignoring stack values completely, but I'm aware that those wanting more detail wouldn't be happy about that - but throwing it out here in case there's a chance for having both type of checks.

It's also not consistent with the behaviour of the newly added pressure plates, that give off a signal with one item.

As annoying as it is, it would make some redstone signal strengths encompass a wider range of items, making this feature less precise. Also, it would break the functionality in http://www.youtube.com/watch?v=a92_VBLTjAQ because hoppers filled with five diamonds would output a signal.

5 more comments

Thanks Dinnerbone! The only problem I see is, does it let us check if a chest is 100% full, to prevent overflow? If I'm calculating this correctly, the average fullness of slots for a chest missing a single item is 0.999421296...%, and a chest with 26 of 27 slots consumed is 0.962%. Where does that ceiling occur? Would those situations output 15, or will 15 be reserved for a completely full container? 😛

Also, I could be doing my math wrong, as I landed on the exact same numbers for "average fullness of the whole container" as I did "average fullness of all slots". Not surprising, what with all the numerators and denominators cancelling, making the equations literally the same. But I don't quite understand what difference the two situations imply.

Anyways, thanks again!

Current ("fullness of the whole container") algorithm is pretty much:

  • Guess at how much the max capacity of the container is by assuming empty slots' max == average max of nonempty slots

  • Total the count of all the items that we have

  • Pct == total / guessedMax

  • Round down, convert to redstone

New algorithm is:

  • For each slot, figure out its fullness (count/total, empty slots = 0/64 == 0)

  • Pct == total/numSlots

  • Round up, convert to redstone

There isn't a way to know exactly 100% full, and not "nearly full". Do you have a suggestion for that?

Perhaps reserve signal strength 0 for empty, 15 for full and scale the others by multiplying by 14/15 before ceil-ing? I think people are most concerned with whether their container is full or empty, as useful as a percentage is. I think making it slightly harder to find the exact percentage is worth having a full signal. (I mean, the whole point of redstone signals is that they are blocky and by no means exact.) Again, thanks very much.

Agreed, I think the redstone conversion is where the issue happens. One of my suggestions above, restated here (as the above was actually flawed, go figure) as "(int)(percent * 14) + (total > 0 ? 1 : 0)", would seem to accomplish it.

  • If percent is 0 (as total is 0 if all slots are empty), the ternary will return 0, as will percent*14, totalling 0.

  • The floor done by (int) makes the first term still zero out if it's under 1/14, while the ternary always evaluates to 1 if there is at least one item.

  • After percent is 1/14, we get an output of 2.

  • For a percent of 99.99999%, we still get 13+1 = 14.

  • Only 100% will pass 14 out of the floor and allow an output of 15.

To anybody still wondering, as of snapshot 12w03a (possibly earlier), Dinnerbone has apparently implemented things in exactly the way we suggested above (one item is enough for 1 tick of signal, and a container must be completely full for an output of 15. You get an output of 8 once it is exactly 50% or more full).

Many thanks again, Dinnerbone! 😃

WolfieMario

Nathan Adams

Confirmed

Snapshot 13w01b

Snapshot 13w02a

Retrieved