2015-04-26 20:07:57 +02:00
|
|
|
package ellpeck.actuallyadditions.nei;
|
|
|
|
|
|
|
|
import codechicken.lib.gui.GuiDraw;
|
|
|
|
import codechicken.nei.NEIServerUtils;
|
|
|
|
import codechicken.nei.PositionedStack;
|
2015-04-28 20:54:23 +02:00
|
|
|
import codechicken.nei.recipe.RecipeInfo;
|
2015-04-26 20:07:57 +02:00
|
|
|
import codechicken.nei.recipe.TemplateRecipeHandler;
|
2015-06-12 19:12:06 +02:00
|
|
|
import ellpeck.actuallyadditions.inventory.gui.GuiGrinder;
|
2015-07-01 16:06:40 +02:00
|
|
|
import ellpeck.actuallyadditions.recipe.CrusherRecipeManualRegistry;
|
2015-04-26 20:07:57 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.StringUtil;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import java.awt.*;
|
2015-05-20 22:39:43 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2015-04-26 20:07:57 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class CrusherRecipeHandler extends TemplateRecipeHandler{
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
public static final String NAME = "actuallyadditions.crushing";
|
2015-04-26 20:07:57 +02:00
|
|
|
|
2015-04-28 20:54:23 +02:00
|
|
|
public CrusherRecipeHandler(){
|
|
|
|
super();
|
|
|
|
RecipeInfo.setGuiOffset(this.getGuiClass(), 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-04-26 20:07:57 +02:00
|
|
|
public class CachedCrush extends CachedRecipe{
|
|
|
|
|
|
|
|
public PositionedStack ingredient;
|
|
|
|
public PositionedStack resultOne;
|
|
|
|
public PositionedStack resultTwo;
|
|
|
|
public int secondChance;
|
|
|
|
|
|
|
|
public CachedCrush(ItemStack in, ItemStack resultOne, ItemStack resultTwo, int secondChance){
|
|
|
|
in.stackSize = 1;
|
2015-04-28 20:54:23 +02:00
|
|
|
this.ingredient = new PositionedStack(in, 80, 21);
|
|
|
|
this.resultOne = new PositionedStack(resultOne, 66, 69);
|
|
|
|
if(resultTwo != null) this.resultTwo = new PositionedStack(resultTwo, 94, 69);
|
2015-04-26 20:07:57 +02:00
|
|
|
this.secondChance = secondChance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<PositionedStack> getIngredients(){
|
|
|
|
return getCycledIngredients(cycleticks / 48, Collections.singletonList(ingredient));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PositionedStack getResult(){
|
|
|
|
return resultOne;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<PositionedStack> getOtherStacks(){
|
|
|
|
ArrayList<PositionedStack> list = new ArrayList<PositionedStack>();
|
|
|
|
if(this.resultTwo != null) list.add(this.resultTwo);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 20:54:23 +02:00
|
|
|
@Override
|
|
|
|
public int recipiesPerPage(){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-26 20:07:57 +02:00
|
|
|
@Override
|
|
|
|
public void loadTransferRects(){
|
2015-04-28 20:54:23 +02:00
|
|
|
transferRects.add(new RecipeTransferRect(new Rectangle(80, 40, 24, 22), NAME));
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends GuiContainer> getGuiClass(){
|
|
|
|
return GuiGrinder.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getRecipeName(){
|
2015-06-12 19:12:06 +02:00
|
|
|
return StatCollector.translateToLocal("container.nei." + NAME + ".name");
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(String outputId, Object... results){
|
|
|
|
if(outputId.equals(NAME) && getClass() == CrusherRecipeHandler.class){
|
2015-07-01 16:06:40 +02:00
|
|
|
ArrayList<CrusherRecipeManualRegistry.CrusherRecipe> recipes = CrusherRecipeManualRegistry.recipes;
|
|
|
|
for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){
|
2015-04-26 20:07:57 +02:00
|
|
|
arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else super.loadCraftingRecipes(outputId, results);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(ItemStack result){
|
2015-07-01 16:06:40 +02:00
|
|
|
ArrayList<CrusherRecipeManualRegistry.CrusherRecipe> recipes = CrusherRecipeManualRegistry.recipes;
|
|
|
|
for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){
|
2015-04-26 20:07:57 +02:00
|
|
|
if(NEIServerUtils.areStacksSameType(recipe.firstOutput, result) || NEIServerUtils.areStacksSameType(recipe.secondOutput, result)) arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadUsageRecipes(ItemStack ingredient){
|
2015-07-01 16:06:40 +02:00
|
|
|
ArrayList<CrusherRecipeManualRegistry.CrusherRecipe> recipes = CrusherRecipeManualRegistry.recipes;
|
|
|
|
for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){
|
2015-04-26 20:07:57 +02:00
|
|
|
if(NEIServerUtils.areStacksSameTypeCrafting(recipe.input, ingredient)){
|
|
|
|
CachedCrush theRecipe = new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance);
|
|
|
|
theRecipe.setIngredientPermutation(Collections.singletonList(theRecipe.ingredient), ingredient);
|
|
|
|
arecipes.add(theRecipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGuiTexture(){
|
2015-04-28 20:54:23 +02:00
|
|
|
return ModUtil.MOD_ID_LOWER + ":textures/gui/guiGrinder.png";
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawBackground(int recipeIndex){
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
GuiDraw.changeTexture(getGuiTexture());
|
2015-05-20 22:39:43 +02:00
|
|
|
GuiDraw.drawTexturedModalRect(60, 13, 60, 13, 56, 79);
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawExtras(int recipe){
|
2015-04-28 20:54:23 +02:00
|
|
|
drawProgressBar(80, 40, 176, 0, 24, 23, 48, 1);
|
2015-04-26 20:07:57 +02:00
|
|
|
|
|
|
|
CachedCrush crush = (CachedCrush)this.arecipes.get(recipe);
|
|
|
|
if(crush.resultTwo != null){
|
|
|
|
int secondChance = crush.secondChance;
|
|
|
|
String secondString = secondChance + "%";
|
2015-04-28 20:54:23 +02:00
|
|
|
GuiDraw.drawString(secondString, 118, 73, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false);
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOverlayIdentifier(){
|
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
}
|