Advertisement
Fej

FejRecipeHandler

Fej
Apr 21st, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. package com.fejcraft.FejCraftRPG;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6.  
  7. import com.fejcraft.FejCraftRPG.FejRecipeTypes.FejRecipeShaped;
  8.  
  9. import net.minecraft.block.Block;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemArmor;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.item.crafting.CraftingManager;
  14. import net.minecraft.item.crafting.ShapedRecipes;
  15.  
  16. public class FejRecipeHandler {
  17.    
  18.     public final static int LEVEL_REQUIRED_DIAMOND_ARMOR = 5;
  19.    
  20.     public static void removeRecipes(List recipeList)
  21.     {
  22.  
  23.         for(int i = 0; i < recipeList.size(); i++)
  24.         {
  25.             if(recipeList.get(i) instanceof ShapedRecipes)
  26.             {
  27.                 if(isItemStackOfType(((ShapedRecipes)recipeList.get(i)).getRecipeOutput() , Item.helmetDiamond) ) {
  28.                     recipeList.remove(i);
  29.                     addFejRecipe(LEVEL_REQUIRED_DIAMOND_ARMOR,new ItemStack(ItemArmor.helmetDiamond), "OOO","O O", 'O', new ItemStack(Item.diamond));
  30.                 }
  31.                                
  32.             }
  33.                
  34.         }
  35.     }
  36.    
  37.     //Slightly edited from CraftingManager, only change is that it uses FejRecipeShaped instead of ShapedRecipes and adds an integer parameter to fit
  38.     public static FejRecipeShaped addFejRecipe(int levelRequired, ItemStack par1ItemStack, Object ... par2ArrayOfObj)
  39.     {
  40.         String s = "";
  41.         int i = 0;
  42.         int j = 0;
  43.         int k = 0;
  44.  
  45.         if (par2ArrayOfObj[i] instanceof String[])
  46.         {
  47.             String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
  48.  
  49.             for (int l = 0; l < astring.length; ++l)
  50.             {
  51.                 String s1 = astring[l];
  52.                 ++k;
  53.                 j = s1.length();
  54.                 s = s + s1;
  55.             }
  56.         }
  57.         else
  58.         {
  59.             while (par2ArrayOfObj[i] instanceof String)
  60.             {
  61.                 String s2 = (String)par2ArrayOfObj[i++];
  62.                 ++k;
  63.                 j = s2.length();
  64.                 s = s + s2;
  65.             }
  66.         }
  67.  
  68.         HashMap hashmap;
  69.  
  70.         for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2)
  71.         {
  72.             Character character = (Character)par2ArrayOfObj[i];
  73.             ItemStack itemstack1 = null;
  74.  
  75.             if (par2ArrayOfObj[i + 1] instanceof Item)
  76.             {
  77.                 itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
  78.             }
  79.             else if (par2ArrayOfObj[i + 1] instanceof Block)
  80.             {
  81.                 itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
  82.             }
  83.             else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
  84.             {
  85.                 itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];
  86.             }
  87.  
  88.             hashmap.put(character, itemstack1);
  89.         }
  90.  
  91.         ItemStack[] aitemstack = new ItemStack[j * k];
  92.  
  93.         for (int i1 = 0; i1 < j * k; ++i1)
  94.         {
  95.             char c0 = s.charAt(i1);
  96.  
  97.             if (hashmap.containsKey(Character.valueOf(c0)))
  98.             {
  99.                 aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy();
  100.             }
  101.             else
  102.             {
  103.                 aitemstack[i1] = null;
  104.             }
  105.         }
  106.  
  107.         FejRecipeShaped shapedrecipes = new FejRecipeShaped(j, k, aitemstack, par1ItemStack, levelRequired);
  108.         CraftingManager.getInstance().getRecipeList().add(shapedrecipes);
  109.         return shapedrecipes;
  110.     }
  111.    
  112.     private static boolean isItemStackOfType(ItemStack stack, Item item)
  113.     {
  114.         if(stack.getItem().itemID == item.itemID)
  115.             return true;
  116.         else
  117.             return false;
  118.     }
  119.    
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement