Initial Comment

This commit is contained in:
jaredlll08 committed 2015-01-11 21:59:45 +02:00
commit 419ac849d0
276 files changed
+17939

No files matched your search

@@ -0,0 +1,141 @@
package naruto1310.extendedWorkbench.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
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 ExtendedCraftingManager
{
/** The static instance of this class */
private static final ExtendedCraftingManager instance = new ExtendedCraftingManager();
/** A list of all the recipes added */
private List<IRecipe> recipes = new ArrayList<IRecipe>();
/**
* Returns the static instance of this class
*/
public static final ExtendedCraftingManager getInstance()
{
return instance;
}
private void addExtendedRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String var3 = "";
int var4 = 0;
int var5 = 0;
int var6 = 0;
if(par2ArrayOfObj[var4] instanceof String[])
{
String[] var7 =((String[])par2ArrayOfObj[var4++]);
for(int var8 = 0; var8 < var7.length; ++var8)
{
String var9 = var7[var8];
++var6;
var5 = var9.length();
var3 = var3 + var9;
}
}
else
{
while(par2ArrayOfObj[var4] instanceof String)
{
String var11 =(String)par2ArrayOfObj[var4++];
++var6;
var5 = var11.length();
var3 = var3 + var11;
}
}
HashMap<Character, ItemStack> var12;
for(var12 = new HashMap<Character, ItemStack>(); var4 < par2ArrayOfObj.length; var4 += 2)
{
Character var13 =(Character)par2ArrayOfObj[var4];
ItemStack var14 = null;
if(par2ArrayOfObj[var4 + 1] instanceof Item)
var14 = new ItemStack((Item)par2ArrayOfObj[var4 + 1], 1, 32767);
if(par2ArrayOfObj[var4 + 1] instanceof Block)
var14 = new ItemStack((Block)par2ArrayOfObj[var4 + 1], 1, 32767);
if(par2ArrayOfObj[var4 + 1] instanceof ItemStack)
var14 =(ItemStack)par2ArrayOfObj[var4 + 1];
var12.put(var13, var14);
}
ItemStack[] var15 = new ItemStack[var5 * var6];
for(int var16 = 0; var16 < var5 * var6; ++var16)
{
char var10 = var3.charAt(var16);
if(var12.containsKey(Character.valueOf(var10)))
var15[var16] = var12.get(Character.valueOf(var10)).copy();
else
var15[var16] = null;
}
this.recipes.add(new ExtendedShapedRecipes(var5, var6, var15, par1ItemStack));
}
private void addExtendedShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
ArrayList<ItemStack> var3 = new ArrayList<ItemStack>();
Object[] var4 = par2ArrayOfObj;
int var5 = par2ArrayOfObj.length;
for(int var6 = 0; var6 < var5; var6++)
{
Object var7 = var4[var6];
if(var7 instanceof Item)
var3.add(new ItemStack((Item)var7, 1, 32767));
else if(var7 instanceof Block)
var3.add(new ItemStack((Block)var7, 1, 32767));
else if(var7 instanceof ItemStack)
var3.add(((ItemStack)var7).copy());
else throw new RuntimeException("Invalid shapeless recipy!");
}
this.recipes.add(new ExtendedShapelessRecipes(par1ItemStack, var3));
}
public ItemStack findMatchingRecipe(InventoryCrafting inv, World world)
{
for(int i = 0; i < this.recipes.size(); i++)
{
IRecipe recipe = this.recipes.get(i);
if(recipe.matches(inv, world))
return recipe.getCraftingResult(inv);
}
return null;
}
public List<IRecipe> getRecipeList()
{
return this.recipes;
}
public static void addRecipe(ItemStack output, Object ... input)
{
ExtendedCraftingManager.getInstance().addExtendedRecipe(output, input);
}
public static void addShapelessRecipe(ItemStack output, Object ... input)
{
ExtendedCraftingManager.getInstance().addExtendedShapelessRecipe(output, input);
}
}
@@ -0,0 +1,103 @@
package naruto1310.extendedWorkbench.crafting;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ExtendedShapedRecipes implements IExtendedRecipe
{
private int maxRecipeSize = 6;
/** How many horizontal slots this recipe is wide. */
private int recipeWidth;
/** How many vertical slots this recipe uses. */
private int recipeHeight;
/** Is a array of ItemStack that composes the recipe. */
private ItemStack[] recipeItems;
/** Is the ItemStack that you get when craft the recipe. */
private ItemStack recipeOutput;
public ExtendedShapedRecipes(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)
{
this.recipeWidth = par1;
this.recipeHeight = par2;
this.recipeItems = par3ArrayOfItemStack;
this.recipeOutput = par4ItemStack;
}
@Override
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
@Override
public boolean matches(InventoryCrafting par1InventoryCrafting, World world)
{
for(int x = 0; x <= this.maxRecipeSize - this.recipeWidth; ++x)
for(int y = 0; y <= this.maxRecipeSize - this.recipeHeight; ++y)
if(this.checkMatch(par1InventoryCrafting, x, y, true) || this.checkMatch(par1InventoryCrafting, x, y, false))
return true;
return false;
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int x, int y, boolean mirrored)
{
for(int i = 0; i < this.maxRecipeSize; ++i)
{
for(int j = 0; j < this.maxRecipeSize; ++j)
{
int var7 = i - x;
int var8 = j - y;
ItemStack stackFound = null;
if(var7 >= 0 && var8 >= 0 && var7 < this.recipeWidth && var8 < this.recipeHeight)
if(mirrored)
stackFound = this.recipeItems[this.recipeWidth - var7 - 1 + var8 * this.recipeWidth];
else
stackFound = this.recipeItems[var7 + var8 * this.recipeWidth];
ItemStack stackExcpected = par1InventoryCrafting.getStackInRowAndColumn(i, j);
if(stackFound == null && stackExcpected == null)
continue;
if((stackExcpected == null && stackFound != null) || (stackExcpected != null && stackFound == null))
return false;
if(stackFound.getItem() != stackExcpected.getItem())
return false;
if(stackFound.getItemDamage() != 32767 && stackFound.getItemDamage() != stackExcpected.getItemDamage())
return false;
}
}
return true;
}
/**
* Returns an Item that is the result of this recipe
*/
@Override
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.getRecipeOutput().copy();
}
/**
* Returns the size of the recipe area
*/
@Override
public int getRecipeSize()
{
return this.recipeWidth * this.recipeHeight;
}
}
@@ -0,0 +1,92 @@
package naruto1310.extendedWorkbench.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ExtendedShapelessRecipes implements IExtendedRecipe
{
private int maxRecipeSize = 6;
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
/** Is a List of ItemStack that composes the recipe. */
private final List<ItemStack> recipeItems;
public ExtendedShapelessRecipes(ItemStack par1ItemStack, List<ItemStack> par2List)
{
this.recipeOutput = par1ItemStack;
this.recipeItems = par2List;
}
@Override
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
@Override
public boolean matches(InventoryCrafting par1InventoryCrafting, World world)
{
ArrayList<ItemStack> var2 = new ArrayList<ItemStack>(this.recipeItems);
for (int var3 = 0; var3 < this.maxRecipeSize; ++var3)
{
for (int var4 = 0; var4 < this.maxRecipeSize; ++var4)
{
ItemStack var5 = par1InventoryCrafting.getStackInRowAndColumn(var4, var3);
if (var5 != null)
{
boolean var6 = false;
Iterator<ItemStack> var7 = var2.iterator();
while (var7.hasNext())
{
ItemStack var8 = var7.next();
if (var5 == var8 && (var8.getItemDamage() == 32767 || var5.getItemDamage() == var8.getItemDamage()))
{
var6 = true;
var2.remove(var8);
break;
}
}
if (!var6)
{
return false;
}
}
}
}
return var2.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
@Override
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.recipeOutput.copy();
}
/**
* Returns the size of the recipe area
*/
@Override
public int getRecipeSize()
{
return this.recipeItems.size();
}
}
@@ -0,0 +1,8 @@
package naruto1310.extendedWorkbench.crafting;
import net.minecraft.item.crafting.IRecipe;
public interface IExtendedRecipe extends IRecipe
{
}