Merge pull request #750 from iTitus/master

NEI recipe handlers for the Calcinator and the Aludel
This commit is contained in:
Pahimar 2014-11-10 19:52:36 -05:00
commit bb2de5e967
4 changed files with 389 additions and 1 deletions

View file

@ -0,0 +1,158 @@
package com.pahimar.ee3.nei;
import static codechicken.lib.gui.GuiDraw.changeTexture;
import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect;
import java.awt.Rectangle;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.FurnaceRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import com.pahimar.ee3.client.gui.inventory.GuiAludel;
import com.pahimar.ee3.exchange.WrappedStack;
import com.pahimar.ee3.item.crafting.RecipeAludel;
import com.pahimar.ee3.recipe.RecipesAludel;
import com.pahimar.ee3.reference.Names;
import com.pahimar.ee3.reference.Reference;
import com.pahimar.ee3.reference.Textures;
public class AludelRecipeHandler extends TemplateRecipeHandler
{
public class CachedAludelRecipe extends CachedRecipe
{
public List<PositionedStack> inputs;
public PositionedStack output;
public CachedAludelRecipe(RecipeAludel recipe)
{
WrappedStack[] wrappedInputs = recipe.getRecipeInputs();
inputs = Arrays.asList(new PositionedStack(new ItemStack(((ItemStack) wrappedInputs[0].getWrappedStack()).getItem(), wrappedInputs[0].getStackSize(), ((ItemStack) wrappedInputs[0].getWrappedStack()).getItemDamage()), 37, 7), new PositionedStack(new ItemStack(((ItemStack) wrappedInputs[1].getWrappedStack()).getItem(), wrappedInputs[1].getStackSize(), ((ItemStack) wrappedInputs[1].getWrappedStack()).getItemDamage()), 37, 28));
output = new PositionedStack(recipe.getRecipeOutput(), 113, 28);
}
@Override
public List<PositionedStack> getIngredients()
{
return inputs;
}
public PositionedStack getOtherStack()
{
return new PositionedStack(FurnaceRecipeHandler.afuels.get((cycleticks / 48) % FurnaceRecipeHandler.afuels.size()).stack.item, 37, 63);
}
@Override
public PositionedStack getResult()
{
return output;
}
}
@Override
public void drawBackground(int recipe)
{
GL11.glColor4f(1, 1, 1, 1);
changeTexture(getGuiTexture());
drawTexturedModalRect(1, -1, 8, 10, 164, 91);
}
@Override
public void drawExtras(int recipe)
{
drawProgressBar(37, 46, 176, 0, 14, 14, 48, 7);
drawProgressBar(73, 29, 176, 14, 24, 16, 48, 0);
}
@Override
public Class<? extends GuiContainer> getGuiClass()
{
return GuiAludel.class;
}
@Override
public String getGuiTexture()
{
return Textures.Gui.ALUDEL.toString();
}
public String getRecipeID()
{
return Reference.MOD_ID + ":" + Names.Blocks.ALUDEL;
}
@Override
public String getRecipeName()
{
return StatCollector.translateToLocal("gui.nei.ee3:aludel");
}
@Override
public void loadCraftingRecipes(ItemStack result)
{
for (RecipeAludel recipe : RecipesAludel.getInstance().getRecipes())
{
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getRecipeOutput(), result))
{
arecipes.add(new CachedAludelRecipe(recipe));
}
}
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if (outputId.equals(getRecipeID()))
{
for (RecipeAludel recipe : RecipesAludel.getInstance().getRecipes())
{
arecipes.add(new CachedAludelRecipe(recipe));
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadTransferRects()
{
transferRects.add(new RecipeTransferRect(new Rectangle(36, 44, 18, 18), "fuel"));
transferRects.add(new RecipeTransferRect(new Rectangle(74, 28, 24, 16), getRecipeID()));
}
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for (RecipeAludel recipe : RecipesAludel.getInstance().getRecipes())
{
for (WrappedStack wrappedStack : recipe.getRecipeInputs())
{
if (NEIServerUtils.areStacksSameTypeCrafting((ItemStack) wrappedStack.getWrappedStack(), ingredient))
{
arecipes.add(new CachedAludelRecipe(recipe));
}
}
}
}
@Override
public int recipiesPerPage()
{
return 1;
}
}

