DevNatan / inventory-framework

Minecraft Inventory API framework
MIT License
127 stars 22 forks source link

Find a better way to check this "noneMatch" to remove isContainedWithin from bui... #591

Open github-actions[bot] opened 11 months ago

github-actions[bot] commented 11 months ago

since slot can be re-defined on render and this interceptor runs before it

https://github.com/DevNatan/inventory-framework/blob/09ee0f14910ea3ab906136bea558806762b8af3e/inventory-framework-core/src/main/java/me/devnatan/inventoryframework/pipeline/AvailableSlotInterceptor.java#L124


                }
            }

            final BiFunction<Integer, Integer, ComponentBuilder> factory = availableSlotFactories.get(i);
            result.add(factory.apply(i, slot));
        }

        return result;
    }

    private boolean isSlotNotAvailableForAutoFilling(IFRenderContext context, int slot) {
        if (!context.getContainer().getType().canPlayerInteractOn(slot)) return true;

        // fast path -- check for already rendered items
        if (context.getContainer().hasItem(slot)) return true;

        // we need to check component factories since components don't have been yet rendered
        // TODO Find a better way to check this "noneMatch" to remove isContainedWithin from builder
        //      since slot can be re-defined on render and this interceptor runs before it
        return context.getNotRenderedComponents().stream()
                .filter(componentFactory -> componentFactory instanceof ItemComponentBuilder)
                .map(componentFactory -> (ItemComponentBuilder) componentFactory)
                .anyMatch(itemBuilder -> itemBuilder.isContainedWithin(slot));
    }
}