diff --git a/src/main/java/com/glodblock/github/nei/NEIItemFilter.java b/src/main/java/com/glodblock/github/nei/NEIItemFilter.java new file mode 100644 index 00000000..f7a97789 --- /dev/null +++ b/src/main/java/com/glodblock/github/nei/NEIItemFilter.java @@ -0,0 +1,62 @@ +package com.glodblock.github.nei; + +import java.util.regex.Pattern; + +import net.minecraft.item.ItemStack; + +import appeng.api.AEApi; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEFluidStack; +import codechicken.nei.SearchField; +import codechicken.nei.api.ItemFilter; + +import com.glodblock.github.common.storage.IFluidCellInventory; +import com.glodblock.github.common.storage.IFluidCellInventoryHandler; +import com.glodblock.github.common.storage.IStorageFluidCell; + +public class NEIItemFilter implements SearchField.ISearchProvider { + + @Override + public ItemFilter getFilter(String searchText) { + Pattern pattern = SearchField.getPattern(searchText); + return pattern == null ? null : new Filter(pattern); + } + + @Override + public boolean isPrimary() { + return false; + } + + public static class Filter implements ItemFilter { + + Pattern pattern; + + public Filter(Pattern pattern) { + this.pattern = pattern; + } + + @Override + public boolean matches(ItemStack itemStack) { + if (itemStack.getItem() instanceof IStorageFluidCell) { + final IMEInventoryHandler inventory = AEApi.instance().registries().cell() + .getCellInventory(itemStack, null, StorageChannel.FLUIDS); + if (inventory instanceof IFluidCellInventoryHandler) { + final IFluidCellInventoryHandler handler = (IFluidCellInventoryHandler) inventory; + final IFluidCellInventory cellInventory = handler.getCellInv(); + if (cellInventory != null) { + for (IAEFluidStack fluid : cellInventory.getContents()) { + if (fluid != null) { + return pattern.matcher(fluid.getFluidStack().getLocalizedName().toLowerCase()).find(); + } + } + + } + } + } + return false; + } + + } + +} diff --git a/src/main/java/com/glodblock/github/nei/NEI_FC_Config.java b/src/main/java/com/glodblock/github/nei/NEI_FC_Config.java index d4e42279..dda71243 100644 --- a/src/main/java/com/glodblock/github/nei/NEI_FC_Config.java +++ b/src/main/java/com/glodblock/github/nei/NEI_FC_Config.java @@ -14,7 +14,7 @@ public class NEI_FC_Config implements IConfigureNEI { @Override public void loadConfig() { API.registerNEIGuiHandler(new NEIGuiHandler()); - + API.addSearchProvider(new NEIItemFilter()); for (String identifier : FluidRecipe.getSupportRecipes()) { API.registerGuiOverlayHandler( GuiPatternPortableCell.class,