-
Notifications
You must be signed in to change notification settings - Fork 755
/
RecipeHandlerToolMaterials.java
258 lines (235 loc) · 8.68 KB
/
RecipeHandlerToolMaterials.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package tconstruct.plugins.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.crafting.PatternBuilder.ItemKey;
import tconstruct.library.crafting.PatternBuilder.MaterialSet;
import tconstruct.library.tools.DynamicToolPart;
import tconstruct.library.tools.ToolMaterial;
import tconstruct.library.util.HarvestLevels;
import tconstruct.library.util.IToolPart;
import tconstruct.tools.items.ToolPart;
import tconstruct.util.config.PHConstruct;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
public class RecipeHandlerToolMaterials extends RecipeHandlerBase
{
public class CachedToolMaterialsRecipe extends CachedBaseRecipe
{
public List<PositionedStack> toolParts;
public ToolMaterial material;
public CachedToolMaterialsRecipe(List<ItemStack> toolParts, int materialID)
{
this.toolParts = new ArrayList<PositionedStack>();
for (ItemStack stack : toolParts)
{
this.toolParts.add(new PositionedStack(stack, 10, 10));
}
this.material = TConstructRegistry.getMaterial(materialID);
}
@Override
public PositionedStack getIngredient ()
{
return this.toolParts.get((cycleticks / 20) % this.toolParts.size());
}
@Override
public PositionedStack getResult ()
{
return null;
}
}
@Override
public String getRecipeName ()
{
return "Tool Materials";
}
@Override
public String getRecipeID ()
{
return "tconstruct.tools.materials";
}
@Override
public String getGuiTexture ()
{
return "tinker:textures/gui/nei/toolmaterials.png";
}
@Override
public int recipiesPerPage ()
{
return 1;
}
@Override
public void drawBackground (int recipe)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiDraw.changeTexture(this.getGuiTexture());
GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 160, 130);
}
@Override
public void loadTransferRects ()
{
this.transferRects.add(new RecipeTransferRect(new Rectangle(10, 30, 16, 16), this.getRecipeID(), new Object[0]));
}
@Override
public void drawExtras (int recipe)
{
CachedToolMaterialsRecipe crecipe = (CachedToolMaterialsRecipe) this.arecipes.get(recipe);
if (crecipe.material != null)
{
GuiDraw.drawString(EnumChatFormatting.BOLD + crecipe.material.localizedName(), 35, 10, 0x404040, false);
GuiDraw.drawString(StatCollector.translateToLocal("gui.partcrafter4") + crecipe.material.durability, 35, 20, 0x404040, false);
GuiDraw.drawString(StatCollector.translateToLocal("gui.partcrafter5") + crecipe.material.handleModifier + "x", 35, 30, 0x404040, false);
GuiDraw.drawString(StatCollector.translateToLocal("gui.partcrafter11") + Math.round(crecipe.material.durability * crecipe.material.handleModifier), 35, 40, 0x404040, false);
GuiDraw.drawString(StatCollector.translateToLocal("gui.partcrafter6") + crecipe.material.miningspeed / 100F, 35, 50, 0x404040, false);
GuiDraw.drawString(StatCollector.translateToLocal("gui.partcrafter7") + HarvestLevels.getHarvestLevelName(crecipe.material.harvestLevel), 35, 60, 0x404040, false);
String heart = crecipe.material.attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (crecipe.material.attack() % 2 == 0)
{
GuiDraw.drawString(StatCollector.translateToLocal("gui.partcrafter10") + crecipe.material.attack / 2 + heart, 35, 70, 0x404040, false);
}
else
{
GuiDraw.drawString(StatCollector.translateToLocal("gui.partcrafter11") + crecipe.material.attack / 2F + heart, 35, 70, 0x404040, false);
}
int abilityY = 85;
if (crecipe.material.reinforced > 0)
{
GuiDraw.drawString(getReinforcedString(crecipe.material.reinforced), 35, 85, 0x404040, false);
abilityY += 10;
}
String ability = crecipe.material.ability();
if (ability != null)
{
if (crecipe.material.stonebound != 0)
{
GuiDraw.drawString(ability + " (" + Math.abs(crecipe.material.stonebound) + ")", 35, abilityY, 0x404040, false);
}
else
{
GuiDraw.drawString(ability, 35, abilityY, 0x404040, false);
}
}
}
}
@Override
public void loadCraftingRecipes (String outputId, Object... results)
{
if (outputId.equals(this.getRecipeID()))
{
ToolMaterial mat;
for (int matID : TConstructRegistry.toolMaterials.keySet())
{
List<ItemStack> toolParts = new ArrayList<ItemStack>();
mat = TConstructRegistry.toolMaterials.get(matID);
for (ItemKey key : PatternBuilder.instance.materials)
{
MaterialSet set = PatternBuilder.instance.materialSets.get(key.key);
if (set.materialID == matID)
{
ItemStack stack = new ItemStack(key.item, 1, key.damage);
toolParts.add(stack);
}
}
for (List list : TConstructRegistry.patternPartMapping.keySet())
{
if ((Integer) list.get(2) == matID)
{
toolParts.add(TConstructRegistry.patternPartMapping.get(list));
}
}
if (!PHConstruct.craftMetalTools)
{
for (CastingRecipe recipe : TConstructRegistry.getTableCasting().getCastingRecipes())
{
ItemStack castResult = recipe.getResult();
if (castResult.getItem() instanceof IToolPart)
{
if (((IToolPart) castResult.getItem()).getMaterialID(castResult) == matID)
{
toolParts.add(castResult);
}
}
}
}
if(toolParts.size() > 0)
this.arecipes.add(new CachedToolMaterialsRecipe(toolParts, matID));
}
}
else
{
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadUsageRecipes (ItemStack ingred)
{
if (ingred.getItem() instanceof ToolPart || ingred.getItem() instanceof DynamicToolPart)
{
int materialID = ((IToolPart) ingred.getItem()).getMaterialID(ingred);
if (materialID >= 0)
{
List toolParts = getSingleList(ingred);
if(toolParts.size() > 0)
this.arecipes.add(new CachedToolMaterialsRecipe(toolParts, materialID));
}
}
else if (PatternBuilder.instance.getPartID(ingred) < Short.MAX_VALUE)
{
int materialID = PatternBuilder.instance.getPartID(ingred);
List toolParts = getSingleList(ingred);
if(toolParts.size() > 0)
this.arecipes.add(new CachedToolMaterialsRecipe(toolParts, materialID));
}
else
{
super.loadUsageRecipes(ingred);
}
}
public static String getReinforcedString (int reinforced)
{
if (reinforced > 9)
return "Unbreakable";
String ret = "Reinforced ";
switch (reinforced)
{
case 1:
ret += "I";
break;
case 2:
ret += "II";
break;
case 3:
ret += "III";
break;
case 4:
ret += "IV";
break;
case 5:
ret += "V";
break;
case 6:
ret += "VI";
break;
case 7:
ret += "VII";
break;
case 8:
ret += "VIII";
break;
case 9:
ret += "IX";
break;
default:
ret += "X";
break;
}
return ret;
}
}