Mekanism-tilera-Edition/toreturn/nei/ChemicalInfuserRecipeHandler.java

308 lines
7.7 KiB
Java
Raw Normal View History

package mekanism.client.nei;
import static codechicken.core.gui.GuiDraw.changeTexture;
import static codechicken.core.gui.GuiDraw.drawTexturedModalRect;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
2014-01-10 18:58:05 +01:00
import mekanism.api.ChemicalPair;
import mekanism.api.gas.GasStack;
import mekanism.client.gui.GuiChemicalInfuser;
2014-01-10 02:47:06 +01:00
import mekanism.client.nei.ChemicalOxidizerRecipeHandler.CachedIORecipe;
import mekanism.common.ObfuscatedNames;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.gui.inventory.GuiContainer;
import org.lwjgl.opengl.GL11;
import codechicken.core.gui.GuiDraw;
2014-01-10 02:47:06 +01:00
import codechicken.nei.NEIClientConfig;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
public class ChemicalInfuserRecipeHandler extends BaseRecipeHandler
{
private int ticksPassed;
2014-01-10 02:47:06 +01:00
public static int xOffset = 5;
public static int yOffset = 3;
@Override
public String getRecipeName()
{
2014-01-25 22:29:36 +01:00
return MekanismUtils.localize("tile.MachineBlock2.ChemicalInfuser.name");
}
@Override
public String getOverlayIdentifier()
{
return "chemicalinfuser";
}
@Override
public String getGuiTexture()
{
2014-01-10 02:47:06 +01:00
return "mekanism:gui/nei/GuiChemicalInfuser.png";
}
@Override
public Class getGuiClass()
{
return GuiChemicalInfuser.class;
}
public String getRecipeId()
{
return "mekanism.chemicalinfuser";
}
2014-01-10 18:58:05 +01:00
public Set<Entry<ChemicalPair, GasStack>> getRecipes()
{
return Recipe.CHEMICAL_INFUSER.get().entrySet();
}
@Override
public void drawBackground(int i)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
changeTexture(getGuiTexture());
2014-01-10 02:47:06 +01:00
drawTexturedModalRect(-2, 0, 3, yOffset, 170, 80);
}
@Override
public void drawExtras(int i)
{
2014-01-10 02:47:06 +01:00
CachedIORecipe recipe = (CachedIORecipe)arecipes.get(i);
2014-01-10 02:47:06 +01:00
drawTexturedModalRect(47-xOffset, 39-yOffset, 176, 71, 28, 8);
drawTexturedModalRect(101-xOffset, 39-yOffset, 176, 63, 28, 8);
2014-01-10 02:47:06 +01:00
if(recipe.chemicalInput.leftGas != null)
{
displayGauge(58, 26-xOffset, 14-yOffset, 176, 4, 58, null, recipe.chemicalInput.leftGas);
2014-01-10 02:47:06 +01:00
}
2014-01-10 02:47:06 +01:00
if(recipe.outputStack != null)
{
displayGauge(58, 80-xOffset, 5-yOffset, 176, 4, 58, null, recipe.outputStack);
2014-01-10 02:47:06 +01:00
}
2014-01-10 02:47:06 +01:00
if(recipe.chemicalInput.rightGas != null)
{
displayGauge(58, 134-xOffset, 14-yOffset, 176, 4, 58, null, recipe.chemicalInput.rightGas);
}
}
@Override
public void onUpdate()
{
super.onUpdate();
ticksPassed++;
}
@Override
public void loadTransferRects()
{
2014-01-10 02:47:06 +01:00
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(47-xOffset, 39-yOffset, 28, 8), getRecipeId(), new Object[0]));
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(101-xOffset, 39-yOffset, 28, 8), getRecipeId(), new Object[0]));
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if(outputId.equals(getRecipeId()))
{
for(Map.Entry irecipe : getRecipes())
{
arecipes.add(new CachedIORecipe(irecipe));
}
}
2014-01-10 02:47:06 +01:00
else if(outputId.equals("gas") && results.length == 1 && results[0] instanceof GasStack)
{
2014-01-10 18:58:05 +01:00
for(Map.Entry<ChemicalPair, GasStack> irecipe : getRecipes())
2014-01-10 02:47:06 +01:00
{
if(((GasStack)results[0]).isGasEqual(irecipe.getValue()))
{
arecipes.add(new CachedIORecipe(irecipe));
}
}
}
else {
super.loadCraftingRecipes(outputId, results);
}
}
2014-01-10 02:47:06 +01:00
@Override
public void loadUsageRecipes(String inputId, Object... ingredients)
{
if(inputId.equals("gas") && ingredients.length == 1 && ingredients[0] instanceof GasStack)
{
2014-01-10 18:58:05 +01:00
for(Map.Entry<ChemicalPair, GasStack> irecipe : getRecipes())
2014-01-10 02:47:06 +01:00
{
if(irecipe.getKey().containsType((GasStack)ingredients[0]))
{
arecipes.add(new CachedIORecipe(irecipe));
}
}
}
else {
super.loadUsageRecipes(inputId, ingredients);
}
}
@Override
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe)
{
Point point = GuiDraw.getMousePosition();
int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft);
int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop);
2014-01-10 02:47:06 +01:00
if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13)
{
currenttip.add(((CachedIORecipe)arecipes.get(recipe)).chemicalInput.leftGas.getGas().getLocalizedName());
}
else if(xAxis >= 80 && xAxis <= 96 && yAxis >= 5+13 && yAxis <= 63+13)
{
currenttip.add(((CachedIORecipe)arecipes.get(recipe)).outputStack.getGas().getLocalizedName());
}
2014-01-10 02:47:06 +01:00
else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13)
{
currenttip.add(((CachedIORecipe)arecipes.get(recipe)).chemicalInput.rightGas.getGas().getLocalizedName());
}
return super.handleTooltip(gui, currenttip, recipe);
}
@Override
2014-01-10 02:47:06 +01:00
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe)
{
2014-01-10 02:47:06 +01:00
Point point = GuiDraw.getMousePosition();
2014-01-10 02:47:06 +01:00
int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft);
int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop);
2014-01-10 02:47:06 +01:00
GasStack stack = null;
2014-01-10 02:47:06 +01:00
if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13)
{
stack = ((CachedIORecipe)arecipes.get(recipe)).chemicalInput.leftGas;
}
else if(xAxis >= 80 && xAxis <= 96 && yAxis >= 5+13 && yAxis <= 63+13)
{
stack = ((CachedIORecipe)arecipes.get(recipe)).outputStack;
}
else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13)
{
stack = ((CachedIORecipe)arecipes.get(recipe)).chemicalInput.rightGas;
}
2014-01-10 02:47:06 +01:00
if(stack != null)
{
if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
{
if(doGasLookup(stack, false))
{
return true;
}
}
else if(keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
{
if(doGasLookup(stack, true))
{
return true;
}
}
}
2014-01-10 02:47:06 +01:00
return super.keyTyped(gui, keyChar, keyCode, recipe);
}
@Override
2014-01-10 02:47:06 +01:00
public boolean mouseClicked(GuiRecipe gui, int button, int recipe)
{
2014-01-10 02:47:06 +01:00
Point point = GuiDraw.getMousePosition();
2014-01-10 02:47:06 +01:00
int xAxis = point.x - (Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft);
int yAxis = point.y - (Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop);
2014-01-10 02:47:06 +01:00
GasStack stack = null;
2014-01-10 02:47:06 +01:00
if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13)
{
2014-01-10 02:47:06 +01:00
stack = ((CachedIORecipe)arecipes.get(recipe)).chemicalInput.leftGas;
}
else if(xAxis >= 80 && xAxis <= 96 && yAxis >= 5+13 && yAxis <= 63+13)
{
stack = ((CachedIORecipe)arecipes.get(recipe)).outputStack;
}
else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13)
{
stack = ((CachedIORecipe)arecipes.get(recipe)).chemicalInput.rightGas;
}
2014-01-10 02:47:06 +01:00
if(stack != null)
{
if(button == 0)
{
2014-01-10 02:47:06 +01:00
if(doGasLookup(stack, false))
{
return true;
}
}
else if(button == 1)
{
if(doGasLookup(stack, true))
{
return true;
}
}
}
2014-01-10 02:47:06 +01:00
return super.mouseClicked(gui, button, recipe);
}
2014-01-10 02:47:06 +01:00
@Override
public int recipiesPerPage()
{
return 1;
}
@Override
public void addGuiElements()
{
}
public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe
{
2014-01-10 18:58:05 +01:00
public ChemicalPair chemicalInput;
public GasStack outputStack;
@Override
public PositionedStack getResult()
{
return null;
}
2014-01-10 18:58:05 +01:00
public CachedIORecipe(ChemicalPair input, GasStack output)
{
chemicalInput = input;
outputStack = output;
}
public CachedIORecipe(Map.Entry recipe)
{
2014-01-10 18:58:05 +01:00
this((ChemicalPair)recipe.getKey(), (GasStack)recipe.getValue());
}
}
}