-
Notifications
You must be signed in to change notification settings - Fork 755
/
CraftingStationGui.java
383 lines (341 loc) · 16.5 KB
/
CraftingStationGui.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
package tconstruct.client.gui;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import tconstruct.blocks.logic.CraftingStationLogic;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.tools.ToolCore;
public class CraftingStationGui extends GuiContainer
{
public boolean active;
public String toolName;
public GuiTextField text;
public String title, body = "";
CraftingStationLogic logic;
public CraftingStationGui(InventoryPlayer inventory, CraftingStationLogic logic, World world, int x, int y, int z)
{
super(logic.getGuiContainer(inventory, world, x, y, z));
this.logic = logic;
//text = new GuiTextField(this.fontRenderer, this.xSize / 2 - 5, 8, 30, 12);
//this.text.setText("");
title = "\u00A7nRepair and Modification";
body = "The main way to repair or change your tools or armor.\n\nPlace an item and a material on the left to get started.";
toolName = "";
}
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
this.fontRenderer.drawString(StatCollector.translateToLocal(logic.tinkerTable ? "crafters.TinkerTable" : logic.getInvName()), 8, 6, 0x202020);
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 0x202020);
if (logic.chest != null)
this.fontRenderer.drawString(StatCollector.translateToLocal(logic.chest.get().getInvName()), -108, this.ySize - 160, 0x202020);
//this.fontRenderer.drawString(toolName + "_", this.xSize / 2 - 18, 8, 0xffffff);
if (logic.tinkerTable)
{
if (logic.isStackInSlot(0))
drawToolStats();
else
drawToolInformation();
}
}
void drawToolStats ()
{
ItemStack stack = logic.getStackInSlot(0);
if (stack.getItem() instanceof ToolCore)
{
ToolCore tool = (ToolCore) stack.getItem();
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
this.drawCenteredString(fontRenderer, "\u00A7n" + tool.getToolName(), xSize + 63, 8, 0xffffff);
drawModularToolStats(stack, tool, tags);
}
else if (stack.getItem() instanceof ArmorCore)
{
ArmorCore armor = (ArmorCore) stack.getItem();
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("TinkerArmor");
this.drawCenteredString(fontRenderer, "\u00A7n" + StatCollector.translateToLocal("armortype."+armor.getArmorName()), xSize + 63, 8, 0xffffff);
drawModularArmorStats(stack, armor, tags);
}
}
void drawModularArmorStats (ItemStack stack, ArmorCore tool, NBTTagCompound tags)
{
int modifiers = tags.getInteger("Modifiers");
int base = 24;
int offset = 0;
if (modifiers > 0)
{
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation18") + tags.getInteger("Modifiers"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
}
void drawModularToolStats (ItemStack stack, ToolCore tool, NBTTagCompound tags)
{
List categories = Arrays.asList(tool.toolCategories());
final int durability = tags.getInteger("Damage");
final int maxDur = tags.getInteger("TotalDurability");
int availableDurability = maxDur - durability;
//Durability
int base = 24;
int offset = 0;
if (maxDur > 0)
{
if (maxDur >= 10000)
{
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation1"), xSize + 8, base + offset * 11, 0xffffff);
offset++;
fontRenderer.drawString("- " + availableDurability + "/" + maxDur, xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
else
{
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation2") + availableDurability + "/" + maxDur, xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
}
final float stonebound = tags.getFloat("Shoddy");
//Attack
if (categories.contains("weapon"))
{
int attack = (int) (tags.getInteger("Attack"));
float stoneboundDamage = (float) Math.log(durability / 72f + 1) * -2 * stonebound;
attack += stoneboundDamage;
attack *= tool.getDamageModifier();
if (attack < 1)
attack = 1;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter9") : StatCollector.translateToLocal("gui.partcrafter10");
if (attack % 2 == 0)
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation3") + attack / 2 + heart, xSize + 8, base + offset * 10, 0xffffff);
else
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation3") + attack / 2f + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
if (stoneboundDamage != 0)
{
heart = stoneboundDamage == 2 ? StatCollector.translateToLocal("gui.partcrafter9") : StatCollector.translateToLocal("gui.partcrafter10");
String bloss = stoneboundDamage > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
this.fontRenderer.drawString(bloss + (int) stoneboundDamage / 2 + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
offset++;
}
if (categories.contains("bow"))
{
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
int drawSpeed = tags.getInteger("DrawSpeed");
float flightSpeed = tags.getFloat("FlightSpeed");
float trueDraw = drawSpeed / 20f * flightSpeed;
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation6") + df.format(trueDraw) + "s", xSize + 8, base + offset * 10, 0xffffff);
offset++;
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation7") + df.format(flightSpeed) + "x", xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
}
if (categories.contains("ammo"))
{
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
int attack = (int) (tags.getInteger("Attack"));
float mass = tags.getFloat("Mass");
float shatter = tags.getFloat("BreakChance");
float accuracy = tags.getFloat("Accuracy");
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation10"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter9") : StatCollector.translateToLocal("gui.partcrafter10");
if (attack % 2 == 0)
this.fontRenderer.drawString("- " + attack / 2 + heart, xSize + 8, base + offset * 10, 0xffffff);
else
this.fontRenderer.drawString("- " + attack / 2f + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
int minAttack = attack;
int maxAttack = attack * 2;
heart = StatCollector.translateToLocal("gui.partcrafter10");
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation11"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
this.fontRenderer.drawString(df.format(minAttack / 2f) + "-" + df.format(maxAttack / 2f) + heart, xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation8") + df.format(mass), xSize + 8, base + offset * 10, 0xffffff);
offset++;
this.fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation9") + df.format(accuracy - 4) + "%", xSize + 8, base + offset * 10, 0xffffff);
offset++;
/*this.fontRenderer.drawString("Chance to break: " + df.format(shatter)+"%", xSize + 8, base + offset * 10, 0xffffff);
offset++;*/
offset++;
}
//Mining
if (categories.contains("dualharvest"))
{
float mineSpeed = tags.getInteger("MiningSpeed") / 100f;
float mineSpeed2 = tags.getInteger("MiningSpeed2") / 100f;
float stoneboundSpeed = (float) Math.log(durability / 90f + 1) * 2 * stonebound;
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
float trueSpeed = mineSpeed + stoneboundSpeed;
float trueSpeed2 = mineSpeed + stoneboundSpeed;
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation12"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
fontRenderer.drawString("- " + df.format(trueSpeed) + ", " + df.format(trueSpeed2), xSize + 8, base + offset * 10, 0xffffff);
offset++;
if (stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
fontRenderer.drawString(bloss + df.format(stoneboundSpeed), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
offset++;
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation13"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
fontRenderer
.drawString("- " + getHarvestLevelName(tags.getInteger("HarvestLevel")) + ", " + getHarvestLevelName(tags.getInteger("HarvestLevel2")), xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
}
else if (categories.contains("harvest"))
{
float mineSpeed = tags.getInteger("MiningSpeed");
int heads = 1;
if (tags.hasKey("MiningSpeed2"))
{
mineSpeed += tags.getInteger("MiningSpeed2");
heads++;
}
if (tags.hasKey("MiningSpeedHandle"))
{
mineSpeed += tags.getInteger("MiningSpeedHandle");
heads++;
}
if (tags.hasKey("MiningSpeedExtra"))
{
mineSpeed += tags.getInteger("MiningSpeedExtra");
heads++;
}
float trueSpeed = mineSpeed / (heads * 100f);
float stoneboundSpeed = (float) Math.log(durability / 90f + 1) * 2 * stonebound;
DecimalFormat df = new DecimalFormat("##.##");
df.setRoundingMode(RoundingMode.DOWN);
trueSpeed += stoneboundSpeed;
if (trueSpeed < 0)
trueSpeed = 0;
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation14") + df.format(trueSpeed), xSize + 8, base + offset * 10, 0xffffff);
offset++;
if (stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
fontRenderer.drawString(bloss + df.format(stoneboundSpeed), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation15") + getHarvestLevelName(tags.getInteger("HarvestLevel")), xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
}
else if (categories.contains("utility"))
{
float mineSpeed = tags.getInteger("MiningSpeed");
float trueSpeed = mineSpeed / (100f);
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation16") + trueSpeed, xSize + 8, base + offset * 10, 0xffffff);
offset++;
offset++;
}
int modifiers = tags.getInteger("Modifiers");
if (modifiers > 0)
{
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation18") + tags.getInteger("Modifiers"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
if (tags.hasKey("Tooltip1"))
{
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation17"), xSize + 8, base + offset * 10, 0xffffff);
}
boolean displayToolTips = true;
int tipNum = 0;
while (displayToolTips)
{
tipNum++;
String tooltip = "ModifierTip" + tipNum;
if (tags.hasKey(tooltip))
{
String tipName = tags.getString(tooltip);
fontRenderer.drawString("- " + tipName, xSize + 8, base + (offset + tipNum) * 10, 0xffffff);
}
else
displayToolTips = false;
}
}
protected String getHarvestLevelName (int num)
{
switch (num)
{
case 0:
return StatCollector.translateToLocal("gui.partcrafter.mining1");
case 1:
return StatCollector.translateToLocal("gui.partcrafter.mining2");
case 2:
return StatCollector.translateToLocal("gui.partcrafter.mining3");
case 3:
return StatCollector.translateToLocal("gui.partcrafter.mining4");
case 4:
return StatCollector.translateToLocal("gui.partcrafter.mining5");
case 5:
return StatCollector.translateToLocal("gui.partcrafter.mining6");
default:
return String.valueOf(num);
}
}
void drawToolInformation ()
{
this.drawCenteredString(fontRenderer, title, xSize + 63, 8, 0xffffff);
fontRenderer.drawSplitString(body, xSize + 8, 24, 115, 0xffffff);
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/tinkertable.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
private static final ResourceLocation chest = new ResourceLocation("tinker", "textures/gui/chestside.png");
@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
// Draw the background
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, this.xSize, this.ySize);
if (active)
{
this.drawTexturedModalRect(cornerX + 62, cornerY, 0, this.ySize, 112, 22);
}
this.mc.getTextureManager().bindTexture(icons);
// Draw the slots
if (logic.tinkerTable && !logic.isStackInSlot(5))
this.drawTexturedModalRect(cornerX + 47, cornerY + 33, 0, 233, 18, 18);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(icons);
//Draw chest side
if (logic.chest != null)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(chest);
if (logic.doubleChest == null)
this.drawTexturedModalRect(cornerX - 116, cornerY, 0, 0, 121, this.ySize);
else
this.drawTexturedModalRect(cornerX - 116, cornerY, 125, 0, 122, this.ySize + 21);
}
// Draw description
if (logic.tinkerTable)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(description);
cornerX = (this.width + this.xSize) / 2;
cornerY = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, 126, this.ySize + 30);
}
}
}