-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiCombustionEngine.java
96 lines (86 loc) · 3.93 KB
/
GuiCombustionEngine.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
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.energy.gui;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.core.DefaultProps;
import buildcraft.core.render.RenderUtils;
import buildcraft.core.utils.StringUtils;
import buildcraft.energy.TileEngineIron;
import buildcraft.energy.TileEngineWithInventory;
public class GuiCombustionEngine extends GuiEngine {
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/combustion_engine_gui.png");
private static final ResourceLocation BLOCK_TEXTURE = TextureMap.locationBlocksTexture;
public GuiCombustionEngine(InventoryPlayer inventoryplayer, TileEngineWithInventory tileEngine) {
super(new ContainerEngine(inventoryplayer, tileEngine), tileEngine, TEXTURE);
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
super.drawGuiContainerForegroundLayer(par1, par2);
String title = StringUtils.localize("tile.engineIron.name");
fontRendererObj.drawString(title, getCenteredOffset(title), 6, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, (ySize - 96) + 2, 0x404040);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
super.drawGuiContainerBackgroundLayer(f, x, y);
int j = (width - xSize) / 2;
int k = (height - ySize) / 2;
TileEngineIron engine = (TileEngineIron) tile;
drawFluid(engine.getFuel(), engine.getScaledBurnTime(58), j + 104, k + 19, 16, 58);
drawFluid(engine.getCoolant(), engine.getScaledCoolant(58), j + 122, k + 19, 16, 58);
mc.renderEngine.bindTexture(TEXTURE);
drawTexturedModalRect(j + 104, k + 19, 176, 0, 16, 60);
drawTexturedModalRect(j + 122, k + 19, 176, 0, 16, 60);
}
private void drawFluid(FluidStack fluid, int level, int x, int y, int width, int height) {
if (fluid == null || fluid.getFluid() == null) {
return;
}
IIcon icon = fluid.getFluid().getIcon(fluid);
mc.renderEngine.bindTexture(BLOCK_TEXTURE);
RenderUtils.setGLColorFromInt(fluid.getFluid().getColor(fluid));
int fullX = width / 16;
int fullY = height / 16;
int lastX = width - fullX * 16;
int lastY = height - fullY * 16;
int fullLvl = (height - level) / 16;
int lastLvl = (height - level) - fullLvl * 16;
for (int i = 0; i < fullX; i++) {
for (int j = 0; j < fullY; j++) {
if (j >= fullLvl) {
drawCutIcon(icon, x + i * 16, y + j * 16, 16, 16, j == fullLvl ? lastLvl : 0);
}
}
}
for (int i = 0; i < fullX; i++) {
drawCutIcon(icon, x + i * 16, y + fullY * 16, 16, lastY, fullLvl == fullY ? lastLvl : 0);
}
for (int i = 0; i < fullY; i++) {
if (i >= fullLvl) {
drawCutIcon(icon, x + fullX * 16, y + i * 16, lastX, 16, i == fullLvl ? lastLvl : 0);
}
}
drawCutIcon(icon, x + fullX * 16, y + fullY * 16, lastX, lastY, fullLvl == fullY ? lastLvl : 0);
}
//The magic is here
private void drawCutIcon(IIcon icon, int x, int y, int width, int height, int cut) {
Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
tess.addVertexWithUV(x, y + height, zLevel, icon.getMinU(), icon.getInterpolatedV(height));
tess.addVertexWithUV(x + width, y + height, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(height));
tess.addVertexWithUV(x + width, y + cut, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(cut));
tess.addVertexWithUV(x, y + cut, zLevel, icon.getMinU(), icon.getInterpolatedV(cut));
tess.draw();
}
}