Made a Recipe Handler for the Double Furnace

This commit is contained in:
Ellpeck 2015-08-09 11:36:52 +02:00
parent 89834bf918
commit 8a791da5b5
4 changed files with 169 additions and 14 deletions

View file

@ -32,6 +32,24 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{
transferRects.add(new RecipeTransferRect(new Rectangle(51, 40, 24, 22), this.getName()));
transferRects.add(new RecipeTransferRect(new Rectangle(101, 40, 24, 22), this.getName()));
}
@Override
public String getGuiTexture(){
return ModUtil.MOD_ID_LOWER+":textures/gui/guiGrinderDouble.png";
}
@Override
public void drawBackground(int recipeIndex){
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(getGuiTexture());
GuiDraw.drawTexturedModalRect(33, 20, 33, 20, 110, 70);
}
@Override
public void drawExtras(int recipe){
drawProgressBar(51, 40, 176, 0, 24, 23, 48, 1);
this.drawChanceString(66, 93, recipe);
}
}
public CrusherRecipeHandler(){
@ -45,11 +63,12 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{
public PositionedStack resultTwo;
public int secondChance;
public CachedCrush(ItemStack in, ItemStack resultOne, ItemStack resultTwo, int secondChance){
public CachedCrush(ItemStack in, ItemStack resultOne, ItemStack resultTwo, int secondChance, CrusherRecipeHandler handler){
boolean isDouble = handler instanceof CrusherDoubleRecipeHandler;
in.stackSize = 1;
this.ingredient = new PositionedStack(in, 80, 21);
this.resultOne = new PositionedStack(resultOne, 66, 69);
if(resultTwo != null) this.resultTwo = new PositionedStack(resultTwo, 94, 69);
this.ingredient = new PositionedStack(in, isDouble ? 51 : 80, 21);
this.resultOne = new PositionedStack(resultOne, isDouble ? 38 : 66, 69);
if(resultTwo != null) this.resultTwo = new PositionedStack(resultTwo, isDouble ? 63 : 94, 69);
this.secondChance = secondChance;
}
@ -96,7 +115,7 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{
if(outputId.equals(this.getName()) && (getClass() == CrusherRecipeHandler.class || getClass() == CrusherDoubleRecipeHandler.class)){
ArrayList<CrusherRecipeManualRegistry.CrusherRecipe> recipes = CrusherRecipeManualRegistry.recipes;
for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){
arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance));
arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance, this));
}
}
else super.loadCraftingRecipes(outputId, results);
@ -107,7 +126,7 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{
ArrayList<CrusherRecipeManualRegistry.CrusherRecipe> recipes = CrusherRecipeManualRegistry.recipes;
for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){
if(NEIServerUtils.areStacksSameType(recipe.firstOutput, result) || NEIServerUtils.areStacksSameType(recipe.secondOutput, result))
arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance));
arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance, this));
}
}
@ -116,7 +135,7 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{
ArrayList<CrusherRecipeManualRegistry.CrusherRecipe> recipes = CrusherRecipeManualRegistry.recipes;
for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){
if(NEIServerUtils.areStacksSameTypeCrafting(recipe.input, ingredient)){
CachedCrush theRecipe = new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance);
CachedCrush theRecipe = new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance, this);
theRecipe.setIngredientPermutation(Collections.singletonList(theRecipe.ingredient), ingredient);
arecipes.add(theRecipe);
}
@ -138,13 +157,7 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{
@Override
public void drawExtras(int recipe){
drawProgressBar(80, 40, 176, 0, 24, 23, 48, 1);
CachedCrush crush = (CachedCrush)this.arecipes.get(recipe);
if(crush.resultTwo != null){
int secondChance = crush.secondChance;
String secondString = secondChance+"%";
GuiDraw.drawString(secondString, 118, 73, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false);
}
this.drawChanceString(118, 73, recipe);
}
@Override
@ -155,4 +168,13 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{
protected String getName(){
return "actuallyadditions."+(this instanceof CrusherDoubleRecipeHandler ? "crushingDouble" : "crushing");
}
protected void drawChanceString(int x, int y, int recipe){
CachedCrush crush = (CachedCrush)this.arecipes.get(recipe);
if(crush.resultTwo != null){
int secondChance = crush.secondChance;
String secondString = secondChance+"%";
GuiDraw.drawString(secondString, x, y, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false);
}
}
}

View file

@ -0,0 +1,128 @@
package ellpeck.actuallyadditions.nei;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import ellpeck.actuallyadditions.inventory.gui.GuiFurnaceDouble;
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.item.crafting.FurnaceRecipes;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class FurnaceDoubleRecipeHandler extends TemplateRecipeHandler{
public static final String NAME = "actuallyadditions.furnaceDouble";
public FurnaceDoubleRecipeHandler(){
RecipeInfo.setGuiOffset(this.getGuiClass(), 0, 0);
}
public class CachedFurn extends CachedRecipe{
public PositionedStack ingredient;
public PositionedStack resultOne;
public CachedFurn(ItemStack in, ItemStack resultOne){
in.stackSize = 1;
this.ingredient = new PositionedStack(in, 51, 21);
this.resultOne = new PositionedStack(resultOne, 50, 69);
}
@Override
public List<PositionedStack> getIngredients(){
return getCycledIngredients(cycleticks/48, Collections.singletonList(ingredient));
}
@Override
public PositionedStack getResult(){
return resultOne;
}
}
@Override
public Class<? extends GuiContainer> getGuiClass(){
return GuiFurnaceDouble.class;
}
@Override
public void loadTransferRects(){
transferRects.add(new RecipeTransferRect(new Rectangle(51, 40, 24, 22), NAME));
transferRects.add(new RecipeTransferRect(new Rectangle(101, 40, 24, 22), NAME));
}
@Override
public String getGuiTexture(){
return ModUtil.MOD_ID_LOWER+":textures/gui/guiFurnaceDouble.png";
}
@Override
public void drawBackground(int recipeIndex){
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(getGuiTexture());
GuiDraw.drawTexturedModalRect(46, 20, 46, 20, 84, 70);
}
@Override
public void drawExtras(int recipe){
drawProgressBar(51, 40, 176, 0, 24, 23, 48, 1);
}
@Override
public int recipiesPerPage(){
return 1;
}
@Override
public String getRecipeName(){
return StringUtil.localize("container.nei."+NAME+".name");
}
@SuppressWarnings("unchecked")
@Override
public void loadCraftingRecipes(String outputId, Object... results){
if(outputId.equals(NAME) && getClass() == FurnaceDoubleRecipeHandler.class){
Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>)FurnaceRecipes.smelting().getSmeltingList();
for(Map.Entry<ItemStack, ItemStack> recipe : recipes.entrySet()){
arecipes.add(new CachedFurn(recipe.getKey(), recipe.getValue()));
}
}
else super.loadCraftingRecipes(outputId, results);
}
@SuppressWarnings("unchecked")
@Override
public void loadCraftingRecipes(ItemStack result){
Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>)FurnaceRecipes.smelting().getSmeltingList();
for(Map.Entry<ItemStack, ItemStack> recipe : recipes.entrySet()){
if(NEIServerUtils.areStacksSameType(recipe.getValue(), result))
arecipes.add(new CachedFurn(recipe.getKey(), recipe.getValue()));
}
}
@SuppressWarnings("unchecked")
@Override
public void loadUsageRecipes(ItemStack ingredient){
Map<ItemStack, ItemStack> recipes = (Map<ItemStack, ItemStack>)FurnaceRecipes.smelting().getSmeltingList();
for(Map.Entry<ItemStack, ItemStack> recipe : recipes.entrySet()){
if(NEIServerUtils.areStacksSameTypeCrafting(recipe.getKey(), ingredient)){
CachedFurn theRecipe = new CachedFurn(recipe.getKey(), recipe.getValue());
theRecipe.setIngredientPermutation(Collections.singletonList(theRecipe.ingredient), ingredient);
arecipes.add(theRecipe);
}
}
}
@Override
public String getOverlayIdentifier(){
return NAME;
}
}

View file

@ -26,6 +26,10 @@ public class NEIActuallyAdditionsConfig implements IConfigureNEI{
API.registerRecipeHandler(crusherDoubleRecipeHandler);
API.registerUsageHandler(crusherDoubleRecipeHandler);
FurnaceDoubleRecipeHandler furnaceDoubleRecipeHandler = new FurnaceDoubleRecipeHandler();
API.registerRecipeHandler(furnaceDoubleRecipeHandler);
API.registerUsageHandler(furnaceDoubleRecipeHandler);
HairyBallRecipeHandler ballRecipeHandler = new HairyBallRecipeHandler();
API.registerRecipeHandler(ballRecipeHandler);
API.registerUsageHandler(ballRecipeHandler);

View file

@ -640,6 +640,7 @@ container.nei.actuallyadditions.crushing.name=Crusher
container.nei.actuallyadditions.crushingDouble.name=Double Crusher
container.nei.actuallyadditions.ballOfHair.name=Ball Of Hair Usage
container.nei.actuallyadditions.compost.name=Compost
container.nei.actuallyadditions.furnaceDouble.name=Double Furnace
container.nei.actuallyadditions.treasureChest.name=Treasure Chest
container.nei.actuallyadditions.treasureChest.info=Items at