-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: decouple storage state from multistorage
We will need it for the portable grid soon, which is not a mulistorage.
- Loading branch information
1 parent
b372340
commit c406843
Showing
29 changed files
with
109 additions
and
92 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ork/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/StorageState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.refinedmods.refinedstorage2.api.network.impl.node; | ||
|
||
import com.refinedmods.refinedstorage2.api.storage.Storage; | ||
import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorage; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.3") | ||
public enum StorageState { | ||
/** | ||
* There is no storage in the container. | ||
*/ | ||
NONE, | ||
/** | ||
* There is a storage present in the container, but the container is inactive. | ||
*/ | ||
INACTIVE, | ||
/** | ||
* The storage is active and has enough capacity to store more resources. | ||
*/ | ||
NORMAL, | ||
/** | ||
* The storage is active and has less than 25% capacity left. | ||
*/ | ||
NEAR_CAPACITY, | ||
/** | ||
* The storage is active and full. | ||
*/ | ||
FULL; | ||
|
||
private static final double NEAR_CAPACITY_THRESHOLD = .75; | ||
|
||
public static <T> StorageState compute(final Storage<T> storage) { | ||
if (storage instanceof LimitedStorage<T> limitedStorage) { | ||
return compute(limitedStorage.getCapacity(), storage.getStored()); | ||
} | ||
return StorageState.NORMAL; | ||
} | ||
|
||
private static StorageState compute(final long capacity, final long stored) { | ||
final double fullness = stored / (double) capacity; | ||
if (fullness >= 1D) { | ||
return FULL; | ||
} else if (fullness >= NEAR_CAPACITY_THRESHOLD) { | ||
return NEAR_CAPACITY; | ||
} | ||
return NORMAL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
...inedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageStorageState.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...va/com/refinedmods/refinedstorage2/platform/api/storage/AbstractStorageContainerItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
.../main/java/com/refinedmods/refinedstorage2/platform/api/storage/StorageContainerItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...java/com/refinedmods/refinedstorage2/platform/api/storage/StorageContainerItemHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/StorageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/refinedmods/refinedstorage2/platform/common/storage/StorageContainerItemHelperImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveContainerMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveDisk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.refinedmods.refinedstorage2.platform.common.storage.diskdrive; | ||
|
||
import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageStorageState; | ||
import com.refinedmods.refinedstorage2.api.network.impl.node.StorageState; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.world.item.Item; | ||
|
||
public record DiskDriveDisk(@Nullable Item item, MultiStorageStorageState state) { | ||
public record DiskDriveDisk(@Nullable Item item, StorageState state) { | ||
} |
2 changes: 1 addition & 1 deletion
2
...dmods/refinedstorage2/platform/common/storage/diskdrive/EmptyStorageDiskInfoAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...efinedmods/refinedstorage2/platform/common/storage/diskdrive/StorageDiskInfoAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.