mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-28 16:06:03 +00:00
Added fluid support in recipes (#1020)
This commit is contained in:
1 parent
3f38e6f39b
commit
fda7688807
31 files changed
+831
-127
No files matched your search
@@ -1,13 +1,17 @@
|
||||
package codechicken.nei.search;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.item.ItemFluidDisplay;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
@@ -15,6 +19,7 @@ import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
|
||||
public class ModNameFilter implements ItemFilter {
|
||||
|
||||
private static final Map<String, String> fluidOwners = new HashMap<>();
|
||||
private final Pattern pattern;
|
||||
|
||||
public ModNameFilter(Pattern pattern) {
|
||||
@@ -23,31 +28,52 @@ public class ModNameFilter implements ItemFilter {
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack itemStack) {
|
||||
return this.pattern.matcher(nameFromStack(itemStack.getItem())).find();
|
||||
return this.pattern.matcher(nameFromStack(itemStack)).find();
|
||||
}
|
||||
|
||||
protected static String nameFromStack(Item item) {
|
||||
protected static String nameFromStack(ItemStack itemStack) {
|
||||
try {
|
||||
ModContainer mod = Loader.instance().getIndexedModList().get(getModId(item));
|
||||
ModContainer mod = Loader.instance().getIndexedModList().get(getModId(itemStack));
|
||||
return mod == null ? "Minecraft" : mod.getName();
|
||||
} catch (NullPointerException e) {
|
||||
} catch (Throwable e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected static String getModId(Item item) {
|
||||
protected static String getModId(ItemStack itemStack) {
|
||||
|
||||
if (!ItemInfo.itemOwners.containsKey(item)) {
|
||||
if (itemStack.getItem() instanceof ItemFluidDisplay fluidDisplay) {
|
||||
return getFluidModId(fluidDisplay, itemStack);
|
||||
}
|
||||
|
||||
if (!ItemInfo.itemOwners.containsKey(itemStack.getItem())) {
|
||||
try {
|
||||
UniqueIdentifier ident = GameRegistry.findUniqueIdentifierFor(item);
|
||||
ItemInfo.itemOwners.put(item, ident.modId);
|
||||
final UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(itemStack.getItem());
|
||||
ItemInfo.itemOwners.put(itemStack.getItem(), identifier.modId);
|
||||
} catch (Exception ignored) {
|
||||
NEIClientConfig.logger.error("Failed to find identifier for: " + item);
|
||||
ItemInfo.itemOwners.put(item, "Unknown");
|
||||
NEIClientConfig.logger.error("Failed to find identifier for: " + itemStack.getItem());
|
||||
ItemInfo.itemOwners.put(itemStack.getItem(), "Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
return ItemInfo.itemOwners.get(item);
|
||||
return ItemInfo.itemOwners.get(itemStack.getItem());
|
||||
}
|
||||
|
||||
private static String getFluidModId(ItemFluidDisplay fluidDisplay, ItemStack itemStack) {
|
||||
final Fluid fluid = FluidRegistry.getFluid(itemStack.getItemDamage());
|
||||
final String fluidName = FluidRegistry.getDefaultFluidName(fluid);
|
||||
|
||||
if (!fluidOwners.containsKey(fluidName)) {
|
||||
try {
|
||||
final UniqueIdentifier identifier = new UniqueIdentifier(fluidName);
|
||||
fluidOwners.put(fluidName, identifier.modId);
|
||||
} catch (Exception ignored) {
|
||||
NEIClientConfig.logger.error("Failed to find identifier for fluid: " + fluidName);
|
||||
fluidOwners.put(fluidName, "Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
return fluidOwners.get(fluidName);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user