aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/gui')
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java12
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java31
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java33
3 files changed, 37 insertions, 39 deletions
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java b/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java
index 62a933cfa6..20586b9c48 100644
--- a/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java
+++ b/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java
@@ -1,6 +1,7 @@
package gregtech.api.gui.modularui;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraftforge.common.util.ForgeDirection;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import gregtech.api.interfaces.tileentity.ICoverable;
@@ -9,7 +10,7 @@ public class GT_CoverUIBuildContext extends UIBuildContext {
// cover data is not synced to client, while ID is
private final int coverID;
- private final byte side;
+ private final ForgeDirection side;
private final ICoverable tile;
private final boolean anotherWindow;
private final int guiColorization;
@@ -22,8 +23,8 @@ public class GT_CoverUIBuildContext extends UIBuildContext {
* @param anotherWindow If cover UI is shown on top of another window
* @param guiColorization The color used to render machine's GUI
*/
- public GT_CoverUIBuildContext(EntityPlayer player, int coverID, byte side, ICoverable tile, boolean anotherWindow,
- int guiColorization) {
+ public GT_CoverUIBuildContext(EntityPlayer player, int coverID, ForgeDirection side, ICoverable tile,
+ boolean anotherWindow, int guiColorization) {
super(player);
this.coverID = coverID;
this.side = side;
@@ -39,7 +40,8 @@ public class GT_CoverUIBuildContext extends UIBuildContext {
* @param tile Tile this cover is attached to
* @param anotherWindow If cover GUI is shown in opened on top of another window
*/
- public GT_CoverUIBuildContext(EntityPlayer player, int coverID, byte side, ICoverable tile, boolean anotherWindow) {
+ public GT_CoverUIBuildContext(EntityPlayer player, int coverID, ForgeDirection side, ICoverable tile,
+ boolean anotherWindow) {
this(player, coverID, side, tile, anotherWindow, tile.getGUIColorization());
}
@@ -47,7 +49,7 @@ public class GT_CoverUIBuildContext extends UIBuildContext {
return coverID;
}
- public byte getCoverSide() {
+ public ForgeDirection getCoverSide() {
return side;
}
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
index b132f33d63..afa60e5583 100644
--- a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
+++ b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
@@ -40,23 +40,16 @@ public class GT_UIInfos {
.of()
.container((player, world, x, y, z) -> {
TileEntity te = world.getTileEntity(x, y, z);
- if (te instanceof ITileWithModularUI) {
- return createTileEntityContainer(
- player,
- ((ITileWithModularUI) te)::createWindow,
- te::markDirty,
- containerConstructor);
+ if (te instanceof ITileWithModularUI mui) {
+ return createTileEntityContainer(player, mui::createWindow, te::markDirty, containerConstructor);
}
return null;
})
.gui(((player, world, x, y, z) -> {
if (!world.isRemote) return null;
TileEntity te = world.getTileEntity(x, y, z);
- if (te instanceof ITileWithModularUI) {
- return createTileEntityGuiContainer(
- player,
- ((ITileWithModularUI) te)::createWindow,
- containerConstructor);
+ if (te instanceof ITileWithModularUI mui) {
+ return createTileEntityGuiContainer(player, mui::createWindow, containerConstructor);
}
return null;
}))
@@ -64,18 +57,17 @@ public class GT_UIInfos {
private static final UIInfo<?, ?> GTTileEntityDefaultUI = GTTileEntityUIFactory.apply(ModularUIContainer::new);
- private static final Map<Byte, UIInfo<?, ?>> coverUI = new HashMap<>();
+ private static final Map<ForgeDirection, UIInfo<?, ?>> coverUI = new HashMap<>();
static {
- for (byte i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
- final byte side = i;
+ for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
coverUI.put(
side,
UIBuilder.of()
.container((player, world, x, y, z) -> {
final TileEntity te = world.getTileEntity(x, y, z);
if (!(te instanceof ICoverable gtTileEntity)) return null;
- GT_CoverBehaviorBase<?> cover = gtTileEntity.getCoverBehaviorAtSideNew(side);
+ final GT_CoverBehaviorBase<?> cover = gtTileEntity.getCoverBehaviorAtSideNew(side);
return createCoverContainer(
player,
cover::createWindow,
@@ -116,7 +108,7 @@ public class GT_UIInfos {
/**
* Opens cover UI, created by {@link GT_CoverBehaviorBase#createWindow}.
*/
- public static void openCoverUI(ICoverable tileEntity, EntityPlayer player, byte side) {
+ public static void openCoverUI(ICoverable tileEntity, EntityPlayer player, ForgeDirection side) {
if (tileEntity.isClientSide()) return;
GT_Values.NW.sendToPlayer(
@@ -167,8 +159,8 @@ public class GT_UIInfos {
}
private static ModularUIContainer createCoverContainer(EntityPlayer player,
- Function<GT_CoverUIBuildContext, ModularWindow> windowCreator, Runnable onWidgetUpdate, int coverID, byte side,
- ICoverable tile) {
+ Function<GT_CoverUIBuildContext, ModularWindow> windowCreator, Runnable onWidgetUpdate, int coverID,
+ ForgeDirection side, ICoverable tile) {
final GT_CoverUIBuildContext buildContext = new GT_CoverUIBuildContext(player, coverID, side, tile, false);
final ModularWindow window = windowCreator.apply(buildContext);
if (window == null) return null;
@@ -177,7 +169,8 @@ public class GT_UIInfos {
@SideOnly(Side.CLIENT)
private static ModularGui createCoverGuiContainer(EntityPlayer player,
- Function<GT_CoverUIBuildContext, ModularWindow> windowCreator, int coverID, byte side, ICoverable tile) {
+ Function<GT_CoverUIBuildContext, ModularWindow> windowCreator, int coverID, ForgeDirection side,
+ ICoverable tile) {
final ModularUIContainer container = createCoverContainer(player, windowCreator, null, coverID, side, tile);
if (container == null) {
return null;
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
index 9694316bee..890e6298c9 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
@@ -8,6 +8,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
+import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@@ -66,10 +67,10 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine {
* Add a tab for each existing cover on this IGregTechTileEntity at creation time
*/
private void setupTabs() {
- for (byte tSide = 0; tSide < 6; tSide++) {
- final ItemStack cover = tile.getCoverItemAtSide(tSide);
+ for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
+ final ItemStack cover = tile.getCoverItemAtSide(side);
if (cover != null) {
- addCoverToTabs(tSide, cover);
+ addCoverToTabs(side, cover);
}
}
}
@@ -101,26 +102,27 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine {
/**
* Add the cover on this side of the IGregTechTileEntity to the tabs
- *
+ *
* @param side
* @param cover
*/
- private void addCoverToTabs(byte side, ItemStack cover) {
+ private void addCoverToTabs(ForgeDirection side, ItemStack cover) {
final boolean enabled = this.tile.getCoverBehaviorAtSideNew(side)
.hasCoverGUI();
- this.setTab(side, cover, null, getTooltipForCoverTab(side, cover, enabled));
- this.setTabEnabled(side, enabled);
+ final int ordinalSide = side.ordinal();
+ this.setTab(ordinalSide, cover, null, getTooltipForCoverTab(side, cover, enabled));
+ this.setTabEnabled(ordinalSide, 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) {
+ private String[] getTooltipForCoverTab(ForgeDirection side, ItemStack cover, boolean enabled) {
final List<String> tooltip = cover.getTooltip(Minecraft.getMinecraft().thePlayer, true);
tooltip.set(
0,
@@ -132,16 +134,17 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine {
/**
* 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]);
+ private String getSideDescription(ForgeDirection side) {
+ final int ordinalSide = side.ordinal();
+ if (ordinalSide < SIDES.length) {
+ if (this.translatedSides[ordinalSide] == null) {
+ this.translatedSides[ordinalSide] = StatCollector.translateToLocal(SIDES[ordinalSide]);
}
- return this.translatedSides[side];
+ return this.translatedSides[ordinalSide];
}
return null;
}