Fix ME Storage Buses reporting contents regardless of settings (#384)
This commit is contained in:
@@ -80,6 +80,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -220,11 +221,13 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
|
|||||||
@Override
|
@Override
|
||||||
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source) {
|
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source) {
|
||||||
if (this.getProxy().isActive()) {
|
if (this.getProxy().isActive()) {
|
||||||
|
var filteredChanges = this.filterChanges(change);
|
||||||
|
|
||||||
AccessRestriction currentAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS);
|
AccessRestriction currentAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS);
|
||||||
if (readOncePass) {
|
if (readOncePass) {
|
||||||
readOncePass = false;
|
readOncePass = false;
|
||||||
try {
|
try {
|
||||||
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, this.source);
|
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), filteredChanges, this.source);
|
||||||
} catch (final GridAccessException e) {
|
} catch (final GridAccessException e) {
|
||||||
// :(
|
// :(
|
||||||
}
|
}
|
||||||
@@ -234,7 +237,7 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, source);
|
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), filteredChanges, source);
|
||||||
} catch (final GridAccessException e) {
|
} catch (final GridAccessException e) {
|
||||||
// :(
|
// :(
|
||||||
}
|
}
|
||||||
@@ -426,6 +429,7 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
|
|||||||
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
||||||
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||||
this.handler.setPriority(this.getPriority());
|
this.handler.setPriority(this.getPriority());
|
||||||
|
this.handler.setStorageFilter((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER));
|
||||||
|
|
||||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList();
|
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList();
|
||||||
|
|
||||||
@@ -537,4 +541,26 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
|
|||||||
public GuiBridge getGuiBridge() {
|
public GuiBridge getGuiBridge() {
|
||||||
return GuiBridge.GUI_STORAGEBUS_FLUID;
|
return GuiBridge.GUI_STORAGEBUS_FLUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.parts.misc.PartStorageBus#filterChanges
|
||||||
|
*/
|
||||||
|
protected Iterable<IAEFluidStack> filterChanges(Iterable<IAEFluidStack> change) {
|
||||||
|
var storageFilter = this.getConfigManager().getSetting(Settings.STORAGE_FILTER);
|
||||||
|
if (storageFilter == StorageFilter.EXTRACTABLE_ONLY) {
|
||||||
|
var filteredList = new ArrayList<IAEFluidStack>();
|
||||||
|
for (final IAEFluidStack stack : change) {
|
||||||
|
if (this.handler.passesBlackOrWhitelist(stack)) {
|
||||||
|
filteredList.add(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredList;
|
||||||
|
}
|
||||||
|
return change;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package appeng.me.storage;
|
|||||||
import appeng.api.config.AccessRestriction;
|
import appeng.api.config.AccessRestriction;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.IncludeExclude;
|
import appeng.api.config.IncludeExclude;
|
||||||
|
import appeng.api.config.StorageFilter;
|
||||||
import appeng.api.networking.security.IActionSource;
|
import appeng.api.networking.security.IActionSource;
|
||||||
import appeng.api.storage.IMEInventory;
|
import appeng.api.storage.IMEInventory;
|
||||||
import appeng.api.storage.IMEInventoryHandler;
|
import appeng.api.storage.IMEInventoryHandler;
|
||||||
@@ -38,12 +39,14 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||||||
private int myPriority;
|
private int myPriority;
|
||||||
private IncludeExclude myWhitelist;
|
private IncludeExclude myWhitelist;
|
||||||
private AccessRestriction myAccess;
|
private AccessRestriction myAccess;
|
||||||
|
private StorageFilter storageFilter;
|
||||||
private IPartitionList<T> myPartitionList;
|
private IPartitionList<T> myPartitionList;
|
||||||
|
|
||||||
private AccessRestriction cachedAccessRestriction;
|
private AccessRestriction cachedAccessRestriction;
|
||||||
private boolean hasReadAccess;
|
private boolean hasReadAccess;
|
||||||
private boolean hasWriteAccess;
|
private boolean hasWriteAccess;
|
||||||
private boolean isSticky;
|
private boolean isSticky;
|
||||||
|
private boolean gettingAvailableContent;
|
||||||
|
|
||||||
public MEInventoryHandler(final IMEInventory<T> i, final IStorageChannel<T> channel) {
|
public MEInventoryHandler(final IMEInventory<T> i, final IStorageChannel<T> channel) {
|
||||||
if (i instanceof IMEInventoryHandler) {
|
if (i instanceof IMEInventoryHandler) {
|
||||||
@@ -77,7 +80,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||||||
this.hasWriteAccess = this.cachedAccessRestriction.hasPermission(AccessRestriction.WRITE);
|
this.hasWriteAccess = this.cachedAccessRestriction.hasPermission(AccessRestriction.WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPartitionList<T> getPartitionList() {
|
public IPartitionList<T> getPartitionList() {
|
||||||
return this.myPartitionList;
|
return this.myPartitionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +99,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T extractItems(final T request, final Actionable type, final IActionSource src) {
|
public T extractItems(final T request, final Actionable type, final IActionSource src) {
|
||||||
if (!this.hasReadAccess) {
|
if (!this.canExtract(request)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +108,27 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IItemList<T> getAvailableItems(final IItemList<T> out) {
|
public IItemList<T> getAvailableItems(final IItemList<T> out) {
|
||||||
if (!this.hasReadAccess) {
|
if (this.gettingAvailableContent || !this.hasReadAccess) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.internal.getAvailableItems(out);
|
this.gettingAvailableContent = true;
|
||||||
|
try {
|
||||||
|
if (this.storageFilter == StorageFilter.EXTRACTABLE_ONLY) {
|
||||||
|
var stackList = this.internal.getAvailableItems(this.getChannel().createList());
|
||||||
|
for (final T t : stackList) {
|
||||||
|
if (this.canExtract(t)) {
|
||||||
|
out.add(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return this.internal.getAvailableItems(out);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.gettingAvailableContent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -136,13 +155,11 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.myWhitelist == IncludeExclude.BLACKLIST && this.myPartitionList.isListed(input)) {
|
if (!this.passesBlackOrWhitelist(input)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.myPartitionList.isEmpty() || this.myWhitelist == IncludeExclude.BLACKLIST) {
|
|
||||||
return this.internal.canAccept(input);
|
return this.internal.canAccept(input);
|
||||||
}
|
|
||||||
return this.myPartitionList.isListed(input) && this.internal.canAccept(input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,4 +193,27 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||||||
public void setSticky(boolean isSticky) {
|
public void setSticky(boolean isSticky) {
|
||||||
this.isSticky = isSticky;
|
this.isSticky = isSticky;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean canExtract(T request) {
|
||||||
|
return this.hasReadAccess && passesBlackOrWhitelist(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean passesBlackOrWhitelist(T input) {
|
||||||
|
if (this.myPartitionList.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch (this.myWhitelist) {
|
||||||
|
case WHITELIST -> this.myPartitionList.isListed(input);
|
||||||
|
case BLACKLIST -> !this.myPartitionList.isListed(input);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public StorageFilter getStorageFilter() {
|
||||||
|
return storageFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStorageFilter(StorageFilter storageFilter) {
|
||||||
|
this.storageFilter = storageFilter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ public class PartOreDicStorageBus extends PartStorageBus {
|
|||||||
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
||||||
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||||
this.handler.setPriority(this.priority);
|
this.handler.setPriority(this.priority);
|
||||||
|
|
||||||
this.handler.setPartitionList(this.getPriorityList());
|
this.handler.setPartitionList(this.getPriorityList());
|
||||||
|
this.handler.setStorageFilter((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER));
|
||||||
|
|
||||||
if (inv instanceof IBaseMonitor) {
|
if (inv instanceof IBaseMonitor) {
|
||||||
if (((AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS)).hasPermission(AccessRestriction.READ)) {
|
if (((AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS)).hasPermission(AccessRestriction.READ)) {
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ import net.minecraftforge.common.capabilities.CapabilityInject;
|
|||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -221,11 +222,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
|||||||
@Override
|
@Override
|
||||||
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source) {
|
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source) {
|
||||||
if (this.getProxy().isActive()) {
|
if (this.getProxy().isActive()) {
|
||||||
|
var filteredChanges = this.filterChanges(change);
|
||||||
|
|
||||||
AccessRestriction currentAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS);
|
AccessRestriction currentAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS);
|
||||||
if (readOncePass) {
|
if (readOncePass) {
|
||||||
readOncePass = false;
|
readOncePass = false;
|
||||||
try {
|
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) {
|
} catch (final GridAccessException e) {
|
||||||
// :(
|
// :(
|
||||||
}
|
}
|
||||||
@@ -235,7 +238,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
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) {
|
} 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.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
||||||
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||||
this.handler.setPriority(this.priority);
|
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();
|
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() {
|
public GuiBridge getGuiBridge() {
|
||||||
return GuiBridge.GUI_STORAGEBUS;
|
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