-
Notifications
You must be signed in to change notification settings - Fork 754
/
ToolStationGuiHelper.java
298 lines (251 loc) · 11.4 KB
/
ToolStationGuiHelper.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
package tconstruct.tools.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import tconstruct.library.accessory.AccessoryCore;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.DualHarvestTool;
import tconstruct.library.tools.HarvestTool;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.util.HarvestLevels;
import tconstruct.library.weaponry.AmmoWeapon;
import tconstruct.library.weaponry.IAmmo;
import tconstruct.library.weaponry.ProjectileWeapon;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public final class ToolStationGuiHelper {
// non-instantiable
private ToolStationGuiHelper() {}
private static final FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRenderer;
private static int xPos, yPos;
private static final DecimalFormat df = new DecimalFormat("#.##");
private static void newline()
{
yPos += 10;
}
private static void write(String s)
{
fontRendererObj.drawString(s, xPos, yPos, 0xffffffff);
newline();
}
public static void drawToolStats (ItemStack stack, int x, int y)
{
String name = stack.getItem() instanceof ToolCore ? ((ToolCore) stack.getItem()).getLocalizedToolName() : stack.getDisplayName();
Item item = stack.getItem();
NBTTagCompound tags = stack.getTagCompound();
Collection<String> categories = new LinkedList<String>();
// initialize drawing variables
xPos = x;
yPos = y + 8;
// get the correct tags
if(item instanceof IModifyable) {
IModifyable modifyable = (IModifyable) item;
tags = tags.getCompoundTag(modifyable.getBaseTagName());
categories = Arrays.asList(modifyable.getTraits());
}
drawCenteredString(fontRendererObj, "\u00A7n" + name, xPos + 55, yPos, 0xffffffff);
newline();
newline();
// does it have ammo instead of durability?
if(item instanceof IAmmo)
drawAmmo((IAmmo) item, stack);
// regular durability?
else if(item instanceof ToolCore || item instanceof ArmorCore)
drawDurability(tags);
// tools
if(item instanceof ToolCore) {
ToolCore tool = (ToolCore) item;
// DualHarvest tool?
if (categories.contains("dualharvest"))
drawDualHarvestStats(tool, tags);
// or regular Harvest tool?
else if (categories.contains("harvest"))
drawHarvestStats(tool, tags);
// weapon?
if (categories.contains("weapon"))
drawWeaponStats(tool, tags);
// throwing weapon?
if (categories.contains("thrown") && tool instanceof AmmoWeapon)
drawThrowingWeaponStats((AmmoWeapon) tool, tags);
// projectile weapon?
if (categories.contains("bow") && tool instanceof ProjectileWeapon)
drawProjectileWeaponStats((ProjectileWeapon) tool, tags, stack);
// projectile?
if (categories.contains("projectile"))
drawProjectileStats(tags);
}
// armor
if(item instanceof ArmorCore)
{
ArmorCore armor = (ArmorCore) item;
drawArmorStats(armor, tags, stack);
}
// Accessory
if(item instanceof AccessoryCore)
{
AccessoryCore accessory = (AccessoryCore) item;
drawAccessoryStats(accessory, tags);
}
newline();
// Modifiers
drawModifiers(tags);
}
private static void drawDurability(NBTTagCompound tags) {
final int durability = tags.getInteger("Damage");
final int maxDur = tags.getInteger("TotalDurability");
final int availableDurability = maxDur - durability;
// big durabilities have to split to 2 lines
if (maxDur >= 10000)
{
write(StatCollector.translateToLocal("gui.toolstation1"));
write("- " + availableDurability + "/" + maxDur);
}
else
{
write(StatCollector.translateToLocal("gui.toolstation2") + availableDurability + "/" + maxDur);
}
}
private static void drawAmmo(IAmmo ammoItem, ItemStack stack)
{
final int max = ammoItem.getMaxAmmo(stack);
final int current = ammoItem.getAmmoCount(stack);
write(StatCollector.translateToLocal("gui.toolstation21") + current + "/" + max);
}
private static void drawModifiers(NBTTagCompound tags)
{
int modifiers = tags.getInteger("Modifiers");
// remaining modifiers
if (modifiers != 0)
write(StatCollector.translateToLocal("gui.toolstation18") + modifiers);
// Modifier-header (if we have modifiers)
if (tags.hasKey("ModifierTip1")) {
write(StatCollector.translateToLocal("gui.toolstation17"));
String tooltip = "ModifierTip";
int tipNum = 1;
while (tags.hasKey(tooltip + tipNum)) {
write("- " + tags.getString(tooltip + tipNum));
tipNum++;
}
}
}
private static void drawHarvestStats(ToolCore tool, NBTTagCompound tags)
{
float mineSpeed = AbilityHelper.calcToolSpeed(tool, tags);
float stoneboundSpeed = AbilityHelper.calcStoneboundBonus(tool, tags);
write(StatCollector.translateToLocal("gui.toolstation14") + df.format(mineSpeed));
if(stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
write(bloss + df.format(stoneboundSpeed));
}
write(StatCollector.translateToLocal("gui.toolstation15") + HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel")));
}
private static void drawDualHarvestStats(ToolCore tool, NBTTagCompound tags)
{
float mineSpeed = AbilityHelper.calcDualToolSpeed(tool, tags, false);
float mineSpeed2 = AbilityHelper.calcDualToolSpeed(tool, tags, true);
float stoneboundSpeed = AbilityHelper.calcStoneboundBonus(tool, tags);
write(StatCollector.translateToLocal("gui.toolstation12"));
write("- " + df.format(mineSpeed) + ", " + df.format(mineSpeed2));
if (stoneboundSpeed != 0)
{
String bloss = stoneboundSpeed > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
write(bloss + df.format(stoneboundSpeed));
}
write(StatCollector.translateToLocal("gui.toolstation13"));
write("- " + HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel")) + ", " + HarvestLevels.getHarvestLevelName(tags.getInteger("HarvestLevel2")));
}
private static void drawWeaponStats(ToolCore tool, NBTTagCompound tags)
{
// DAMAGE
int attack = (tags.getInteger("Attack"));
// factor in Stonebound
float stoneboundDamage = -AbilityHelper.calcStoneboundBonus(tool, tags);
attack += stoneboundDamage;
attack *= tool.getDamageModifier();
if (attack < 1)
attack = 1;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
write(StatCollector.translateToLocal("gui.toolstation3") + attack / 2 + heart);
else
write(StatCollector.translateToLocal("gui.toolstation3") + df.format(attack / 2f) + heart);
if (stoneboundDamage != 0)
{
heart = stoneboundDamage == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
String bloss = stoneboundDamage > 0 ? StatCollector.translateToLocal("gui.toolstation4") : StatCollector.translateToLocal("gui.toolstation5");
write(bloss + df.format(stoneboundDamage / 2f) + heart);
}
}
private static void drawThrowingWeaponStats(AmmoWeapon weapon, NBTTagCompound tags) {
float attackf = (tags.getInteger("Attack"));
attackf *= weapon.getDamageModifier();
attackf *= weapon.getProjectileSpeed();
if (attackf < 1)
attackf = 1;
int attack = (int)attackf;
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
write(StatCollector.translateToLocal("gui.toolstation23") + attack / 2 + heart);
else
write(StatCollector.translateToLocal("gui.toolstation23") + df.format(attack / 2f) + heart);
}
private static void drawProjectileWeaponStats(ProjectileWeapon weapon, NBTTagCompound tags, ItemStack stack)
{
// drawspeed
final int drawSpeed = weapon.getWindupTime(stack);
final float trueDraw = drawSpeed / 20f;
write(StatCollector.translateToLocal("gui.toolstation6") + df.format(trueDraw) + "s");
// flightspeed
final float flightSpeed = weapon.getProjectileSpeed(stack);
write(StatCollector.translateToLocal("gui.toolstation7") + df.format(flightSpeed) + "x");
}
private static void drawProjectileStats(NBTTagCompound tags)
{
// weight
final float weight = tags.getFloat("Mass");
write(StatCollector.translateToLocal("gui.toolstation8") + df.format(weight));
// accuracy
final float accuracy = tags.getFloat("Accuracy");
write(StatCollector.translateToLocal("gui.toolstation9") + df.format(accuracy) + "%");
// breakchance
final float breakChance = tags.getFloat("BreakChance");
write(StatCollector.translateToLocal("gui.toolstation22") + df.format(breakChance) + "%");
}
private static void drawArmorStats(ArmorCore armor, NBTTagCompound tags, ItemStack stack)
{
// Damage reduction
double damageReduction = tags.getDouble("DamageReduction");
if(damageReduction > 0)
write(StatCollector.translateToLocal("gui.toolstation19") + df.format(damageReduction));
// Protection
double protection = armor.getProtection(stack);
double maxProtection = tags.getDouble("MaxDefense");
write(StatCollector.translateToLocal("gui.toolstation20") + df.format(protection) + "/" + df.format(maxProtection));
}
private static void drawAccessoryStats(AccessoryCore core, NBTTagCompound tags)
{
if(tags.hasKey("MiningSpeed")) {
float mineSpeed = tags.getInteger("MiningSpeed");
float trueSpeed = mineSpeed / (100f);
write(StatCollector.translateToLocal("gui.toolstation16") + trueSpeed);
}
}
/**
* Renders the specified text to the screen, center-aligned.
* Copied out of GUI
*/
public static void drawCenteredString(FontRenderer p_73732_1_, String p_73732_2_, int p_73732_3_, int p_73732_4_, int p_73732_5_)
{
p_73732_1_.drawStringWithShadow(p_73732_2_, p_73732_3_ - p_73732_1_.getStringWidth(p_73732_2_) / 2, p_73732_4_, p_73732_5_);
}
}