/
GuiHFurnace.java
128 lines (110 loc) · 4.52 KB
/
GuiHFurnace.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
package com.Hmod.gui;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import com.Hmod.container.ContainerCustomFurnace;
import com.Hmod.helper.Reference;
import com.Hmod.tile_entity.TileEntityFurnaceH;
public class GuiHFurnace extends GuiContainer {
public static final ResourceLocation BACKGROUND = new ResourceLocation(
Reference.MODID + ":textures/gui/furnace.png");
private TileEntityFurnaceH tileEntity;
public GuiHFurnace(InventoryPlayer invPlayer,
TileEntityFurnaceH tileInventoryFurnace) {
super(new ContainerCustomFurnace(invPlayer, tileInventoryFurnace));
// Set the width and height of the gui
xSize = 176;
ySize = 209;
this.tileEntity = tileInventoryFurnace;
}
final int COOK_BAR_XPOS = 49;
final int COOK_BAR_YPOS = 75;
final int COOK_BAR_ICON_U = 0; // texture position of white arrow icon
final int COOK_BAR_ICON_V = 210;
final int COOK_BAR_WIDTH = 80;
final int COOK_BAR_HEIGHT = 17;
final int FLAME_XPOS = 81;
final int FLAME_YPOS = 96;
final int FLAME_ICON_U = 176; // texture position of flame icon
final int FLAME_ICON_V = 0;
final int FLAME_WIDTH = 14;
final int FLAME_HEIGHT = 14;
// final int FLAME_X_SPACING = 18;
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int x,
int y) {
// Bind the image texture
Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND);
// Draw the image
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
// get cook progress as a double between 0 and 1
double cookProgress = tileEntity.fractionOfCookTimeComplete();
// draw the cook progress bar
drawTexturedModalRect(guiLeft + COOK_BAR_XPOS, guiTop + COOK_BAR_YPOS,
COOK_BAR_ICON_U, COOK_BAR_ICON_V,
(int) (cookProgress * COOK_BAR_WIDTH), COOK_BAR_HEIGHT);
// draw the fuel remaining bar for each fuel slot flame
for (int i = 0; i < 1; ++i) {
double burnRemaining = tileEntity.fractionOfFuelRemaining(i);
int yOffset = (int) ((1.0 - burnRemaining) * FLAME_HEIGHT);
drawTexturedModalRect(guiLeft + FLAME_XPOS, guiTop + FLAME_YPOS
+ yOffset, FLAME_ICON_U, FLAME_ICON_V + yOffset,
FLAME_WIDTH, FLAME_HEIGHT - yOffset);
}
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
final int LABEL_XPOS = 5;
final int LABEL_YPOS = 5;
fontRendererObj.drawString(tileEntity.getDisplayName()
.getUnformattedText(), LABEL_XPOS, LABEL_YPOS, Color.darkGray
.getRGB());
List<String> hoveringText = new ArrayList<String>();
// If the mouse is over the progress bar add the progress bar hovering
// text
if (isInRect(guiLeft + COOK_BAR_XPOS, guiTop + COOK_BAR_YPOS,
COOK_BAR_WIDTH, COOK_BAR_HEIGHT, mouseX, mouseY)) {
hoveringText.add("Progress:");
int cookPercentage = (int) (tileEntity.fractionOfCookTimeComplete() * 100);
hoveringText.add(cookPercentage + "%");
}
// If the mouse is over one of the burn time indicator add the burn time
// indicator hovering text
for (int i = 0; i < tileEntity.FUEL_SLOTS_COUNT; ++i) {
if (isInRect(guiLeft + FLAME_XPOS, guiTop
+ FLAME_YPOS, FLAME_WIDTH, FLAME_HEIGHT, mouseX, mouseY)) {
hoveringText.add("Fuel Time:");
hoveringText.add(tileEntity.secondsOfFuelRemaining(i) + "s");
}
}
if (isInRect(guiLeft + 35, guiTop
+ 98, 10, 10, mouseX, mouseY)) {
hoveringText.add("Fuel: Purple Ingot, Purple Compressed Ingot");
hoveringText.add(" and Coal");
}
if (isInRect(guiLeft + 47, guiTop
+ 26, 10, 10, mouseX, mouseY)) {
hoveringText.add("Soon Upgrades Slots");
}
// If hoveringText is not empty draw the hovering text
if (!hoveringText.isEmpty()) {
drawHoveringText(hoveringText, mouseX - guiLeft, mouseY - guiTop,
fontRendererObj);
}
// // You must re bind the texture and reset the colour if you still
// need to use it after drawing a string
// Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
// GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
}
// Returns true if the given x,y coordinates are within the given rectangle
public static boolean isInRect(int x, int y, int xSize, int ySize, int mouseX, int mouseY){
return ((mouseX >= x && mouseX <= x+xSize) && (mouseY >= y && mouseY <= y+ySize));
}
}