Skip to content

Commit

Permalink
fix calculation of item count in bulk filter item
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Feb 4, 2025
1 parent f7c0c8f commit 1ef2e96
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import net.minecraft.core.component.DataComponentType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemContainerContents;
import net.neoforged.neoforge.items.IItemHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.IntStream;

public abstract class BaseModuleHandler extends GhostItemHandler {
Expand Down Expand Up @@ -74,8 +76,8 @@ protected void onContentsChanged(int slot) {
*
* @return number of items in the filter
*/
public static int getFilterItemCount(ItemStack holderStack) {
ModuleFilterHandler handler = new ModuleFilterHandler(holderStack, null);
public static int getFilterItemCount(ItemStack holderStack, BiFunction<ItemStack, ModularRouterBlockEntity, BaseModuleHandler> factory) {
BaseModuleHandler handler = factory.apply(holderStack, null);
return (int) IntStream.range(0, handler.getSlots())
.filter(i -> !handler.getStackInSlot(i).isEmpty())
.count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public InteractionResult useOn(UseOnContext ctx) {

@Override
public int getSize(ItemStack filterStack) {
return BaseModuleHandler.getFilterItemCount(filterStack);
return BaseModuleHandler.getFilterItemCount(filterStack, BulkFilterHandler::new);
}

private InteractionResult handleUseServerSide(UseOnContext ctx) {
Expand Down

0 comments on commit 1ef2e96

Please sign in to comment.