-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRecipesList.java
More file actions
151 lines (134 loc) · 4.43 KB
/
Copy pathRecipesList.java
File metadata and controls
151 lines (134 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package com.custommods.ai;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.lwjgl.Sys;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.RecipeBookCloning;
import net.minecraft.item.crafting.RecipesArmorDyes;
import net.minecraft.item.crafting.RecipesMapExtending;
import net.minecraft.item.crafting.RecipesTools;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.ShapedOreRecipe;
public class RecipesList {
private static List list = CraftingManager.getInstance().getRecipeList();
private static Map smeltingList = FurnaceRecipes.smelting().getSmeltingList();
///Get the ShapedRecipes from the list
public static IRecipe getRecipes(ItemStack item){
for (Object object : list) {
if (((IRecipe)object).getRecipeOutput()!=null){
if (Util.isContain(((IRecipe)object).getRecipeOutput(),item)){
return ((IRecipe)object);
}
}
}
return null;
}
///Get the list of ingredient of the recipe
public static List<ItemStack> getIngredientList(ItemStack item){
List<ItemStack> toReturn = new ArrayList<ItemStack>();
IRecipe irecipe = getRecipes(item);
if (irecipe == null){
return null;
}
if (irecipe instanceof ShapedRecipes){
ShapedRecipes recipe = (ShapedRecipes) irecipe;
for (int i = 0 ; i < recipe.recipeItems.length ; i++){
if (toReturn.contains(recipe.recipeItems[i])){
for (ItemStack itemStack : toReturn) {
if (itemStack.getItem().equals(item.getItem())){
itemStack.stackSize++;
}
}
}
else{
toReturn.add(recipe.recipeItems[i].copy());
}
}
}
else if (irecipe instanceof ShapedOreRecipe){
ShapedOreRecipe recipe = (ShapedOreRecipe) irecipe;
for (int i = 0 ; i < recipe.getInput().length ; i++){
if (recipe.getInput()[i] == null){
}
else if (recipe.getInput()[i] instanceof ArrayList){
ArrayList<ItemStack> itemList = (ArrayList<ItemStack>)recipe.getInput()[i];
for (ItemStack itemInList : itemList) {
if (itemInList !=null){
boolean find = false;
for (ItemStack itemStack : toReturn) {
if (itemStack.getItem().equals(itemInList.getItem())){
find = true;
itemStack.stackSize++;
}
}
if (!find){
toReturn.add((ItemStack) itemInList.copy());
}
}
}
}
else if (toReturn.contains(recipe.getInput()[i])){
for (ItemStack itemStack : toReturn) {
if (itemStack.getItem().equals(item.getItem())){
itemStack.stackSize++;
}
}
}
else{
toReturn.add((ItemStack)(recipe.getInput()[i]));
}
}
}
else if (irecipe instanceof ShapelessRecipes){
ShapelessRecipes recipe = (ShapelessRecipes) irecipe;
ArrayList<ItemStack> itemList = (ArrayList<ItemStack>)(recipe.recipeItems);
for (ItemStack itemInList : itemList) {
if (itemInList !=null){
boolean find = false;
for (ItemStack itemStack : toReturn) {
if (itemStack.getItem().equals(itemInList.getItem())){
find = true;
itemStack.stackSize++;
}
}
if (!find){
toReturn.add((ItemStack) itemInList.copy());
}
}
}
}
return toReturn;
}
///Get a item for the smelting
public static ItemStack getSmeltingItem(ItemStack outPut){
Iterator iterator = smeltingList.entrySet().iterator();
Entry entry = null;
do
{
if (!iterator.hasNext())
{
return null;
}
entry = (Entry)iterator.next();
}
while (!Util.idItemEqual(outPut, (ItemStack)entry.getValue()));
return (ItemStack)entry.getKey();
}
///Get the result item for the smelting
public static ItemStack getSmeltingResult(ItemStack item){
return FurnaceRecipes.smelting().getSmeltingResult(item);
}
}