Skip to content

Commit

Permalink
Fix wonky capability code
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Oct 11, 2023
1 parent 7d1668d commit a72b693
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gripe._90.arseng.definition;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -71,22 +73,24 @@ private boolean isNotBlackListed(ISourceTile tile) {
}

var genericInvWrapper = new ICapabilityProvider() {
private LazyOptional<ISourceTile> sourceHandler = LazyOptional.empty();
private final Set<LazyOptional<ISourceTile>> sourceHandlers = new HashSet<>();

@SuppressWarnings("UnstableApiUsage")
@NotNull
@Override
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
if (cap == SOURCE_TILE) {
sourceHandler = be.getCapability(Capabilities.GENERIC_INTERNAL_INV, side)
var handler = be.getCapability(Capabilities.GENERIC_INTERNAL_INV, side)
.lazyMap(GenericStackSourceStorage::new);
sourceHandlers.add(handler.cast());
return handler.cast();
}

return sourceHandler.cast();
return LazyOptional.empty();
}

private void invalidate() {
sourceHandler.invalidate();
sourceHandlers.forEach(LazyOptional::invalidate);
}
};

Expand Down

0 comments on commit a72b693

Please sign in to comment.