diff --git a/integration/modules/dead/NEI.java b/integration/modules/NEI.java similarity index 76% rename from integration/modules/dead/NEI.java rename to integration/modules/NEI.java index 4942e270..0285ec53 100644 --- a/integration/modules/dead/NEI.java +++ b/integration/modules/NEI.java @@ -1,9 +1,10 @@ -package appeng.integration.modules.dead; +package appeng.integration.modules; import java.lang.reflect.Method; import appeng.integration.IIntegrationModule; -import appeng.integration.modules.helpers.NEIQuartzShapedRecipeHandler; +import appeng.integration.modules.helpers.NEIAEShapedRecipeHandler; +import appeng.integration.modules.helpers.NEIAEShapelessRecipeHandler; public class NEI implements IIntegrationModule { @@ -14,11 +15,15 @@ public class NEI implements IIntegrationModule public void Init() throws Throwable { Class API = Class.forName( "codechicken.nei.api.API" ); + Method registerRecipeHandler = API.getDeclaredMethod( "registerRecipeHandler", new Class[] { codechicken.nei.recipe.ICraftingHandler.class } ); Method registerUsageHandler = API.getDeclaredMethod( "registerUsageHandler", new Class[] { codechicken.nei.recipe.IUsageHandler.class } ); - registerRecipeHandler.invoke( API, new NEIQuartzShapedRecipeHandler() ); - registerUsageHandler.invoke( API, new NEIQuartzShapedRecipeHandler() ); + registerRecipeHandler.invoke( API, new NEIAEShapedRecipeHandler() ); + registerUsageHandler.invoke( API, new NEIAEShapedRecipeHandler() ); + + registerRecipeHandler.invoke( API, new NEIAEShapelessRecipeHandler() ); + registerUsageHandler.invoke( API, new NEIAEShapelessRecipeHandler() ); /* * Method registerGuiOverlay = API.getDeclaredMethod( "registerGuiOverlay", new Class[] { Class.class, diff --git a/integration/modules/helpers/dead/NEIQuartzShapedRecipeHandler.java b/integration/modules/helpers/NEIAEShapedRecipeHandler.java similarity index 87% rename from integration/modules/helpers/dead/NEIQuartzShapedRecipeHandler.java rename to integration/modules/helpers/NEIAEShapedRecipeHandler.java index d8756b4b..8665e9b9 100644 --- a/integration/modules/helpers/dead/NEIQuartzShapedRecipeHandler.java +++ b/integration/modules/helpers/NEIAEShapedRecipeHandler.java @@ -1,4 +1,4 @@ -package appeng.integration.modules.helpers.dead; +package appeng.integration.modules.helpers; import java.awt.Rectangle; import java.util.ArrayList; @@ -10,7 +10,7 @@ import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; -import appeng.recipes.AEShapedQuartzRecipe; +import appeng.recipes.game.ShapedRecipe; import codechicken.nei.NEIClientUtils; import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; @@ -21,7 +21,7 @@ import codechicken.nei.api.IStackPositioner; import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; -public class NEIQuartzShapedRecipeHandler extends TemplateRecipeHandler +public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler { public void loadTransferRects() @@ -43,14 +43,14 @@ public class NEIQuartzShapedRecipeHandler extends TemplateRecipeHandler @Override public void loadCraftingRecipes(String outputId, Object[] results) { - if ( (outputId.equals( "crafting" )) && (getClass() == NEIQuartzShapedRecipeHandler.class) ) + if ( (outputId.equals( "crafting" )) && (getClass() == NEIAEShapedRecipeHandler.class) ) { List allrecipes = CraftingManager.getInstance().getRecipeList(); for (IRecipe irecipe : allrecipes) { CachedShapedRecipe recipe = null; - if ( (irecipe instanceof AEShapedQuartzRecipe) ) - recipe = new CachedShapedRecipe( (AEShapedQuartzRecipe) irecipe ); + if ( (irecipe instanceof ShapedRecipe) ) + recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe ); if ( recipe != null ) { @@ -73,8 +73,8 @@ public class NEIQuartzShapedRecipeHandler extends TemplateRecipeHandler if ( NEIServerUtils.areStacksSameTypeCrafting( irecipe.getRecipeOutput(), result ) ) { CachedShapedRecipe recipe = null; - if ( (irecipe instanceof AEShapedQuartzRecipe) ) - recipe = new CachedShapedRecipe( (AEShapedQuartzRecipe) irecipe ); + if ( (irecipe instanceof ShapedRecipe) ) + recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe ); if ( recipe != null ) { @@ -91,10 +91,10 @@ public class NEIQuartzShapedRecipeHandler extends TemplateRecipeHandler for (IRecipe irecipe : allrecipes) { CachedShapedRecipe recipe = null; - if ( (irecipe instanceof AEShapedQuartzRecipe) ) - recipe = new CachedShapedRecipe( (AEShapedQuartzRecipe) irecipe ); + if ( (irecipe instanceof ShapedRecipe) ) + recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe ); - if ( (recipe != null) && (recipe.contains( recipe.ingredients, ingredient.itemID )) ) + if ( (recipe != null) && (recipe.contains( recipe.ingredients, ingredient.getItem() )) ) { recipe.computeVisuals(); if ( recipe.contains( recipe.ingredients, ingredient ) ) @@ -163,7 +163,7 @@ public class NEIQuartzShapedRecipeHandler extends TemplateRecipeHandler public ArrayList ingredients; public PositionedStack result; - public CachedShapedRecipe(AEShapedQuartzRecipe irecipe) { + public CachedShapedRecipe(ShapedRecipe irecipe) { result = new PositionedStack( irecipe.getRecipeOutput(), 119, 24 ); ingredients = new ArrayList(); setIngredients( irecipe.getWidth(), irecipe.getHeight(), irecipe.getIngredients() ); diff --git a/integration/modules/helpers/NEIAEShapelessRecipeHandler.java b/integration/modules/helpers/NEIAEShapelessRecipeHandler.java new file mode 100644 index 00000000..db189bac --- /dev/null +++ b/integration/modules/helpers/NEIAEShapelessRecipeHandler.java @@ -0,0 +1,209 @@ +package appeng.integration.modules.helpers; + +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.gui.inventory.GuiCrafting; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import appeng.recipes.game.ShapelessRecipe; +import codechicken.nei.NEIClientUtils; +import codechicken.nei.NEIServerUtils; +import codechicken.nei.PositionedStack; +import codechicken.nei.api.DefaultOverlayRenderer; +import codechicken.nei.api.IOverlayHandler; +import codechicken.nei.api.IRecipeOverlayRenderer; +import codechicken.nei.api.IStackPositioner; +import codechicken.nei.recipe.RecipeInfo; +import codechicken.nei.recipe.TemplateRecipeHandler; + +public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler +{ + + public void loadTransferRects() + { + this.transferRects.add( new TemplateRecipeHandler.RecipeTransferRect( new Rectangle( 84, 23, 24, 18 ), "crafting", new Object[0] ) ); + } + + public Class getGuiClass() + { + return GuiCrafting.class; + } + + @Override + public String getRecipeName() + { + return NEIClientUtils.translate( "recipe.shapeless", new Object[0] ); + } + + @Override + public void loadCraftingRecipes(String outputId, Object[] results) + { + if ( (outputId.equals( "crafting" )) && (getClass() == NEIAEShapelessRecipeHandler.class) ) + { + List allrecipes = CraftingManager.getInstance().getRecipeList(); + for (IRecipe irecipe : allrecipes) + { + CachedShapelessRecipe recipe = null; + if ( (irecipe instanceof ShapelessRecipe) ) + recipe = new CachedShapelessRecipe( (ShapelessRecipe) irecipe ); + + if ( recipe != null ) + { + recipe.computeVisuals(); + this.arecipes.add( recipe ); + } + } + } + else + { + super.loadCraftingRecipes( outputId, results ); + } + } + + public void loadCraftingRecipes(ItemStack result) + { + List allrecipes = CraftingManager.getInstance().getRecipeList(); + for (IRecipe irecipe : allrecipes) + { + if ( NEIServerUtils.areStacksSameTypeCrafting( irecipe.getRecipeOutput(), result ) ) + { + CachedShapelessRecipe recipe = null; + if ( (irecipe instanceof ShapelessRecipe) ) + recipe = new CachedShapelessRecipe( (ShapelessRecipe) irecipe ); + + if ( recipe != null ) + { + recipe.computeVisuals(); + this.arecipes.add( recipe ); + } + } + } + } + + public void loadUsageRecipes(ItemStack ingredient) + { + List allrecipes = CraftingManager.getInstance().getRecipeList(); + for (IRecipe irecipe : allrecipes) + { + CachedShapelessRecipe recipe = null; + if ( (irecipe instanceof ShapelessRecipe) ) + recipe = new CachedShapelessRecipe( (ShapelessRecipe) 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() + { + return "textures/gui/container/crafting_table.png"; + } + + public String getOverlayIdentifier() + { + return "crafting"; + } + + @Override + public boolean hasOverlay(GuiContainer gui, Container container, int recipe) + { + return (super.hasOverlay( gui, container, recipe )) || ((isRecipe2x2( recipe )) && (RecipeInfo.hasDefaultOverlay( gui, "crafting2x2" ))); + } + + @Override + public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe) + { + IRecipeOverlayRenderer renderer = super.getOverlayRenderer( gui, recipe ); + if ( renderer != null ) + { + return renderer; + } + IStackPositioner positioner = RecipeInfo.getStackPositioner( gui, "crafting2x2" ); + if ( positioner == null ) + return null; + return new DefaultOverlayRenderer( getIngredientStacks( recipe ), positioner ); + } + + @Override + public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe) + { + IOverlayHandler handler = super.getOverlayHandler( gui, recipe ); + if ( handler != null ) + { + return handler; + } + return RecipeInfo.getOverlayHandler( gui, "crafting2x2" ); + } + + public boolean isRecipe2x2(int recipe) + { + for (PositionedStack stack : getIngredientStacks( recipe )) + { + if ( (stack.relx > 43) || (stack.rely > 24) ) + return false; + } + return true; + } + + public class CachedShapelessRecipe extends TemplateRecipeHandler.CachedRecipe + { + + public ArrayList ingredients; + public PositionedStack result; + + public CachedShapelessRecipe(ShapelessRecipe irecipe) { + result = new PositionedStack( irecipe.getRecipeOutput(), 119, 24 ); + ingredients = new ArrayList(); + setIngredients( irecipe.getInput().toArray() ); + } + + public void setIngredients(Object[] items) + { + for (int x = 0; x < 3; x++) + { + for (int y = 0; y < 3; y++) + { + if ( items.length > (y * 3 + x) ) + { + PositionedStack stack = new PositionedStack( items[(y * 3 + x)], 25 + x * 18, 6 + y * 18, false ); + stack.setMaxSize( 1 ); + this.ingredients.add( stack ); + } + } + } + } + + @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/recipes/game/ShapedRecipe.java b/recipes/game/ShapedRecipe.java index 4ff1b8b3..735730a9 100644 --- a/recipes/game/ShapedRecipe.java +++ b/recipes/game/ShapedRecipe.java @@ -254,4 +254,20 @@ public class ShapedRecipe implements IRecipe { return this.input; } + + public int getWidth() + { + return width; + } + + public int getHeight() + { + return height; + } + + public Object[] getIngredients() + { + return input; + } + } \ No newline at end of file diff --git a/recipes/game/ShapelessRecipe.java b/recipes/game/ShapelessRecipe.java index 6b269876..18e46692 100644 --- a/recipes/game/ShapelessRecipe.java +++ b/recipes/game/ShapelessRecipe.java @@ -140,4 +140,5 @@ public class ShapelessRecipe implements IRecipe { return this.input; } + } \ No newline at end of file