Registred NEI usage recipe handlers

This commit is contained in:
mistaqur committed 2013-11-11 13:43:08 +04:00
1 parent 9710710d4d
commit 198f6c6424
3 files changed
+102 -26

No files matched your search

@@ -3,6 +3,7 @@ package crazypants.enderio.nei;
import static codechicken.core.gui.GuiDraw.changeTexture;
import static codechicken.core.gui.GuiDraw.drawTexturedModalRect;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
@@ -49,7 +50,7 @@ public class AlloySmelterRecipeHandler extends TemplateRecipeHandler {
@Override
public void loadTransferRects() {
//Set this up later to show all alloy recipes
//transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(77, 7, 22, 12), "EnderIOAlloySmelter", new Object[0]));
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(77-5, 26-3, 19, 25), "EnderIOAlloySmelter", new Object[0]));
}
@Override
@@ -58,18 +59,46 @@ public class AlloySmelterRecipeHandler extends TemplateRecipeHandler {
List<IEnderIoRecipe> recipes = RecipeReigistry.instance.getRecipesForOutput(IEnderIoRecipe.ALLOY_SMELTER_ID, result);
for (IEnderIoRecipe recipe : recipes) {
List<IRecipeInput> ri = recipe.getInputs();
ItemStack[] ingredients = new ItemStack[ri.size()];
for (int i = 0; i < ingredients.length; i++) {
ingredients[i] = ri.get(i).getItem();
}
for (IRecipeOutput output : recipe.getOutputs()) {
AlloySmelterRecipe res = new AlloySmelterRecipe(recipe.getRequiredEnergy(), ingredients, output.getItem());
AlloySmelterRecipe res = new AlloySmelterRecipe(recipe.getRequiredEnergy(), recipe.getInputs(), output.getItem());
arecipes.add(res);
}
}
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if(outputId.equals("EnderIOAlloySmelter") && getClass() == AlloySmelterRecipeHandler.class)
{
List<IEnderIoRecipe> recipes = RecipeReigistry.instance.getRecipesForCrafter(IEnderIoRecipe.ALLOY_SMELTER_ID);
for (IEnderIoRecipe recipe : recipes) {
for (IRecipeOutput output : recipe.getOutputs()) {
AlloySmelterRecipe res = new AlloySmelterRecipe(recipe.getRequiredEnergy(), recipe.getInputs(), output.getItem());
arecipes.add(res);
}
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
List<IEnderIoRecipe> recipes = RecipeReigistry.instance.getRecipesForCrafter(IEnderIoRecipe.ALLOY_SMELTER_ID);
for (IEnderIoRecipe recipe : recipes) {
if (recipe.isInput(ingredient)) {
for (IRecipeOutput output : recipe.getOutputs()) {
AlloySmelterRecipe res = new AlloySmelterRecipe(recipe.getRequiredEnergy(), recipe.getInputs(), output.getItem());
res.setIngredientPermutation(res.input, ingredient);
arecipes.add(res);
}
}
}
}
//Move the GUI down 8 pixels.
@Override
public void drawBackground(int recipe) {
@@ -87,6 +116,13 @@ public class AlloySmelterRecipeHandler extends TemplateRecipeHandler {
GuiDraw.drawString(energyString, 100, 57, 0xFFFFFFFF);
}
public List<ItemStack> getInputs(IRecipeInput input) {
List<ItemStack> result = new ArrayList<ItemStack>();
result.add(input.getItem());
result.addAll(input.getEquivelentInputs());
return result;
}
public class AlloySmelterRecipe extends TemplateRecipeHandler.CachedRecipe {
private ArrayList<PositionedStack> input;
@@ -100,7 +136,7 @@ public class AlloySmelterRecipeHandler extends TemplateRecipeHandler {
@Override
public List<PositionedStack> getIngredients() {
return input;
return getCycledIngredients(cycleticks / 20, input);
}
@Override
@@ -108,27 +144,20 @@ public class AlloySmelterRecipeHandler extends TemplateRecipeHandler {
return output;
}
public AlloySmelterRecipe(float energy, ItemStack ingredients[], ItemStack result) {
int recipeSize = ingredients.length;
public AlloySmelterRecipe(float energy, List<IRecipeInput> ingredients, ItemStack result) {
int recipeSize = ingredients.size();
this.input = new ArrayList<PositionedStack>();
if(recipeSize > 0) {
this.input.add(new PositionedStack(ingredients[0], 49, 14));
this.input.add(new PositionedStack(getInputs(ingredients.get(0)), 49, 14));
}
if(recipeSize > 1) {
this.input.add(new PositionedStack(ingredients[1], 73, 4));
this.input.add(new PositionedStack(getInputs(ingredients.get(1)), 73, 4));
}
if(recipeSize > 2) {
this.input.add(new PositionedStack(ingredients[2], 98, 14));
this.input.add(new PositionedStack(getInputs(ingredients.get(2)), 98, 14));
}
this.output = new PositionedStack(result, 74, 54);
this.energy = energy; //If we wanted to do an energy cost
}
public AlloySmelterRecipe(float energy, ItemStack ingredient, ItemStack result) {
this.input = new ArrayList<PositionedStack>();
this.input.add(new PositionedStack(ingredient, 49, 14));
this.output = new PositionedStack(result, 74, 54);
this.energy = energy;
}
}
}
@@ -12,7 +12,9 @@ public class NEIEnderIOConfig implements IConfigureNEI {
public void loadConfig() {
API.registerRecipeHandler(new AlloySmelterRecipeHandler());
API.registerRecipeHandler(new SagMillRecipeHandler());
API.setGuiOffset(GuiAlloySmelter.class, 50, 50);
API.registerUsageHandler(new AlloySmelterRecipeHandler());
API.registerUsageHandler(new SagMillRecipeHandler());
API.setGuiOffset(GuiAlloySmelter.class, 5, 3);
API.hideItem(EnderIO.blockConduitFacade.blockID);
if(!Config.photovoltaicCellEnabled) {
API.hideItem(EnderIO.blockSolarPanel.blockID);
@@ -1,6 +1,7 @@
package crazypants.enderio.nei;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -18,6 +19,7 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
import crazypants.enderio.crafting.IEnderIoRecipe;
import crazypants.enderio.crafting.IRecipeInput;
import crazypants.enderio.crafting.IRecipeOutput;
import crazypants.enderio.crafting.RecipeReigistry;
import crazypants.enderio.machine.crusher.GuiCrusher;
@@ -54,7 +56,7 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
@Override
public void loadTransferRects() {
//Set this up later to show all alloy recipes
//transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(77, 7, 22, 12), "EnderIOAlloySmelter", new Object[0]));
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(81-5, 32-11, 15, 23), "EnderIOSagMill", new Object[0]));
}
@Override
@@ -66,7 +68,7 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
for (IEnderIoRecipe recipe : recipes) {
List<IRecipeOutput> ro = recipe.getOutputs();
MillRecipe res = new MillRecipe(result, recipe.getRequiredEnergy(), recipe.getInputs().get(0).getItem(), ro);
MillRecipe res = new MillRecipe(result, recipe.getRequiredEnergy(), recipe.getInputs().get(0), ro);
toAdd.add(res);
}
@@ -75,6 +77,37 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
arecipes.addAll(toAdd);
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if(outputId.equals("EnderIOSagMill") && getClass() == SagMillRecipeHandler.class)
{
List<IEnderIoRecipe> recipes = RecipeReigistry.instance.getRecipesForCrafter(IEnderIoRecipe.SAG_MILL_ID);
for (IEnderIoRecipe recipe : recipes) {
for (IRecipeOutput output : recipe.getOutputs()) {
MillRecipe res = new MillRecipe(recipe.getRequiredEnergy(), recipe.getInputs().get(0), recipe.getOutputs());
arecipes.add(res);
}
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
List<IEnderIoRecipe> recipes = RecipeReigistry.instance.getRecipesForCrafter(IEnderIoRecipe.SAG_MILL_ID);
for (IEnderIoRecipe recipe : recipes) {
if (recipe.isInput(ingredient)) {
MillRecipe res = new MillRecipe(recipe.getRequiredEnergy(), recipe.getInputs().get(0), recipe.getOutputs());
arecipes.add(res);
}
}
}
@Override
public void drawExtras(int recipeIndex) {
drawProgressBar(98, 33, 176, 0, 22, 13, 48, 3);
@@ -125,6 +158,13 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
super.drawProgressBar(87 - 13, 37 - 16, 200, 0, 17, 24, completion, 1);
}
public List<ItemStack> getInputs(IRecipeInput input) {
List<ItemStack> result = new ArrayList<ItemStack>();
result.add(input.getItem());
result.addAll(input.getEquivelentInputs());
return result;
}
private static Point offset = new Point(5, 11);
public class MillRecipe extends TemplateRecipeHandler.CachedRecipe {
@@ -156,6 +196,7 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
@Override
public PositionedStack getIngredient() {
randomRenderPermutation(input, cycleticks / 20);
return input;
}
@@ -169,9 +210,13 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
return otherOutputs;
}
public MillRecipe(ItemStack targetedResult, float energy, ItemStack ingredient, List<IRecipeOutput> outputs) {
public MillRecipe(float energy, IRecipeInput ingredient, List<IRecipeOutput> outputs) {
this(null, energy, ingredient, outputs);
}
public MillRecipe(ItemStack targetedResult, float energy, IRecipeInput ingredient, List<IRecipeOutput> outputs) {
this.energy = energy;
input = new PositionedStack(ingredient, 80 - offset.x, 12 - offset.y);
input = new PositionedStack(getInputs(ingredient), 80 - offset.x, 12 - offset.y);
output = new PositionedStack(outputs.get(0).getItem(), 49 - offset.x, 59 - offset.y);
otherOutputs = new ArrayList<PositionedStack>();
if(outputs.size() > 1) {
@@ -189,7 +234,7 @@ public class SagMillRecipeHandler extends TemplateRecipeHandler {
numTargetOuput = 1;
for (int i = 0; i < outputChance.length; i++) {
outputChance[i] = outputs.get(i).getChance();
if(outputs.get(i).isEquivalent(targetedResult)) {
if(targetedResult != null && outputs.get(i).isEquivalent(targetedResult)) {
indexOfTargetOutput = i;
numTargetOuput = outputs.get(i).getQuantity();
}