aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/gui/GT_GUIContainer_OutputHatch.java
blob: 7e27a7409a0715304858cc3fac8eec565e8adbed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gregtech.common.gui;

import static gregtech.api.enums.GT_Values.RES_PATH_GUI;

import gregtech.api.enums.GT_Values;
import gregtech.api.gui.GT_GUIContainerMetaTile_Machine;
import gregtech.api.interfaces.IDragAndDropSupport;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.net.GT_Packet_SetLockedFluid;
import gregtech.api.util.GT_Utility;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidStack;

public class GT_GUIContainer_OutputHatch extends GT_GUIContainerMetaTile_Machine implements IDragAndDropSupport {

    private final String mName;
    private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF),
            textColorTitle = this.getTextColorOrDefault("title", 0x404040),
            textColorValue = this.getTextColorOrDefault("value", 0xFAFAFF);

    public GT_GUIContainer_OutputHatch(
            InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) {
        super(new GT_Container_OutputHatch(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "OutputHatch.png");
        mName = aName;
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
        fontRendererObj.drawString(
                StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColorTitle);
        fontRendererObj.drawString(mName, 8, 6, textColorTitle);
        if (mContainer != null) {
            fontRendererObj.drawString("Liquid Amount", 10, 20, textColor);
            fontRendererObj.drawString(
                    GT_Utility.parseNumberToString(((GT_Container_OutputHatch) mContainer).mContent),
                    10,
                    30,
                    textColorValue);
            fontRendererObj.drawString("Locked Fluid", 101, 20, textColor);
            ItemStack tLockedDisplayStack =
                    (ItemStack) mContainer.getInventory().get(3);
            String fluidName = tLockedDisplayStack == null ? "None" : tLockedDisplayStack.getDisplayName();
            fontRendererObj.drawString(fluidName, 101, 30, textColorValue);
        }
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) {
        super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY);
        int x = (width - xSize) / 2;
        int y = (height - ySize) / 2;
        drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
    }

    @Override
    public boolean handleDragAndDropGT(
            GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button, boolean isGhost) {
        if (gui instanceof GT_GUIContainer_OutputHatch
                && ((GT_GUIContainer_OutputHatch) gui).isMouseOverSlot(3, mousex, mousey)) {
            // the instanceof check should be unnecessary, but we will do it regardless, just in case.
            FluidStack tFluidStack = GT_Utility.getFluidFromContainerOrFluidDisplay(draggedStack);
            if (tFluidStack != null) {
                GT_Values.NW.sendToServer(new GT_Packet_SetLockedFluid(
                        ((GT_GUIContainer_OutputHatch) gui).mContainer.mTileEntity, tFluidStack));
                draggedStack.stackSize = 0;
                return true;
            }
        }
        return false;
    }
}