Untested fluid support for RecipeHandlers...

This commit is contained in:
Alex_hawks 2014-03-11 23:26:25 +08:00
parent 60f13cabe8
commit 38ee016c37

View file

@ -1,12 +1,18 @@
package resonantinduction.core.nei;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import calclavia.lib.utility.LanguageUtility;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.RecipeResource;
@ -14,7 +20,9 @@ import resonantinduction.api.recipe.RecipeResource.FluidStackResource;
import resonantinduction.api.recipe.RecipeResource.ItemStackResource;
import resonantinduction.api.recipe.RecipeResource.OreDictResource;
import resonantinduction.core.Reference;
import codechicken.core.gui.GuiDraw;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
public abstract class RITemplateRecipeHandler extends TemplateRecipeHandler
@ -68,12 +76,92 @@ public abstract class RITemplateRecipeHandler extends TemplateRecipeHandler
this.arecipes.add(recipe);
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void drawExtras(int recipeID)
{
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
CachedRecipe cachedRecipe = this.arecipes.get(recipeID);
if (cachedRecipe instanceof CachedRIRecipe)
{
CachedRIRecipe recipe = (CachedRIRecipe) cachedRecipe;
for (int i = 0; i < recipe.inputFluids.length; i++)
{
FluidStack fluid = recipe.inputFluids[i];
if (fluid == null)
break;
gui.drawTexturedModelRectFromIcon(inputSlots[i][0], inputSlots[i][1], fluid.getFluid().getIcon(), 16, 16);
}
for (int i = 0; i < recipe.outputFluids.length; i++)
{
FluidStack fluid = recipe.outputFluids[i];
if (fluid == null)
break;
gui.drawTexturedModelRectFromIcon(outputSlots[i][0], outputSlots[i][1], fluid.getFluid().getIcon(), 16, 16);
}
}
}
@Override
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipeID)
{
if(currenttip.size() == 0)
{
Point offset = gui.getRecipePosition(recipeID);
Point mouse = GuiDraw.getMousePosition();
CachedRecipe cachedRecipe = this.arecipes.get(recipeID);
if (cachedRecipe instanceof CachedRIRecipe)
{
CachedRIRecipe recipe = (CachedRIRecipe) cachedRecipe;
FluidStack fluid;
Rectangle rect;
for (int i = 0; i < recipe.inputFluids.length; i++)
{
fluid = recipe.inputFluids[i];
if (fluid == null)
break;
rect = new Rectangle(offset.x + inputSlots[i][0] - 1, offset.y + inputSlots[i][1] - 1, 18, 18);
if (rect.contains(mouse))
{
currenttip.add(fluid.getFluid().getLocalizedName());
currenttip.add(LanguageUtility.getLocal("tooltip.ri.amount").replace("%s", fluid.amount + ""));
return currenttip;
}
}
for (int i = 0; i < recipe.outputFluids.length; i++)
{
fluid = recipe.outputFluids[i];
if (fluid == null)
break;
rect = new Rectangle(offset.x + outputSlots[i][0] - 1, offset.y + outputSlots[i][1] - 1, 18, 18);
if (rect.contains(mouse))
{
currenttip.add(fluid.getFluid().getLocalizedName());
currenttip.add(LanguageUtility.getLocal("tooltip.ri.amount").replace("%s", fluid.amount + ""));
return currenttip;
}
}
}
}
return currenttip;
}
@Override
public void loadCraftingRecipes(ItemStack result)
{
@ -98,10 +186,10 @@ public abstract class RITemplateRecipeHandler extends TemplateRecipeHandler
this.arecipes.add(recipe);
}
}
else
{
super.loadUsageRecipes(inputId, ingredients);
}
else
{
super.loadUsageRecipes(inputId, ingredients);
}
}
@Override
@ -127,6 +215,9 @@ public abstract class RITemplateRecipeHandler extends TemplateRecipeHandler
private List<PositionedStack> inputs = new ArrayList<PositionedStack>();
private List<PositionedStack> outputs = new ArrayList<PositionedStack>();
final FluidStack[] inputFluids = new FluidStack[inputSlots.length];
final FluidStack[] outputFluids = new FluidStack[outputSlots.length];
@Override
public List<PositionedStack> getOtherStacks()
{
@ -147,9 +238,7 @@ public abstract class RITemplateRecipeHandler extends TemplateRecipeHandler
}
else if (output instanceof FluidStackResource)
{
// this.inputs.add(new PositionedStack(((FluidStackResource) output),
// outputSlots[i][0], outputSlots[i++][1]));
// TODO fluidstack compatibility
this.outputFluids[i++] = ((FluidStackResource) output).fluidStack;
}
this.outputs.get(this.outputs.size() - 1).generatePermutations();
}
@ -176,9 +265,7 @@ public abstract class RITemplateRecipeHandler extends TemplateRecipeHandler
}
else if (input instanceof FluidStackResource)
{
// this.inputs.add(new PositionedStack(((FluidStackResource) input),
// inputSlots[i][0], inputSlots[i++][1]));
// TODO fluidstack compatibility
this.inputFluids[i++] = ((FluidStackResource) input).fluidStack;
}
if (this.inputs.size() > 0)