-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix grid not handling network changes
- Loading branch information
Showing
28 changed files
with
482 additions
and
95 deletions.
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
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
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
8 changes: 8 additions & 0 deletions
8
...dmods/refinedstorage2/api/network/impl/node/container/NetworkNodeContainerPriorities.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,8 @@ | ||
package com.refinedmods.refinedstorage2.api.network.impl.node.container; | ||
|
||
public final class NetworkNodeContainerPriorities { | ||
public static final int GRID = Integer.MAX_VALUE; | ||
|
||
private NetworkNodeContainerPriorities() { | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...in/java/com/refinedmods/refinedstorage2/api/network/impl/node/container/package-info.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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@FieldsAndMethodsAreNonnullByDefault | ||
package com.refinedmods.refinedstorage2.api.network.impl.node.container; | ||
|
||
import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
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
42 changes: 42 additions & 0 deletions
42
...a/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatcherRegistration.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,42 @@ | ||
package com.refinedmods.refinedstorage2.api.network.impl.node.grid; | ||
|
||
import com.refinedmods.refinedstorage2.api.grid.GridWatcher; | ||
import com.refinedmods.refinedstorage2.api.resource.list.listenable.ResourceListListener; | ||
import com.refinedmods.refinedstorage2.api.storage.Actor; | ||
import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; | ||
import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class GridWatcherRegistration { | ||
private final GridWatcher watcher; | ||
private final Class<? extends Actor> actorType; | ||
private final Map<StorageChannelType<?>, ResourceListListener<?>> listeners = new HashMap<>(); | ||
|
||
public GridWatcherRegistration(final GridWatcher watcher, final Class<? extends Actor> actorType) { | ||
this.watcher = watcher; | ||
this.actorType = actorType; | ||
} | ||
|
||
public <T> void attach(final StorageChannel<T> storageChannel, final StorageChannelType<T> storageChannelType) { | ||
final ResourceListListener<T> listener = change -> watcher.onChanged( | ||
storageChannelType, | ||
change.resourceAmount().getResource(), | ||
change.change(), | ||
storageChannel.findTrackedResourceByActorType( | ||
change.resourceAmount().getResource(), | ||
actorType | ||
).orElse(null) | ||
); | ||
storageChannel.addListener(listener); | ||
listeners.put(storageChannelType, listener); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> void detach(final StorageChannel<T> storageChannel, final StorageChannelType<T> storageChannelType) { | ||
final ResourceListListener<T> listener = (ResourceListListener<T>) listeners.get(storageChannelType); | ||
storageChannel.removeListener(listener); | ||
listeners.remove(storageChannelType); | ||
} | ||
} |
Oops, something went wrong.