Fluid cleanup and performance improvements (#3581)
Use custom gui widget with custom synchronization for rendering fake fluid slots.
This commit is contained in:
@@ -21,11 +21,14 @@ package appeng.fluids.client.gui;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidIO;
|
||||
import appeng.fluids.parts.PartFluidImportBus;
|
||||
import appeng.fluids.parts.PartSharedFluidBus;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
|
||||
/**
|
||||
@@ -35,10 +38,34 @@ import appeng.fluids.parts.PartFluidImportBus;
|
||||
*/
|
||||
public class GuiFluidIO extends GuiUpgradeable
|
||||
{
|
||||
private final PartSharedFluidBus bus;
|
||||
|
||||
public GuiFluidIO( InventoryPlayer inventoryPlayer, IUpgradeableHost te )
|
||||
public GuiFluidIO( InventoryPlayer inventoryPlayer, PartSharedFluidBus te )
|
||||
{
|
||||
super( new ContainerFluidIO( inventoryPlayer, te ) );
|
||||
this.bus = te;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
|
||||
final ContainerFluidIO container = (ContainerFluidIO) this.inventorySlots;
|
||||
final IAEFluidTank inv = this.bus.getConfig();
|
||||
final int y = 40;
|
||||
final int x = 80;
|
||||
|
||||
this.guiSlots.add( new GuiFluidSlot( inv, 0, 0, x, y ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 1, 1, 1, x, y, -1, 0 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 2, 2, 1, x, y, 1, 0 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 3, 3, 1, x, y, 0, -1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 4, 4, 1, x, y, 0, 1 ) );
|
||||
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 5, 5, 2, x, y, -1, -1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 6, 6, 2, x, y, 1, -1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 7, 7, 2, x, y, -1, 1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 8, 8, 2, x, y, 1, 1 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,20 +24,21 @@ import java.io.IOException;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.GuiFluidTank;
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketSwitchGuis;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidTank;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.helper.AEFluidTank;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
import appeng.fluids.helper.IFluidInterfaceHost;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
|
||||
public class GuiFluidInterface extends AEBaseGui
|
||||
public class GuiFluidInterface extends GuiUpgradeable
|
||||
{
|
||||
public final static int ID_BUTTON_TANK = 222;
|
||||
|
||||
@@ -56,17 +57,26 @@ public class GuiFluidInterface extends AEBaseGui
|
||||
{
|
||||
super.initGui();
|
||||
|
||||
final IAEFluidTank configFluids = this.host.getDualityFluidInterface().getConfig();
|
||||
final IAEFluidTank fluidTank = this.host.getDualityFluidInterface().getTanks();
|
||||
|
||||
for( int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i )
|
||||
{
|
||||
final AEFluidTank fluidTank = this.host.getDualityFluidInterface().getTank( i );
|
||||
final GuiFluidTank guiTank = new GuiFluidTank( ID_BUTTON_TANK + i, fluidTank, this.getGuiLeft() + 35 + 18 * i, this.getGuiTop() + 53, 16, 68 );
|
||||
final GuiFluidTank guiTank = new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, this.getGuiLeft() + 35 + 18 * i, this
|
||||
.getGuiTop() + 53, 16, 68 );
|
||||
this.buttonList.add( guiTank );
|
||||
this.guiSlots.add( new GuiFluidSlot( configFluids, i, i, 35 + 18 * i, 35 ) );
|
||||
}
|
||||
|
||||
this.priority = new GuiTabButton( this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender );
|
||||
this.buttonList.add( this.priority );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addButtons()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
|
||||
{
|
||||
@@ -93,4 +103,10 @@ public class GuiFluidInterface extends AEBaseGui
|
||||
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean drawUpgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,11 @@ import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketConfigButton;
|
||||
import appeng.core.sync.packets.PacketSwitchGuis;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidStorageBus;
|
||||
import appeng.fluids.parts.PartFluidStorageBus;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,11 +60,41 @@ public class GuiFluidStorageBus extends GuiUpgradeable
|
||||
private GuiTabButton priority;
|
||||
private GuiImgButton partition;
|
||||
private GuiImgButton clear;
|
||||
private final PartFluidStorageBus bus;
|
||||
|
||||
public GuiFluidStorageBus( InventoryPlayer inventoryPlayer, PartFluidStorageBus te )
|
||||
{
|
||||
super( new ContainerFluidStorageBus( inventoryPlayer, te ) );
|
||||
this.ySize = 251;
|
||||
this.bus = te;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
|
||||
final int xo = 8;
|
||||
final int yo = 23 + 6;
|
||||
|
||||
final IAEFluidTank config = this.bus.getConfig();
|
||||
final ContainerFluidStorageBus container = (ContainerFluidStorageBus) this.inventorySlots;
|
||||
|
||||
for( int y = 0; y < 7; y++ )
|
||||
{
|
||||
for( int x = 0; x < 9; x++ )
|
||||
{
|
||||
final int idx = y * 9 + x;
|
||||
if( y < 2 )
|
||||
{
|
||||
this.guiSlots.add( new GuiFluidSlot( config, idx, idx, xo + x * 18, yo + y * 18 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( config, container, idx, idx, y - 2, xo, yo, x, y ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,7 +73,6 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi
|
||||
private final ContainerFluidTerminal container;
|
||||
private final int offsetX = 9;
|
||||
private int rows = 6;
|
||||
private int maxRows = Integer.MAX_VALUE;
|
||||
private int perRow = 9;
|
||||
|
||||
protected PartFluidTerminal terminal;
|
||||
@@ -172,7 +171,7 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi
|
||||
{
|
||||
final IMEFluidSlot fluidSlot = (IMEFluidSlot) slot;
|
||||
|
||||
if( fluidSlot.getFluidStack() != null && fluidSlot.shouldRenderAsFluid() )
|
||||
if( fluidSlot.getAEFluidStack() != null && fluidSlot.shouldRenderAsFluid() )
|
||||
{
|
||||
final IAEFluidStack fluidStack = fluidSlot.getAEFluidStack();
|
||||
final String formattedAmount = NumberFormat.getNumberInstance( Locale.US ).format( fluidStack.getStackSize() ) + " mB";
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
|
||||
package appeng.fluids.client.gui.widgets;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.gui.widgets.GuiCustomSlot;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketFluidSlot;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
|
||||
public class GuiFluidSlot extends GuiCustomSlot
|
||||
{
|
||||
private final IAEFluidTank fluids;
|
||||
private final int slot;
|
||||
|
||||
public GuiFluidSlot( final IAEFluidTank fluids, final int slot, final int id, final int x, final int y )
|
||||
{
|
||||
super( id, x, y );
|
||||
this.fluids = fluids;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawContent( final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks )
|
||||
{
|
||||
final IAEFluidStack fs = this.getFluidStack();
|
||||
if( fs != null )
|
||||
{
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableBlend();
|
||||
final Fluid fluid = fs.getFluid();
|
||||
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
||||
final TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getStill().toString() );
|
||||
|
||||
// Set color for dynamic fluids
|
||||
// Convert int color to RGB
|
||||
final float red = ( fluid.getColor() >> 16 & 255 ) / 255.0F;
|
||||
final float green = ( fluid.getColor() >> 8 & 255 ) / 255.0F;
|
||||
final float blue = ( fluid.getColor() & 255 ) / 255.0F;
|
||||
GlStateManager.color( red, green, blue );
|
||||
|
||||
this.drawTexturedModalRect( this.xPos(), this.yPos(), sprite, this.getWidth(), this.getHeight() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canClick( final EntityPlayer player )
|
||||
{
|
||||
final ItemStack mouseStack = player.inventory.getItemStack();
|
||||
return mouseStack.isEmpty() || mouseStack.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void slotClicked( final ItemStack clickStack, int mouseButton )
|
||||
{
|
||||
if( clickStack.isEmpty() || mouseButton == 1 )
|
||||
{
|
||||
this.setFluidStack( null );
|
||||
}
|
||||
else if( mouseButton == 0 )
|
||||
{
|
||||
final FluidStack fluid = FluidUtil.getFluidContained( clickStack );
|
||||
if( fluid != null )
|
||||
{
|
||||
this.setFluidStack( AEFluidStack.fromFluidStack( fluid ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
final IAEFluidStack fluid = getFluidStack();
|
||||
if( fluid != null )
|
||||
{
|
||||
return fluid.getFluidStack().getLocalizedName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public IAEFluidStack getFluidStack()
|
||||
{
|
||||
return this.fluids.getFluidInSlot( this.slot );
|
||||
}
|
||||
|
||||
public void setFluidStack( final IAEFluidStack stack )
|
||||
{
|
||||
this.fluids.setFluidInSlot( this.slot, stack );
|
||||
NetworkHandler.instance().sendToServer( new PacketFluidSlot( Collections.singletonMap( this.getId(), this.getFluidStack() ) ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.fluids.client.gui.widgets;
|
||||
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.gui.widgets.ITooltip;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public class GuiFluidTank extends GuiButton implements ITooltip
|
||||
{
|
||||
private final IAEFluidTank tank;
|
||||
private final int slot;
|
||||
|
||||
public GuiFluidTank( IAEFluidTank tank, int slot, int id, int x, int y, int w, int h )
|
||||
{
|
||||
super( id, x, y, w, h, "" );
|
||||
this.tank = tank;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton( final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks )
|
||||
{
|
||||
if( this.visible )
|
||||
{
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.disableLighting();
|
||||
|
||||
drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 );
|
||||
|
||||
final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot );
|
||||
if( fluid != null && fluid.getStackSize() > 0 )
|
||||
{
|
||||
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
||||
|
||||
float red = ( fluid.getFluid().getColor() >> 16 & 255 ) / 255.0F;
|
||||
float green = ( fluid.getFluid().getColor() >> 8 & 255 ) / 255.0F;
|
||||
float blue = ( fluid.getFluid().getColor() & 255 ) / 255.0F;
|
||||
GlStateManager.color( red, green, blue );
|
||||
|
||||
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getFluid().getStill().toString() );
|
||||
final int scaledHeight = (int) ( this.height * ( (float) fluid.getStackSize() / this.tank.getTankProperties()[this.slot].getCapacity() ) );
|
||||
|
||||
int iconHeightRemainder = scaledHeight % 16;
|
||||
if( iconHeightRemainder > 0 )
|
||||
{
|
||||
drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder, sprite, 16, iconHeightRemainder );
|
||||
}
|
||||
for( int i = 0; i < scaledHeight / 16; i++ )
|
||||
{
|
||||
drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder - ( i + 1 ) * 16, sprite, 16, 16 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot );
|
||||
if( fluid != null && fluid.getStackSize() > 0 )
|
||||
{
|
||||
String desc = fluid.getFluid().getLocalizedName( fluid.getFluidStack() );
|
||||
String amountToText = fluid.getStackSize() + "mB";
|
||||
|
||||
return desc + "\n" + amountToText;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int xPos()
|
||||
{
|
||||
return this.x - 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int yPos()
|
||||
{
|
||||
return this.y - 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth()
|
||||
{
|
||||
return this.width + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return this.height + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
|
||||
package appeng.fluids.client.gui.widgets;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.container.slot.IOptionalSlotHost;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
|
||||
public class GuiOptionalFluidSlot extends GuiFluidSlot
|
||||
{
|
||||
private final IOptionalSlotHost containerBus;
|
||||
private final int groupNum;
|
||||
private final int srcX;
|
||||
private final int srcY;
|
||||
|
||||
public GuiOptionalFluidSlot( IAEFluidTank fluids, final IOptionalSlotHost containerBus, int slot, int id, int groupNum, int x, int y, int xoffs, int yoffs )
|
||||
{
|
||||
super( fluids, slot, id, x + xoffs * 18, y + yoffs * 18 );
|
||||
this.containerBus = containerBus;
|
||||
this.groupNum = groupNum;
|
||||
this.srcX = x;
|
||||
this.srcY = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSlotEnabled()
|
||||
{
|
||||
if( this.containerBus == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.containerBus.isSlotEnabled( this.groupNum );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack getFluidStack()
|
||||
{
|
||||
if( !this.isSlotEnabled() && super.getFluidStack() != null )
|
||||
{
|
||||
this.setFluidStack( null );
|
||||
}
|
||||
return super.getFluidStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground( int guileft, int guitop )
|
||||
{
|
||||
GlStateManager.enableBlend();
|
||||
if( this.isSlotEnabled() )
|
||||
{
|
||||
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.color( 1.0F, 1.0F, 1.0F, 0.4F );
|
||||
}
|
||||
this.drawTexturedModalRect( guileft + this.xPos() - 1, guitop + this.yPos() - 1, this.srcX - 1, this.srcY - 1, this.getWidth() + 2,
|
||||
this.getHeight() + 2 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user