forked from xsun2001/Applied-Energistics-2-Unofficial
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Fix/same network multiple extract only storage buses #612
Open
hiroscho
wants to merge
22
commits into
GTNewHorizons:master
Choose a base branch
from
hiroscho:fix/same-network-multiple-extract-only-storage-bus
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a4aea95
Fix that having multiple extract-only storage busses extracting from …
hiroscho 7f354ad
Fix extract-only storage bus with filter and extract-only storage bus…
hiroscho 6a0943e
refine
hiroscho 06521bf
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
hiroscho d2f4e47
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master b9b53ad
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
hiroscho 2854f41
extract changes to StorageBusInventoryHandler
hiroscho 76742a8
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master 2df603c
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
MCTBL f5ae6cd
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master 503cf8d
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master c38ece9
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master 4221d0c
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master 08ba722
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master 01be57e
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master dbac463
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master b0bb992
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master c963c97
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
serenibyss a1a5c00
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
serenibyss fbf461e
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master b29081e
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
Dream-Master 024b9c5
Merge branch 'master' into fix/same-network-multiple-extract-only-sto…
serenibyss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
100 changes: 100 additions & 0 deletions
100
src/main/java/appeng/me/storage/StorageBusInventoryHandler.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,100 @@ | ||
package appeng.me.storage; | ||
|
||
import java.util.Collections; | ||
import java.util.IdentityHashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import appeng.api.storage.IMEInventory; | ||
import appeng.api.storage.StorageChannel; | ||
import appeng.api.storage.data.IAEStack; | ||
import appeng.api.storage.data.IItemList; | ||
import appeng.me.cache.NetworkMonitor; | ||
|
||
public class StorageBusInventoryHandler<T extends IAEStack<T>> extends MEInventoryHandler<T> { | ||
|
||
private static final ThreadLocal<Map<Integer, Map<NetworkInventoryHandler<?>, IItemList<?>>>> networkItemsForIteration = new ThreadLocal<>(); | ||
|
||
public StorageBusInventoryHandler(IMEInventory<T> i, StorageChannel channel) { | ||
super(i, channel); | ||
} | ||
|
||
@Override | ||
public IItemList<T> getAvailableItems(final IItemList<T> out, int iteration) { | ||
if (!this.hasReadAccess && !isVisible()) { | ||
return out; | ||
} | ||
|
||
if (this.isExtractFilterActive() && !this.getExtractPartitionList().isEmpty()) { | ||
return this.filterAvailableItems(out, iteration); | ||
} else { | ||
return this.getAvailableItems(out, iteration, e -> true); | ||
} | ||
} | ||
|
||
@Override | ||
protected IItemList<T> filterAvailableItems(IItemList<T> out, int iteration) { | ||
Predicate<T> filterCondition = this.getExtractFilterCondition(); | ||
getAvailableItems(out, iteration, filterCondition); | ||
return out; | ||
} | ||
|
||
private IItemList<T> getAvailableItems(IItemList<T> out, int iteration, Predicate<T> filterCondition) { | ||
final IItemList<T> allAvailableItems = this.getAllAvailableItems(iteration); | ||
Iterator<T> it = allAvailableItems.iterator(); | ||
while (it.hasNext()) { | ||
T items = it.next(); | ||
if (filterCondition.test(items)) { | ||
out.add(items); | ||
// have to remove the item otherwise it could be counted double | ||
it.remove(); | ||
} | ||
} | ||
return out; | ||
} | ||
|
||
private IItemList<T> getAllAvailableItems(int iteration) { | ||
NetworkInventoryHandler<T> networkInventoryHandler = getNetworkInventoryHandler(); | ||
if (networkInventoryHandler == null) { | ||
return this.getInternal() | ||
.getAvailableItems((IItemList<T>) this.getInternal().getChannel().createList(), iteration); | ||
} | ||
|
||
Map<Integer, Map<NetworkInventoryHandler<?>, IItemList<?>>> s = networkItemsForIteration.get(); | ||
if (s != null && !s.containsKey(iteration)) { | ||
s = null; | ||
} | ||
if (s == null) { | ||
s = Collections.singletonMap(iteration, new IdentityHashMap<>()); | ||
networkItemsForIteration.set(s); | ||
} | ||
Map<NetworkInventoryHandler<?>, IItemList<?>> networkInventoryItems = s.get(iteration); | ||
if (!networkInventoryItems.containsKey(networkInventoryHandler)) { | ||
IItemList<T> allAvailableItems = this.getInternal() | ||
.getAvailableItems((IItemList<T>) this.getInternal().getChannel().createList(), iteration); | ||
networkInventoryItems.put(networkInventoryHandler, allAvailableItems); | ||
} | ||
|
||
return (IItemList<T>) networkInventoryItems.get(networkInventoryHandler); | ||
} | ||
|
||
/** | ||
* Find the NetworkInventoryHandler for this storage bus | ||
*/ | ||
private NetworkInventoryHandler<T> getNetworkInventoryHandler() { | ||
return (NetworkInventoryHandler<T>) findNetworkInventoryHandler(this.getInternal()); | ||
} | ||
|
||
private NetworkInventoryHandler<?> findNetworkInventoryHandler(IMEInventory<?> inventory) { | ||
if (inventory instanceof MEPassThrough<?>passThrough) { | ||
return findNetworkInventoryHandler(passThrough.getInternal()); | ||
} else if (inventory instanceof NetworkMonitor<?>networkMonitor) { | ||
return findNetworkInventoryHandler(networkMonitor.getHandler()); | ||
} else if (inventory instanceof NetworkInventoryHandler<?>networkInventoryHandler) { | ||
return networkInventoryHandler; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this cache getting invalidated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every time the iteration number changes the cache is replaced with a new one