mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-11-26 15:03:17 +00:00
implement storage interceptor & fix locking card (#993)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
0c34b1dd47
commit
0b03886f6f
5 files changed
+149
-57
No files matched your search
+26
-1
@@ -13,9 +13,11 @@ package appeng.me.cache;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -29,6 +31,7 @@ import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.events.MENetworkStorageEvent;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.storage.IStorageInterceptor;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
@@ -65,6 +68,8 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T> {
|
||||
@Nonnegative
|
||||
private int localDepthSemaphore = 0;
|
||||
|
||||
private final Set<IStorageInterceptor> storageInterceptors = new HashSet<>();
|
||||
|
||||
public NetworkMonitor(final GridStorageCache cache, final StorageChannel chan) {
|
||||
this.myGridCache = cache;
|
||||
this.myChannel = chan;
|
||||
@@ -148,7 +153,19 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems(final T input, final Actionable mode, final BaseActionSource src) {
|
||||
public T injectItems(T input, final Actionable mode, final BaseActionSource src) {
|
||||
|
||||
for (Iterator<IStorageInterceptor> iterator = storageInterceptors.iterator(); iterator.hasNext();) {
|
||||
final IStorageInterceptor isi = iterator.next();
|
||||
if (isi.canAccept(input)) {
|
||||
input = (T) isi.injectItems(input, mode, src);
|
||||
|
||||
if (isi.shouldRemoveInterceptor(input)) iterator.remove();
|
||||
|
||||
if (input == null) return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == Actionable.SIMULATE) {
|
||||
return this.getHandler().injectItems(input, mode, src);
|
||||
}
|
||||
@@ -326,4 +343,12 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T> {
|
||||
this.myGridCache.getGrid().postEvent(new MENetworkStorageEvent(this, this.myChannel));
|
||||
}
|
||||
}
|
||||
|
||||
public void addStorageInterceptor(IStorageInterceptor storageInterceptor) {
|
||||
this.storageInterceptors.add(storageInterceptor);
|
||||
}
|
||||
|
||||
public void removeStorageInterceptor(IStorageInterceptor storageInterceptor) {
|
||||
this.storageInterceptors.remove(storageInterceptor);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user