New energy and fluid displays, part 1!

This commit is contained in:
Ellpeck 2016-07-21 01:49:01 +02:00
parent ae4af4b804
commit 5dc1951fa1
9 changed files with 178 additions and 20 deletions

View file

@ -0,0 +1,67 @@
/*
* This file ("EnergyDisplay.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
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraftforge.fml.client.config.GuiUtils;
import java.util.Collections;
public class EnergyDisplay extends Gui{
private final EnergyStorage rfReference;
private final int x;
private final int y;
private final boolean outline;
public EnergyDisplay(int x, int y, EnergyStorage rfReference, boolean outline){
this.x = x;
this.y = y;
this.rfReference = rfReference;
this.outline = outline;
}
public EnergyDisplay(int x, int y, EnergyStorage rfReference){
this(x, y, rfReference, false);
}
public void draw(){
Minecraft mc = Minecraft.getMinecraft();
mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
int barX = this.x;
int barY = this.y;
if(this.outline){
this.drawTexturedModalRect(this.x, this.y, 52, 163, 26, 93);
barX += 4;
barY += 4;
}
this.drawTexturedModalRect(barX, barY, 18, 171, 18, 85);
if(this.rfReference.getEnergyStored() > 0){
int i = this.rfReference.getEnergyStored()*83/this.rfReference.getMaxEnergyStored();
this.drawTexturedModalRect(barX+1, barY+84-i, 36, 172, 16, i);
}
}
public void drawOverlay(int mouseX, int mouseY){
if(mouseX >= this.x && mouseY >= this.y && mouseX < this.x+(this.outline ? 26 : 18) && mouseY < this.y+(this.outline ? 93 : 85)){
Minecraft mc = Minecraft.getMinecraft();
String text = this.rfReference.getEnergyStored()+"/"+this.rfReference.getMaxEnergyStored()+" RF";
GuiUtils.drawHoveringText(Collections.singletonList(text), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
}
}
}

View file

@ -0,0 +1,96 @@
/*
* 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
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fml.client.config.GuiUtils;
import java.util.Collections;
public class FluidDisplay extends Gui{
private final FluidTank fluidReference;
private Fluid oldFluid;
private final int x;
private final int y;
private final boolean outline;
private ResourceLocation resLoc;
public FluidDisplay(int x, int y, FluidTank fluidReference, boolean outline){
this.x = x;
this.y = y;
this.fluidReference = fluidReference;
this.outline = outline;
}
public FluidDisplay(int x, int y, FluidTank fluidReference){
this(x, y, fluidReference, false);
}
public void draw(){
Minecraft mc = Minecraft.getMinecraft();
mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
int barX = this.x;
int barY = this.y;
if(this.outline){
this.drawTexturedModalRect(this.x, this.y, 52, 163, 26, 93);
barX += 4;
barY += 4;
}
this.drawTexturedModalRect(barX, barY, 0, 171, 18, 85);
FluidStack stack = this.fluidReference.getFluid();
Fluid fluid = stack == null ? null : stack.getFluid();
if(this.resLoc == null || this.oldFluid != fluid){
this.oldFluid = fluid;
if(fluid != null){
this.resLoc = new ResourceLocation(fluid.getStill().getResourceDomain(), "textures/"+fluid.getStill().getResourcePath()+".png");
}
}
if(stack != null && fluid != null && this.resLoc != null){
mc.getTextureManager().bindTexture(this.resLoc);
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
int i = this.fluidReference.getFluidAmount()*83/this.fluidReference.getCapacity();
GuiInputter.drawModalRectWithCustomSizedTexture(barX+1, barY+84-i, 36, 172, 16, i, 16, 512);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
}
}
public void drawOverlay(int mouseX, int mouseY){
if(mouseX >= this.x && mouseY >= this.y && mouseX < this.x+(this.outline ? 26 : 18) && mouseY < this.y+(this.outline ? 93 : 85)){
FluidStack stack = this.fluidReference.getFluid();
Minecraft mc = Minecraft.getMinecraft();
String text = stack == null || stack.getFluid() == null ? "0/"+this.fluidReference.getCapacity()+" mB" : this.fluidReference.getFluidAmount()+"/"+this.fluidReference.getCapacity()+" mB "+stack.getLocalizedName();
GuiUtils.drawHoveringText(Collections.singletonList(text), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
}
}
}

View file

@ -29,6 +29,8 @@ public class GuiCanolaPress extends GuiContainer{
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiCanolaPress");
private final TileEntityCanolaPress press;
private EnergyDisplay energy;
private FluidDisplay fluid;
public GuiCanolaPress(InventoryPlayer inventory, TileEntityBase tile){
super(new ContainerCanolaPress(inventory, tile));
@ -37,18 +39,19 @@ public class GuiCanolaPress extends GuiContainer{
this.ySize = 93+86;
}
@Override
public void initGui(){
super.initGui();
this.energy = new EnergyDisplay(this.guiLeft+42, this.guiTop+5, this.press.storage);
this.fluid = new FluidDisplay(this.guiLeft+116, this.guiTop+5, this.press.tank);
}
@Override
public void drawScreen(int x, int y, float f){
super.drawScreen(x, y, f);
String text1 = this.press.storage.getEnergyStored()+"/"+this.press.storage.getMaxEnergyStored()+" RF";
if(x >= this.guiLeft+43 && y >= this.guiTop+6 && x <= this.guiLeft+58 && y <= this.guiTop+88){
this.drawHoveringText(Collections.singletonList(text1), x, y);
}
String text2 = StringUtil.getFluidInfo(this.press.tank);
if(x >= this.guiLeft+117 && y >= this.guiTop+6 && x <= this.guiLeft+132 && y <= this.guiTop+88){
this.drawHoveringText(Collections.singletonList(text2), x, y);
}
this.energy.drawOverlay(x, y);
this.fluid.drawOverlay(x, y);
}
@Override
@ -66,19 +69,12 @@ public class GuiCanolaPress extends GuiContainer{
this.mc.getTextureManager().bindTexture(RES_LOC);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93);
if(this.press.storage.getEnergyStored() > 0){
int i = this.press.getEnergyScaled(83);
this.drawTexturedModalRect(this.guiLeft+43, this.guiTop+89-i, 176, 29, 16, i);
}
if(this.press.tank.getFluidAmount() > 0){
int i = this.press.getTankScaled(83);
this.drawTexturedModalRect(this.guiLeft+117, this.guiTop+89-i, 192, 29, 16, i);
}
if(this.press.currentProcessTime > 0){
int i = this.press.getProcessScaled(29);
this.drawTexturedModalRect(this.guiLeft+83, this.guiTop+32, 176, 0, 12, i);
}
this.energy.draw();
this.fluid.draw();
}
}

View file

@ -48,8 +48,7 @@ public final class StringUtil{
}
}
@SideOnly(Side.CLIENT)
public static String getFluidInfo(FluidTank tank){
return tank.getFluid() == null || tank.getFluid().getFluid() == null ? "0/"+tank.getCapacity()+" mB" : tank.getFluidAmount()+"/"+tank.getCapacity()+" mB "+tank.getFluid().getLocalizedName();
return "";
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB