/
RecipesCompressor.java
205 lines (178 loc) · 6.32 KB
/
RecipesCompressor.java
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*******************************************************************************
* Copyright (c) 2015, Superloup10
*
* Wolf's Addons is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* https://www.dropbox.com/s/6l16rc7b1aks211/MMPL-1.0.txt
******************************************************************************/
package fr.wolf.addons.common.recipe;
import fr.wolf.addons.common.item.WolfItemList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
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.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
public final class RecipesCompressor
{
private static final RecipesCompressor instance = new RecipesCompressor();
private List recipes = new ArrayList();
private RecipesCompressor()
{
this.addRecipe(new ItemStack(WolfItemList.redstoneIngot, 1), new Object[] {"XXX", 'X', Items.redstone});
this.addRecipe(new ItemStack(WolfItemList.lapisIngot, 1), new Object[] {"XXX", 'X', new ItemStack(Items.dye, 1, 4)});
this.addRecipe(new ItemStack(WolfItemList.emeraldIngot, 1), new Object[] {"XXX", 'X', Items.emerald});
this.addRecipe(new ItemStack(WolfItemList.silverIngot, 1), new Object[] {"XXX", 'X', WolfItemList.silverDust});
Collections.sort(this.recipes, new RecipesSorterCompressor(this));
}
public static RecipesCompressor getInstance()
{
return instance;
}
void addRecipe(ItemStack par1ItemStack, Object... par2ArrayOfObj)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if(par2ArrayOfObj[i] instanceof String[])
{
String[] astring = ((String[])par2ArrayOfObj[i++]);
for(int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while(par2ArrayOfObj[i] instanceof String)
{
String s2 = (String)par2ArrayOfObj[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for(hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2)
{
Character character = (Character)par2ArrayOfObj[i];
ItemStack itemstack1 = null;
if(par2ArrayOfObj[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
}
else if(par2ArrayOfObj[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
}
else if(par2ArrayOfObj[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)par2ArrayOfObj[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;
}
}
this.recipes.add(new ShapedRecipesCompressor(j, k, aitemstack, par1ItemStack));
}
void addShapelessRecipe(ItemStack par1ItemStack, Object... par2ArrayOfObj)
{
ArrayList arraylist = new ArrayList();
Object[] aobject = par2ArrayOfObj;
int i = par2ArrayOfObj.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 RuntimeException("Invalid shapeless recipy!");
}
arraylist.add(new ItemStack((Block)object1));
}
}
this.recipes.add(new ShapelessRecipes(par1ItemStack, arraylist));
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
for(j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)
{
ItemStack itemstack2 = par1InventoryCrafting.getStackInSlot(j);
if(itemstack2 != null)
{
if(i == 0)
{
itemstack = itemstack2;
}
if(i == 1)
{
itemstack1 = itemstack2;
}
++i;
}
}
if(i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable())
{
Item item = itemstack.getItem();
int j1 = item.getMaxDamage() - itemstack.getItemDamage();
int k = item.getMaxDamage() - itemstack1.getItemDamage();
int l = j1 + k + item.getMaxDamage() * 5 / 100;
int i1 = item.getMaxDamage() - l;
if(i1 < 0)
{
i1 = 0;
}
return new ItemStack(itemstack.getItem(), 1, i1);
}
else
{
for(j = 0; j < this.recipes.size(); ++j)
{
IRecipe irecipe = (IRecipe)this.recipes.get(j);
if(irecipe.matches(par1InventoryCrafting, par2World))
{
return irecipe.getCraftingResult(par1InventoryCrafting);
}
}
return null;
}
}
public List getRecipeList()
{
return this.recipes;
}
}