Skip to content

Instantly share code, notes, and snippets.

@NikolaTheProgrammingNoob
Created November 17, 2015 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NikolaTheProgrammingNoob/20bcf687b3a49f31a824 to your computer and use it in GitHub Desktop.
Save NikolaTheProgrammingNoob/20bcf687b3a49f31a824 to your computer and use it in GitHub Desktop.
The Crafting Manager
package com.nikola.carbonmod.crafting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.nikola.carbonmod.init.CarbonBlocks;
import com.nikola.carbonmod.init.CarbonItems;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class CraftingManager
{
private static final CraftingManager instance = new CraftingManager();
private List recipes = Lists.newArrayList();
private static final String __OBFID = "CL_00000090";
public static CraftingManager getInstance()
{
return instance;
}
private CraftingManager() {
recipes = new ArrayList();
/../
Collections.sort(this.recipes, new IronForgeRecipeSorter(this));
}
public IronForgeShapedRecipes addRecipe(ItemStack stack, Object ... recipeComponents)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (recipeComponents[i] instanceof String[])
{
String[] astring = (String[])((String[])recipeComponents[i++]);
for (int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while (recipeComponents[i] instanceof String)
{
String s2 = (String)recipeComponents[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for (hashmap = Maps.newHashMap(); i < recipeComponents.length; i += 2)
{
Character character = (Character)recipeComponents[i];
ItemStack itemstack1 = null;
if (recipeComponents[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)recipeComponents[i + 1]);
}
else if (recipeComponents[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)recipeComponents[i + 1], 1, 32767);
}
else if (recipeComponents[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)recipeComponents[i + 1];
}
hashmap.put(character, itemstack1);
}
ItemStack[] aitemstack = new ItemStack[j * k];
for (int i1 = 0; i1 < j * k; ++i1)
{
char c0 = s.charAt(i1);
if (hashmap.containsKey(Character.valueOf(c0)))
{
aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy();
}
else
{
aitemstack[i1] = null;
}
}
IronForgeShapedRecipes shapedrecipes = new IronForgeShapedRecipes(j, k, aitemstack, stack);
this.recipes.add(shapedrecipes);
return shapedrecipes;
}
public void addShapelessRecipe(ItemStack stack, Object ... recipeComponents)
{
ArrayList arraylist = Lists.newArrayList();
Object[] aobject = recipeComponents;
int i = recipeComponents.length;
for (int j = 0; j < i; ++j)
{
Object object1 = aobject[j];
if (object1 instanceof ItemStack)
{
arraylist.add(((ItemStack)object1).copy());
}
else if (object1 instanceof Item)
{
arraylist.add(new ItemStack((Item)object1));
}
else
{
if (!(object1 instanceof Block))
{
throw new IllegalArgumentException("Invalid shapeless recipe: unknown type " + object1.getClass().getName() + "!");
}
arraylist.add(new ItemStack((Block)object1));
}
}
this.recipes.add(new IronForgeShapelessRecipes(stack, arraylist));
}
public void addRecipe(IRecipe recipe)
{
this.recipes.add(recipe);
}
public ItemStack findMatchingRecipe(InventoryCrafting p_82787_1_, World worldIn)
{
Iterator iterator = this.recipes.iterator();
IRecipe irecipe;
do
{
if (!iterator.hasNext())
{
return null;
}
irecipe = (IRecipe)iterator.next();
}
while (!irecipe.matches(p_82787_1_, worldIn));
return irecipe.getCraftingResult(p_82787_1_);
}
public ItemStack[] func_180303_b(InventoryCrafting p_180303_1_, World worldIn)
{
Iterator iterator = this.recipes.iterator();
while (iterator.hasNext())
{
IRecipe irecipe = (IRecipe)iterator.next();
if (irecipe.matches(p_180303_1_, worldIn))
{
return irecipe.getRemainingItems(p_180303_1_);
}
}
ItemStack[] aitemstack = new ItemStack[p_180303_1_.getSizeInventory()];
for (int i = 0; i < aitemstack.length; ++i)
{
aitemstack[i] = p_180303_1_.getStackInSlot(i);
}
return aitemstack;
}
public List getRecipeList()
{
return this.recipes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment