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

Threshold Switch does not accurately calculate the level of storage views with different capacity #1044

Closed
JiDW opened this issue Aug 8, 2023 · 1 comment
Labels
type: bug Issue where something isn't working

Comments

@JiDW
Copy link

JiDW commented Aug 8, 2023

Describe the Bug

Hello!

In ThresholdSwitchBlockEntity.java, the method updateCurrentLevel inaccurately calculates the fill level when storage views have different capacities. It treats all storage views as if they have the same weight, leading to incorrect results.

Here's a simple example to illustrate the problem:

Suppose there are two storage views, one with a capacity of 100 and one with a capacity of 200.
Suppose the first storage is completely full (100/100) and the second storage is half full (100/200).
Using the current code, occupied would be calculated as (100/100) + (100/200) = 1 + 0.5 = 1.5, and totalSpace would be 2.
Therefore, currentLevel would be occupied / totalSpace = 1.5 / 2 = 0.75.

However, the actual fill level of the storage system would be 200 out of a total capacity of 300, or approximately 66.67%.

Proposed Fix:
Calculate Total Space by Summing Actual Capacities: Add the actual space of each storage view to totalSpace instead of incrementing by 1.
Calculate Occupied Space by Summing Actual Counts: Add the actual count of each storage view to occupied instead of calculating count * (1f / space).

As I'm not sure about potential edge cases, I preferred to post about it here instead of submitting a PR (I'm new to the Minecraft mod scene)

Thank you!

Reproduction Steps

  1. Use a Threshold Switch on a storage system with at least two views with different capacity
  2. Fill one and leave the other one empty
  3. Look at the level reported by the Threshold Switch

Expected Result

Accurately calculate the fill level

Screenshots and Videos

No response

Crash Report or Log

No response

Operating System

Windows 11

Mod Version

0.5.1d

Minecraft Version

1.20.1

Other Mods

I've discovered this issue while using the Extended Drawers mod for Fabric but confirmed with the author that it was an issue with the Create block.

Additional Context

No response

@JiDW JiDW added the type: bug Issue where something isn't working label Aug 8, 2023
@JiDW
Copy link
Author

JiDW commented Aug 8, 2023

Same bug was posted today here: Creators-of-Create#5299
I'm closing this report

@JiDW JiDW closed this as completed Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Issue where something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant