aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorYannickMG <yannickmg@gmail.com>2022-01-10 01:09:07 -0500
committerGitHub <noreply@github.com>2022-01-10 07:09:07 +0100
commitbef0bf37ddb79da70803321069287d1dd9050623 (patch)
tree144d467869baed90a5f94cf70dbe86d950dc685d /src/main
parentef48ab5513f7e63f8d8d181a28b9f416fd94f476 (diff)
downloadGT5-Unofficial-bef0bf37ddb79da70803321069287d1dd9050623.tar.gz
GT5-Unofficial-bef0bf37ddb79da70803321069287d1dd9050623.tar.bz2
GT5-Unofficial-bef0bf37ddb79da70803321069287d1dd9050623.zip
Cover tabs (#856)
* Add network support for chanining GT Tile GUIs * Implemented Cover Tabs for IGregTechTileEntity See GTNewHorizons/GT-New-Horizons-Modpack#9367 for details * Added IGuiIcon For easier addon extensibility of GT_GuiIcon Also fixed Ghost Circuit tab tooltip overlapping right-side cover tabs * Typo fix * Fixed unintended scala import * Tabs -> Spaces on the files I've touched
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java163
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java22
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUICover.java29
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java170
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java100
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java166
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java271
-rw-r--r--src/main/java/gregtech/api/interfaces/IGuiIcon.java13
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java112
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java74
-rw-r--r--src/main/java/gregtech/common/GT_Network.java3
-rw-r--r--src/main/java/gregtech/common/GT_Proxy.java26
-rw-r--r--src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java28
-rw-r--r--src/main/java/gregtech/loaders/preload/GT_PreLoad.java2
-rw-r--r--src/main/resources/assets/gregtech/lang/en_US.lang13
-rw-r--r--src/main/resources/assets/gregtech/textures/gui/GuiTabs.pngbin0 -> 1193 bytes
16 files changed, 1143 insertions, 49 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java
index 7fd4f9f0b2..73da114b38 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java
@@ -1,9 +1,24 @@
package gregtech.api.gui;
+import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Dyes;
+import gregtech.api.gui.widgets.GT_GuiCoverTabLine;
+import gregtech.api.gui.widgets.GT_GuiIcon;
+import gregtech.api.gui.widgets.GT_GuiTooltip;
+import gregtech.api.gui.widgets.GT_GuiTooltipManager;
+import gregtech.api.gui.widgets.GT_GuiTabLine.DisplayStyle;
+import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet;
+import gregtech.api.gui.widgets.GT_GuiTabLine.GT_ITabRenderer;
+import gregtech.api.gui.widgets.GT_GuiTooltipManager.GT_IToolTipRenderer;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.MetaTileEntity;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.player.InventoryPlayer;
+
+import java.util.List;
+
import org.lwjgl.opengl.GL11;
/**
@@ -11,24 +26,93 @@ import org.lwjgl.opengl.GL11;
* <p/>
* The GUI-Container I use for all my MetaTileEntities
*/
-public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer {
+public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer implements GT_IToolTipRenderer, GT_ITabRenderer {
public final GT_ContainerMetaTile_Machine mContainer;
+ // IGuiScreen implementation
+ protected GT_GuiTooltipManager mTooltipManager = new GT_GuiTooltipManager();
+
+ // Cover Tabs support. Subclasses can override display position, style and visuals by overriding setupCoverTabs
+ public GT_GuiCoverTabLine coverTabs;
+ private static final int
+ COVER_TAB_LEFT = -16,
+ COVER_TAB_TOP = 1,
+ COVER_TAB_HEIGHT = 20,
+ COVER_TAB_WIDTH = 18,
+ COVER_TAB_SPACING = 2;
+ private static final DisplayStyle
+ COVER_TAB_X_DIR = DisplayStyle.NONE,
+ COVER_TAB_Y_DIR = DisplayStyle.NORMAL;
+ private static final GT_GuiTabIconSet TAB_ICONSET = new GT_GuiTabIconSet(
+ GT_GuiIcon.TAB_NORMAL,
+ GT_GuiIcon.TAB_HIGHLIGHT,
+ GT_GuiIcon.TAB_DISABLED);
+
public GT_GUIContainerMetaTile_Machine(GT_ContainerMetaTile_Machine aContainer, String aGUIbackground) {
super(aContainer, aGUIbackground);
mContainer = aContainer;
+
+ DisplayStyle preferredDisplayStyle = GT_Mod.gregtechproxy.mCoverTabsVisible
+ ? (GT_Mod.gregtechproxy.mCoverTabsFlipped ? DisplayStyle.INVERSE : DisplayStyle.NORMAL)
+ : DisplayStyle.NONE;
+ setupCoverTabs(preferredDisplayStyle);
}
- public GT_GUIContainerMetaTile_Machine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aGUIbackground) {
+ public GT_GUIContainerMetaTile_Machine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity,
+ String aGUIbackground) {
this(new GT_ContainerMetaTile_Machine(aInventoryPlayer, aTileEntity), aGUIbackground);
}
+ /**
+ * Initialize the coverTabs object according to client preferences
+ */
+ protected void setupCoverTabs(DisplayStyle preferredDisplayStyle) {
+ coverTabs = new GT_GuiCoverTabLine(
+ this,
+ COVER_TAB_LEFT,
+ COVER_TAB_TOP,
+ COVER_TAB_HEIGHT,
+ COVER_TAB_WIDTH,
+ COVER_TAB_SPACING,
+ COVER_TAB_X_DIR,
+ COVER_TAB_Y_DIR,
+ preferredDisplayStyle,
+ getTabBackground(),
+ getMachine().getBaseMetaTileEntity(),
+ getColorization());
+ }
+
+ @Override
+ public void drawScreen(int mouseX, int mouseY, float parTicks) {
+ super.drawScreen(mouseX, mouseY, parTicks);
+ if (mc.thePlayer.inventory.getItemStack() == null) {
+ GL11.glPushMatrix();
+ GL11.glTranslatef(guiLeft, guiTop, 0.0F);
+ mTooltipManager.onTick(this, mouseX, mouseY);
+ GL11.glPopMatrix();
+ }
+ }
+
@Override
- protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
- super.drawGuiContainerBackgroundLayer(par1, par2, par3);
+ protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) {
+ // Drawing tabs
+ coverTabs.drawTabs(parTicks, mouseX, mouseY);
+
+ // Applying machine coloration, which subclasses rely on
+ Dyes color = getColorization();
+ GL11.glColor3ub((byte) color.mRGBa[0], (byte) color.mRGBa[1], (byte) color.mRGBa[2]);
+
+ // Binding machine's own texture, which subclasses rely on being set
+ super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY);
+ }
+
+ /**
+ * @return The color used to render this machine's GUI
+ */
+ private Dyes getColorization() {
if (GregTech_API.sMachineMetalGUI) {
- GL11.glColor3ub((byte) Dyes.MACHINE_METAL.mRGBa[0], (byte) Dyes.MACHINE_METAL.mRGBa[1], (byte) Dyes.MACHINE_METAL.mRGBa[2]);
+ return Dyes.MACHINE_METAL;
} else if (GregTech_API.sColoredGUI && mContainer != null && mContainer.mTileEntity != null) {
byte colorByte = mContainer.mTileEntity.getColorization();
Dyes color;
@@ -36,9 +120,74 @@ public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer {
color = Dyes.get(colorByte);
else
color = Dyes.MACHINE_METAL;
- GL11.glColor3ub((byte) color.mRGBa[0], (byte) color.mRGBa[1], (byte) color.mRGBa[2]);
+ return color;
} else {
- GL11.glColor3ub((byte) 255, (byte) 255, (byte) 255);
+ return Dyes.dyeWhite;
}
}
+
+ /**
+ * @return This machine's MetaTileEntity
+ */
+ private MetaTileEntity getMachine() {
+ return (MetaTileEntity ) mContainer.mTileEntity.getMetaTileEntity();
+ }
+
+ // Tabs support
+
+ @Override
+ protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
+ {
+ super.mouseClicked(mouseX, mouseY, mouseButton);
+ // Check for clicked tabs
+ coverTabs.onMouseClicked(mouseX, mouseY, mouseButton);
+ }
+
+ @Override
+ public void initGui() {
+ super.initGui();
+ // Perform layout of tabs
+ coverTabs.onInit();
+ }
+
+ /**
+ * @return the background textures used by this machine GUI's tabs
+ */
+ protected GT_GuiTabIconSet getTabBackground() {
+ return TAB_ICONSET;
+ }
+
+ // GT_IToolTipRenderer and GT_ITabRenderer implementations
+ @Override
+ public void drawHoveringText(List text, int x, int y, FontRenderer font) {
+ super.drawHoveringText(text, x, y, font);
+ }
+ @Override
+ public int getGuiTop() {
+ return guiTop;
+ }
+ @Override
+ public int getGuiLeft() {
+ return guiLeft;
+ }
+ @Override
+ public int getXSize() {
+ return xSize;
+ }
+ @Override
+ public FontRenderer getFontRenderer() {
+ return fontRendererObj;
+ }
+ @Override
+ public RenderItem getItemRenderer() {
+ return itemRender;
+ }
+ @Override
+ public void addToolTip(GT_GuiTooltip toolTip) {
+ mTooltipManager.addToolTip(toolTip);
+ }
+ @Override
+ public boolean removeToolTip(GT_GuiTooltip toolTip) {
+ return mTooltipManager.removeToolTip(toolTip);
+ }
}
diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java
index dc61578362..c13d151188 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java
@@ -1,9 +1,12 @@
package gregtech.api.gui;
import gregtech.api.enums.GT_Values;
+import gregtech.api.gui.widgets.GT_GuiIcon;
+import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine_Bronze;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine_Steel;
import gregtech.api.net.GT_Packet_SetConfigurationCircuit;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.InventoryPlayer;
@@ -33,6 +36,14 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin
"GT5U.machines.select_circuit.tooltip.2",
"GT5U.machines.select_circuit.tooltip.3"
);
+ private final static GT_GuiTabIconSet TAB_ICONSET_BRONZE = new GT_GuiTabIconSet(
+ GT_GuiIcon.TAB_NORMAL_BRONZE,
+ GT_GuiIcon.TAB_HIGHLIGHT_BRONZE,
+ GT_GuiIcon.TAB_DISABLED_BRONZE);
+ private final static GT_GuiTabIconSet TAB_ICONSET_STEEL = new GT_GuiTabIconSet(
+ GT_GuiIcon.TAB_NORMAL_STEEL,
+ GT_GuiIcon.TAB_HIGHLIGHT_STEEL,
+ GT_GuiIcon.TAB_DISABLED_STEEL);
public final String
mName,
mNEI;
@@ -102,7 +113,7 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin
if (mRenderAutoOutputSlots && x >= 25 && x <= 42) {
drawHoveringText(Collections.singletonList("Item Auto-Output"), x2, y2, fontRendererObj);
}
- if (getMachine().allowSelectCircuit() && getMachine().getStackInSlot(getMachine().getCircuitSlot()) == null && x >= 153 && x <= 180) {
+ if (getMachine().allowSelectCircuit() && getMachine().getStackInSlot(getMachine().getCircuitSlot()) == null && x >= 153 && x <= 171) {
drawHoveringText(GHOST_CIRCUIT_TOOLTIP.stream().map(StatCollector::translateToLocal).collect(Collectors.toList()), x2, y2, fontRendererObj);
}
}
@@ -172,6 +183,15 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin
}
}
+ @Override
+ protected GT_GuiTabIconSet getTabBackground() {
+ if (getMachine().isSteampowered()) {
+ return getMachine() instanceof GT_MetaTileEntity_BasicMachine_Steel
+ ? TAB_ICONSET_STEEL : TAB_ICONSET_BRONZE;
+ }
+ return super.getTabBackground();
+ }
+
private GT_Container_BasicMachine getContainer() {
return (GT_Container_BasicMachine) mContainer;
}
diff --git a/src/main/java/gregtech/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java
index 5a299d7ff9..4f61c95dd3 100644
--- a/src/main/java/gregtech/api/gui/GT_GUICover.java
+++ b/src/main/java/gregtech/api/gui/GT_GUICover.java
@@ -1,11 +1,14 @@
package gregtech.api.gui;
+import gregtech.api.enums.GT_Values;
import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.net.GT_Packet_GtTileEntityGuiRequest;
import net.minecraft.item.ItemStack;
public abstract class GT_GUICover extends GT_GUIScreen {
public final ICoverable tile;
+ public int parentGuiId = -1;
public GT_GUICover(ICoverable tile, int width, int height, ItemStack cover) {
super(width, height, cover == null ? "" : cover.getDisplayName());
@@ -20,4 +23,30 @@ public abstract class GT_GUICover extends GT_GUIScreen {
closeScreen();
}
}
+
+ /**
+ * The parent GUI to exit to. -1 is ignored.
+ * @param parentGuiId
+ */
+ public void setParentGuiId(int parentGuiId) {
+ this.parentGuiId = parentGuiId;
+ }
+
+
+ @Override
+ public void closeScreen() {
+ // If this cover was given a guiId, tell the server to open it for us when this GUI closes.
+ if (parentGuiId != -1 && tile.isUseableByPlayer(mc.thePlayer)) {
+ GT_Values.NW.sendToServer(new GT_Packet_GtTileEntityGuiRequest(
+ tile.getXCoord(),
+ tile.getYCoord(),
+ tile.getZCoord(),
+ parentGuiId,
+ tile.getWorld().provider.dimensionId,
+ mc.thePlayer.getEntityId()));
+ } else {
+ this.mc.displayGuiScreen(null);
+ this.mc.setIngameFocus();
+ }
+ }
}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
new file mode 100644
index 0000000000..c470936db2
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
@@ -0,0 +1,170 @@
+package gregtech.api.gui.widgets;
+
+import java.awt.Rectangle;
+import java.util.List;
+
+import org.lwjgl.opengl.GL11;
+
+import codechicken.nei.api.API;
+import codechicken.nei.api.INEIGuiAdapter;
+import gregtech.api.enums.Dyes;
+import gregtech.api.enums.GT_Values;
+import gregtech.api.gui.GT_GUIContainerMetaTile_Machine;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.net.GT_Packet_GtTileEntityGuiRequest;
+import gregtech.common.GT_Proxy;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
+
+/**
+ * Let's you access a GregTech IGregTechTileEntity's covers as tabs on the GUI's sides
+ */
+public class GT_GuiCoverTabLine extends GT_GuiTabLine {
+ // Names of the block a cover could be on
+ private final static String[] SIDES = new String[]{
+ "GT5U.interface.coverTabs.down",
+ "GT5U.interface.coverTabs.up",
+ "GT5U.interface.coverTabs.north",
+ "GT5U.interface.coverTabs.south",
+ "GT5U.interface.coverTabs.west",
+ "GT5U.interface.coverTabs.east"};
+
+ // Not sure there's a point in JIT translation but that's what this is
+ private String[] translatedSides;
+ private IGregTechTileEntity tile;
+ private Dyes colorization;
+
+ /**
+ * Let's you access an IGregTechTileEntity's covers as tabs on the GUI's sides
+ *
+ * @param gui GT_ITabRenderer gui which this tab line attaches to
+ * @param tabLineLeft left position of the tab line in relation to the gui
+ * @param tabLineTop top position of the tab line in relation to the gui
+ * @param tabHeight height of a tab
+ * @param tabWidth width of a tab
+ * @param tabSpacing pixels between each tab
+ * @param xDir whether to extend the line horizontally to the right (NORMAL),
+ * the left (INVERSE) or not at all (NONE)
+ * @param yDir whether to extend the line vertically down (NORMAL), up (INVERSE)
+ * or not at all (NONE)
+ * @param displayMode whether to display on the left side of the GT_ITabRenderer
+ * (NORMAL), on it's right side (INVERSE) or not at all (NONE)
+ * @param tabBackground the set of textures used to draw this tab line's tab backgrounds
+ * @param tile The IGregTechTileEntity the covers of which we are accessing
+ * @param colorization The colorization of the GUI we are adding tabs to
+ */
+ public GT_GuiCoverTabLine(GT_GUIContainerMetaTile_Machine gui, int tabLineLeft, int tabLineTop, int tabHeight,
+ int tabWidth, int tabSpacing, DisplayStyle xDir, DisplayStyle yDir, DisplayStyle displayMode,
+ GT_GuiTabIconSet tabBackground, IGregTechTileEntity tile, Dyes colorization) {
+ super(gui, 6, tabLineLeft, tabLineTop, tabHeight, tabWidth, tabSpacing, xDir, yDir, displayMode, tabBackground);
+ this.tile = tile;
+ this.colorization = colorization;
+ this.translatedSides = new String[6];
+ setupTabs();
+ }
+
+ /**
+ * Add a tab for each existing cover on this IGregTechTileEntity at creation time
+ */
+ private void setupTabs() {
+ for (byte tSide = 0; tSide < 6; tSide++) {
+ ItemStack cover = tile.getCoverItemAtSide(tSide);
+ if (cover != null) {
+ addCoverToTabs(tSide, cover);
+ }
+ }
+ }
+
+ @Override
+ protected void drawBackground(float parTicks, int mouseX, int mouseY) {
+ // Apply this tile's coloration to draw the background
+ GL11.glColor3ub((byte) colorization.mRGBa[0], (byte) colorization.mRGBa[1], (byte) colorization.mRGBa[2]);
+ super.drawBackground(parTicks, mouseX, mouseY);
+ }
+
+ @Override
+ protected void tabClicked(int tabId, int mouseButton) {
+ if (mouseButton == 0 && mTabs[tabId].enabled) {
+ GT_Values.NW.sendToServer(new GT_Packet_GtTileEntityGuiRequest(
+ this.tile.getXCoord(),
+ this.tile.getYCoord(),
+ this.tile.getZCoord(),
+ tabId + GT_Proxy.GUI_ID_COVER_SIDE_BASE,
+ this.tile.getWorld().provider.dimensionId,
+ Minecraft.getMinecraft().thePlayer.getEntityId(),
+ 0));
+ }
+ }
+
+ /**
+ * Add the cover on this side of the IGregTechTileEntity to the tabs
+ * @param side
+ * @param cover
+ */
+ private void addCoverToTabs(byte side, ItemStack cover) {
+ boolean enabled = this.tile.getCoverBehaviorAtSideNew(side).hasCoverGUI();
+ this.setTab(side, cover, null, getTooltipForCoverTab(side, cover, enabled));
+ this.setTabEnabled(side, enabled);
+
+ }
+
+ /**
+ * Decorate the cover's tooltips according to the side it's on and on whether the tab is enabled or not
+ * @param side
+ * @param cover
+ * @param enabled
+ * @return This cover tab's tooltip
+ */
+ private String[] getTooltipForCoverTab(byte side, ItemStack cover, boolean enabled) {
+ List<String> tooltip = cover.getTooltip(Minecraft.getMinecraft().thePlayer, true);
+ tooltip.set(0,
+ (enabled ? EnumChatFormatting.UNDERLINE : EnumChatFormatting.DARK_GRAY)
+ + getSideDescription(side)
+ + (enabled ? EnumChatFormatting.RESET + ": " : ": " + EnumChatFormatting.RESET)
+ + tooltip.get(0));
+ return tooltip.toArray(new String[0]);
+ }
+
+ /**
+ * Get the translated name for a side of the IGregTechTileEntity
+ * @param side
+ * @return translated name for a side of the IGregTechTileEntity
+ */
+ private String getSideDescription(byte side) {
+ if (side < SIDES.length) {
+ if (this.translatedSides[side] == null) {
+ this.translatedSides[side] = StatCollector.translateToLocal(SIDES[side]);
+ }
+ return this.translatedSides[side] ;
+ }
+ return null;
+ }
+
+ /**
+ * Hide any NEI slots that would intersect with a cover tab
+ */
+ static class CoverTabLineNEIHandler extends INEIGuiAdapter{
+ @Override
+ public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
+ Rectangle neiSlotArea = new Rectangle(x, y, w, h);
+ if (gui instanceof GT_GUIContainerMetaTile_Machine) {
+ GT_GuiTabLine tabLine = ((GT_GUIContainerMetaTile_Machine) gui).coverTabs;
+ if (!tabLine.visible) {
+ return false;
+ }
+ for (int i = 0; i < tabLine.mTabs.length; i++ ) {
+ if (tabLine.mTabs[i] != null && tabLine.mTabs[i].getBounds().intersects(neiSlotArea)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ }
+ static {
+ API.registerNEIGuiHandler(new CoverTabLineNEIHandler());
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
index 0b9231b40f..92fda43f1f 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
@@ -1,10 +1,13 @@
package gregtech.api.gui.widgets;
+import java.util.Arrays;
+
+import gregtech.api.interfaces.IGuiIcon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
-public enum GT_GuiIcon {
+public enum GT_GuiIcon implements IGuiIcon{
BUTTON_NORMAL (0, 0, 0),
BUTTON_DOWN (0, 32, 0),
BUTTON_HIGHLIGHT (0, 32*2, 0),
@@ -28,19 +31,37 @@ public enum GT_GuiIcon {
GREEN_ARROW_DOWN (0, 32*5, 32*2),
SLOT_DARKGRAY (1, 176,0,18,18),
- SLOT_GRAY (1, 176,18,18,18);
+ SLOT_GRAY (1, 176,18,18,18),
+
+ TAB_NORMAL (2, 0, 0,18,20),
+ TAB_HIGHLIGHT (2, 18, 0,18,20),
+ TAB_DISABLED (2, 18*2, 0,18,20),
+ TAB_NORMAL_BRONZE (2, 0, 20,18,20),
+ TAB_HIGHLIGHT_BRONZE (2, 18, 20,18,20),
+ TAB_DISABLED_BRONZE (2, 18*2, 20,18,20),
+ TAB_NORMAL_STEEL (2, 0,2*20,18,20),
+ TAB_HIGHLIGHT_STEEL (2, 18,2*20,18,20),
+ TAB_DISABLED_STEEL (2, 18*2,2*20,18,20),
+ TAB_NORMAL_BRICK (2, 0,3*20,18,20),
+ TAB_HIGHLIGHT_BRICK (2, 18,3*20,18,20),
+ TAB_DISABLED_BRICK (2, 18*2,3*20,18,20),
+ TAB_INFO_GRAY (2, 220, 0,18,20),
+ TAB_INFO_BLUE (2,220+18, 0,18,20),
+;
+
private static final int T_SIZE = 256;
- private static final ResourceLocation[] TEXTURES = {
+ private static ResourceLocation[] TEXTURES = {
new ResourceLocation("gregtech", "textures/gui/GuiButtons.png"),
- new ResourceLocation("gregtech", "textures/gui/GuiCover.png")
+ new ResourceLocation("gregtech", "textures/gui/GuiCover.png"),
+ new ResourceLocation("gregtech", "textures/gui/GuiTabs.png"),
};
public final int x, y, width, height;
- public final GT_GuiIcon overlay;
+ public final IGuiIcon overlay;
private final int texID;
- GT_GuiIcon(int texID, int x, int y, int width, int height, GT_GuiIcon overlay) {
+ GT_GuiIcon(int texID, int x, int y, int width, int height, IGuiIcon overlay) {
this.x = x;
this.y = y;
this.width = width;
@@ -55,26 +76,77 @@ public enum GT_GuiIcon {
GT_GuiIcon(int texID, int x, int y, int width, int height) {
this(texID, x, y, width, height,null);
}
+ public static void render(IGuiIcon icon, double x, double y, double width, double height, double zLevel,
+ boolean doDraw) {
+ render(icon, x, y, width, height, zLevel, doDraw, false);
+ }
- public static void render(GT_GuiIcon icon, double x, double y, double width, double height, double zLevel, boolean doDraw) {
+ public static void render(IGuiIcon icon, double x, double y, double width, double height, double zLevel,
+ boolean doDraw, boolean flipHoritontally) {
Tessellator tess = Tessellator.instance;
if (doDraw) {
- Minecraft.getMinecraft().renderEngine.bindTexture(TEXTURES[icon.texID]);
+ Minecraft.getMinecraft().renderEngine.bindTexture(TEXTURES[icon.getTexId()]);
tess.startDrawingQuads();
}
- double minU = (double) icon.x / T_SIZE;
- double maxU = (double) (icon.x + icon.width) / T_SIZE;
- double minV = (double) icon.y / T_SIZE;
- double maxV = (double) (icon.y + icon.height) / T_SIZE;
+ double minU = (double) (icon.getX() + (flipHoritontally ? icon.getWidth() : 0)) / T_SIZE;
+ double maxU = (double) (icon.getX() + (flipHoritontally ? 0: icon.getWidth())) / T_SIZE;
+ double minV = (double) icon.getY() / T_SIZE;
+ double maxV = (double) (icon.getY() + icon.getHeight()) / T_SIZE;
tess.addVertexWithUV(x, y + height, zLevel, minU, maxV);
tess.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
tess.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV);
tess.addVertexWithUV(x, y + 0, zLevel, minU, minV);
- if (icon.overlay != null)
- render(icon.overlay, x, y, width, height, zLevel, false);
+ if (icon.getOverlay() != null)
+ render(icon.getOverlay(), x, y, width, height, zLevel, false);
if (doDraw)
tess.draw();
}
+
+ /**
+ * This is intended to enable addon mods to register additional textures. They can then add to this enum using
+ * EnumHelper.addEnum or by creating your their enum that implements IGuiIcon (still requires adding a texture here)
+ *
+ * @param location
+ */
+ public static void addTextures(ResourceLocation... location) {
+ if (location == null || location.length == 0) return;
+
+ int startIndex = TEXTURES.length;
+ TEXTURES = (ResourceLocation[]) Arrays.copyOf(TEXTURES, location.length);
+ for (int i = 0; i < location.length; i++) {
+ TEXTURES[startIndex + i] = location[i];
+ }
+ }
+
+ @Override
+ public int getX() {
+ return this.x;
+ }
+
+ @Override
+ public int getY() {
+ return this.y;
+ }
+
+ @Override
+ public int getWidth() {
+ return this.width;
+ }
+
+ @Override
+ public int getHeight() {
+ return this.height;
+ }
+
+ @Override
+ public int getTexId() {
+ return this.texID;
+ }
+
+ @Override
+ public IGuiIcon getOverlay() {
+ return this.overlay;
+ }
}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java
new file mode 100644
index 0000000000..60672db880
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java
@@ -0,0 +1,166 @@
+package gregtech.api.gui.widgets;
+
+import java.awt.Rectangle;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL12;
+
+import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet;
+import gregtech.api.gui.widgets.GT_GuiTabLine.GT_ITabRenderer;
+import gregtech.api.interfaces.IGuiIcon;
+import net.minecraft.client.Minecraft;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+
+/**
+ * A tab to be attached to a tab line
+ */
+public class GT_GuiTab {
+ private static final int SLOT_SIZE = 18;
+
+ public boolean
+ visible = true,
+ mousedOver,
+ enabled = true;
+
+ private Rectangle bounds;
+ private GT_GuiTabIconSet tabBackground;
+ private ItemStack item;
+ private GT_ITabRenderer gui;
+ private GT_GuiTooltip tooltip;
+ private IGuiIcon overlay;
+ private boolean flipHorizontally;
+
+ /**
+ * A tab to be attached to a tab line
+ *
+ * @param gui IGregTechTileEntity the tab line this tab belongs to is attached to
+ * @param id both the ID and position in the tab line of this tab
+ * @param bounds bounds of this tab
+ * @param tabBackground set of background textures
+ * @param item item to draw atop the background texture, not colored
+ * @param overlay texture to draw atop the background texture, not colored
+ * @param tooltipText tooltip of this tab
+ * @param flipHorizontally whether to draw this tab on the right side of the IGregTechTileEntity
+ */
+ public GT_GuiTab( GT_ITabRenderer gui, int id, Rectangle bounds, GT_GuiTabIconSet tabBackground, ItemStack item,
+ IGuiIcon overlay, String[] tooltipText, boolean flipHorizontally) {
+ this.gui = gui;
+ this.bounds = bounds;
+ this.item = item;
+ this.tabBackground = tabBackground;
+ this.overlay = overlay;
+ if (tooltipText != null) {
+ setTooltipText(tooltipText);
+ }
+ this.flipHorizontally = flipHorizontally;
+ }
+
+ public GT_GuiTab( GT_ITabRenderer gui, int id, Rectangle bounds, GT_GuiTabIconSet tabBackground) {
+ this(gui, id, bounds, tabBackground, null, null, null, false);
+ }
+
+ /**
+ * Set this tab's tooltip text
+ *
+ * @param text
+ * @return This tab for chaining
+ */
+ public GT_GuiTab setTooltipText(String... text) {
+ if (tooltip == null) {
+ tooltip = new GT_GuiTooltip(bounds, text);
+ gui.addToolTip(tooltip);
+ }
+ else {
+ tooltip.setToolTipText(text);
+ }
+ return this;
+ }
+
+ /**
+ * @return This tab's tooltip object
+ */
+ public GT_GuiTooltip getTooltip() {
+ return tooltip;
+ }
+
+ /**
+ * Draw the background texture for this tab
+ *
+ * @param mouseX
+ * @param mouseY
+ * @param parTicks
+ */
+ public void drawBackground(int mouseX, int mouseY, float parTicks) {
+ if (this.visible) {
+ GT_GuiIcon.render(getBackgroundTexture(), bounds.x, bounds.y, bounds.width, bounds.height, 1, true,
+ this.flipHorizontally);
+ }
+ }
+
+ /**
+ * Draw overlay textures and items atop the background texture
+ *
+ * @param mouseX
+ * @param mouseY
+ * @param parTicks
+ */
+ public void drawOverlays(int mouseX, int mouseY, float parTicks) {
+ this.mousedOver = bounds.contains(mouseX, mouseY);
+
+ if (this.tooltip != null) {
+ this.tooltip.enabled = this.visible;
+ }
+
+ if (this.visible) {
+ if (overlay != null) {
+ GL11.glColor4f(1, 1, 1, 1);
+ GT_GuiIcon.render(overlay, bounds.x, bounds.y, bounds.width, bounds.height, 1, true);
+ }
+ if (item != null) {
+ GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
+
+ if (item.getItem() instanceof ItemBlock) {
+ GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
+ GL11.glEnable(GL12.GL_RESCALE_NORMAL);
+ }
+ int margin = (bounds.height - SLOT_SIZE);
+ gui.getItemRenderer().renderItemAndEffectIntoGUI(gui.getFontRenderer(),
+ Minecraft.getMinecraft().getTextureManager(), item,
+ bounds.x + (this.flipHorizontally ? 0 : margin), bounds.y + margin);
+
+ if (item.getItem() instanceof ItemBlock)
+ GL11.glPopAttrib();
+
+ GL11.glPopAttrib();
+ }
+ }
+ }
+
+ /**
+ * @return the texture this tab should currently use as it's background
+ */
+ protected IGuiIcon getBackgroundTexture() {
+ if (!enabled)
+ return tabBackground.disabled;
+
+ return mousedOver ? tabBackground.highlight : tabBackground.normal;
+ }
+
+ /**
+ * @return the screen space occupied by this tab
+ */
+ public Rectangle getBounds() {
+ return this.bounds;
+ }
+
+ /**
+ * Reposition this tab on the screen
+ *
+ * @param xPos
+ * @param yPos
+ */
+ public void setPosition(int xPos, int yPos) {
+ this.bounds = new Rectangle( xPos, yPos, bounds.width, bounds.height);
+ }
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java
new file mode 100644
index 0000000000..e7ac596dee
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java
@@ -0,0 +1,271 @@
+package gregtech.api.gui.widgets;
+
+import java.awt.Rectangle;
+
+import org.lwjgl.opengl.GL11;
+
+import gregtech.api.interfaces.IGuiIcon;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.renderer.entity.RenderItem;
+import net.minecraft.item.ItemStack;
+
+/**
+ * Draws clickable and configurable tabs on the left or right side of another GUI
+ */
+public class GT_GuiTabLine {
+ /**
+ * Defines a set of textures a tab line can use to render it's tab backgrounds
+ */
+ public static class GT_GuiTabIconSet {
+ public IGuiIcon disabled;
+ public IGuiIcon normal;
+ public IGuiIcon highlight;
+
+ public GT_GuiTabIconSet(IGuiIcon normalIcon, IGuiIcon highlightIcon, IGuiIcon disabledIcon) {
+ this. normal = normalIcon;
+ this. highlight = highlightIcon;
+ this. disabled = disabledIcon;
+ }
+ }
+
+ /**
+ * Controls the rendering style of the tab line
+ */
+ public static enum DisplayStyle {
+ NONE((byte)0),
+ NORMAL((byte)1),
+ INVERSE((byte)-1);
+
+ private byte value;
+ DisplayStyle(byte value) {
+ this.value = value;
+ }
+
+ public byte getValue() {
+ return value;
+ }
+ }
+
+ /**
+ * A GUI should implement these methods as well as call the tab line's
+ * onMouseClicked, onInit and drawTabs for the tab line to attach to it properly.
+ */
+ public interface GT_ITabRenderer {
+ int getGuiLeft();
+ int getGuiTop();
+ int getXSize();
+
+ RenderItem getItemRenderer();
+ FontRenderer getFontRenderer();
+
+ void addToolTip(GT_GuiTooltip tooltip);
+ boolean removeToolTip(GT_GuiTooltip tooltip);
+ }
+
+ // The tabs are arranged according to their index in this array
+ protected final GT_GuiTab[] mTabs;
+
+ private int
+ tabLineLeft,
+ tabLineTop,
+ tabHeight,
+ tabWidth,
+ tabSpacing;
+
+ // In which direction to draw the tab line
+ private DisplayStyle
+ xDir,
+ yDir;
+
+ // Whether to display on the right side of the GT_ITabRenderer instead of left
+ protected boolean
+ flipHorizontally,
+ visible;
+
+ private GT_GuiTabIconSet tabBackground;
+ private GT_ITabRenderer gui;
+
+
+ /**
+ * Draws clickable and configurable tabs on the left or right side of a GT_ITabRenderer
+ *
+ * @param gui GT_ITabRenderer gui which this tab line attaches to
+ * @param numTabs number of tab positions in this tab line
+ * @param tabLineLeft left position of the tab line in relation to the gui
+ * @param tabLineTop top position of the tab line in relation to the gui
+ * @param tabHeight height of a tab
+ * @param tabWidth width of a tab
+ * @param tabSpacing pixels between each tab
+ * @param xDir whether to extend the line horizontally to the right (NORMAL),
+ * the left (INVERSE) or not at all (NONE)
+ * @param yDir whether to extend the line vertically down (NORMAL), up (INVERSE)
+ * or not at all (NONE)
+ * @param displayMode whether to display on the left side of the GT_ITabRenderer
+ * (NORMAL), on it's right side (INVERSE) or not at all (NONE)
+ * @param tabBackground the set of textures used to draw this tab line's tab backgrounds
+ */
+ public GT_GuiTabLine(GT_ITabRenderer gui, int numTabs, int tabLineLeft, int tabLineTop, int tabHeight, int tabWidth,
+ int tabSpacing, DisplayStyle xDir, DisplayStyle yDir, DisplayStyle displayMode, GT_GuiTabIconSet tabBackground) {
+ this.gui = gui;
+ this.mTabs = new GT_GuiTab[numTabs];
+ this.tabLineLeft = tabLineLeft;
+ this.tabLineTop = tabLineTop;
+ this.tabHeight = tabHeight;
+ this.tabWidth = tabWidth;
+ this.tabSpacing = tabSpacing;
+ this.xDir = xDir;
+ this.yDir = yDir;
+ this.tabBackground = tabBackground;
+ this.flipHorizontally = displayMode == DisplayStyle.INVERSE;
+ this.visible = !(displayMode == DisplayStyle.NONE);
+ }
+
+ /**
+ * Creates a new tab at the specified position with the given parameters.
+ * This class handles the positioning.
+ *
+ * @param tabId
+ * @param item
+ * @param overlay
+ * @param text
+ */
+ public void setTab(int tabId, ItemStack item, IGuiIcon overlay, String[] text) {
+ mTabs[tabId] = new GT_GuiTab( this.gui, tabId, getBoundsForTab(tabId),
+ this.tabBackground, item, overlay, text, this.flipHorizontally);
+ }
+
+ /**
+ * Get the bounds a given tab should occupy
+ *
+ * @param tabId
+ * @return
+ */
+ protected Rectangle getBoundsForTab(int tabId) {
+ return new Rectangle (
+ getTabX(tabId),
+ getTabY(tabId),
+ this.tabWidth,
+ this.tabHeight);
+ }
+
+ /**
+ * Enable or disable a tab. Disabled tabs have a dark background.
+ *
+ * @param tabId
+ * @param value
+ */
+ public void setTabEnabled(int tabId, boolean value) {
+ if (mTabs[tabId] != null) {
+ mTabs[tabId].enabled = value;
+ }
+ }
+
+
+ /**
+ * Draw the tabs for this tab bar
+ * GT_ITabRenderer must call this method on drawGuiContainerBackgroundLayer
+ * or on drawScreen.
+ *
+ * @param parTicks
+ * @param mouseX
+ * @param mouseY
+ */
+ public void drawTabs(float parTicks, int mouseX, int mouseY) {
+ if (this.visible) {
+ GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ drawBackground(parTicks, mouseX, mouseY);
+ drawOverlays(parTicks, mouseX, mouseY);
+ GL11.glPopAttrib();
+ }
+ }
+
+ /**
+ * Draw the tab's backgrounds first
+ *
+ * @param parTicks
+ * @param mouseX
+ * @param mouseY
+ */
+ protected void drawOverlays(float parTicks, int mouseX, int mouseY) {
+ for (int i = 0; i < mTabs.length; i++) {
+ if (mTabs[i] != null) {
+ mTabs[i].drawOverlays(mouseX, mouseY, parTicks);
+ }
+ }
+ }
+
+ /**
+ * Draw anything that overlays the tab's background texture
+ *
+ * @param parTicks
+ * @param mouseX
+ * @param mouseY
+ */
+ protected void drawBackground(float parTicks, int mouseX, int mouseY) {
+ for (int i = 0; i < mTabs.length; i++) {
+ if (mTabs[i] != null) {
+ mTabs[i].drawBackground(mouseX, mouseY, parTicks);
+ }
+ }
+ }
+
+ /**
+ * Call tabClick for every tab that was clicked.
+ * GT_ITabRenderer must call this method on mouseClicked.
+ *
+ * @param mouseX
+ * @param mouseY
+ * @param mouseButton
+ */
+ public void onMouseClicked(int mouseX, int mouseY, int mouseButton) {
+ for(int tabId = 0; tabId < mTabs.length; tabId++) {
+ if (mTabs[tabId] != null && mTabs[tabId].getBounds().contains(mouseX, mouseY)) {
+ tabClicked(tabId, mouseButton);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Act on a tab being clicked.
+ *
+ * @param tabId
+ * @param mouseButton
+ */
+ protected void tabClicked(int tabId, int mouseButton) { }
+
+ /**
+ * Reposition ourselves whenever the GT_ITabRenderer does so.
+ * GT_ITabRenderer must call this method on Init.
+ */
+ public void onInit() {
+ for (int i = 0; i < mTabs.length; i++) {
+ if (mTabs[i] != null) {
+ mTabs[i].setPosition(getTabX(i), getTabY(i));
+ }
+ }
+ }
+
+ /**
+ * Get the proper X position for a given tab
+ *
+ * @param tabId
+ * @return
+ */
+ private int getTabX(int tabId) {
+ return this.gui.getGuiLeft() + (flipHorizontally ? (gui.getXSize() - tabLineLeft - tabWidth) : tabLineLeft)
+ + (tabId * (tabWidth + tabSpacing) * xDir.getValue());
+ }
+
+ /**
+ * Get the proper Y position for a given tab
+ *
+ * @param tabId
+ * @return
+ */
+ private int getTabY(int tabId) {
+ return this.gui.getGuiTop() + tabLineTop + (tabId * (tabHeight + tabSpacing) * yDir.getValue());
+ }
+}
diff --git a/src/main/java/gregtech/api/interfaces/IGuiIcon.java b/src/main/java/gregtech/api/interfaces/IGuiIcon.java
new file mode 100644
index 0000000000..2167270e6c
--- /dev/null
+++ b/src/main/java/gregtech/api/interfaces/IGuiIcon.java
@@ -0,0 +1,13 @@
+package gregtech.api.interfaces;
+
+/**
+ * To allow addons to make use of GT_GuiIcon
+ */
+public interface IGuiIcon {
+ int getX();
+ int getY();
+ int getWidth();
+ int getHeight();
+ int getTexId();
+ IGuiIcon getOverlay();
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java b/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java
new file mode 100644
index 0000000000..bf412c4400
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java
@@ -0,0 +1,112 @@
+package gregtech.api.net;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.enums.GT_Values;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.common.GT_Proxy;
+import io.netty.buffer.ByteBuf;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+
+/**
+ * Client -> Server: Request that the server opens a Gregtech GUI for us after providing us with the required data.
+ */
+public class GT_Packet_GtTileEntityGuiRequest extends GT_Packet_New {
+
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected int guiId;
+ protected int dimId, playerId;
+
+ protected int parentGuiId;
+
+ public GT_Packet_GtTileEntityGuiRequest() {
+ super(true);
+ }
+
+ public GT_Packet_GtTileEntityGuiRequest(int mX, short mY, int mZ, int guiId, int dimID, int playerID, int parentGuiId) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.guiId = guiId;
+
+ this.dimId = dimID;
+ this.playerId = playerID;
+
+ this.parentGuiId = parentGuiId;
+ }
+
+ public GT_Packet_GtTileEntityGuiRequest(int mX, short mY, int mZ, int guiId, int dimID, int playerID) {
+ this(mX, mY, mZ, guiId, dimID, playerID, -1);
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeInt(guiId);
+
+ aOut.writeInt(dimId);
+ aOut.writeInt(playerId);
+
+ aOut.writeInt(parentGuiId);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_GtTileEntityGuiRequest(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+
+ aData.readInt(),
+
+ aData.readInt(),
+ aData.readInt(),
+
+ aData.readInt());
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 15;
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ World world = DimensionManager.getWorld(this.dimId);
+ if (world == null) return;
+ TileEntity tile = world.getTileEntity(this.mX, this.mY, this.mZ);
+ if (!(tile instanceof IGregTechTileEntity) || ((IGregTechTileEntity) tile).isDead()) return;
+
+ IGregTechTileEntity gtTile = ((IGregTechTileEntity) tile);
+ EntityPlayerMP player = (EntityPlayerMP) world.getEntityByID(playerId);
+ // If the requested Gui ID corresponds to a cover, send the cover data to the client so they can open it.
+ if (GT_Proxy.GUI_ID_COVER_SIDE_BASE <= guiId && guiId < GT_Proxy.GUI_ID_COVER_SIDE_BASE+6) {
+ byte coverSide = (byte) (guiId - GT_Proxy.GUI_ID_COVER_SIDE_BASE);
+ GT_Packet_TileEntityCoverGUI packet = new GT_Packet_TileEntityCoverGUI(
+ this.mX, this.mY, this.mZ,
+ coverSide,
+ gtTile.getCoverIDAtSide(coverSide),
+ gtTile.getComplexCoverDataAtSide(coverSide),
+ this.dimId,
+ this.playerId,
+ parentGuiId);
+ GT_Values.NW.sendToPlayer(packet, player);
+ } else if (guiId == 0) {
+ gtTile.openGUI(player);
+ }
+ }
+
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java
index e5cb184339..687bceb726 100644
--- a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java
+++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java
@@ -2,14 +2,15 @@ package gregtech.api.net;
import com.google.common.io.ByteArrayDataInput;
import gregtech.api.GregTech_API;
-import gregtech.api.enums.GT_Values;
+import gregtech.api.gui.GT_GUICover;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.util.GT_CoverBehaviorBase;
import gregtech.api.util.ISerializableObject;
-import gregtech.common.GT_Proxy;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.entity.EntityClientPlayerMP;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
@@ -27,11 +28,14 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
protected int coverID, dimID, playerID;
protected ISerializableObject coverData;
+ protected int parentGuiId;
+
public GT_Packet_TileEntityCoverGUI() {
super(true);
}
- public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, byte coverSide, int coverID, int coverData, int dimID, int playerID) {
+ public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, byte coverSide, int coverID, int coverData, int dimID,
+ int playerID) {
super(false);
this.mX = mX;
this.mY = mY;
@@ -43,9 +47,26 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
this.dimID = dimID;
this.playerID = playerID;
+ this.parentGuiId = -1;
+ }
+
+ public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, byte coverSide, int coverID,
+ ISerializableObject coverData, int dimID, int playerID) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+ this.dimID = dimID;
+ this.playerID = playerID;
+ this.parentGuiId = -1;
}
- public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, byte coverSide, int coverID, ISerializableObject coverData, int dimID, int playerID) {
+ public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, byte coverSide, int coverID,
+ ISerializableObject coverData, int dimID, int playerID, int parentGuiId) {
super(false);
this.mX = mX;
this.mY = mY;
@@ -56,6 +77,7 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
this.coverData = coverData;
this.dimID = dimID;
this.playerID = playerID;
+ this.parentGuiId = parentGuiId;
}
@@ -72,6 +94,7 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
this.dimID = tile.getWorld().provider.dimensionId;
this.playerID = aPlayer.getEntityId();
+ this.parentGuiId = -1;
}
public GT_Packet_TileEntityCoverGUI(byte coverSide, int coverID, int coverData, IGregTechTileEntity tile) {
@@ -85,9 +108,11 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
this.coverData = new ISerializableObject.LegacyCoverData(coverData);
this.dimID = tile.getWorld().provider.dimensionId;
+ this.parentGuiId = -1;
}
- public GT_Packet_TileEntityCoverGUI(byte side, int coverID, ISerializableObject coverData, ICoverable tile, EntityPlayerMP aPlayer) {
+ public GT_Packet_TileEntityCoverGUI(byte side, int coverID, ISerializableObject coverData, ICoverable tile,
+ EntityPlayerMP aPlayer) {
super(false);
this.mX = tile.getXCoord();
this.mY = tile.getYCoord();
@@ -99,6 +124,7 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
this.dimID = tile.getWorld().provider.dimensionId;
this.playerID = aPlayer.getEntityId();
+ this.parentGuiId = -1;
}
@Override
@@ -118,6 +144,8 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
aOut.writeInt(dimID);
aOut.writeInt(playerID);
+
+ aOut.writeInt(parentGuiId);
}
@Override
@@ -133,19 +161,45 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
GregTech_API.getCoverBehaviorNew(coverID).createDataObject().readFromPacket(aData, null),
aData.readInt(),
+ aData.readInt(),
+
aData.readInt());
}
@Override
public void process(IBlockAccess aWorld) {
if (aWorld instanceof World) {
- EntityClientPlayerMP a = Minecraft.getMinecraft().thePlayer;
+ // Using EntityPlayer instead of EntityClientPlayerMP so both client and server can load this
+ EntityPlayer thePlayer = ((EntityPlayer) ((World)aWorld).getEntityByID(playerID));
TileEntity tile = aWorld.getTileEntity(mX, mY, mZ);
if (tile instanceof IGregTechTileEntity && !((IGregTechTileEntity) tile).isDead()) {
-
- ((IGregTechTileEntity) tile).setCoverDataAtSide(side, coverData); //Set it client side to read later.
- a.openGui(GT_Values.GT, GT_Proxy.GUI_ID_COVER_SIDE_BASE + side, a.worldObj, mX, mY, mZ);
+ IGregTechTileEntity gtTile = ((IGregTechTileEntity) tile);
+ gtTile.setCoverDataAtSide(side, coverData); //Set it client side to read later.
+
+ GuiScreen gui = (GuiScreen) getCoverGUI(side, thePlayer, thePlayer.worldObj, gtTile);
+ // If it's one of this mod's covers, tell it to exit to the GUI with the specified ID (-1 is ignored)
+ if (gui instanceof GT_GUICover) {
+ ((GT_GUICover) gui).setParentGuiId(parentGuiId);
+ }
+ Minecraft.getMinecraft().displayGuiScreen(gui);
}
}
}
+
+ /**
+ * Gets the specified cover's GUI object, if one exists
+ * @param aSide Block side (0 through 5)
+ * @param aPlayer Current player
+ * @param aWorld Current world
+ * @param aGtTile IGregTechTileEntity instance
+ * @return The specified cover's GUI, if one exists
+ */
+ private Object getCoverGUI(byte aSide, EntityPlayer aPlayer, World aWorld, IGregTechTileEntity aGtTile) {
+ GT_CoverBehaviorBase<?> cover = aGtTile.getCoverBehaviorAtSideNew(aSide);
+ if (cover.hasCoverGUI()) {
+ return cover.getClientGUI(
+ aSide, aGtTile.getCoverIDAtSide(aSide), aGtTile.getComplexCoverDataAtSide(aSide), aGtTile, aPlayer, aWorld);
+ }
+ return null;
+ }
}
diff --git a/src/main/java/gregtech/common/GT_Network.java b/src/main/java/gregtech/common/GT_Network.java
index d3387209c3..ef28a26a97 100644
--- a/src/main/java/gregtech/common/GT_Network.java
+++ b/src/main/java/gregtech/common/GT_Network.java
@@ -50,7 +50,8 @@ public class GT_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet>
new GT_Packet_TileEntityCoverNew(),
new GT_Packet_SetConfigurationCircuit(),
new GT_Packet_UpdateItem(),
- new GT_Packet_SetLockedFluid()
+ new GT_Packet_SetLockedFluid(),
+ new GT_Packet_GtTileEntityGuiRequest()
);
}
diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java
index 8e755dbac4..e375ba480f 100644
--- a/src/main/java/gregtech/common/GT_Proxy.java
+++ b/src/main/java/gregtech/common/GT_Proxy.java
@@ -268,6 +268,16 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
*/
public boolean mRenderPollutionFog = true;
+ /**
+ * This makes cover tabs visible on GregTech machines
+ */
+ public boolean mCoverTabsVisible = true;
+
+ /**
+ * This controls whether cover tabs display on the left (default) or right side of the UI
+ */
+ public boolean mCoverTabsFlipped = false;
+
public static final int GUI_ID_COVER_SIDE_BASE = 10; // Takes GUI ID 10 - 15
public static Map<String, Integer> oreDictBurnTimes = new HashMap<>();
@@ -1304,8 +1314,8 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
return;
}
}
-// GT_FML_LOGGER.info("Material Name: "+aEvent.Name+ " !!!Unknown Material detected!!! Please report to GregTech Intergalactical for additional compatiblity. This is not an Error, an Issue nor a Lag Source, it is just an Information, which you should pass to me.");
-// GT_Log.ore.println(tModToName + " uses an unknown Material. Report this to GregTech.");
+// GT_FML_LOGGER.info("Material Name: "+aEvent.Name+ " !!!Unknown Material detected!!! Please report to GregTech Intergalactical for additional compatiblity. This is not an Error, an Issue nor a Lag Source, it is just an Information, which you should pass to me.");
+// GT_Log.ore.println(tModToName + " uses an unknown Material. Report this to GregTech.");
return;
}
} else {
@@ -1437,7 +1447,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
@SubscribeEvent
public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) {
- if(aEvent.world.provider.dimensionId == 0)
+ if(aEvent.world.provider.dimensionId == 0)
mTicksUntilNextCraftSound--;
if (aEvent.side.isServer()) {
if (this.mUniverse == null) {
@@ -1519,7 +1529,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
aOre.mPrefix.processOre(aOre.mMaterial == null ? Materials._NULL : aOre.mMaterial, aOre.mEvent.Name, aOre.mModID, GT_Utility.copyAmount(1L, aOre.mEvent.Ore));
}
} else {
-// GT_FML_LOGGER.info("Thingy Name: "+ aOre.mEvent.Name+ " !!!Unknown 'Thingy' detected!!! This Object seems to probably not follow a valid OreDictionary Convention, or I missed a Convention. Please report to GregTech Intergalactical for additional compatiblity. This is not an Error, an Issue nor a Lag Source, it is just an Information, which you should pass to me.");
+// GT_FML_LOGGER.info("Thingy Name: "+ aOre.mEvent.Name+ " !!!Unknown 'Thingy' detected!!! This Object seems to probably not follow a valid OreDictionary Convention, or I missed a Convention. Please report to GregTech Intergalactical for additional compatiblity. This is not an Error, an Issue nor a Lag Source, it is just an Information, which you should pass to me.");
}
}
@@ -1791,10 +1801,10 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
aMaterial.mRGBa, 1, aMaterial.getLiquidTemperature(), GT_OreDictUnificator.get(OrePrefixes.cell, aMaterial, 1L), ItemList.Cell_Empty.get(1L), 1000);
}
- public Fluid addAutoGeneratedCorrespondingGas(Materials aMaterial) {
- return addFluid(aMaterial.mName.toLowerCase(Locale.ENGLISH), "molten.autogenerated", aMaterial.mDefaultLocalName, aMaterial,
+ public Fluid addAutoGeneratedCorrespondingGas(Materials aMaterial) {
+ return addFluid(aMaterial.mName.toLowerCase(Locale.ENGLISH), "molten.autogenerated", aMaterial.mDefaultLocalName, aMaterial,
aMaterial.mRGBa, 2, aMaterial.getGasTemperature(), GT_OreDictUnificator.get(OrePrefixes.cell, aMaterial, 1L), ItemList.Cell_Empty.get(1L), 1000);
- }
+ }
public Fluid addAutogeneratedMoltenFluid(Materials aMaterial) {
return addFluid("molten." + aMaterial.mName.toLowerCase(Locale.ENGLISH), "molten.autogenerated", "Molten " + aMaterial.mDefaultLocalName, aMaterial,
@@ -2023,7 +2033,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
@Deprecated
public static final HashMap<Integer,HashMap<ChunkCoordIntPair,int []>> dimensionWiseChunkData = new HashMap<>(16);//stores chunk data that is loaded/saved
public static final HashMap<Integer,GT_Pollution> dimensionWisePollution = new HashMap<>(16);//stores GT_Polluttors objects
- public static final byte GTOIL=3,GTOILFLUID=2,GTPOLLUTION=1,GTMETADATA=0,NOT_LOADED=0,LOADED=1;//consts
+ public static final byte GTOIL=3,GTOILFLUID=2,GTPOLLUTION=1,GTMETADATA=0,NOT_LOADED=0,LOADED=1;//consts
//TO get default's fast
@Deprecated
diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java
index 5f93197f05..d804b3858e 100644
--- a/src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java
+++ b/src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java
@@ -1,18 +1,25 @@
package gregtech.common.gui;
import gregtech.api.gui.GT_GUIContainerMetaTile_Machine;
+import gregtech.api.gui.widgets.GT_GuiIcon;
+import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import net.minecraft.entity.player.InventoryPlayer;
public class GT_GUIContainer_PrimitiveBlastFurnace extends GT_GUIContainerMetaTile_Machine { private String name;
- public String mNEI;
-
- public GT_GUIContainer_PrimitiveBlastFurnace(InventoryPlayer inventoryPlayer, IGregTechTileEntity tileEntity, String name, String aNEI) {
- super(new GT_Container_PrimitiveBlastFurnace(inventoryPlayer, tileEntity),
- String.format("gregtech:textures/gui/%s.png", name.replace(" ", "")));
- this.name = name;
- this.mNEI = aNEI;
- }
+ public String mNEI;
+ private final static GT_GuiTabIconSet TAB_ICONSET = new GT_GuiTabIconSet(
+ GT_GuiIcon.TAB_NORMAL_BRICK,
+ GT_GuiIcon.TAB_HIGHLIGHT_BRICK,
+ GT_GuiIcon.TAB_DISABLED_BRICK);
+
+ public GT_GUIContainer_PrimitiveBlastFurnace(InventoryPlayer inventoryPlayer, IGregTechTileEntity tileEntity,
+ String name, String aNEI) {
+ super(new GT_Container_PrimitiveBlastFurnace(inventoryPlayer, tileEntity),
+ String.format("gregtech:textures/gui/%s.png", name.replace(" ", "")));
+ this.name = name;
+ this.mNEI = aNEI;
+ }
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
@@ -31,4 +38,9 @@ public class GT_GUIContainer_PrimitiveBlastFurnace extends GT_GUIContainerMetaTi
11);
}
}
+
+ @Override
+ protected GT_GuiTabIconSet getTabBackground() {
+ return TAB_ICONSET;
+ }
}
diff --git a/src/main/java/gregtech/loaders/preload/GT_PreLoad.java b/src/main/java/gregtech/loaders/preload/GT_PreLoad.java
index 9984b229c9..cb8b597726 100644
--- a/src/main/java/gregtech/loaders/preload/GT_PreLoad.java
+++ b/src/main/java/gregtech/loaders/preload/GT_PreLoad.java
@@ -528,5 +528,7 @@ public class GT_PreLoad {
GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch = GregTech_API.sClientDataFile.get("render", "RenderIndicatorsOnHatch", true);
GT_Mod.gregtechproxy.mRenderDirtParticles = GregTech_API.sClientDataFile.get("render", "RenderDirtParticles", true);
GT_Mod.gregtechproxy.mRenderPollutionFog = GregTech_API.sClientDataFile.get("render", "RenderPollutionFog", true);
+ GT_Mod.gregtechproxy.mCoverTabsVisible = GregTech_API.sClientDataFile.get("interface", "DisplayCoverTabs", true);
+ GT_Mod.gregtechproxy.mCoverTabsFlipped = GregTech_API.sClientDataFile.get("interface", "FlipCoverTabs", false);
}
}
diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang
index f4a43e9ba0..440f85b374 100644
--- a/src/main/resources/assets/gregtech/lang/en_US.lang
+++ b/src/main/resources/assets/gregtech/lang/en_US.lang
@@ -126,6 +126,11 @@ GT5U.config.colormodulation.machine_metal=Machine Metal (Default GUI color)
GT5U.config.colormodulation.machine_metal.B=Blue
GT5U.config.colormodulation.machine_metal.G=Green
GT5U.config.colormodulation.machine_metal.R=Red
+GT5U.config.interface=Interface
+GT5U.config.interface.DisplayCoverTabs=Display Cover Tabs
+GT5U.config.interface.DisplayCoverTabs.tooltip=Displays Cover Tabs on all Gregtech machines
+GT5U.config.interface.FlipCoverTabs=Flip Cover Tabs
+GT5U.config.interface.FlipCoverTabs.tooltip=Displays Cover Tabs on the right side instead of left
GT5U.config.preference=Client Preference
GT5U.config.preference.mInputBusInitialFilter=Input Bus Initial Input Filter Status
GT5U.config.preference.mInputBusInitialFilter.tooltip=Whether Input busses enable the input filter upon placed\nDoes not affect busses placed by others\nDoes not affect existing busses
@@ -141,6 +146,14 @@ GT5U.config.render.RenderIndicatorsOnHatch=Render indicator on hatch
GT5U.config.render.RenderPollutionFog=Render pollution fog
GT5U.config.render.TileAmbientOcclusion=Enable Ambient Occlusion
+// Cover tabs
+GT5U.interface.coverTabs.down=Bottom
+GT5U.interface.coverTabs.up=Top
+GT5U.interface.coverTabs.north=North
+GT5U.interface.coverTabs.south=South
+GT5U.interface.coverTabs.west=West
+GT5U.interface.coverTabs.east=East
+
achievement.Naquadah=Find Naquadah Ore
achievement.Naquadah.desc=Height: 10-90, Chance: 10, Asteroids/Venus/Titan/Oberon/Pluto/KuiperBelt/VegaB/BarnardE/BarnardF//
achievement.NaquadahEnriched=Find Enriched Naquadah Ore
diff --git a/src/main/resources/assets/gregtech/textures/gui/GuiTabs.png b/src/main/resources/assets/gregtech/textures/gui/GuiTabs.png
new file mode 100644
index 0000000000..eea6e586d7
--- /dev/null
+++ b/src/main/resources/assets/gregtech/textures/gui/GuiTabs.png
Binary files differ