diff --git a/src/main/java/mekanism/client/nei/BaseRecipeHandler.java b/src/main/java/mekanism/client/nei/BaseRecipeHandler.java index 527765518..1d30048c1 100644 --- a/src/main/java/mekanism/client/nei/BaseRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/BaseRecipeHandler.java @@ -19,6 +19,8 @@ import static codechicken.lib.gui.GuiDraw.*; public abstract class BaseRecipeHandler extends TemplateRecipeHandler implements IGuiWrapper { + public static final String FLUID_LOOKUP_ID = "mekanism.fluid"; + public BaseRecipeHandler() { addGuiElements(); @@ -28,6 +30,11 @@ public abstract class BaseRecipeHandler extends TemplateRecipeHandler implements public abstract void addGuiElements(); + public static boolean isFluidLookup(String id) + { + return "fluid".equals(id) || FLUID_LOOKUP_ID.equals(id); + } + public void displayGauge(int length, int xPos, int yPos, int overlayX, int overlayY, int scale, FluidStack fluid, GasStack gas) { if(fluid == null && gas == null) @@ -122,20 +129,29 @@ public abstract class BaseRecipeHandler extends TemplateRecipeHandler implements */ public boolean doFluidLookup(FluidStack stack, boolean type) { - if(stack != null && stack.amount > 0) + if(stack != null && stack.amount > 0 && stack.getFluid() != null) { - if(type) + FluidStack copy = stack.copy(); + + try { - if(!GuiUsageRecipe.openRecipeGui("fluid", new Object[] {stack})) + if(type) { - return false; + if(!GuiUsageRecipe.openRecipeGui(FLUID_LOOKUP_ID, new Object[] {copy})) + { + return false; + } + } + else { + if(!GuiCraftingRecipe.openRecipeGui(FLUID_LOOKUP_ID, new Object[] {copy})) + { + return false; + } } } - else { - if(!GuiCraftingRecipe.openRecipeGui("fluid", new Object[] {stack})) - { - return false; - } + catch(Throwable ignored) + { + return false; } return true; @@ -143,7 +159,7 @@ public abstract class BaseRecipeHandler extends TemplateRecipeHandler implements return false; } - + @Override public void drawTexturedRect(int x, int y, int u, int v, int w, int h) { diff --git a/src/main/java/mekanism/client/nei/ChemicalWasherRecipeHandler.java b/src/main/java/mekanism/client/nei/ChemicalWasherRecipeHandler.java index 0ea6c9ce6..746874ca8 100644 --- a/src/main/java/mekanism/client/nei/ChemicalWasherRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/ChemicalWasherRecipeHandler.java @@ -135,9 +135,11 @@ public class ChemicalWasherRecipeHandler extends BaseRecipeHandler @Override public void loadUsageRecipes(String inputId, Object... ingredients) { - if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + if(isFluidLookup(inputId) && ingredients.length == 1 && ingredients[0] instanceof FluidStack) { - if(((FluidStack)ingredients[0]).getFluid() == FluidRegistry.WATER) + FluidStack fluid = (FluidStack)ingredients[0]; + + if(fluid.getFluid() == FluidRegistry.WATER) { for(WasherRecipe irecipe : getRecipes()) { diff --git a/src/main/java/mekanism/client/nei/ElectrolyticSeparatorRecipeHandler.java b/src/main/java/mekanism/client/nei/ElectrolyticSeparatorRecipeHandler.java index 455ee84cd..7a8d77925 100644 --- a/src/main/java/mekanism/client/nei/ElectrolyticSeparatorRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/ElectrolyticSeparatorRecipeHandler.java @@ -187,11 +187,18 @@ public class ElectrolyticSeparatorRecipeHandler extends BaseRecipeHandler @Override public void loadUsageRecipes(String inputId, Object... ingredients) { - if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + if(isFluidLookup(inputId) && ingredients.length == 1 && ingredients[0] instanceof FluidStack) { + FluidStack fluid = (FluidStack)ingredients[0]; + + if(fluid.getFluid() == null) + { + return; + } + for(SeparatorRecipe irecipe : getRecipes()) { - if(irecipe.recipeInput.ingredient.isFluidEqual((FluidStack)ingredients[0])) + if(irecipe != null && irecipe.recipeInput != null && irecipe.recipeInput.ingredient != null && irecipe.recipeInput.ingredient.isFluidEqual(fluid)) { arecipes.add(new CachedIORecipe(irecipe)); } diff --git a/src/main/java/mekanism/client/nei/PRCRecipeHandler.java b/src/main/java/mekanism/client/nei/PRCRecipeHandler.java index 5c11dceac..0bb21f65f 100644 --- a/src/main/java/mekanism/client/nei/PRCRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/PRCRecipeHandler.java @@ -219,11 +219,18 @@ public class PRCRecipeHandler extends BaseRecipeHandler } } } - else if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + else if(isFluidLookup(inputId) && ingredients.length == 1 && ingredients[0] instanceof FluidStack) { + FluidStack fluid = (FluidStack)ingredients[0]; + + if(fluid.getFluid() == null) + { + return; + } + for(Map.Entry irecipe : getRecipes()) { - if(irecipe.getKey().containsType((FluidStack)ingredients[0])) + if(irecipe != null && irecipe.getKey() != null && irecipe.getKey().containsType(fluid)) { arecipes.add(new CachedIORecipe(irecipe)); } diff --git a/src/main/java/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java b/src/main/java/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java index d95a7d111..0f339e8b3 100644 --- a/src/main/java/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java @@ -128,9 +128,15 @@ public class RotaryCondensentratorRecipeHandler extends BaseRecipeHandler arecipes.add(new CachedIORecipe(new GasStack(gas.getGas(), 1), new FluidStack(gas.getGas().getFluid(), 1), false)); } } - else if(outputId.equals("fluid") && results.length == 1 && results[0] instanceof FluidStack) + else if(isFluidLookup(outputId) && results.length == 1 && results[0] instanceof FluidStack) { FluidStack fluid = (FluidStack)results[0]; + + if(fluid.getFluid() == null) + { + return; + } + Gas gas = GasRegistry.getGas(fluid.getFluid()); if(gas != null) @@ -155,9 +161,15 @@ public class RotaryCondensentratorRecipeHandler extends BaseRecipeHandler arecipes.add(new CachedIORecipe(new GasStack(gas.getGas(), 1), new FluidStack(gas.getGas().getFluid(), 1), true)); } } - else if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + else if(isFluidLookup(inputId) && ingredients.length == 1 && ingredients[0] instanceof FluidStack) { FluidStack fluid = (FluidStack)ingredients[0]; + + if(fluid.getFluid() == null) + { + return; + } + Gas gas = GasRegistry.getGas(fluid.getFluid()); if(gas != null) diff --git a/src/main/java/mekanism/client/nei/ThermalEvaporationRecipeHandler.java b/src/main/java/mekanism/client/nei/ThermalEvaporationRecipeHandler.java index 588b9c704..55e937eef 100644 --- a/src/main/java/mekanism/client/nei/ThermalEvaporationRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/ThermalEvaporationRecipeHandler.java @@ -113,11 +113,18 @@ public class ThermalEvaporationRecipeHandler extends BaseRecipeHandler arecipes.add(new CachedIORecipe(irecipe)); } } - else if(outputId.equals("fluid") && results.length == 1 && results[0] instanceof FluidStack) + else if(isFluidLookup(outputId) && results.length == 1 && results[0] instanceof FluidStack) { + FluidStack fluid = (FluidStack)results[0]; + + if(fluid.getFluid() == null) + { + return; + } + for(ThermalEvaporationRecipe irecipe : getRecipes()) { - if(((FluidStack)results[0]).isFluidEqual(irecipe.recipeOutput.output)) + if(irecipe != null && irecipe.recipeOutput != null && irecipe.recipeOutput.output != null && fluid.isFluidEqual(irecipe.recipeOutput.output)) { arecipes.add(new CachedIORecipe(irecipe)); } @@ -131,11 +138,18 @@ public class ThermalEvaporationRecipeHandler extends BaseRecipeHandler @Override public void loadUsageRecipes(String inputId, Object... ingredients) { - if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + if(isFluidLookup(inputId) && ingredients.length == 1 && ingredients[0] instanceof FluidStack) { + FluidStack fluid = (FluidStack)ingredients[0]; + + if(fluid.getFluid() == null) + { + return; + } + for(ThermalEvaporationRecipe irecipe : getRecipes()) { - if(irecipe.recipeInput.ingredient.isFluidEqual((FluidStack)ingredients[0])) + if(irecipe != null && irecipe.recipeInput != null && irecipe.recipeInput.ingredient != null && irecipe.recipeInput.ingredient.isFluidEqual(fluid)) { arecipes.add(new CachedIORecipe(irecipe)); }