From 9238a530bb84cef2d2b35e4740c2b3d3c8d0da1a Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Thu, 1 May 2014 00:32:58 -0500 Subject: [PATCH] Added World and Grindstone NEI Plugins. --- .../registries/GrinderRecipeManager.java | 15 +- core/localization/GuiText.java | 2 +- integration/modules/NEI.java | 4 + .../helpers/NEIGrinderRecipeHandler.java | 208 ++++++++++++++++++ .../helpers/NEIWorldCraftingHandler.java | 63 ++++-- 5 files changed, 274 insertions(+), 18 deletions(-) create mode 100644 integration/modules/helpers/NEIGrinderRecipeHandler.java diff --git a/core/features/registries/GrinderRecipeManager.java b/core/features/registries/GrinderRecipeManager.java index b73ae2924..c108c1165 100644 --- a/core/features/registries/GrinderRecipeManager.java +++ b/core/features/registries/GrinderRecipeManager.java @@ -11,8 +11,8 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import appeng.api.features.IGrinderEntry; import appeng.api.features.IGrinderRegistry; -import appeng.core.AELog; import appeng.core.AEConfig; +import appeng.core.AELog; import appeng.core.features.registries.entries.AppEngGrinderRecipe; import appeng.recipes.ores.IOreListener; import appeng.recipes.ores.OreDictionaryHandler; @@ -60,6 +60,15 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener return RecipeList; } + private void injectRecipe(AppEngGrinderRecipe appEngGrinderRecipe) + { + for (IGrinderEntry gr : RecipeList) + if ( Platform.isSameItemPrecise( gr.getInput(), appEngGrinderRecipe.getInput() ) ) + return; + + RecipeList.add( appEngGrinderRecipe ); + } + @Override public void addRecipe(ItemStack in, ItemStack out, int cost) { @@ -70,7 +79,7 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener } log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " for " + cost ); - RecipeList.add( new AppEngGrinderRecipe( copy( in ), copy( out ), cost ) ); + injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), cost ) ); } @Override @@ -84,7 +93,7 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " with optional " + Platform.getItemDisplayName( optional ) + " for " + cost ); - RecipeList.add( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); + injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); } @Override diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index df9d17310..64696dae1 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -26,7 +26,7 @@ public enum GuiText METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel, StoredSize, - StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, inWorldFluix, inWorldPurification, inWorldSingularity; + StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, inWorldFluix, inWorldPurification, inWorldSingularity, OfSecondOutput, NoSecondOutput; String root; diff --git a/integration/modules/NEI.java b/integration/modules/NEI.java index c4255b38e..1d4413631 100644 --- a/integration/modules/NEI.java +++ b/integration/modules/NEI.java @@ -15,7 +15,9 @@ import appeng.integration.abstraction.INEI; import appeng.integration.modules.helpers.NEIAEShapedRecipeHandler; import appeng.integration.modules.helpers.NEIAEShapelessRecipeHandler; import appeng.integration.modules.helpers.NEICraftingHandler; +import appeng.integration.modules.helpers.NEIGrinderRecipeHandler; import appeng.integration.modules.helpers.NEIInscriberRecipeHandler; +import appeng.integration.modules.helpers.NEIWorldCraftingHandler; import codechicken.nei.guihook.GuiContainerManager; public class NEI implements IIntegrationModule, INEI @@ -48,6 +50,8 @@ public class NEI implements IIntegrationModule, INEI registerRecipeHandler( new NEIAEShapedRecipeHandler() ); registerRecipeHandler( new NEIAEShapelessRecipeHandler() ); registerRecipeHandler( new NEIInscriberRecipeHandler() ); + registerRecipeHandler( new NEIWorldCraftingHandler() ); + registerRecipeHandler( new NEIGrinderRecipeHandler() ); // crafting terminal... Method registerGuiOverlay = API.getDeclaredMethod( "registerGuiOverlay", new Class[] { Class.class, String.class, int.class, int.class } ); diff --git a/integration/modules/helpers/NEIGrinderRecipeHandler.java b/integration/modules/helpers/NEIGrinderRecipeHandler.java new file mode 100644 index 000000000..79235d2b2 --- /dev/null +++ b/integration/modules/helpers/NEIGrinderRecipeHandler.java @@ -0,0 +1,208 @@ +package appeng.integration.modules.helpers; + +import static codechicken.lib.gui.GuiDraw.changeTexture; +import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect; + +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import appeng.api.AEApi; +import appeng.api.features.IGrinderEntry; +import appeng.client.gui.implementations.GuiInscriber; +import appeng.core.localization.GuiText; +import codechicken.nei.NEIServerUtils; +import codechicken.nei.PositionedStack; +import codechicken.nei.api.IOverlayHandler; +import codechicken.nei.api.IRecipeOverlayRenderer; +import codechicken.nei.recipe.TemplateRecipeHandler; + +public class NEIGrinderRecipeHandler extends TemplateRecipeHandler +{ + + public void drawBackground(int recipe) + { + GL11.glColor4f( 1, 1, 1, 1 ); + changeTexture( getGuiTexture() ); + drawTexturedModalRect( 40, 10, 75, 16 + 10, 90, 66 ); + } + + @Override + public void drawForeground(int recipe) + { + super.drawForeground( recipe ); + if ( this.arecipes.size() > recipe ) + { + CachedRecipe cr = this.arecipes.get( recipe ); + if ( cr instanceof CachedGrindStoneRecipe ) + { + CachedGrindStoneRecipe cgsr = (CachedGrindStoneRecipe) cr; + if ( cgsr.hasOptional ) + { + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + int width = fr.getStringWidth( cgsr.Chance ); + fr.drawString( cgsr.Chance, (168 - width) / 2, 5, 0 ); + } + else + { + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + int width = fr.getStringWidth( GuiText.NoSecondOutput.getLocal() ); + fr.drawString( GuiText.NoSecondOutput.getLocal(), (168 - width) / 2, 5, 0 ); + } + } + } + } + + public void loadTransferRects() + { + this.transferRects.add( new TemplateRecipeHandler.RecipeTransferRect( new Rectangle( 84, 23, 24, 18 ), "inscriber", new Object[0] ) ); + } + + public Class getGuiClass() + { + return GuiInscriber.class; + } + + @Override + public String getRecipeName() + { + return GuiText.GrindStone.getLocal(); + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) + { + if ( (outputId.equals( "grindstone" )) && (getClass() == NEIGrinderRecipeHandler.class) ) + { + for (IGrinderEntry irecipe : AEApi.instance().registries().grinder().getRecipes()) + { + CachedGrindStoneRecipe recipe = new CachedGrindStoneRecipe( irecipe ); + if ( recipe != null ) + { + recipe.computeVisuals(); + this.arecipes.add( recipe ); + } + } + } + else + { + super.loadCraftingRecipes( outputId, results ); + } + } + + public void loadCraftingRecipes(ItemStack result) + { + for (IGrinderEntry irecipe : AEApi.instance().registries().grinder().getRecipes()) + { + if ( NEIServerUtils.areStacksSameTypeCrafting( irecipe.getOutput(), result ) ) + { + CachedGrindStoneRecipe recipe = new CachedGrindStoneRecipe( irecipe ); + recipe.computeVisuals(); + this.arecipes.add( recipe ); + } + } + } + + public void loadUsageRecipes(ItemStack ingredient) + { + for (IGrinderEntry irecipe : AEApi.instance().registries().grinder().getRecipes()) + { + CachedGrindStoneRecipe recipe = new CachedGrindStoneRecipe( irecipe ); + + if ( (recipe != null) && (recipe.contains( recipe.ingredients, ingredient.getItem() )) ) + { + recipe.computeVisuals(); + if ( recipe.contains( recipe.ingredients, ingredient ) ) + { + recipe.setIngredientPermutation( recipe.ingredients, ingredient ); + this.arecipes.add( recipe ); + } + } + } + } + + public String getGuiTexture() + { + ResourceLocation loc = new ResourceLocation( "appliedenergistics2", "textures/guis/grinder.png" ); + String f = loc.toString(); + return f; + } + + public String getOverlayIdentifier() + { + return "grindstone"; + } + + @Override + public boolean hasOverlay(GuiContainer gui, Container container, int recipe) + { + return false; + } + + @Override + public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe) + { + return null; + } + + @Override + public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe) + { + return null; + } + + public class CachedGrindStoneRecipe extends TemplateRecipeHandler.CachedRecipe + { + + public ArrayList ingredients; + public PositionedStack result; + + boolean hasOptional = false; + public String Chance; + + public CachedGrindStoneRecipe(IGrinderEntry irecipe) { + result = new PositionedStack( irecipe.getOutput(), -30 + 107, 47 ); + ingredients = new ArrayList(); + + if ( irecipe.getOptionalOutput() != null ) + { + hasOptional = true; + Chance = ((int) (irecipe.getOptionalChance() * 100)) + GuiText.OfSecondOutput.getLocal(); + ingredients.add( new PositionedStack( irecipe.getOptionalOutput(), -30 + 107 + 18, 47 ) ); + } + + if ( irecipe.getInput() != null ) + ingredients.add( new PositionedStack( irecipe.getInput(), 45, 24 ) ); + } + + @Override + public List getIngredients() + { + return getCycledIngredients( cycleticks / 20, this.ingredients ); + } + + @Override + public PositionedStack getResult() + { + return this.result; + } + + public void computeVisuals() + { + for (PositionedStack p : this.ingredients) + { + p.generatePermutations(); + } + this.result.generatePermutations(); + } + } +} \ No newline at end of file diff --git a/integration/modules/helpers/NEIWorldCraftingHandler.java b/integration/modules/helpers/NEIWorldCraftingHandler.java index 6f57e0ca9..197275c36 100644 --- a/integration/modules/helpers/NEIWorldCraftingHandler.java +++ b/integration/modules/helpers/NEIWorldCraftingHandler.java @@ -5,14 +5,20 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; + +import org.lwjgl.opengl.GL11; + import appeng.api.AEApi; import appeng.api.util.AEItemDefinition; import appeng.core.AEConfig; import appeng.core.features.AEFeature; import appeng.core.localization.GuiText; +import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.api.IRecipeOverlayRenderer; @@ -25,15 +31,22 @@ public class NEIWorldCraftingHandler implements ICraftingHandler, IUsageHandler HashMap details = new HashMap(); List offsets = new LinkedList(); + List outputs = new LinkedList(); + + ItemStack target; private void addRecipe(AEItemDefinition def, String msg) { - offsets.add( def ); - details.put( def, msg ); + if ( NEIServerUtils.areStacksSameTypeCrafting( def.stack( 1 ), target ) ) + { + offsets.add( def ); + outputs.add( new PositionedStack( def.stack( 1 ), 75, 4 ) ); + details.put( def, msg ); + } } - public NEIWorldCraftingHandler() { - + private void addRecipes() + { if ( AEConfig.instance.isFeatureEnabled( AEFeature.inWorldFluix ) ) addRecipe( AEApi.instance().materials().materialFluixCrystal, GuiText.inWorldFluix.getLocal() ); @@ -46,7 +59,6 @@ public class NEIWorldCraftingHandler implements ICraftingHandler, IUsageHandler addRecipe( AEApi.instance().materials().materialPureifiedNetherQuartzCrystal, GuiText.inWorldPurification.getLocal() ); addRecipe( AEApi.instance().materials().materialPureifiedFluixCrystal, GuiText.inWorldPurification.getLocal() ); } - } @Override @@ -61,18 +73,22 @@ public class NEIWorldCraftingHandler implements ICraftingHandler, IUsageHandler return offsets.size(); } - @Override public void drawBackground(int recipe) { - // TODO Auto-generated method stub - + GL11.glColor4f( 1, 1, 1, 1 );// nothing. } @Override public void drawForeground(int recipe) { - // TODO Auto-generated method stub + if ( this.outputs.size() > recipe ) + { + PositionedStack cr = this.outputs.get( recipe ); + String details = this.details.get( this.offsets.get( recipe ) ); + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + fr.drawSplitString( details, 10, 25, 150, 0 ); + } } @Override @@ -90,7 +106,7 @@ public class NEIWorldCraftingHandler implements ICraftingHandler, IUsageHandler @Override public PositionedStack getResultStack(int recipe) { - return null; + return outputs.get( recipe ); } @Override @@ -126,13 +142,13 @@ public class NEIWorldCraftingHandler implements ICraftingHandler, IUsageHandler @Override public List handleTooltip(GuiRecipe gui, List currenttip, int recipe) { - return null; + return currenttip; } @Override public List handleItemTooltip(GuiRecipe gui, ItemStack stack, List currenttip, int recipe) { - return null; + return currenttip; } @Override @@ -147,16 +163,35 @@ public class NEIWorldCraftingHandler implements ICraftingHandler, IUsageHandler return false; } + public NEIWorldCraftingHandler newInstance() + { + try + { + return getClass().newInstance(); + } + catch (Exception e) + { + throw new RuntimeException( e ); + } + } + @Override public IUsageHandler getUsageHandler(String inputId, Object... ingredients) { - return null; + return this; } @Override public ICraftingHandler getRecipeHandler(String outputId, Object... results) { - return null; + NEIWorldCraftingHandler g = newInstance(); + if ( results.length > 0 && results[0] instanceof ItemStack ) + { + g.target = (ItemStack) results[0]; + g.addRecipes(); + return g; + } + return this; } } \ No newline at end of file