-
Notifications
You must be signed in to change notification settings - Fork 755
/
PartCrafterGui.java
299 lines (264 loc) · 11.3 KB
/
PartCrafterGui.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
package tconstruct.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import tconstruct.blocks.logic.PartBuilderLogic;
import tconstruct.inventory.ActiveContainer;
import tconstruct.inventory.PartCrafterChestContainer;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.tools.ToolMaterial;
public class PartCrafterGui extends NewContainerGui
{
PartBuilderLogic logic;
String title, otherTitle = "";
boolean drawChestPart;
boolean hasTop, hasBottom;
ItemStack topMaterial, bottomMaterial;
ToolMaterial topEnum, bottomEnum;
public PartCrafterGui(InventoryPlayer inventoryplayer, PartBuilderLogic partlogic, World world, int x, int y, int z)
{
super((ActiveContainer) partlogic.getGuiContainer(inventoryplayer, world, x, y, z));
logic = partlogic;
drawChestPart = container instanceof PartCrafterChestContainer;
title = "\u00A7nTool Part Crafting";
}
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
this.fontRenderer.drawString(StatCollector.translateToLocal("crafters.PartBuilder"), 6, 6, 4210752);
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
if (drawChestPart)
this.fontRenderer.drawString(StatCollector.translateToLocal("inventory.PatternChest"), -108, this.ySize - 148, 4210752);
drawMaterialInformation();
}
void drawDefaultInformation ()
{
title = "\u00A7nTool Part Building";
this.drawCenteredString(fontRenderer, title, xSize + 63, 8, 16777215);
fontRenderer.drawSplitString("Place a pattern and a material on the left to get started.", xSize + 8, 24, 115, 16777215);
}
void drawMaterialInformation ()
{
ItemStack top = logic.getStackInSlot(2);
//ItemStack topResult = logic.getStackInSlot(4);
ItemStack bottom = logic.getStackInSlot(3);
//ItemStack bottomResult = logic.getStackInSlot(6);
if (topMaterial != top)
{
topMaterial = top;
int topID = PatternBuilder.instance.getPartID(top);
if (topID != Short.MAX_VALUE)// && topResult != null)
{
topEnum = TConstructRegistry.getMaterial(topID);
hasTop = true;
title = "\u00A7n" + topEnum.name();
}
else
hasTop = false;
}
if (bottomMaterial != bottom)
{
bottomMaterial = bottom;
int bottomID = PatternBuilder.instance.getPartID(bottom);
if (bottomID != Short.MAX_VALUE)// && bottomResult != null)
{
bottomEnum = TConstructRegistry.getMaterial(bottomID);
hasBottom = true;
otherTitle = "\u00A7n" + bottomEnum.name();
}
else
hasBottom = false;
}
int offset = 8;
if (hasTop)
{
this.drawCenteredString(fontRenderer, title, xSize + 63, offset, 16777215);
this.fontRenderer.drawString("Base Durability: " + topEnum.durability(), xSize + 8, offset + 16, 16777215);
this.fontRenderer.drawString("Handle Modifier: " + topEnum.handleDurability() + "x", xSize + 8, offset + 27, 16777215);
this.fontRenderer.drawString("Mining Speed: " + topEnum.toolSpeed() / 100f, xSize + 8, offset + 38, 16777215);
this.fontRenderer.drawString("Mining Level: " + getHarvestLevelName(topEnum.harvestLevel()), xSize + 8, offset + 49, 16777215);
int attack = topEnum.attack();
String heart = attack == 2 ? " Heart" : " Hearts";
if (attack % 2 == 0)
this.fontRenderer.drawString("Attack: " + attack / 2 + heart, xSize + 8, offset + 60, 0xffffff);
else
this.fontRenderer.drawString("Attack: " + attack / 2f + heart, xSize + 8, offset + 60, 0xffffff);
}
offset = 90;
if (hasBottom)
{
this.drawCenteredString(fontRenderer, otherTitle, xSize + 63, offset, 16777215);
this.fontRenderer.drawString("Base Durability: " + bottomEnum.durability(), xSize + 8, offset + 16, 16777215);
this.fontRenderer.drawString("Handle Modifier: " + bottomEnum.handleDurability() + "x", xSize + 8, offset + 27, 16777215);
this.fontRenderer.drawString("Mining Speed: " + bottomEnum.toolSpeed() / 100f, xSize + 8, offset + 38, 16777215);
this.fontRenderer.drawString("Mining Level: " + getHarvestLevelName(bottomEnum.harvestLevel()), xSize + 8, offset + 49, 16777215);
int attack = bottomEnum.attack();
String heart = attack == 2 ? " Heart" : " Hearts";
if (attack % 2 == 0)
this.fontRenderer.drawString("Attack: " + attack / 2 + heart, xSize + 8, offset + 60, 0xffffff);
else
this.fontRenderer.drawString("Attack: " + attack / 2f + heart, xSize + 8, offset + 60, 0xffffff);
}
if (!hasTop && !hasBottom)
drawDefaultInformation();
}
public static String getHarvestLevelName (int num)
{
switch (num)
{
case 0:
return "Stone";
case 1:
return "Iron";
case 2:
return "Redstone";
case 3:
return "Obsidian";
case 4:
return "Cobalt";
case 5:
return "Manyullyn";
default:
return String.valueOf(num);
}
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/toolparts.png");
private static final ResourceLocation minichest = new ResourceLocation("tinker", "textures/gui/patternchestmini.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
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);
// Draw Slots
this.drawTexturedModalRect(cornerX + 39, cornerY + 26, 0, 166, 98, 36);
if (!logic.isStackInSlot(0))
{
this.drawTexturedModalRect(cornerX + 39, cornerY + 26, 176, 0, 18, 18);
}
if (!logic.isStackInSlot(2))
{
this.drawTexturedModalRect(cornerX + 57, cornerY + 26, 176, 18, 18, 18);
}
if (!logic.isStackInSlot(1))
{
this.drawTexturedModalRect(cornerX + 39, cornerY + 44, 176, 0, 18, 18);
}
if (!logic.isStackInSlot(3))
{
this.drawTexturedModalRect(cornerX + 57, cornerY + 44, 176, 36, 18, 18);
}
// Draw chest
if (drawChestPart)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(minichest);
this.drawTexturedModalRect(cornerX - 116, cornerY + 11, 0, 0, this.xSize, this.ySize);
}
// Draw description
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, 126, 0, 126, this.ySize);
}
@Override
protected void mouseClicked (int mouseX, int mouseY, int clickNum)
{
boolean flag = clickNum == this.mc.gameSettings.keyBindPickBlock.keyCode + 100;
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
long l = Minecraft.getSystemTime();
this.field_94074_J = this.field_94072_H == slot && l - this.field_94070_G < 250L && this.field_94073_I == clickNum;
this.field_94068_E = false;
int offsetLeft = drawChestPart ? 108 : 0;
if (clickNum == 0 || clickNum == 1 || flag)
{
int i1 = this.guiLeft;
int j1 = this.guiTop;
boolean flag1 = mouseX < i1 - offsetLeft || mouseY < j1 || mouseX >= i1 + this.xSize || mouseY >= j1 + this.ySize;
int k1 = -1;
if (slot != null)
{
k1 = slot.slotNumber;
}
if (flag1)
{
k1 = -999;
}
if (this.mc.gameSettings.touchscreen && flag1 && this.mc.thePlayer.inventory.getItemStack() == null)
{
this.mc.displayGuiScreen((GuiScreen) null);
return;
}
if (k1 != -1)
{
if (this.mc.gameSettings.touchscreen)
{
if (slot != null && slot.getHasStack())
{
this.clickedSlot = slot;
this.draggedStack = null;
this.isRightMouseClick = clickNum == 1;
}
else
{
this.clickedSlot = null;
}
}
else if (!this.field_94076_q)
{
if (this.mc.thePlayer.inventory.getItemStack() == null)
{
if (clickNum == this.mc.gameSettings.keyBindPickBlock.keyCode + 100)
{
this.handleMouseClick(slot, k1, clickNum, 3);
}
else
{
boolean flag2 = k1 != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
byte b0 = 0;
if (flag2)
{
this.field_94075_K = slot != null && slot.getHasStack() ? slot.getStack() : null;
b0 = 1;
}
else if (k1 == -999)
{
b0 = 4;
}
this.handleMouseClick(slot, k1, clickNum, b0);
}
this.field_94068_E = true;
}
else
{
this.field_94076_q = true;
this.field_94067_D = clickNum;
this.field_94077_p.clear();
if (clickNum == 0)
{
this.field_94071_C = 0;
}
else if (clickNum == 1)
{
this.field_94071_C = 1;
}
}
}
}
}
this.field_94072_H = slot;
this.field_94070_G = l;
this.field_94073_I = clickNum;
}
}