Skip to content

Commit

Permalink
Merge pull request #73 from asdflj/bookmark
Browse files Browse the repository at this point in the history
add NEI Highlighting for Text on AE2FC Fluid Storage Cells
  • Loading branch information
GlodBlock authored Feb 2, 2023
2 parents f14e168 + b2eafe5 commit 8655189
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
62 changes: 62 additions & 0 deletions src/main/java/com/glodblock/github/nei/NEIItemFilter.java
Original file line number Diff line number Diff line change
@@ -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;
}

}

}
2 changes: 1 addition & 1 deletion src/main/java/com/glodblock/github/nei/NEI_FC_Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8655189

Please sign in to comment.