aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_UITextures.java30
-rw-r--r--src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java71
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java57
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_IndustrialElectromagneticSeparator.java38
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiCanner.java33
5 files changed, 204 insertions, 25 deletions
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
index 54666567db..c39b47e903 100644
--- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
+++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
@@ -398,6 +398,36 @@ public class GT_UITextures {
public static final UITexture OVERLAY_BUTTON_LIQUIDMODE_OFF = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/LiquidMode_off");
+ // These icons are for mode switching machine modes
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_DEFAULT = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_default");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_CHEMBATH = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_chembath");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_WASHPLANT = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_washplant");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_SIMPLEWASHER = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_simplewasher");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_PACKAGER = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_packager");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_UNPACKAGER = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_unpackager");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_SEPARATOR = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_separator");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_POLARIZER = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_polarizer");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_LPF_FLUID = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_lpf_fluid");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_LPF_METAL = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_lpf_metal");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_BENDING = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_bending");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_FORMING = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_forming");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_SLICING = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_slicing");
+ public static final UITexture OVERLAY_BUTTON_MACHINEMODE_CUTTING = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/machine_mode_cutting");
+
/**
* Can adjust size as needed.
*/
diff --git a/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java
index 22694cdafd..a877492907 100644
--- a/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java
+++ b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java
@@ -33,6 +33,7 @@ import gregtech.api.interfaces.tileentity.IVoidable;
* <li>Separated input buses</li>
* <li>Batch mode</li>
* <li>Recipe locking</li>
+ * <li>Multiple machine modes</li>
* </ul>
*/
public interface ControllerWithOptionalFeatures extends IVoidable, IRecipeLockable {
@@ -118,6 +119,76 @@ public interface ControllerWithOptionalFeatures extends IVoidable, IRecipeLockab
}
/**
+ * @return if the multi has more than 1 mode
+ */
+ default boolean supportsMachineModeSwitch() {
+ return false;
+ }
+
+ /**
+ * @return the current mode number. This is a getter is used for displaying the icon in the GUI
+ */
+ default int getMachineMode() {
+ return 0;
+ }
+
+ /**
+ * @param index Index of machineModeIcons to pull from
+ * @return UITexture associated with that machineMode
+ */
+ default UITexture getMachineModeIcon(int index) {
+ return null;
+ }
+
+ /**
+ * @param index Number to set machineMode to
+ */
+ default void setMachineMode(int index) {}
+
+ /**
+ * @return Returns the next machineMode number in the sequence
+ */
+ default int nextMachineMode() {
+ return 0;
+ }
+
+ /**
+ * @return Returns whether machine supports mode switch by default
+ */
+ default boolean getDefaultModeSwitch() {
+ return supportsMachineModeSwitch();
+ }
+
+ Pos2d getMachineModeSwitchButtonPos();
+
+ default void onMachineModeSwitchClick() {}
+
+ default ButtonWidget createModeSwitchButton(IWidgetBuilder<?> builder) {
+ if (!supportsMachineModeSwitch()) return null;
+ Widget button = new ButtonWidget().setOnClick((clickData, widget) -> {
+ if (supportsMachineModeSwitch()) {
+ onMachineModeSwitchClick();
+ setMachineMode(nextMachineMode());
+ }
+ })
+ .setPlayClickSound(supportsMachineModeSwitch())
+ .setBackground(() -> {
+ List<UITexture> ret = new ArrayList<>();
+ if (supportsMachineModeSwitch()) {
+ ret.add(GT_UITextures.BUTTON_STANDARD);
+ ret.add(getMachineModeIcon(getMachineMode()));
+ } else return null;
+ return ret.toArray(new IDrawable[0]);
+ })
+ .attachSyncer(new FakeSyncWidget.IntegerSyncer(this::getMachineMode, this::setMachineMode), builder)
+ .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.mode_switch"))
+ .setTooltipShowUpDelay(TOOLTIP_DELAY)
+ .setPos(getMachineModeSwitchButtonPos())
+ .setSize(16, 16);
+ return (ButtonWidget) button;
+ }
+
+ /**
* @return if the multi supports input separation.
*/
boolean supportsInputSeparation();
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
index 3d34a6c62a..735119d8bf 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
@@ -44,6 +44,7 @@ import org.lwjgl.input.Keyboard;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.gtnewhorizons.modularui.api.NumberFormatMUI;
+import com.gtnewhorizons.modularui.api.drawable.UITexture;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.math.Pos2d;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
@@ -127,6 +128,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
public String mNEI;
public int damageFactorLow = 5;
public float damageFactorHigh = 0.6f;
+ public int machineMode = 0;
+ public List<UITexture> machineModeIcons = new ArrayList<UITexture>();
public boolean mLockedToSingleRecipe = getDefaultRecipeLockingMode();
protected boolean inputSeparation = getDefaultInputSeparationMode();
@@ -253,6 +256,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
aNBT.setInteger("mEfficiency", mEfficiency);
aNBT.setInteger("mPollution", mPollution);
aNBT.setInteger("mRuntime", mRuntime);
+
+ if (supportsMachineModeSwitch()) {
+ aNBT.setInteger("machineMode", machineMode);
+ }
+
if (supportsSingleRecipeLocking()) {
aNBT.setBoolean("mLockedToSingleRecipe", mLockedToSingleRecipe);
if (mLockedToSingleRecipe && mSingleRecipeCheck != null)
@@ -294,6 +302,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
mEfficiency = aNBT.getInteger("mEfficiency");
mPollution = aNBT.getInteger("mPollution");
mRuntime = aNBT.getInteger("mRuntime");
+ if (aNBT.hasKey("machineMode")) {
+ machineMode = aNBT.getInteger("machineMode");
+ }
if (supportsSingleRecipeLocking()) {
mLockedToSingleRecipe = aNBT.getBoolean("mLockedToSingleRecipe");
if (mLockedToSingleRecipe && aNBT.hasKey("mSingleRecipeCheck", Constants.NBT.TAG_COMPOUND)) {
@@ -2212,6 +2223,50 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
return new Pos2d(26, 91);
}
+ /**
+ * Creates the icon list for this machine. Override this and add the overlays to machineModeIcons in order.
+ */
+ public void setMachineModeIcons() {
+ machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_DEFAULT);
+ machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_DEFAULT);
+ }
+
+ /**
+ * Override this if you are a multi-machine and want a GUI button. You will also want to override
+ * setMachineModeIcons().
+ * Override nextMachineMode() if you have more than 2 modes.
+ */
+ @Override
+ public boolean supportsMachineModeSwitch() {
+ return false;
+ }
+
+ @Override
+ public int getMachineMode() {
+ return machineMode;
+ }
+
+ @Override
+ public UITexture getMachineModeIcon(int index) {
+ return machineModeIcons.get(index);
+ }
+
+ @Override
+ public void setMachineMode(int index) {
+ machineMode = index;
+ }
+
+ @Override
+ public int nextMachineMode() {
+ if (machineMode == 0) return 1;
+ else return 0;
+ }
+
+ @Override
+ public Pos2d getMachineModeSwitchButtonPos() {
+ return new Pos2d(80, 91);
+ }
+
@Override
public boolean supportsBatchMode() {
return false;
@@ -2300,9 +2355,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
drawTexts(screenElements, inventorySlot);
builder.widget(screenElements);
+ setMachineModeIcons();
builder.widget(createPowerSwitchButton(builder))
.widget(createVoidExcessButton(builder))
.widget(createInputSeparationButton(builder))
+ .widget(createModeSwitchButton(builder))
.widget(createBatchModeButton(builder))
.widget(createLockToSingleRecipeButton(builder));
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_IndustrialElectromagneticSeparator.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_IndustrialElectromagneticSeparator.java
index 7d877e4b42..6f74f4d6ae 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_IndustrialElectromagneticSeparator.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_IndustrialElectromagneticSeparator.java
@@ -36,6 +36,7 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Materials;
import gregtech.api.enums.Textures;
+import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -102,7 +103,9 @@ public class GT_MetaTileEntity_IndustrialElectromagneticSeparator
final int MIN_CASING = 64;
private GT_MetaTileEntity_MagHatch mMagHatch = null;
private MagnetTiers magnetTier = null;
- private boolean polarizerMode = false;
+
+ private static final int MACHINEMODE_SEPARATOR = 0;
+ private static final int MACHINEMODE_POLARIZER = 1;
private static final String STRUCTURE_PIECE_MAIN = "main";
private static final IStructureDefinition<GT_MetaTileEntity_IndustrialElectromagneticSeparator> STRUCTURE_DEFINITION = StructureDefinition
@@ -312,7 +315,8 @@ public class GT_MetaTileEntity_IndustrialElectromagneticSeparator
@Override
public RecipeMap<?> getRecipeMap() {
- return polarizerMode ? RecipeMaps.polarizerRecipes : RecipeMaps.electroMagneticSeparatorRecipes;
+ return (machineMode == MACHINEMODE_POLARIZER) ? RecipeMaps.polarizerRecipes
+ : RecipeMaps.electroMagneticSeparatorRecipes;
}
@Nonnull
@@ -322,21 +326,29 @@ public class GT_MetaTileEntity_IndustrialElectromagneticSeparator
}
@Override
- public void saveNBTData(NBTTagCompound aNBT) {
- aNBT.setBoolean("polarizerMode", polarizerMode);
- super.saveNBTData(aNBT);
+ public void loadNBTData(NBTTagCompound aNBT) {
+ if (aNBT.hasKey("polarizerMode")) {
+ machineMode = aNBT.getBoolean("polarizerMode") ? MACHINEMODE_POLARIZER : MACHINEMODE_SEPARATOR;
+ aNBT.removeTag("polarizerMode");
+ }
+ super.loadNBTData(aNBT);
}
@Override
- public void loadNBTData(NBTTagCompound aNBT) {
- polarizerMode = aNBT.getBoolean("polarizerMode");
- super.loadNBTData(aNBT);
+ public boolean supportsMachineModeSwitch() {
+ return true;
+ }
+
+ @Override
+ public void setMachineModeIcons() {
+ machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_SEPARATOR);
+ machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_POLARIZER);
}
@Override
public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {
- polarizerMode = !polarizerMode;
- if (polarizerMode) {
+ setMachineMode(nextMachineMode());
+ if (machineMode == MACHINEMODE_POLARIZER) {
PlayerUtils.messagePlayer(aPlayer, "Now running in Polarizing Mode.");
} else {
PlayerUtils.messagePlayer(aPlayer, "Now running in Separating Mode.");
@@ -353,7 +365,7 @@ public class GT_MetaTileEntity_IndustrialElectromagneticSeparator
public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
int z) {
super.getWailaNBTData(player, tile, tag, world, x, y, z);
- tag.setBoolean("mode", polarizerMode);
+ tag.setInteger("mode", machineMode);
}
@Override
@@ -364,8 +376,8 @@ public class GT_MetaTileEntity_IndustrialElectromagneticSeparator
currentTip.add(
StatCollector.translateToLocal("GT5U.machines.oreprocessor1") + " "
+ EnumChatFormatting.WHITE
- + StatCollector.translateToLocal(
- "GT5U.INDUSTRIAL_ELECTROMAGNETIC_SEPARATOR.mode." + (tag.getBoolean("mode") ? 1 : 0))
+ + StatCollector
+ .translateToLocal("GT5U.INDUSTRIAL_ELECTROMAGNETIC_SEPARATOR.mode." + tag.getInteger("mode"))
+ EnumChatFormatting.RESET);
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiCanner.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiCanner.java
index d678c6df1f..0ead4cbe6b 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiCanner.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiCanner.java
@@ -32,6 +32,7 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Textures;
+import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -50,7 +51,8 @@ import mcp.mobius.waila.api.IWailaDataAccessor;
public class GT_MetaTileEntity_MultiCanner
extends GT_MetaTileEntity_EnhancedMultiBlockBase<GT_MetaTileEntity_MultiCanner> implements ISurvivalConstructable {
- private boolean fluidMode = false;
+ private static final int MACHINEMODE_CANNER = 0;
+ private static final int MACHINEMODE_FLUIDCANNER = 1;
private static final String STRUCTURE_PIECE_MAIN = "main";
private static final IStructureDefinition<GT_MetaTileEntity_MultiCanner> STRUCTURE_DEFINITION = StructureDefinition
@@ -204,7 +206,7 @@ public class GT_MetaTileEntity_MultiCanner
@Override
public RecipeMap<?> getRecipeMap() {
- return fluidMode ? RecipeMaps.fluidCannerRecipes : RecipeMaps.cannerRecipes;
+ return (machineMode == MACHINEMODE_FLUIDCANNER) ? RecipeMaps.fluidCannerRecipes : RecipeMaps.cannerRecipes;
}
@Nonnull
@@ -214,21 +216,28 @@ public class GT_MetaTileEntity_MultiCanner
}
@Override
- public void saveNBTData(NBTTagCompound aNBT) {
- aNBT.setBoolean("fluidMode", fluidMode);
- super.saveNBTData(aNBT);
+ public void loadNBTData(NBTTagCompound aNBT) {
+ if (aNBT.hasKey("fluidMode")) {
+ machineMode = aNBT.getBoolean("fluidMode") ? MACHINEMODE_FLUIDCANNER : MACHINEMODE_CANNER;
+ }
+ super.loadNBTData(aNBT);
}
@Override
- public void loadNBTData(NBTTagCompound aNBT) {
- fluidMode = aNBT.getBoolean("fluidMode");
- super.loadNBTData(aNBT);
+ public boolean supportsMachineModeSwitch() {
+ return true;
+ }
+
+ @Override
+ public void setMachineModeIcons() {
+ machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_PACKAGER);
+ machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_LPF_FLUID);
}
@Override
public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {
- fluidMode = !fluidMode;
- if (fluidMode) {
+ setMachineMode(nextMachineMode());
+ if (machineMode == MACHINEMODE_FLUIDCANNER) {
PlayerUtils.messagePlayer(aPlayer, "Now running in Fluid Canning Mode.");
} else {
PlayerUtils.messagePlayer(aPlayer, "Now running in Canning Mode.");
@@ -239,7 +248,7 @@ public class GT_MetaTileEntity_MultiCanner
public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
int z) {
super.getWailaNBTData(player, tile, tag, world, x, y, z);
- tag.setBoolean("mode", fluidMode);
+ tag.setInteger("mode", machineMode);
}
@Override
@@ -250,7 +259,7 @@ public class GT_MetaTileEntity_MultiCanner
currentTip.add(
StatCollector.translateToLocal("GT5U.machines.oreprocessor1") + " "
+ EnumChatFormatting.WHITE
- + StatCollector.translateToLocal("GT5U.MULTI_CANNER.mode." + (tag.getBoolean("mode") ? 1 : 0))
+ + StatCollector.translateToLocal("GT5U.MULTI_CANNER.mode." + tag.getInteger("mode"))
+ EnumChatFormatting.RESET);
}