Roughly Enough Items Fabric/Forge/NeoForge (REI)

Roughly Enough Items Fabric/Forge/NeoForge (REI)

40M Downloads

Difficulty with refreshing entries after filtering

Draylar opened this issue · 4 comments

commented

I'm updating Game Phases from 1.16.5 to 1.17.1 (REI 5.11.202 => 6.1.329), and I'm having some trouble getting my REI compatibility to work again. When the player does not have a phase unlocked, any item inside that phase is hidden from the REI menu. In 1.16.5, I achieved this with (called when phase data syncs S2C):

EntryRegistry.getInstance().removeEntryIf(entry -> {
        if(entry.getValue() instanceof ItemStack stack) {
            // return false if the item should not be shown in REI
        });

        EntryRegistry.getInstance().refilter();
        REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
}

(The above code was written while talking to you about this a while back in 1.16 era - not sure how it works.)

In 1.17.1 / REI 6.1.329, the filtering works when removing items, but I can't get it to re-add items a second time when reloading/refiltering the overlay. I have been poking around internals for a while but can't seem to find a way to do this. Would you mind pointing me in the right direction? Thanks!

commented

The idea is that it would automatically refilter on the fly by its own, and queue the search reload, I will keep this issue open for the future me, thanks

commented

REI itself would queue a reload now when you modify the list at runtime, I am unsure if I properly queue it for the Predicate remove, but it should work for the normal remove, please try that, and if only the Predicate one doesn't work, I am happy to fix that

commented

I wasn't able to get the non-predicate remove method to reload after calling refilter, but I ended up storing a list of hidden entries & re-adding them before re-filtering, which seems to work fine (& is a bit more intuitive):

List<EntryStack<?>> hidden = new ArrayList<>();

hideBlockedItems() {
    // Re-add hidden entries for reload system
    EntryRegistry.getInstance().addEntries(hidden);
    hidden.clear();

    // Iterate over REI entries, removing & storing entries that the player can't see.
    Iterator<EntryStack<?>> iterator = EntryRegistry.getInstance().getEntryStacks().iterator();
    while (iterator.hasNext()) {
        EntryStack<?> next = iterator.next();

        // Determine if entry should be hidden
        if(invalid) {
            EntryRegistry.getInstance().removeEntry(next);
            hidden.add(next);
        }
    }

    EntryRegistry.getInstance().refilter();
    REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
}

Thank you for the help!

commented

It is queue the overlay reload automatically now!