From 8a791da5b52602518f384996834ed2d6005a355f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 9 Aug 2015 11:36:52 +0200 Subject: [PATCH] Made a Recipe Handler for the Double Furnace --- .../nei/CrusherRecipeHandler.java | 50 +++++-- .../nei/FurnaceDoubleRecipeHandler.java | 128 ++++++++++++++++++ .../nei/NEIActuallyAdditionsConfig.java | 4 + .../assets/actuallyadditions/lang/en_US.lang | 1 + 4 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/nei/FurnaceDoubleRecipeHandler.java diff --git a/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java b/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java index 4aa1a2f97..14d16ff4d 100644 --- a/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java @@ -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 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 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 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); + } + } } \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/nei/FurnaceDoubleRecipeHandler.java b/src/main/java/ellpeck/actuallyadditions/nei/FurnaceDoubleRecipeHandler.java new file mode 100644 index 000000000..8bd1ea49d --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/nei/FurnaceDoubleRecipeHandler.java @@ -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 getIngredients(){ + return getCycledIngredients(cycleticks/48, Collections.singletonList(ingredient)); + } + + @Override + public PositionedStack getResult(){ + return resultOne; + } + } + + @Override + public Class 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 recipes = (Map)FurnaceRecipes.smelting().getSmeltingList(); + for(Map.Entry 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 recipes = (Map)FurnaceRecipes.smelting().getSmeltingList(); + for(Map.Entry 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 recipes = (Map)FurnaceRecipes.smelting().getSmeltingList(); + for(Map.Entry 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; + } +} \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/nei/NEIActuallyAdditionsConfig.java b/src/main/java/ellpeck/actuallyadditions/nei/NEIActuallyAdditionsConfig.java index 9f4fdd279..5d126128f 100644 --- a/src/main/java/ellpeck/actuallyadditions/nei/NEIActuallyAdditionsConfig.java +++ b/src/main/java/ellpeck/actuallyadditions/nei/NEIActuallyAdditionsConfig.java @@ -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); diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index df971f207..6448053f2 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -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