2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.client.nei;
|
2013-08-10 21:52:59 +02:00
|
|
|
|
2014-01-02 19:00:09 +01:00
|
|
|
import static codechicken.core.gui.GuiDraw.changeTexture;
|
|
|
|
import static codechicken.core.gui.GuiDraw.drawTexturedModalRect;
|
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
import java.awt.Point;
|
2013-08-10 21:52:59 +02:00
|
|
|
import java.awt.Rectangle;
|
2014-01-02 19:00:09 +01:00
|
|
|
import java.util.List;
|
2013-08-10 21:52:59 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
import mekanism.api.AdvancedInput;
|
2014-01-18 18:16:14 +01:00
|
|
|
import mekanism.api.gas.Gas;
|
2014-01-18 03:29:39 +01:00
|
|
|
import mekanism.api.gas.GasStack;
|
|
|
|
import mekanism.common.ObfuscatedNames;
|
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
2013-08-10 21:52:59 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
import codechicken.core.gui.GuiDraw;
|
|
|
|
import codechicken.nei.NEIClientConfig;
|
2013-08-10 21:52:59 +02:00
|
|
|
import codechicken.nei.NEIServerUtils;
|
|
|
|
import codechicken.nei.PositionedStack;
|
2014-01-18 03:29:39 +01:00
|
|
|
import codechicken.nei.recipe.GuiRecipe;
|
2013-08-10 21:52:59 +02:00
|
|
|
import codechicken.nei.recipe.TemplateRecipeHandler;
|
|
|
|
|
2014-01-10 00:06:44 +01:00
|
|
|
public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
2013-08-14 17:01:44 +02:00
|
|
|
private int ticksPassed;
|
2013-08-10 21:52:59 +02:00
|
|
|
|
|
|
|
public abstract String getRecipeId();
|
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
public abstract Set<Entry<AdvancedInput, ItemStack>> getRecipes();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 18:16:14 +01:00
|
|
|
public abstract List<ItemStack> getFuelStacks(Gas gasType);
|
2013-08-10 21:52:59 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawBackground(int i)
|
|
|
|
{
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
changeTexture(getGuiTexture());
|
|
|
|
drawTexturedModalRect(12, 0, 28, 5, 144, 68);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawExtras(int i)
|
|
|
|
{
|
2014-01-18 17:26:24 +01:00
|
|
|
CachedIORecipe recipe = (CachedIORecipe)arecipes.get(i);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
float f = ticksPassed >= 20 ? (ticksPassed - 20) % 20 / 20.0F : 0;
|
2013-10-19 18:55:21 +02:00
|
|
|
drawProgressBar(63, 34, 176, 0, 24, 7, f, 0);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
if(recipe.input.gasType != null)
|
|
|
|
{
|
|
|
|
int displayInt = ticksPassed < 20 ? ticksPassed*12 / 20 : 12;
|
|
|
|
displayGauge(45, 32 + 12 - displayInt, 6, displayInt, new GasStack(recipe.input.gasType, 1));
|
|
|
|
}
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
super.onUpdate();
|
|
|
|
ticksPassed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadTransferRects()
|
|
|
|
{
|
|
|
|
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(63, 34, 24, 7), getRecipeId(), new Object[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(String outputId, Object... results)
|
|
|
|
{
|
|
|
|
if(outputId.equals(getRecipeId()))
|
|
|
|
{
|
2014-01-18 18:16:14 +01:00
|
|
|
for(Map.Entry<AdvancedInput, ItemStack> irecipe : getRecipes())
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
2014-01-18 18:16:14 +01:00
|
|
|
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks(irecipe.getKey().gasType)));
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
super.loadCraftingRecipes(outputId, results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(ItemStack result)
|
|
|
|
{
|
2014-01-18 18:16:14 +01:00
|
|
|
for(Map.Entry<AdvancedInput, ItemStack> irecipe : getRecipes())
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
|
|
|
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getValue(), result))
|
|
|
|
{
|
2014-01-18 18:16:14 +01:00
|
|
|
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks(irecipe.getKey().gasType)));
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
@Override
|
|
|
|
public void loadUsageRecipes(String inputId, Object... ingredients)
|
|
|
|
{
|
|
|
|
if(inputId.equals("gas") && ingredients.length == 1 && ingredients[0] instanceof GasStack)
|
|
|
|
{
|
|
|
|
for(Map.Entry<AdvancedInput, ItemStack> irecipe : getRecipes())
|
|
|
|
{
|
|
|
|
if(irecipe.getKey().gasType == ((GasStack)ingredients[0]).getGas())
|
|
|
|
{
|
2014-01-18 18:16:14 +01:00
|
|
|
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks(irecipe.getKey().gasType)));
|
2014-01-18 03:29:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
super.loadUsageRecipes(inputId, ingredients);
|
|
|
|
}
|
|
|
|
}
|
2013-08-10 21:52:59 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadUsageRecipes(ItemStack ingredient)
|
|
|
|
{
|
2014-01-18 06:28:42 +01:00
|
|
|
for(Map.Entry<AdvancedInput, ItemStack> irecipe : getRecipes())
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
2014-01-18 06:28:42 +01:00
|
|
|
if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getKey().itemStack, ingredient))
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
2014-01-18 18:16:14 +01:00
|
|
|
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks(irecipe.getKey().gasType)));
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
@Override
|
|
|
|
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe)
|
|
|
|
{
|
|
|
|
Point point = GuiDraw.getMousePosition();
|
2014-01-18 17:26:24 +01:00
|
|
|
Point offset = gui.getRecipePosition(recipe);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft)-offset.x;
|
|
|
|
int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop)-offset.y;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
if(xAxis >= 45 && xAxis <= 51 && yAxis >= 33 && yAxis <= 45)
|
2014-01-18 03:29:39 +01:00
|
|
|
{
|
|
|
|
currenttip.add(((CachedIORecipe)arecipes.get(recipe)).input.gasType.getLocalizedName());
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
return super.handleTooltip(gui, currenttip, recipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe)
|
|
|
|
{
|
|
|
|
Point point = GuiDraw.getMousePosition();
|
2014-01-18 17:26:24 +01:00
|
|
|
Point offset = gui.getRecipePosition(recipe);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft)-offset.x;
|
|
|
|
int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop)-offset.y;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
GasStack stack = null;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
if(xAxis >= 45 && xAxis <= 51 && yAxis >= 33 && yAxis <= 45)
|
2014-01-18 03:29:39 +01:00
|
|
|
{
|
|
|
|
stack = new GasStack(((CachedIORecipe)arecipes.get(recipe)).input.gasType, 1);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +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-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
return super.keyTyped(gui, keyChar, keyCode, recipe);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
@Override
|
|
|
|
public boolean mouseClicked(GuiRecipe gui, int button, int recipe)
|
|
|
|
{
|
|
|
|
Point point = GuiDraw.getMousePosition();
|
2014-01-18 17:26:24 +01:00
|
|
|
Point offset = gui.getRecipePosition(recipe);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft)-offset.x;
|
|
|
|
int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop)-offset.y;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
GasStack stack = null;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 17:26:24 +01:00
|
|
|
if(xAxis >= 45 && xAxis <= 51 && yAxis >= 33 && yAxis <= 45)
|
2014-01-18 03:29:39 +01:00
|
|
|
{
|
|
|
|
stack = new GasStack(((CachedIORecipe)arecipes.get(recipe)).input.gasType, 1);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
if(stack != null)
|
|
|
|
{
|
|
|
|
if(button == 0)
|
|
|
|
{
|
|
|
|
if(doGasLookup(stack, false))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(button == 1)
|
|
|
|
{
|
|
|
|
if(doGasLookup(stack, true))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
return super.mouseClicked(gui, button, recipe);
|
|
|
|
}
|
2013-08-10 21:52:59 +02:00
|
|
|
|
2014-04-19 02:41:48 +02:00
|
|
|
@Override
|
|
|
|
public void addGuiElements()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe
|
|
|
|
{
|
2014-01-02 19:00:09 +01:00
|
|
|
public List<ItemStack> fuelStacks;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
public AdvancedInput input;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
public PositionedStack outputStack;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PositionedStack getIngredient()
|
|
|
|
{
|
2014-01-18 03:29:39 +01:00
|
|
|
return new PositionedStack(input.itemStack, 40, 12);
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PositionedStack getResult()
|
|
|
|
{
|
|
|
|
return outputStack;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
@Override
|
|
|
|
public PositionedStack getOtherStack()
|
|
|
|
{
|
2014-01-02 19:00:09 +01:00
|
|
|
return new PositionedStack(fuelStacks.get(cycleticks/40 % fuelStacks.size()), 40, 48);
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
|
2014-01-18 03:29:39 +01:00
|
|
|
public CachedIORecipe(AdvancedInput adv, ItemStack output, List<ItemStack> fuels)
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
2014-01-18 03:29:39 +01:00
|
|
|
input = adv;
|
2013-08-10 21:52:59 +02:00
|
|
|
outputStack = new PositionedStack(output, 100, 30);
|
2014-01-02 19:00:09 +01:00
|
|
|
fuelStacks = fuels;
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
|
2014-01-02 19:00:09 +01:00
|
|
|
public CachedIORecipe(Map.Entry recipe, List<ItemStack> fuels)
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
2014-01-18 03:29:39 +01:00
|
|
|
this((AdvancedInput)recipe.getKey(), (ItemStack)recipe.getValue(), fuels);
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|