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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import codechicken.nei.NEIServerUtils;
|
|
|
|
import codechicken.nei.PositionedStack;
|
|
|
|
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();
|
|
|
|
|
|
|
|
public abstract Set<Entry<ItemStack, ItemStack>> getRecipes();
|
2014-01-02 19:00:09 +01:00
|
|
|
|
|
|
|
public abstract List<ItemStack> getFuelStacks();
|
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)
|
|
|
|
{
|
|
|
|
float f = ticksPassed >= 40 ? (ticksPassed - 40) % 20 / 20.0F : 0.0F;
|
2013-10-19 18:55:21 +02:00
|
|
|
drawProgressBar(63, 34, 176, 0, 24, 7, f, 0);
|
2013-08-10 21:52:59 +02:00
|
|
|
|
|
|
|
f = ticksPassed >= 20 && ticksPassed < 40 ? (ticksPassed - 20) % 20 / 20.0F : 1.0F;
|
|
|
|
if(ticksPassed < 20) f = 0.0F;
|
2013-10-19 18:55:21 +02:00
|
|
|
drawProgressBar(45, 32, 176, 7, 5, 12, f, 3);
|
2013-08-10 21:52:59 +02:00
|
|
|
|
|
|
|
f = ticksPassed <= 20 ? ticksPassed / 20.0F : 1.0F;
|
2013-10-19 18:55:21 +02:00
|
|
|
drawProgressBar(149, 12, 176, 19, 4, 52, f, 3);
|
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()))
|
|
|
|
{
|
|
|
|
for(Map.Entry irecipe : getRecipes())
|
|
|
|
{
|
2014-01-02 19:00:09 +01:00
|
|
|
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks()));
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
super.loadCraftingRecipes(outputId, results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(ItemStack result)
|
|
|
|
{
|
|
|
|
for(Map.Entry irecipe : getRecipes())
|
|
|
|
{
|
|
|
|
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getValue(), result))
|
|
|
|
{
|
2014-01-02 19:00:09 +01:00
|
|
|
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks()));
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadUsageRecipes(ItemStack ingredient)
|
|
|
|
{
|
|
|
|
for(Map.Entry irecipe : getRecipes())
|
|
|
|
{
|
|
|
|
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getKey(), ingredient))
|
|
|
|
{
|
2014-01-02 19:00:09 +01:00
|
|
|
arecipes.add(new CachedIORecipe(irecipe, getFuelStacks()));
|
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;
|
|
|
|
|
2013-08-10 21:52:59 +02:00
|
|
|
public PositionedStack inputStack;
|
|
|
|
public PositionedStack outputStack;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PositionedStack getIngredient()
|
|
|
|
{
|
|
|
|
return inputStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PositionedStack getResult()
|
|
|
|
{
|
|
|
|
return outputStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-02 19:00:09 +01:00
|
|
|
public CachedIORecipe(ItemStack input, ItemStack output, List<ItemStack> fuels)
|
2013-08-10 21:52:59 +02:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
inputStack = new PositionedStack(input, 40, 12);
|
|
|
|
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-02 19:00:09 +01:00
|
|
|
this((ItemStack)recipe.getKey(), (ItemStack)recipe.getValue(), fuels);
|
2013-08-10 21:52:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|