Skip to content

Commit

Permalink
Fix storage bus extract filter ignores inverter card (#559)
Browse files Browse the repository at this point in the history
Fix watchers are not updated when ore dict string is changed

Co-authored-by: boubou19 <miisterunknown@gmail.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent a4a9d73 commit 0ebab34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
26 changes: 19 additions & 7 deletions src/main/java/appeng/me/storage/MEInventoryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package appeng.me.storage;

import java.util.function.Predicate;

import javax.annotation.Nonnull;

import appeng.api.config.AccessRestriction;
Expand Down Expand Up @@ -102,9 +104,11 @@ public T extractItems(final T request, final Actionable type, final BaseActionSo
if (!this.hasReadAccess) {
return null;
}
if (this.isExtractFilterActive() && !this.myExtractPartitionList.isEmpty()
&& !this.myExtractPartitionList.isListed(request)) {
return null;
if (this.isExtractFilterActive() && !this.myExtractPartitionList.isEmpty()) {
Predicate<T> filterCondition = this.getExtractFilterCondition();
if (!filterCondition.test(request)) {
return null;
}
}

return this.internal.extractItems(request, type, src);
Expand All @@ -126,8 +130,9 @@ public IItemList<T> getAvailableItems(final IItemList<T> out, int iteration) {
protected IItemList<T> filterAvailableItems(IItemList<T> out, int iteration) {
final IItemList<T> allAvailableItems = this.internal
.getAvailableItems((IItemList<T>) this.internal.getChannel().createList(), iteration);
Predicate<T> filterCondition = this.getExtractFilterCondition();
for (T item : allAvailableItems) {
if (this.myExtractPartitionList.isListed(item)) {
if (filterCondition.test(item)) {
out.add(item);
}
}
Expand All @@ -140,14 +145,21 @@ public T getAvailableItem(@Nonnull T request, int iteration) {
return null;
}

if (this.isExtractFilterActive() && !this.myExtractPartitionList.isEmpty()
&& !this.myExtractPartitionList.isListed(request)) {
return null;
if (this.isExtractFilterActive() && !this.myExtractPartitionList.isEmpty()) {
Predicate<T> filterCondition = this.getExtractFilterCondition();
if (!filterCondition.test(request)) {
return null;
}
}

return this.internal.getAvailableItem(request, iteration);
}

public Predicate<T> getExtractFilterCondition() {
return this.myWhitelist == IncludeExclude.WHITELIST ? i -> this.myExtractPartitionList.isListed(i)
: i -> !this.myExtractPartitionList.isListed(i);
}

public boolean isExtractFilterActive() {
return this.isExtractFilterActive;
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/appeng/parts/misc/PartStorageBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -101,7 +102,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
private byte resetCacheLogic = 0;
private String oreFilterString = "";
/**
* used when changing access settings to read the changes once
* used to read changes once when the list of extractable items was changed
*/
private boolean readOncePass = false;

Expand Down Expand Up @@ -146,14 +147,6 @@ protected int getUpgradeSlots() {

@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
if (settingName == Settings.ACCESS && this.handler != null) {
AccessRestriction currentAccess = this.handler.getAccess();
if (newValue != currentAccess && currentAccess.hasPermission(AccessRestriction.READ)) {
if (newValue == AccessRestriction.WRITE || newValue == AccessRestriction.READ) {
this.readOncePass = true;
}
}
}
this.resetCache(true);
this.getHost().markForSave();
}
Expand Down Expand Up @@ -261,8 +254,9 @@ private Iterable<IAEItemStack> filterChanges(final Iterable<IAEItemStack> change
if (this.handler != null && this.handler.isExtractFilterActive()
&& !this.handler.getExtractPartitionList().isEmpty()) {
List<IAEItemStack> filteredChanges = new ArrayList<>();
Predicate<IAEItemStack> extractFilterCondition = this.handler.getExtractFilterCondition();
for (final IAEItemStack changedItem : change) {
if (this.handler.getExtractPartitionList().isListed(changedItem)) {
if (extractFilterCondition.test(changedItem)) {
filteredChanges.add(changedItem);
}
}
Expand Down Expand Up @@ -446,6 +440,7 @@ public MEInventoryHandler<IAEItemStack> getInternalHandler() {
this.handlerHash = newHandlerHash;
this.handler = null;
this.monitor = null;
this.readOncePass = true;
if (target != null) {
final IExternalStorageHandler esh = AEApi.instance().registries().externalStorage()
.getHandler(target, this.getSide().getOpposite(), StorageChannel.ITEMS, this.mySrc);
Expand Down

0 comments on commit 0ebab34

Please sign in to comment.