mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 15:22:57 +00:00
Fix WidgetFluidTank
This commit is contained in:
1 parent
70c5e851c2
commit
ff038cc468
1 file changed
+86
-28
@@ -10,14 +10,25 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui.widgets;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import forestry.api.core.IToolPipette;
|
||||
@@ -61,6 +72,7 @@ public class TankWidget extends Widget {
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
GlStateManager.disableBlend();
|
||||
IFluidTank tank = getTank();
|
||||
if (tank == null || tank.getCapacity() <= 0) {
|
||||
return;
|
||||
@@ -71,43 +83,62 @@ public class TankWidget extends Widget {
|
||||
return;
|
||||
}
|
||||
|
||||
if (contents.getFluid().getStill() == null) {
|
||||
Fluid fluid = contents.getFluid();
|
||||
if (fluid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Proxies.render.bindTexture(contents.getFluid().getStill());
|
||||
int scaledLiquid = (contents.amount * height) / tank.getCapacity();
|
||||
if (scaledLiquid > height) {
|
||||
scaledLiquid = height;
|
||||
TextureMap textureMapBlocks = Minecraft.getMinecraft().getTextureMapBlocks();
|
||||
ResourceLocation fluidStill = fluid.getStill();
|
||||
TextureAtlasSprite fluidStillSprite = null;
|
||||
if (fluidStill != null) {
|
||||
fluidStillSprite = textureMapBlocks.getTextureExtry(fluidStill.toString());
|
||||
}
|
||||
if (fluidStillSprite == null) {
|
||||
fluidStillSprite = textureMapBlocks.getMissingSprite();
|
||||
}
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
{
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
|
||||
int fluidColor = fluid.getColor(contents);
|
||||
|
||||
int start = 0;
|
||||
while (scaledLiquid > 0) {
|
||||
int x;
|
||||
int scaledAmount = (contents.amount * height) / tank.getCapacity();
|
||||
if (contents.amount > 0 && scaledAmount < 1) {
|
||||
scaledAmount = 1;
|
||||
}
|
||||
if (scaledAmount > height) {
|
||||
scaledAmount = height;
|
||||
}
|
||||
|
||||
if (scaledLiquid > 16) {
|
||||
x = 16;
|
||||
scaledLiquid -= 16;
|
||||
} else {
|
||||
x = scaledLiquid;
|
||||
scaledLiquid = 0;
|
||||
Proxies.render.bindTexture(TextureMap.locationBlocksTexture);
|
||||
setGLColorFromInt(fluidColor);
|
||||
|
||||
final int xTileCount = width / 16;
|
||||
final int xRemainder = width - (xTileCount * 16);
|
||||
final int yTileCount = scaledAmount / 16;
|
||||
final int yRemainder = scaledAmount - (yTileCount * 16);
|
||||
|
||||
final int yStart = startY + height;
|
||||
|
||||
for (int xTile = 0; xTile <= xTileCount; xTile++) {
|
||||
for (int yTile = 0; yTile <= yTileCount; yTile++) {
|
||||
int width = (xTile == xTileCount) ? xRemainder : 16;
|
||||
int height = (yTile == yTileCount) ? yRemainder : 16;
|
||||
int x = startX + (xTile * 16);
|
||||
int y = yStart - ((yTile + 1) * 16);
|
||||
if (width > 0 && height > 0) {
|
||||
int maskTop = 16 - height;
|
||||
int maskRight = 16 - width;
|
||||
|
||||
drawFluidTexture(x + xPos, y + yPos, fluidStillSprite, maskTop, maskRight, 100);
|
||||
}
|
||||
|
||||
manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos + height - x - start, 0, 0, 16, 16 - (16 - x));
|
||||
start += 16;
|
||||
}
|
||||
|
||||
if (drawOverlay) {
|
||||
Proxies.render.bindTexture(manager.gui.textureFile);
|
||||
manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, overlayTexX, overlayTexY, 16, 60);
|
||||
}
|
||||
}
|
||||
GL11.glPopAttrib();
|
||||
|
||||
if (drawOverlay) {
|
||||
Proxies.render.bindTexture(manager.gui.textureFile);
|
||||
manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, overlayTexX, overlayTexY, 16, 60);
|
||||
}
|
||||
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,6 +149,33 @@ public class TankWidget extends Widget {
|
||||
}
|
||||
return ((StandardTank) tank).getToolTip();
|
||||
}
|
||||
|
||||
private static void setGLColorFromInt(int color) {
|
||||
float red = (color >> 16 & 0xFF) / 255.0F;
|
||||
float green = (color >> 8 & 0xFF) / 255.0F;
|
||||
float blue = (color & 0xFF) / 255.0F;
|
||||
|
||||
GlStateManager.color(red, green, blue, 1.0F);
|
||||
}
|
||||
|
||||
|
||||
private static void drawFluidTexture(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel) {
|
||||
double uMin = (double) textureSprite.getMinU();
|
||||
double uMax = (double) textureSprite.getMaxU();
|
||||
double vMin = (double) textureSprite.getMinV();
|
||||
double vMax = (double) textureSprite.getMaxV();
|
||||
uMax = uMax - (maskRight / 16.0 * (uMax - uMin));
|
||||
vMax = vMax - (maskTop / 16.0 * (vMax - vMin));
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
worldrenderer.pos(xCoord, yCoord + 16, zLevel).tex(uMin, vMax).endVertex();
|
||||
worldrenderer.pos(xCoord + 16 - maskRight, yCoord + 16, zLevel).tex(uMax, vMax).endVertex();
|
||||
worldrenderer.pos(xCoord + 16 - maskRight, yCoord + maskTop, zLevel).tex(uMax, vMin).endVertex();
|
||||
worldrenderer.pos(xCoord, yCoord + maskTop, zLevel).tex(uMin, vMin).endVertex();
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
Reference in new issue
Block a user