Fix ME Storage Buses reporting contents regardless of settings (#384)
This commit is contained in:
@@ -80,6 +80,7 @@ import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -221,11 +222,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
@Override
|
||||
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source) {
|
||||
if (this.getProxy().isActive()) {
|
||||
var filteredChanges = this.filterChanges(change);
|
||||
|
||||
AccessRestriction currentAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS);
|
||||
if (readOncePass) {
|
||||
readOncePass = false;
|
||||
try {
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class), change, mySrc);
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class), filteredChanges, mySrc);
|
||||
} catch (final GridAccessException e) {
|
||||
// :(
|
||||
}
|
||||
@@ -235,7 +238,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class), change, source);
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class), filteredChanges, source);
|
||||
} catch (final GridAccessException e) {
|
||||
// :(
|
||||
}
|
||||
@@ -457,6 +460,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
||||
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||
this.handler.setPriority(this.priority);
|
||||
this.handler.setStorageFilter((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER));
|
||||
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
@@ -571,4 +575,26 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
public GuiBridge getGuiBridge() {
|
||||
return GuiBridge.GUI_STORAGEBUS;
|
||||
}
|
||||
|
||||
// TODO: 1/28/2024 Unify both methods.
|
||||
/**
|
||||
* Filters the changes to only include items that pass the storage filter.
|
||||
* Optimally, this should be handled by the underlying monitor.
|
||||
*
|
||||
* @see appeng.fluids.parts.PartFluidStorageBus#filterChanges
|
||||
*/
|
||||
protected Iterable<IAEItemStack> filterChanges(Iterable<IAEItemStack> change) {
|
||||
var storageFilter = this.getConfigManager().getSetting(Settings.STORAGE_FILTER);
|
||||
if (storageFilter == StorageFilter.EXTRACTABLE_ONLY) {
|
||||
var filteredList = new ArrayList<IAEItemStack>();
|
||||
for (final IAEItemStack stack : change) {
|
||||
if (this.handler.passesBlackOrWhitelist(stack)) {
|
||||
filteredList.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
return filteredList;
|
||||
}
|
||||
return change;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user