ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java

120 lines
4.2 KiB
Java
Raw Normal View History

2016-07-21 01:49:01 +02:00
/*
* This file ("FluidDisplay.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2016-07-21 01:49:01 +02:00
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
2021-03-01 20:55:50 +01:00
import com.mojang.blaze3d.matrix.MatrixStack;
2016-07-21 01:49:01 +02:00
import net.minecraft.client.Minecraft;
2021-03-01 20:55:50 +01:00
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.fluid.Fluid;
2016-07-21 01:49:01 +02:00
import net.minecraft.util.ResourceLocation;
2021-03-01 20:55:50 +01:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
2016-07-21 01:49:01 +02:00
import net.minecraftforge.fluids.FluidStack;
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2021-03-01 20:55:50 +01:00
public class FluidDisplay extends AbstractGui {
2016-07-21 01:49:01 +02:00
2021-11-21 17:31:57 +01:00
private FluidStack fluidReference;
2016-07-21 01:49:01 +02:00
private Fluid oldFluid;
private int x;
private int y;
private boolean outline;
2016-07-21 01:49:01 +02:00
private ResourceLocation resLoc;
private boolean drawTextNextTo;
2021-11-21 17:31:57 +01:00
public FluidDisplay(int x, int y, FluidStack fluidReference, boolean outline, boolean drawTextNextTo) {
this.setData(x, y, fluidReference, outline, drawTextNextTo);
}
2021-11-21 17:31:57 +01:00
public FluidDisplay(int x, int y, FluidStack fluidReference) {
this(x, y, fluidReference, false, false);
}
2021-11-21 17:31:57 +01:00
public void setData(int x, int y, FluidStack fluidReference, boolean outline, boolean drawTextNextTo) {
2016-07-21 01:49:01 +02:00
this.x = x;
this.y = y;
this.fluidReference = fluidReference;
this.outline = outline;
this.drawTextNextTo = drawTextNextTo;
2016-07-21 01:49:01 +02:00
}
2021-03-01 20:55:50 +01:00
public void draw(MatrixStack matrices) {
2021-11-21 17:31:57 +01:00
/* Minecraft mc = Minecraft.getInstance();
mc.getTextureManager().bind(AssetUtil.GUI_INVENTORY_LOCATION);
2016-07-21 01:49:01 +02:00
int barX = this.x;
int barY = this.y;
2019-05-02 09:10:29 +02:00
if (this.outline) {
this.blit(matrices, this.x, this.y, 52, 163, 26, 93);
2016-07-21 01:49:01 +02:00
barX += 4;
barY += 4;
}
this.blit(matrices, barX, barY, 0, 171, 18, 85);
2016-07-21 01:49:01 +02:00
FluidStack stack = this.fluidReference.getFluid();
2021-02-26 22:15:48 +01:00
Fluid fluid = stack == null
? null
: stack.getFluid();
2016-07-21 01:49:01 +02:00
2019-05-02 09:10:29 +02:00
if (this.resLoc == null || this.oldFluid != fluid) {
2016-07-21 01:49:01 +02:00
this.oldFluid = fluid;
2019-05-02 09:10:29 +02:00
if (fluid != null && fluid.getStill() != null) {
this.resLoc = new ResourceLocation(fluid.getStill().getNamespace(), "textures/" + fluid.getStill().getPath() + ".png");
2016-07-21 01:49:01 +02:00
}
}
2019-05-02 09:10:29 +02:00
if (stack != null && fluid != null && this.resLoc != null) {
mc.getTextureManager().bind(this.resLoc);
2016-07-21 01:49:01 +02:00
GlStateManager._pushMatrix();
GlStateManager._enableBlend();
2016-07-21 01:49:01 +02:00
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
2019-05-02 09:10:29 +02:00
int i = this.fluidReference.getFluidAmount() * 83 / this.fluidReference.getCapacity();
Gui.drawModalRectWithCustomSizedTexture(barX + 1, barY + 84 - i, 36, 172, 16, i, 16, 512);
GlStateManager._disableBlend();
2016-07-21 01:49:01 +02:00
GlStateManager.enableAlpha();
GlStateManager._popMatrix();
2016-07-21 01:49:01 +02:00
}
2019-05-02 09:10:29 +02:00
if (this.drawTextNextTo) {
this.drawString(mc.font, this.getOverlayText(), barX + 25, barY + 78, StringUtil.DECIMAL_COLOR_WHITE);
2021-11-21 17:31:57 +01:00
}*/
2016-07-21 01:49:01 +02:00
}
2021-03-01 20:55:50 +01:00
public void render(MatrixStack matrices, int mouseX, int mouseY) {
2021-02-26 22:15:48 +01:00
if (mouseX >= this.x && mouseY >= this.y && mouseX < this.x + (this.outline
? 26
: 18) && mouseY < this.y + (this.outline
? 93
: 85)) {
Minecraft mc = Minecraft.getInstance();
2021-11-21 17:31:57 +01:00
//GuiUtils.drawHoveringText(Collections.singletonList(this.getOverlayText()), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.font);
2016-07-21 01:49:01 +02:00
}
}
2019-05-02 09:10:29 +02:00
private String getOverlayText() {
2021-11-21 17:31:57 +01:00
/* NumberFormat format = NumberFormat.getInstance();
FluidStack stack = this.fluidReference.getFluid();
String cap = format.format(this.fluidReference.getCapacity());
2021-02-26 22:15:48 +01:00
return stack == null || stack.getFluid() == null
? "0/" + cap + " mB"
2021-11-21 17:31:57 +01:00
: format.format(this.fluidReference.getFluidAmount()) + "/" + cap + " mB " + stack.getLocalizedName();*/
return "";
}
2016-07-21 01:49:01 +02:00
}