Skip to content

Commit

Permalink
Color liquids in smeltery GUI. #1150
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Nov 13, 2014
1 parent 5b2f1f5 commit 367df72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
20 changes: 13 additions & 7 deletions src/main/java/tconstruct/smeltery/gui/SmelteryGui.java
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
Expand Down Expand Up @@ -159,14 +160,17 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY)
this.mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
if (logic.fuelGague > 0)
{
IIcon lavaIcon = logic.getFuelIcon();
FluidStack fuelStack = logic.getFuel();
IIcon lavaIcon = fuelStack.getFluid().getStillIcon();
if(lavaIcon == null)
lavaIcon = Blocks.lava.getIcon(0, 0);
int fuel = logic.getScaledFuelGague(52);
int count = 0;
while (fuel > 0)
{
int size = fuel >= 16 ? 16 : fuel;
fuel -= size;
drawLiquidRect(cornerX + 117, (cornerY + 68) - size - 16 * count, lavaIcon, 12, size);
drawLiquidRect(cornerX + 117, (cornerY + 68) - size - 16 * count, lavaIcon, 12, size, fuelStack.getFluid().getColor(fuelStack));
count++;
}
}
Expand All @@ -183,6 +187,7 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY)
{
FluidStack liquid = logic.moltenMetal.get(i);
IIcon icon = liquid.getFluid().getStillIcon();
int color = liquid.getFluid().getColor(liquid);

if (icon == null)
continue;
Expand All @@ -193,10 +198,10 @@ protected void drawGuiContainerBackgroundLayer (float f, int mouseX, int mouseY)
{
int v = Math.min(16, h);
// we render in 16x16 squares so the texture doesn't get distorted
drawLiquidRect(cornerX + basePos + 00, (cornerY + 68) - h - base, icon, 16, v);
drawLiquidRect(cornerX + basePos + 16, (cornerY + 68) - h - base, icon, 16, v);
drawLiquidRect(cornerX + basePos + 32, (cornerY + 68) - h - base, icon, 16, v);
drawLiquidRect(cornerX + basePos + 48, (cornerY + 68) - h - base, icon, 4, v);
drawLiquidRect(cornerX + basePos + 00, (cornerY + 68) - h - base, icon, 16, v, color);
drawLiquidRect(cornerX + basePos + 16, (cornerY + 68) - h - base, icon, 16, v, color);
drawLiquidRect(cornerX + basePos + 32, (cornerY + 68) - h - base, icon, 16, v, color);
drawLiquidRect(cornerX + basePos + 48, (cornerY + 68) - h - base, icon, 4, v, color);
h -= 16;
}
base += height;
Expand Down Expand Up @@ -492,14 +497,15 @@ protected void drawToolTip (List par1List, int par2, int par3)
}
}

public void drawLiquidRect (int startU, int startV, IIcon icon, int endU, int endV)
public void drawLiquidRect (int startU, int startV, IIcon icon, int endU, int endV, int color)
{
float top = icon.getInterpolatedV(16 - endV);
float bottom = icon.getMaxV();
float left = icon.getMinU();
float right = icon.getInterpolatedU(endU);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorOpaque_I(color);
tessellator.addVertexWithUV(startU + 0, startV + endV, this.zLevel, left, bottom);//Bottom left
tessellator.addVertexWithUV(startU + endU, startV + endV, this.zLevel, right, bottom);//Bottom right
tessellator.addVertexWithUV(startU + endU, startV + 0, this.zLevel, right, top);//Top right
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java
Expand Up @@ -667,17 +667,17 @@ protected void verifyFuelTank()
}

@SideOnly(Side.CLIENT)
public IIcon getFuelIcon ()
public FluidStack getFuel()
{
IIcon defaultLava = Blocks.lava.getIcon(0, 0);
if (activeLavaTank == null)
return defaultLava;
// sane default
return new FluidStack(FluidRegistry.LAVA, 0);

TileEntity tankContainer = worldObj.getTileEntity(activeLavaTank.x, activeLavaTank.y, activeLavaTank.z);
if (tankContainer instanceof IFluidHandler)
return ((IFluidHandler) tankContainer).getTankInfo(ForgeDirection.DOWN)[0].fluid.getFluid().getStillIcon();
return ((IFluidHandler) tankContainer).getTankInfo(ForgeDirection.DOWN)[0].fluid;

return defaultLava;
return new FluidStack(FluidRegistry.LAVA, 0);
}

public FluidStack getResultFor (ItemStack stack)
Expand Down

0 comments on commit 367df72

Please sign in to comment.