View file

@ -0,0 +1,189 @@
package com.pahimar.ee3.nei;
import static codechicken.lib.gui.GuiDraw.changeTexture;
import static codechicken.lib.gui.GuiDraw.drawStringC;
import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect;
import java.awt.Rectangle;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.FurnaceRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler;
import com.pahimar.ee3.api.EnergyValue;
import com.pahimar.ee3.api.EnergyValue.EnergyType;
import com.pahimar.ee3.api.EnergyValueRegistryProxy;
import com.pahimar.ee3.client.gui.inventory.GuiCalcinator;
import com.pahimar.ee3.item.ItemAlchemicalDust;
import com.pahimar.ee3.reference.Names;
import com.pahimar.ee3.reference.Reference;
import com.pahimar.ee3.reference.Textures;
import com.pahimar.ee3.util.CalcinationHelper;
public class CalcinationHandler extends TemplateRecipeHandler
{
private static final DecimalFormat energyValueDecimalFormat = new DecimalFormat("###,###,###,###,###.###");
public class CachedCalcinationRecipe extends CachedRecipe
{
public List<PositionedStack> inputs;
public PositionedStack output;
public EnergyValue minEnergyValue;
public EnergyValue maxEnergyValue;
public CachedCalcinationRecipe(ItemStack outputDust)
{
output = new PositionedStack(outputDust, 101, 19);
inputs = new ArrayList<PositionedStack>();
minEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputDust);
maxEnergyValue = (outputDust.getItemDamage() < (ItemAlchemicalDust.getAlchemicalDusts().size() - 1) ? EnergyValueRegistryProxy.getEnergyValue(ItemAlchemicalDust.getAlchemicalDusts().get(outputDust.getItemDamage() + 1)) : new EnergyValue(Float.MAX_VALUE, EnergyType.CORPOREAL));
for (Object obj : EnergyValueRegistryProxy.getStacksInRange(minEnergyValue, maxEnergyValue))
{
if (obj instanceof ItemStack)
{
inputs.add(new PositionedStack((ItemStack) obj, 40, 0));
}
}
}
public CachedCalcinationRecipe(ItemStack inputStack, ItemStack outputDust)
{
inputStack.stackSize = 1;
inputs = Arrays.asList(new PositionedStack[] { new PositionedStack(inputStack, 40, 0) });
output = new PositionedStack(outputDust, 101, 19);
minEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputDust);
maxEnergyValue = (outputDust.getItemDamage() < (ItemAlchemicalDust.getAlchemicalDusts().size() - 1) ? EnergyValueRegistryProxy.getEnergyValue(ItemAlchemicalDust.getAlchemicalDusts().get(outputDust.getItemDamage() + 1)) : new EnergyValue(Float.MAX_VALUE, EnergyType.CORPOREAL));
}
@Override
public PositionedStack getIngredient()
{
return inputs.get((cycleticks / 48) % inputs.size());
}
public PositionedStack getOtherStack()
{
return new PositionedStack(FurnaceRecipeHandler.afuels.get((cycleticks / 48) % FurnaceRecipeHandler.afuels.size()).stack.item, 40, 45);
}
@Override
public PositionedStack getResult()
{
return output;
}
}
@Override
public Class<? extends GuiContainer> getGuiClass()
{
return GuiCalcinator.class;
}
@Override
public String getGuiTexture()
{
return Textures.Gui.CALCINATOR.toString();
}
@Override
public String getRecipeName()
{
return StatCollector.translateToLocal("gui.nei.ee3:calcination");
}
public String getRecipeID()
{
return Reference.MOD_ID + ":" + Names.Blocks.CALCINATOR;
}
@Override
public void loadCraftingRecipes(ItemStack result)
{
for (ItemStack stack : ItemAlchemicalDust.getAlchemicalDusts())
{
if (NEIServerUtils.areStacksSameTypeCrafting(stack, result))
{
arecipes.add(new CachedCalcinationRecipe(stack));
}
}
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if (outputId.equals(getRecipeID()))
{
for (ItemStack stack : ItemAlchemicalDust.getAlchemicalDusts())
{
arecipes.add(new CachedCalcinationRecipe(stack));
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadTransferRects()
{
transferRects.add(new RecipeTransferRect(new Rectangle(39, 20, 18, 18), "fuel"));
transferRects.add(new RecipeTransferRect(new Rectangle(69, 19, 24, 16), getRecipeID()));
}
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for (ItemStack stack : ItemAlchemicalDust.getAlchemicalDusts())
{
if (NEIServerUtils.areStacksSameTypeCrafting(stack, CalcinationHelper.getCalcinationResult(ingredient)))
{
arecipes.add(new CachedCalcinationRecipe(ingredient, stack));
}
}
}
@Override
public int recipiesPerPage()
{
return 1;
}
@Override
public void drawBackground(int recipe)
{
GL11.glColor4f(1, 1, 1, 1);
changeTexture(getGuiTexture());
drawTexturedModalRect(14, -3, 19, 7, 143, 68);
}
@Override
public void drawExtras(int recipe)
{
drawProgressBar(41, 23, 176, 0, 14, 14, 48, 7);
drawProgressBar(70, 20, 176, 14, 24, 16, 48, 0);
CachedCalcinationRecipe cRecipe = (CachedCalcinationRecipe) arecipes.get(recipe);
drawStringC(StatCollector.translateToLocal("gui.nei.ee3:calcination.tooltip.1"), 83, 75, 0x404040, false);
drawStringC(cRecipe.getResult().item.getDisplayName() + ":", 83, 85, 0x404040, false);
drawStringC(StatCollector.translateToLocalFormatted("gui.nei.ee3:calcination.tooltip.2", (cRecipe.minEnergyValue.getEnergyValue() > 1 ? energyValueDecimalFormat.format(cRecipe.minEnergyValue.getEnergyValue()) : "0"), (cRecipe.maxEnergyValue.getEnergyValue() <= EnergyValueRegistryProxy.getEnergyValue(ItemAlchemicalDust.getAlchemicalDusts().get(ItemAlchemicalDust.getAlchemicalDusts().size() - 1)).getEnergyValue() ? energyValueDecimalFormat.format(cRecipe.maxEnergyValue.getEnergyValue()) : "\u221E")), 83, 95, 0x404040, false);
}
}

View file

@ -0,0 +1,35 @@
package com.pahimar.ee3.nei;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import com.pahimar.ee3.reference.Reference;
public class NEIConfig implements IConfigureNEI
{
@Override
public String getName()
{
return Reference.MOD_NAME;
}
@Override
public String getVersion()
{
return Reference.VERSION;
}
@Override
public void loadConfig()
{
AludelRecipeHandler aludelRecipeHandler = new AludelRecipeHandler();
CalcinationHandler calcinationHandler = new CalcinationHandler();
API.registerRecipeHandler(aludelRecipeHandler);
API.registerUsageHandler(aludelRecipeHandler);
API.registerRecipeHandler(calcinationHandler);
API.registerUsageHandler(calcinationHandler);
}
}

View file

@ -100,6 +100,12 @@ container.ee3:augmentationTable=Augmentation Table [WIP]
container.ee3:alchemicalTome=Tome of Alchemical Knowledge [WIP]
container.ee3:transmutationSquare=Transmutation Square [WIP]
# NEI
gui.nei.ee3:calcination=Calcination
gui.nei.ee3:calcination.tooltip.1=Energy values needed to calcine
gui.nei.ee3:calcination.tooltip.2=From %s to %s
gui.nei.ee3:aludel=Aludel
# Glyphs
glyph.ee3:baseCircle=Circle (Base)
glyph.ee3:circle=Circle