aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYannick Marcotte-Gourde <yannickmg@gmail.com>2023-07-28 09:03:54 -0400
committerGitHub <noreply@github.com>2023-07-28 15:03:54 +0200
commit190d29ec4eecb6508a91288639b1b6194e077fda (patch)
tree900e31baccfaefa5972022db37d605c42ef7025b
parentedf63121630cde22a30b78a4ad7d7fff3d488d93 (diff)
downloadGT5-Unofficial-190d29ec4eecb6508a91288639b1b6194e077fda.tar.gz
GT5-Unofficial-190d29ec4eecb6508a91288639b1b6194e077fda.tar.bz2
GT5-Unofficial-190d29ec4eecb6508a91288639b1b6194e077fda.zip
Less hostile user interfaces (Buffer/Filter/Input bus) (#2165)
* Made Emit Energy button a CycleButtonWidget * Made Emit Redstone button a CycleButtonWidget * Made Invert Redstone button a CycleButtonWidget * Made Stocking Mode button a CycleButtonWidget * Spotless apply * Made Invert Filter button a CycleButtonWidget * public bInvertFilter -> protected invertFilter * Deduplicated filter code * Made Allow NBT button a CycleButtonWidget * Made Ignore NBT button a CycleButtonWidget * public bNBTAllowed -> private allowNbt * public bNBTAllowed -> private ignoreNbt * Grey extended tooltips * Don't hardcode multiline tooltips * Document hidden functionality * Cleaned numeric constants * Fixed string constant declaration * Named constants in filter * Unify filter redstone behavior * Fix cover filter mode being inverted so that the displayed mode is the active one * Less magic numbers * Allow right clicking recipe filter * Display only machine type in recipe filter and cycle through compatible machines * Buffer tooltips show output voltage to clarify their role as passthroughs * Added more info to Emit EU/Redstone buttons * Added Sorting mode button to buffers/filters * Added Sorting mode button and stack limit button to input buses * Don't cycle prefixes when clicking with itemstack * Fixed tooltips to work off of the inventory * Fix RecipeFilter losing filter * Support multiblock machines * Use ModularUi syncers to sync state with client Thanks minecraft7771! * Grey text for recipe filter helper text * AnimatedTooltipHandler -> EnumChatFormatting * Explicited RecipeFilter filter building * Specify color for empty slot tooltip * Don't cache new uses of GT5U.MBTT.MachineType. Also corrected MachineType::description * Removed unused getItemExtraTooltip * Multiple returns in getItemStackMachineRecipeMap
-rw-r--r--src/main/java/gregtech/api/enums/MachineType.java20
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_UITextures.java4
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java10
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java198
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_FilterBase.java106
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java43
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java102
-rw-r--r--src/main/java/gregtech/api/util/GT_LanguageManager.java20
-rw-r--r--src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java8
-rw-r--r--src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java14
-rw-r--r--src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java113
-rw-r--r--src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java9
-rw-r--r--src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java133
-rw-r--r--src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java7
-rw-r--r--src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java2
-rw-r--r--src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java107
-rw-r--r--src/main/resources/assets/gregtech/lang/en_US.lang29
-rw-r--r--src/main/resources/assets/gregtech/textures/gui/overlay_button/one_stack_limit.pngbin0 -> 10548 bytes
-rw-r--r--src/main/resources/assets/gregtech/textures/gui/overlay_button/sorting_mode.pngbin0 -> 10100 bytes
19 files changed, 573 insertions, 352 deletions
diff --git a/src/main/java/gregtech/api/enums/MachineType.java b/src/main/java/gregtech/api/enums/MachineType.java
index ecf894c92f..d0183051b1 100644
--- a/src/main/java/gregtech/api/enums/MachineType.java
+++ b/src/main/java/gregtech/api/enums/MachineType.java
@@ -1,9 +1,8 @@
package gregtech.api.enums;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
-import com.gtnewhorizon.gtnhlib.util.AnimatedTooltipHandler;
-
public enum MachineType {
ALLOY_SMELTER(FunnyTexts.ALLOY_SMELTER, "gt.recipe.alloysmelter"),
@@ -107,26 +106,29 @@ public enum MachineType {
static final String WIREMILL = "gt.recipe.wiremill.description";
}
- private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType");
+ private static final String TT_machineType = "GT5U.MBTT.MachineType";
private final String name;
private final String description;
MachineType(String machineDescription, String machineType) {
- this.description = StatCollector.translateToLocal(machineDescription);
- this.name = StatCollector.translateToLocal(machineType);
+ this.description = machineDescription;
+ this.name = machineType;
}
public String type() {
- return this.name;
+ return StatCollector.translateToLocal(this.name);
}
public String description() {
- return this.name;
+ return StatCollector.translateToLocal(this.description);
}
public String[] tooltipDescription() {
- return new String[] { this.description,
- TT_machineType + ": " + AnimatedTooltipHandler.YELLOW + this.name + AnimatedTooltipHandler.RESET };
+ return new String[] { description(),
+ StatCollector.translateToLocal(TT_machineType) + ": "
+ + EnumChatFormatting.YELLOW
+ + type()
+ + EnumChatFormatting.RESET };
}
}
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 7a21dad8cd..8d0a63702c 100644
--- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
+++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
@@ -327,6 +327,10 @@ public class GT_UITextures {
public static final UITexture OVERLAY_BUTTON_PRINT = UITexture.fullImage(GregTech.ID, "gui/overlay_button/print");
public static final UITexture OVERLAY_BUTTON_TRANSPOSE = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/transpose");
+ public static final UITexture OVERLAY_BUTTON_SORTING_MODE = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/sorting_mode");
+ public static final UITexture OVERLAY_BUTTON_ONE_STACK_LIMIT = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/one_stack_limit");
public static final UITexture OVERLAY_BUTTON_BOUNDING_BOX = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/bounding_box");
public static final UITexture OVERLAY_BUTTON_MINUS_SMALL = UITexture
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java
index 322f62ac09..2ba0ba94f2 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java
@@ -15,10 +15,10 @@ import java.util.Arrays;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
-import com.gtnewhorizon.gtnhlib.util.AnimatedTooltipHandler;
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.math.Pos2d;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
@@ -51,7 +51,7 @@ import gregtech.common.power.SteamPower;
*/
public abstract class GT_MetaTileEntity_BasicMachine_Bronze extends GT_MetaTileEntity_BasicMachine {
- private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType");
+ private static final String TT_machineType = "GT5U.MBTT.MachineType";
private static final int NEEDS_STEAM_VENTING = 64;
public boolean mNeedsSteamVenting = false;
@@ -393,10 +393,10 @@ public abstract class GT_MetaTileEntity_BasicMachine_Bronze extends GT_MetaTileE
@Override
public String[] getDescription() {
String[] description = Arrays.copyOf(mDescriptionArray, mDescriptionArray.length + 1);
- description[mDescriptionArray.length] = TT_machineType + ": "
- + AnimatedTooltipHandler.YELLOW
+ description[mDescriptionArray.length] = StatCollector.translateToLocal(TT_machineType) + ": "
+ + EnumChatFormatting.YELLOW
+ StatCollector.translateToLocal(this.getRecipeList().mUnlocalizedName)
- + AnimatedTooltipHandler.RESET;
+ + EnumChatFormatting.RESET;
return description;
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
index f88bdd0553..1fc347da1f 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
@@ -11,30 +11,40 @@ import static gregtech.api.enums.Textures.BlockIcons.ARROW_UP;
import static gregtech.api.enums.Textures.BlockIcons.ARROW_UP_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT;
+import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
import java.util.stream.IntStream;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
+import com.gtnewhorizons.modularui.api.drawable.UITexture;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
-import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
+import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+import com.gtnewhorizons.modularui.api.widget.Widget;
+import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget;
import com.gtnewhorizons.modularui.common.widget.SlotGroup;
import gregtech.api.gui.modularui.GT_UIInfos;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
+import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.render.TextureFactory;
+import gregtech.api.util.GT_TooltipDataCache;
import gregtech.api.util.GT_Utility;
-public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredMachineBlock {
+public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredMachineBlock implements IAddUIWidgets {
private static final int OUTPUT_INDEX = 0;
private static final int ARROW_RIGHT_INDEX = 1;
@@ -43,11 +53,19 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
private static final int ARROW_UP_INDEX = 4;
private static final int FRONT_INDEX = 5;
+ private static final String EMIT_ENERGY_TOOLTIP = "GT5U.machines.emit_energy.tooltip";
+ private static final String EMIT_REDSTONE_IF_FULL_TOOLTIP = "GT5U.machines.emit_redstone_if_full.tooltip";
+ private static final String INVERT_REDSTONE_TOOLTIP = "GT5U.machines.invert_redstone.tooltip";
+ private static final String STOCKING_MODE_TOOLTIP = "GT5U.machines.buffer_stocking_mode.tooltip";
+ private static final String SORTING_MODE_TOOLTIP = "GT5U.machines.sorting_mode.tooltip";
+ private static final int BUTTON_SIZE = 18;
+
public int mMaxStackSize = 64;
public static int MAX = 8;
public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bStockingMode = false,
bSortStacks = false;
public int mSuccess = 0, mTargetStackSize = 0;
+ private int uiButtonCount = 0;
public GT_MetaTileEntity_Buffer(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount,
String aDescription) {
@@ -234,7 +252,8 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
@Override
public long maxEUOutput() {
- return bOutput ? V[mTier] : 0L;
+ // Return full value if we're an item and don't exist in the world for tooltip purposes
+ return getBaseMetaTileEntity().getWorld() == null || bOutput ? V[mTier] : 0L;
}
@Override
@@ -276,12 +295,7 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
bOutput = aNBT.getBoolean("bOutput");
bRedstoneIfFull = aNBT.getBoolean("bRedstoneIfFull");
bSortStacks = aNBT.getBoolean("bSortStacks");
- if (aNBT.hasKey("bStockingMode")) { // Adding new key to existing NBT, need to protect if it is not there.
- bStockingMode = aNBT.getBoolean("bStockingMode");
- }
- if (aNBT.hasKey("bSortStacks")) {
- bSortStacks = aNBT.getBoolean("bSortStacks");
- }
+ bStockingMode = aNBT.getBoolean("bStockingMode");
mTargetStackSize = aNBT.getInteger("mTargetStackSize");
}
@@ -321,17 +335,18 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
}
protected void handleRedstoneOutput(IGregTechTileEntity aBaseMetaTileEntity) {
- if (bRedstoneIfFull) {
- final boolean hasEmptySlots = IntStream.range(0, mInventory.length)
- .anyMatch(i -> isValidSlot(i) && mInventory[i] == null);
- Arrays.stream(ForgeDirection.VALID_DIRECTIONS)
- .forEach(
- side -> aBaseMetaTileEntity
- .setInternalOutputRedstoneSignal(side, (byte) (bInvert ^ hasEmptySlots ? 0 : 15)));
- } else {
- for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
- aBaseMetaTileEntity.setInternalOutputRedstoneSignal(side, (byte) 0);
- }
+ int redstoneOutput = getRedstoneOutput();
+ Arrays.stream(ForgeDirection.VALID_DIRECTIONS)
+ .forEach(side -> aBaseMetaTileEntity.setInternalOutputRedstoneSignal(side, (byte) redstoneOutput));
+ }
+
+ protected int getRedstoneOutput() {
+ return (!bRedstoneIfFull || (bInvert ^ hasEmptySlots())) ? 0 : 15;
+ }
+
+ private boolean hasEmptySlots() {
+ return IntStream.range(0, mInventory.length)
+ .anyMatch(i -> isValidSlot(i) && mInventory[i] == null);
}
@Override
@@ -463,87 +478,84 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
}
protected void addEmitEnergyButton(ModularWindow.Builder builder) {
- builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bOutput = !bOutput;
- if (bOutput) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("116", "Emit Energy to Outputside"));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("117", "Don't emit Energy"));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_EMIT_ENERGY)
- .setPos(7, 62)
- .setSize(18, 18));
+ builder.widget(
+ createToggleButton(
+ () -> bOutput,
+ val -> bOutput = val,
+ GT_UITextures.OVERLAY_BUTTON_EMIT_ENERGY,
+ this::getEmitEnergyButtonTooltip));
+ }
+
+ private GT_TooltipDataCache.TooltipData getEmitEnergyButtonTooltip() {
+ return mTooltipCache.getData(
+ EMIT_ENERGY_TOOLTIP,
+ EnumChatFormatting.GREEN + GT_Utility.formatNumbers(V[mTier])
+ + " ("
+ + GT_Utility.getColoredTierNameFromTier(mTier)
+ + EnumChatFormatting.GREEN
+ + ")"
+ + EnumChatFormatting.GRAY,
+ maxAmperesOut());
+ }
+
+ protected void addEmitRedstoneIfFullButton(ModularWindow.Builder builder) {
+ builder.widget(
+ createToggleButton(
+ () -> bRedstoneIfFull,
+ val -> bRedstoneIfFull = val,
+ GT_UITextures.OVERLAY_BUTTON_EMIT_REDSTONE,
+ this::getEmitRedstoneIfFullButtonTooltip).setUpdateTooltipEveryTick(true));
}
- protected void addEmitRedstoneButton(ModularWindow.Builder builder) {
- builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bRedstoneIfFull = !bRedstoneIfFull;
- if (bRedstoneIfFull) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("118", "Emit Redstone if no Slot is free"));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("119", "Don't emit Redstone"));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_EMIT_REDSTONE)
- .setPos(25, 62)
- .setSize(18, 18));
+ private GT_TooltipDataCache.TooltipData getEmitRedstoneIfFullButtonTooltip() {
+ return mTooltipCache.getUncachedTooltipData(
+ EMIT_REDSTONE_IF_FULL_TOOLTIP,
+ StatCollector.translateToLocal(hasEmptySlots() ? "gui.yes" : "gui.no"),
+ getRedstoneOutput());
}
protected void addInvertRedstoneButton(ModularWindow.Builder builder) {
- builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bInvert = !bInvert;
- if (bInvert) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("120", "Invert Redstone"));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("121", "Don't invert Redstone"));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_INVERT_REDSTONE)
- .setPos(43, 62)
- .setSize(18, 18));
+ builder.widget(
+ createToggleButton(
+ () -> bInvert,
+ val -> bInvert = val,
+ GT_UITextures.OVERLAY_BUTTON_INVERT_REDSTONE,
+ () -> mTooltipCache.getData(INVERT_REDSTONE_TOOLTIP)));
}
protected void addStockingModeButton(ModularWindow.Builder builder) {
- builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bStockingMode = !bStockingMode;
- if (bStockingMode) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans(
- "217",
- "Stocking mode. Keeps this many items in destination input slots. This mode can be server unfriendly."));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans(
- "218",
- "Transfer size mode. Add exactly this many items in destination input slots as long as there is room."));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_STOCKING_MODE)
- .setPos(61, 62)
- .setSize(18, 18));
+ builder.widget(
+ createToggleButton(
+ () -> bStockingMode,
+ val -> bStockingMode = val,
+ GT_UITextures.OVERLAY_BUTTON_STOCKING_MODE,
+ () -> mTooltipCache.getData(STOCKING_MODE_TOOLTIP)));
+ }
+
+ protected void addSortStacksButton(ModularWindow.Builder builder) {
+ builder.widget(
+ createToggleButton(
+ () -> bSortStacks,
+ val -> bSortStacks = val,
+ GT_UITextures.OVERLAY_BUTTON_SORTING_MODE,
+ () -> mTooltipCache.getData(SORTING_MODE_TOOLTIP)));
+ }
+
+ @Override
+ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
+ buildContext.addCloseListener(() -> uiButtonCount = 0);
+ addEmitEnergyButton(builder);
+ }
+
+ protected Widget createToggleButton(Supplier<Boolean> getter, Consumer<Boolean> setter, UITexture picture,
+ Supplier<GT_TooltipDataCache.TooltipData> tooltipDataSupplier) {
+ return new CycleButtonWidget().setToggle(getter, setter)
+ .setStaticTexture(picture)
+ .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE)
+ .setTooltipShowUpDelay(TOOLTIP_DELAY)
+ .setPos(7 + (uiButtonCount++ * BUTTON_SIZE), 62)
+ .setSize(BUTTON_SIZE, BUTTON_SIZE)
+ .setGTTooltip(tooltipDataSupplier);
}
protected void addInventorySlots(ModularWindow.Builder builder) {
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_FilterBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_FilterBase.java
new file mode 100644
index 0000000000..896cb223f3
--- /dev/null
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_FilterBase.java
@@ -0,0 +1,106 @@
+package gregtech.api.metatileentity.implementations;
+
+import net.minecraft.nbt.NBTTagCompound;
+
+import com.gtnewhorizons.modularui.api.screen.ModularWindow;
+import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+
+import gregtech.api.gui.modularui.GT_UITextures;
+import gregtech.api.interfaces.ITexture;
+import gregtech.api.util.GT_TooltipDataCache;
+
+public abstract class GT_MetaTileEntity_FilterBase extends GT_MetaTileEntity_Buffer {
+
+ private static final String INVERT_FILTER_TOOLTIP = "GT5U.machines.invert_filter.tooltip";
+ protected static final int FILTER_SLOT_INDEX = 9;
+ protected static final int NUM_INVENTORY_SLOTS = 9;
+ private static final String EMIT_REDSTONE_GRADUALLY_TOOLTIP = "GT5U" + ".machines.emit_redstone_gradually.tooltip";
+ protected boolean invertFilter = false;
+
+ public GT_MetaTileEntity_FilterBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount,
+ String aDescription) {
+ super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription);
+ }
+
+ public GT_MetaTileEntity_FilterBase(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount,
+ String[] aDescription) {
+ super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription);
+ }
+
+ public GT_MetaTileEntity_FilterBase(String aName, int aTier, int aInvSlotCount, String aDescription,
+ ITexture[][][] aTextures) {
+ super(aName, aTier, aInvSlotCount, aDescription, aTextures);
+ }
+
+ public GT_MetaTileEntity_FilterBase(String aName, int aTier, int aInvSlotCount, String[] aDescription,
+ ITexture[][][] aTextures) {
+ super(aName, aTier, aInvSlotCount, aDescription, aTextures);
+ }
+
+ @Override
+ public boolean isValidSlot(int aIndex) {
+ return aIndex < NUM_INVENTORY_SLOTS;
+ }
+
+ @Override
+ public void saveNBTData(NBTTagCompound aNBT) {
+ super.saveNBTData(aNBT);
+ aNBT.setBoolean("bInvertFilter", this.invertFilter);
+ }
+
+ @Override
+ public void loadNBTData(NBTTagCompound aNBT) {
+ super.loadNBTData(aNBT);
+ this.invertFilter = aNBT.getBoolean("bInvertFilter");
+ }
+
+ @Override
+ protected int getRedstoneOutput() {
+ if (!bRedstoneIfFull) {
+ return 0;
+ }
+ int redstoneOutput = getEmptySlots();
+ if (!bInvert) redstoneOutput = NUM_INVENTORY_SLOTS - redstoneOutput;
+ return redstoneOutput;
+ }
+
+ private int getEmptySlots() {
+ int emptySlots = 0;
+ for (int i = 0; i < NUM_INVENTORY_SLOTS; i++) {
+ if (mInventory[i] == null) ++emptySlots;
+ }
+ return emptySlots;
+ }
+
+ @Override
+ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
+ super.addUIWidgets(builder, buildContext);
+ addSortStacksButton(builder);
+ addEmitRedstoneGraduallyButton(builder);
+ addInvertRedstoneButton(builder);
+ addInvertFilterButton(builder);
+ }
+
+ private void addEmitRedstoneGraduallyButton(ModularWindow.Builder builder) {
+ builder.widget(
+ createToggleButton(
+ () -> bRedstoneIfFull,
+ val -> bRedstoneIfFull = val,
+ GT_UITextures.OVERLAY_BUTTON_EMIT_REDSTONE,
+ this::getEmitRedstoneGraduallyButtonTooltip).setUpdateTooltipEveryTick(true));
+ }
+
+ private GT_TooltipDataCache.TooltipData getEmitRedstoneGraduallyButtonTooltip() {
+ return mTooltipCache
+ .getUncachedTooltipData(EMIT_REDSTONE_GRADUALLY_TOOLTIP, getEmptySlots(), getRedstoneOutput());
+ }
+
+ private void addInvertFilterButton(ModularWindow.Builder builder) {
+ builder.widget(
+ createToggleButton(
+ () -> invertFilter,
+ val -> invertFilter = val,
+ GT_UITextures.OVERLAY_BUTTON_INVERT_FILTER,
+ () -> mTooltipCache.getData(INVERT_FILTER_TOOLTIP)));
+ }
+}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java
index 858e87d43e..0102b698dd 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java
@@ -2,10 +2,13 @@ package gregtech.api.metatileentity.implementations;
import static gregtech.api.enums.Textures.BlockIcons.ITEM_IN_SIGN;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN;
+import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -13,11 +16,15 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
+import com.gtnewhorizons.modularui.api.drawable.UITexture;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+import com.gtnewhorizons.modularui.api.widget.Widget;
+import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget;
import gregtech.GT_Mod;
import gregtech.api.gui.modularui.GT_UIInfos;
+import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.IConfigurationCircuitSupport;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
@@ -27,16 +34,22 @@ import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_ClientPreference;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
+import gregtech.api.util.GT_TooltipDataCache;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.extensions.ArrayExt;
public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch
implements IConfigurationCircuitSupport, IAddUIWidgets {
+ private static final String SORTING_MODE_TOOLTIP = "GT5U.machines.sorting_mode.tooltip";
+ private static final String ONE_STACK_LIMIT_TOOLTIP = "GT5U.machines.one_stack_limit.tooltip";
+ private static final int BUTTON_SIZE = 18;
+
public GT_Recipe_Map mRecipeMap = null;
public boolean disableSort;
public boolean disableFilter = true;
public boolean disableLimited = true;
+ private int uiButtonCount = 0;
public GT_MetaTileEntity_Hatch_InputBus(int id, String name, String nameRegional, int tier) {
this(id, name, nameRegional, tier, getSlots(tier) + 1);
@@ -268,8 +281,27 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch
return true;
}
+ private void addSortStacksButton(ModularWindow.Builder builder) {
+ builder.widget(
+ createToggleButton(
+ () -> !disableSort,
+ val -> disableSort = !val,
+ GT_UITextures.OVERLAY_BUTTON_SORTING_MODE,
+ () -> mTooltipCache.getData(SORTING_MODE_TOOLTIP)));
+ }
+
+ private void addOneStackLimitButton(ModularWindow.Builder builder) {
+ builder.widget(createToggleButton(() -> !disableLimited, val -> {
+ disableLimited = !val;
+ updateSlots();
+ }, GT_UITextures.OVERLAY_BUTTON_ONE_STACK_LIMIT, () -> mTooltipCache.getData(ONE_STACK_LIMIT_TOOLTIP)));
+ }
+
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
+ buildContext.addCloseListener(() -> uiButtonCount = 0);
+ addSortStacksButton(builder);
+ addOneStackLimitButton(builder);
switch (mTier) {
case 0 -> getBaseMetaTileEntity().add1by1Slot(builder);
case 1 -> getBaseMetaTileEntity().add2by2Slots(builder);
@@ -277,4 +309,15 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch
default -> getBaseMetaTileEntity().add4by4Slots(builder);
}
}
+
+ private Widget createToggleButton(Supplier<Boolean> getter, Consumer<Boolean> setter, UITexture picture,
+ Supplier<GT_TooltipDataCache.TooltipData> tooltipDataSupplier) {
+ return new CycleButtonWidget().setToggle(getter, setter)
+ .setStaticTexture(picture)
+ .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE)
+ .setTooltipShowUpDelay(TOOLTIP_DELAY)
+ .setPos(7 + (uiButtonCount++ * BUTTON_SIZE), 62)
+ .setSize(BUTTON_SIZE, BUTTON_SIZE)
+ .setGTTooltip(tooltipDataSupplier);
+ }
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java
index 63b8160262..cb293e51a9 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java
@@ -1,7 +1,7 @@
package gregtech.api.metatileentity.implementations;
-import java.util.Collections;
import java.util.List;
+import java.util.function.Function;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -11,23 +11,18 @@ import com.gtnewhorizons.modularui.api.drawable.Text;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot;
-import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
import com.gtnewhorizons.modularui.common.widget.SlotGroup;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
-import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.util.GT_Utility;
-public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_Buffer implements IAddUIWidgets {
+public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_FilterBase {
- public static final int BUFFER_SLOT_COUNT = 9;
- public static final int SPECIAL_SLOT_INDEX = 9;
- public boolean bNBTAllowed = false;
- public boolean bInvertFilter = false;
+ private static final String ALLOW_NBT_TOOLTIP = "GT5U.machines.allow_nbt.tooltip";
+ private boolean allowNbt = false;
public GT_MetaTileEntity_SpecialFilter(int aID, String aName, String aNameRegional, int aTier,
String[] aDescription) {
@@ -45,33 +40,26 @@ public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_
super(aName, aTier, aInvSlotCount, aDescription, aTextures);
}
- @Override
- public boolean isValidSlot(int aIndex) {
- return aIndex < 9;
- }
-
public abstract void clickTypeIcon(boolean aRightClick, ItemStack aHandStack);
@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
- aNBT.setBoolean("bInvertFilter", this.bInvertFilter);
- aNBT.setBoolean("bNBTAllowed", this.bNBTAllowed);
+ aNBT.setBoolean("bNBTAllowed", this.allowNbt);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
- this.bInvertFilter = aNBT.getBoolean("bInvertFilter");
- this.bNBTAllowed = aNBT.getBoolean("bNBTAllowed");
+ this.allowNbt = aNBT.getBoolean("bNBTAllowed");
}
@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return (super.allowPutStack(aBaseMetaTileEntity, aIndex, side, aStack))
- && ((this.bNBTAllowed) || (!aStack.hasTagCompound()))
- && (this.isStackAllowed(aStack) != this.bInvertFilter);
+ && ((this.allowNbt) || (!aStack.hasTagCompound()))
+ && (this.isStackAllowed(aStack) != this.invertFilter);
}
protected abstract boolean isStackAllowed(ItemStack aStack);
@@ -80,53 +68,18 @@ public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_
return null;
}
- protected List<String> getItemExtraTooltip() {
- return null;
+ protected Function<List<String>, List<String>> getItemStackReplacementTooltip() {
+ return list -> list;
}
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
- addEmitEnergyButton(builder);
- addEmitRedstoneButton(builder);
- addInvertRedstoneButton(builder);
- builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bInvertFilter = !bInvertFilter;
- if (bInvertFilter) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("124", "Invert Filter"));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("125", "Don't invert Filter"));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_INVERT_FILTER)
- .setPos(61, 62)
- .setSize(18, 18))
- .widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bNBTAllowed = !bNBTAllowed;
- if (bNBTAllowed) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("126", "Ignore NBT"));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("127", "NBT has to match"));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_NBT)
- .setPos(79, 62)
- .setSize(18, 18))
- .widget(
- new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_24_WHITE.apply(27, false))
- .setPos(6, 19)
- .setSize(27, 24))
+ super.addUIWidgets(builder, buildContext);
+ addAllowNbtButton(builder);
+ builder.widget(
+ new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_24_WHITE.apply(27, false))
+ .setPos(6, 19)
+ .setSize(27, 24))
.widget(
new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_24_BLUE.apply(42, true))
.setPos(53, 19)
@@ -144,18 +97,16 @@ public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_
@Override
public void buildTooltip(List<Text> tooltip) {
- if (getEmptySlotTooltip() != null) {
- tooltip.addAll(getEmptySlotTooltip());
- }
super.buildTooltip(tooltip);
+ List<Text> emptySlotTooltip = getEmptySlotTooltip();
+ if (emptySlotTooltip != null) {
+ tooltip.addAll(emptySlotTooltip);
+ }
}
@Override
- public List<String> getExtraTooltip() {
- if (getItemExtraTooltip() != null) {
- return getItemExtraTooltip();
- }
- return Collections.emptyList();
+ public Function<List<String>, List<String>> getOverwriteItemStackTooltip() {
+ return getItemStackReplacementTooltip();
}
}.disableShiftInsert()
.setPos(34, 22)
@@ -166,4 +117,13 @@ public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_
.build()
.setPos(97, 4));
}
+
+ private void addAllowNbtButton(ModularWindow.Builder builder) {
+ builder.widget(
+ createToggleButton(
+ () -> allowNbt,
+ val -> allowNbt = val,
+ GT_UITextures.OVERLAY_BUTTON_NBT,
+ () -> mTooltipCache.getData(ALLOW_NBT_TOOLTIP)));
+ }
}
diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java
index 5bc2d0e9b1..708048cf42 100644
--- a/src/main/java/gregtech/api/util/GT_LanguageManager.java
+++ b/src/main/java/gregtech/api/util/GT_LanguageManager.java
@@ -269,20 +269,20 @@ public class GT_LanguageManager {
addStringLocalization("Interaction_DESCRIPTION_Index_113", "Outputs only Items");
addStringLocalization("Interaction_DESCRIPTION_Index_114", "Outputs only misc. Fluids");
addStringLocalization("Interaction_DESCRIPTION_Index_115", "Outputs nothing");
- addStringLocalization("Interaction_DESCRIPTION_Index_116", "Emit Energy to Outputside");
- addStringLocalization("Interaction_DESCRIPTION_Index_117", "Don't emit Energy");
- addStringLocalization("Interaction_DESCRIPTION_Index_118", "Emit Redstone if no Slot is free");
- addStringLocalization("Interaction_DESCRIPTION_Index_119", "Don't emit Redstone");
- addStringLocalization("Interaction_DESCRIPTION_Index_120", "Invert Redstone");
- addStringLocalization("Interaction_DESCRIPTION_Index_121", "Don't invert Redstone");
+ // 116 moved to lang files
+ // 117 obsolete
+ // 118 moved to lang files
+ // 119 obsolete
+ // 120 moved to lang files
+ // 121 obsolete
addStringLocalization("Interaction_DESCRIPTION_Index_122", "Emit Redstone if slots contain something");
addStringLocalization("Interaction_DESCRIPTION_Index_123", "Don't emit Redstone");
- addStringLocalization("Interaction_DESCRIPTION_Index_124", "Invert Filter");
+ // 124 moved to lang files
addStringLocalization("Interaction_DESCRIPTION_Index_124.1", "Blacklist Mode");
- addStringLocalization("Interaction_DESCRIPTION_Index_125", "Don't invert Filter");
+ // 125 obsolete
addStringLocalization("Interaction_DESCRIPTION_Index_125.1", "Whitelist Mode");
- addStringLocalization("Interaction_DESCRIPTION_Index_126", "Ignore NBT");
- addStringLocalization("Interaction_DESCRIPTION_Index_127", "NBT has to match");
+ // 126 moved to lang files
+ // 127 obsolete
addStringLocalization("Interaction_DESCRIPTION_Index_128", "Redstone");
addStringLocalization("Interaction_DESCRIPTION_Index_128.1", "Redstone ");
addStringLocalization("Interaction_DESCRIPTION_Index_129", "Energy");
diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java
index c0cdee78a3..a142259438 100644
--- a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java
+++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java
@@ -227,10 +227,10 @@ public class GT_Cover_ItemFilter extends GT_CoverBehaviorBase<GT_Cover_ItemFilte
},
widget -> widget
.setToggleTexture(
- GT_UITextures.OVERLAY_BUTTON_WHITELIST,
- GT_UITextures.OVERLAY_BUTTON_BLACKLIST)
- .addTooltip(0, GT_Utility.trans("124.1", "Blacklist Mode"))
- .addTooltip(1, GT_Utility.trans("125.1", "Whitelist Mode"))
+ GT_UITextures.OVERLAY_BUTTON_BLACKLIST,
+ GT_UITextures.OVERLAY_BUTTON_WHITELIST)
+ .addTooltip(0, GT_Utility.trans("125.1", "Whitelist Mode"))
+ .addTooltip(1, GT_Utility.trans("124.1", "Blacklist Mode"))
.setPos(spaceX * 0, spaceY * 0))
.addFollower(
new CoverDataFollower_SlotWidget<>(filterInvHandler, 0, true),
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java
index 1711529de2..67c38fad9e 100644
--- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java
+++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java
@@ -10,12 +10,11 @@ import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
-import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer;
import gregtech.api.render.TextureFactory;
-public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer implements IAddUIWidgets {
+public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer {
private static final int[] tickRate = { 400, 200, 100, 20, 4, 1, 1, 1, 1, 1, 1, 1, 1 };
private static final int[] maxStacks = { 1, 1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 64, 128 };
@@ -28,7 +27,7 @@ public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer impl
aTier,
28,
new String[] { "Buffers up to 27 Item Stacks", "Use Screwdriver to regulate output stack size",
- "Does not consume energy to move Item", getTickRateDesc(aTier) });
+ getTickRateDesc(aTier) });
}
public GT_MetaTileEntity_ChestBuffer(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount,
@@ -120,14 +119,15 @@ public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer impl
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
- addEmitEnergyButton(builder);
- addEmitRedstoneButton(builder);
+ super.addUIWidgets(builder, buildContext);
+ addSortStacksButton(builder);
+ addEmitRedstoneIfFullButton(builder);
addInvertRedstoneButton(builder);
addStockingModeButton(builder);
builder.widget(
new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_22_RED.apply(69, true))
- .setPos(80, 60)
- .setSize(69, 22));
+ .setPos(98, 60)
+ .setSize(51, 22));
addMainUI(builder);
}
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java
index a5b495d73d..b6f1d53604 100644
--- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java
+++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java
@@ -9,23 +9,22 @@ import net.minecraftforge.common.util.ForgeDirection;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
-import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
import com.gtnewhorizons.modularui.common.widget.SlotGroup;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
-import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_FilterBase;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Utility;
-public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer implements IAddUIWidgets {
+public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_FilterBase {
- public boolean bIgnoreNBT = false;
- public boolean bInvertFilter = false;
+ private static final int NUM_FILTER_SLOTS = 9;
+ private static final String IGNORE_NBT_TOOLTIP = "GT5U.machines.ignore_nbt.tooltip";
+ private boolean ignoreNbt = false;
public GT_MetaTileEntity_Filter(int aID, String aName, String aNameRegional, int aTier) {
super(
@@ -34,8 +33,7 @@ public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer implement
aNameRegional,
aTier,
19,
- new String[] { "Filters up to 9 different Items", "Use Screwdriver to regulate output stack size",
- "Does not consume energy to move Item" });
+ new String[] { "Filters up to 9 different Items", "Use Screwdriver to regulate output stack size" });
}
public GT_MetaTileEntity_Filter(String aName, int aTier, int aInvSlotCount, String aDescription,
@@ -69,22 +67,15 @@ public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer implement
}
@Override
- public boolean isValidSlot(int aIndex) {
- return aIndex < 9;
- }
-
- @Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
- aNBT.setBoolean("bInvertFilter", this.bInvertFilter);
- aNBT.setBoolean("bIgnoreNBT", this.bIgnoreNBT);
+ aNBT.setBoolean("bIgnoreNBT", this.ignoreNbt);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
- this.bInvertFilter = aNBT.getBoolean("bInvertFilter");
- this.bIgnoreNBT = aNBT.getBoolean("bIgnoreNBT");
+ this.ignoreNbt = aNBT.getBoolean("bIgnoreNBT");
}
@Override
@@ -93,78 +84,25 @@ public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer implement
if (!super.allowPutStack(aBaseMetaTileEntity, aIndex, side, aStack)) {
return false;
}
- if (this.bInvertFilter) {
- for (byte i = 9; i < 18; i = (byte) (i + 1)) {
- if (GT_Utility.areStacksEqual(this.mInventory[i], aStack, this.bIgnoreNBT)) {
+ if (this.invertFilter) {
+ for (int i = 0; i < NUM_FILTER_SLOTS; i++) {
+ if (GT_Utility.areStacksEqual(this.mInventory[FILTER_SLOT_INDEX + i], aStack, this.ignoreNbt)) {
return false;
}
}
return true;
}
- return GT_Utility.areStacksEqual(this.mInventory[(aIndex + 9)], aStack, this.bIgnoreNBT);
- }
-
- @Override
- protected void handleRedstoneOutput(IGregTechTileEntity aBaseMetaTileEntity) {
- if (bRedstoneIfFull) {
- int emptySlots = 0;
- for (int i = 0; i < 9; i++) {
- if (mInventory[i] == null) ++emptySlots;
- }
- if (!bInvert) emptySlots = 9 - emptySlots;
- for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
- aBaseMetaTileEntity.setInternalOutputRedstoneSignal(side, (byte) emptySlots);
- }
- } else {
- for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
- aBaseMetaTileEntity.setInternalOutputRedstoneSignal(side, (byte) 0);
- }
- }
+ return GT_Utility.areStacksEqual(this.mInventory[(FILTER_SLOT_INDEX + aIndex)], aStack, this.ignoreNbt);
}
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
- addEmitEnergyButton(builder);
- addEmitRedstoneButton(builder);
- addInvertRedstoneButton(builder);
- builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bInvertFilter = !bInvertFilter;
- if (bInvertFilter) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("124", "Invert Filter"));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("125", "Don't invert Filter"));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_INVERT_FILTER)
- .setPos(61, 62)
- .setSize(18, 18))
- .widget(new ButtonWidget().setOnClick((clickData, widget) -> {
- bIgnoreNBT = !bIgnoreNBT;
- if (bIgnoreNBT) {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("126", "Ignore NBT"));
- } else {
- GT_Utility.sendChatToPlayer(
- widget.getContext()
- .getPlayer(),
- GT_Utility.trans("127", "NBT has to match"));
- }
- })
- .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_NBT)
- .setPos(79, 62)
- .setSize(18, 18))
- .widget(
- new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_24_WHITE.apply(9, false))
- .setPos(6, 19)
- .setSize(9, 24))
+ super.addUIWidgets(builder, buildContext);
+ addAllowNbtButton(builder);
+ builder.widget(
+ new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_24_WHITE.apply(9, false))
+ .setPos(6, 19)
+ .setSize(9, 24))
.widget(
new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_24_BLUE.apply(24, true))
.setPos(71, 19)
@@ -179,8 +117,8 @@ public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer implement
.setSize(54, 54))
.widget(
SlotGroup.ofItemHandler(inventoryHandler, 3)
- .startFromSlot(9)
- .endAtSlot(17)
+ .startFromSlot(FILTER_SLOT_INDEX)
+ .endAtSlot(FILTER_SLOT_INDEX + NUM_FILTER_SLOTS - 1)
.phantom(true)
.applyForWidget(
widget -> widget.disableShiftInsert()
@@ -190,8 +128,17 @@ public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer implement
.widget(
SlotGroup.ofItemHandler(inventoryHandler, 3)
.startFromSlot(0)
- .endAtSlot(8)
+ .endAtSlot(NUM_INVENTORY_SLOTS - 1)
.build()
.setPos(97, 4));
}
+
+ private void addAllowNbtButton(ModularWindow.Builder builder) {
+ builder.widget(
+ createToggleButton(
+ () -> ignoreNbt,
+ val -> ignoreNbt = val,
+ GT_UITextures.OVERLAY_BUTTON_NBT,
+ () -> mTooltipCache.getData(IGNORE_NBT_TOOLTIP)));
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java
index 1f4117acc9..58b7fa57df 100644
--- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java
+++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java
@@ -17,13 +17,12 @@ 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.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Utility;
-public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer implements IAddUIWidgets {
+public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer {
private byte[] itemsPerSide = new byte[6];
private ForgeDirection currentSide = ForgeDirection.DOWN;
@@ -37,7 +36,7 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer
aTier,
28,
new String[] { "Distributes Items between different Machine Sides", "Default Items per Machine Side: 0",
- "Use Screwdriver to increase/decrease Items per Side", "Does not consume energy to move Item" });
+ "Use Screwdriver to increase/decrease Items per Side" });
}
public GT_MetaTileEntity_ItemDistributor(int aID, String aName, String aNameRegional, int aTier, int aInvSlotCount,
@@ -193,8 +192,8 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
- addEmitEnergyButton(builder);
- addEmitRedstoneButton(builder);
+ super.addUIWidgets(builder, buildContext);
+ addEmitRedstoneIfFullButton(builder);
addInvertRedstoneButton(builder);
builder.widget(
new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_22_RED.apply(87, true))
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java
index f8e54f9edf..4df9ca55b7 100644
--- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java
+++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java
@@ -3,26 +3,47 @@ package gregtech.common.tileentities.automation;
import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_RECIPEFILTER;
import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_RECIPEFILTER_GLOW;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
+
+import org.jetbrains.annotations.NotNull;
import com.gtnewhorizons.modularui.api.drawable.Text;
+import com.gtnewhorizons.modularui.api.screen.ModularWindow;
+import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
+import codechicken.nei.recipe.RecipeCatalysts;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.interfaces.tileentity.IRecipeLockable;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_SpecialFilter;
+import gregtech.api.multitileentity.MultiTileEntityContainer;
+import gregtech.api.multitileentity.MultiTileEntityItemInternal;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
import gregtech.common.blocks.GT_Item_Machines;
+import gregtech.loaders.preload.GT_Loader_MultiTileEntities;
public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFilter {
+ private static final String TT_machineType = "GT5U.MBTT.MachineType";
+ private static final String REPRESENTATION_SLOT_TOOLTIP = "GT5U.recipe_filter.representation_slot.tooltip";
+ private static final String EMPTY_REPRESENTATION_SLOT_TOOLTIP = "GT5U.recipe_filter.empty_representation_slot.tooltip";
public GT_Recipe.GT_Recipe_Map mRecipeMap;
+ private List<ItemStack> filteredMachines = Collections.emptyList();
+ public int mRotationIndex = 0;
public GT_MetaTileEntity_RecipeFilter(int aID, String aName, String aNameRegional, int aTier) {
super(
@@ -30,8 +51,7 @@ public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFil
aName,
aNameRegional,
aTier,
- new String[] { "Filters 1 Recipe Type", "Use Screwdriver to regulate output stack size",
- "Does not consume energy to move Item" });
+ new String[] { "Filters 1 Recipe Type", "Use Screwdriver to regulate output stack size" });
}
public GT_MetaTileEntity_RecipeFilter(String aName, int aTier, int aInvSlotCount, String aDescription,
@@ -45,20 +65,70 @@ public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFil
}
@Override
- public void clickTypeIcon(boolean aRightClick, ItemStack aHandStack) {
- if (!aRightClick) {
- IMetaTileEntity mte = GT_Item_Machines.getMetaTileEntity(aHandStack);
- if (mte instanceof GT_MetaTileEntity_BasicMachine machine) {
- GT_Recipe.GT_Recipe_Map recipeList = machine.getRecipeList();
- if (recipeList != null) {
- mInventory[SPECIAL_SLOT_INDEX] = machine.getStackForm(1);
- mRecipeMap = recipeList;
- return;
- }
+ public void clickTypeIcon(boolean rightClick, ItemStack heldStack) {
+ mRecipeMap = getItemStackMachineRecipeMap(heldStack);
+ if (mRecipeMap != null) {
+ filteredMachines = getFilteredMachines(mRecipeMap);
+ } else {
+ filteredMachines = Collections.emptyList();
+ mInventory[FILTER_SLOT_INDEX] = null;
+ }
+ mRotationIndex = -1;
+ }
+
+ private static GT_Recipe.GT_Recipe_Map getItemStackMachineRecipeMap(ItemStack stack) {
+ if (stack != null) {
+ IMetaTileEntity metaTileEntity = GT_Item_Machines.getMetaTileEntity(stack);
+ if (metaTileEntity != null) {
+ return getMetaTileEntityRecipeMap(metaTileEntity);
+ } else if (stack.getItem() instanceof MultiTileEntityItemInternal) {
+ return getMuTeRecipeMap(stack);
}
- mInventory[SPECIAL_SLOT_INDEX] = null;
- mRecipeMap = null;
}
+ return null;
+ }
+
+ private static GT_Recipe.GT_Recipe_Map getMetaTileEntityRecipeMap(IMetaTileEntity metaTileEntity) {
+ if (metaTileEntity instanceof GT_MetaTileEntity_BasicMachine machine) {
+ return machine.getRecipeList();
+ } else if (metaTileEntity instanceof IRecipeLockable recipeLockable) {
+ return recipeLockable.getRecipeMap();
+ }
+ return null;
+ }
+
+ private static GT_Recipe.GT_Recipe_Map getMuTeRecipeMap(@NotNull ItemStack stack) {
+ MultiTileEntityContainer muTeEntityContainer = GT_Loader_MultiTileEntities.MACHINE_REGISTRY
+ .getNewTileEntityContainer(stack);
+ if (muTeEntityContainer != null && muTeEntityContainer.mTileEntity instanceof IRecipeLockable recipeLockable) {
+ return recipeLockable.getRecipeMap();
+ }
+ return null;
+ }
+
+ private static List<ItemStack> getFilteredMachines(GT_Recipe.GT_Recipe_Map recipeMap) {
+ return RecipeCatalysts.getRecipeCatalysts(recipeMap.mNEIName)
+ .stream()
+ .map(positionedStack -> positionedStack.item)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ super.onPreTick(aBaseMetaTileEntity, aTick);
+ if ((!getBaseMetaTileEntity().isServerSide()) || ((aTick % 8L != 0L) && mRotationIndex != -1)) return;
+ if (this.filteredMachines.isEmpty()) {
+ if (mRecipeMap != null) {
+ // This should succeed after a few ticks when NEI is fully loaded.
+ filteredMachines = getFilteredMachines(mRecipeMap);
+ } else {
+ return;
+ }
+ }
+ this.mInventory[FILTER_SLOT_INDEX] = GT_Utility.copyAmount(
+ 1L,
+ this.filteredMachines.get(this.mRotationIndex = (this.mRotationIndex + 1) % this.filteredMachines.size()));
+ if (this.mInventory[FILTER_SLOT_INDEX] == null) return;
}
@Override
@@ -99,7 +169,40 @@ public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFil
}
@Override
+ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
+ super.addUIWidgets(builder, buildContext);
+ builder.widget(
+ new FakeSyncWidget.StringSyncer(
+ () -> this.mRecipeMap == null ? "" : this.mRecipeMap.mUniqueIdentifier,
+ (id) -> this.mRecipeMap = GT_Recipe.GT_Recipe_Map.sIndexedMappings.getOrDefault(id, null)));
+ }
+
+ @Override
protected List<Text> getEmptySlotTooltip() {
- return Collections.singletonList(Text.localised("GT5U.recipe_filter.representation_slot.tooltip"));
+ return Collections.singletonList(Text.localised(EMPTY_REPRESENTATION_SLOT_TOOLTIP));
+ }
+
+ @Override
+ public Function<List<String>, List<String>> getItemStackReplacementTooltip() {
+ if (mRecipeMap != null) {
+ List<String> tooltip = assembleItemStackReplacementTooltip(mRecipeMap);
+ return list -> tooltip;
+ }
+ return super.getItemStackReplacementTooltip();
+ }
+
+ @NotNull
+ private List<String> assembleItemStackReplacementTooltip(GT_Recipe.GT_Recipe_Map recipeMap) {
+ List<String> tooltip = new ArrayList<>();
+ tooltip.add(
+ StatCollector.translateToLocal(TT_machineType) + ": "
+ + EnumChatFormatting.YELLOW
+ + StatCollector.translateToLocal(recipeMap.mUnlocalizedName)
+ + EnumChatFormatting.RESET);
+ if (recipeMap.mRecipeItemMap.size() > 0) {
+ tooltip.add("Filter size: §e" + recipeMap.mRecipeItemMap.size() + "§r");
+ }
+ tooltip.addAll(mTooltipCache.getData(REPRESENTATION_SLOT_TOOLTIP).text);
+ return tooltip;
}
}
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java
index 3fa296f9a2..08d3d32512 100644
--- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java
+++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java
@@ -21,13 +21,12 @@ import com.gtnewhorizons.modularui.common.widget.TextWidget;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
-import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Utility;
-public class GT_MetaTileEntity_Regulator extends GT_MetaTileEntity_Buffer implements IAddUIWidgets {
+public class GT_MetaTileEntity_Regulator extends GT_MetaTileEntity_Buffer {
public int[] mTargetSlots = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
private boolean charge = false, decharge = false;
@@ -40,7 +39,7 @@ public class GT_MetaTileEntity_Regulator extends GT_MetaTileEntity_Buffer implem
aTier,
20,
new String[] { "Filters up to 9 different Items", "Allows Item-specific output stack size",
- "Allows Item-specific output slot", "Does not consume energy to move Item" });
+ "Allows Item-specific output slot" });
}
public GT_MetaTileEntity_Regulator(String aName, int aTier, int aInvSlotCount, String aDescription,
@@ -173,7 +172,7 @@ public class GT_MetaTileEntity_Regulator extends GT_MetaTileEntity_Buffer implem
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
- addEmitEnergyButton(builder);
+ super.addUIWidgets(builder, buildContext);
builder.widget(createChargerSlot(43, 62));
builder.widget(
new DrawableWidget().setDrawable(GT_UITextures.PICTURE_ARROW_22_RED.apply(84, true))
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java
index 4687b62fa1..9a1d2d7dcf 100644
--- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java
+++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java
@@ -30,7 +30,7 @@ public class GT_MetaTileEntity_SuperBuffer extends GT_MetaTileEntity_ChestBuffer
aTier,
257,
new String[] { "Buffers up to 256 Item Stacks", "Use Screwdriver to regulate output stack size",
- "Does not consume energy to move Item", getTickRateDesc(aTier) });
+ getTickRateDesc(aTier) });
}
public GT_MetaTileEntity_SuperBuffer(String aName, int aTier, int aInvSlotCount, String aDescription,
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java
index ee79766e30..56ce5877ea 100644
--- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java
+++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java
@@ -4,15 +4,17 @@ import static gregtech.api.enums.GT_Values.W;
import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_TYPEFILTER;
import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_TYPEFILTER_GLOW;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.List;
+import java.util.function.Function;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.util.EnumChatFormatting;
-import net.minecraft.util.StatCollector;
import com.google.common.collect.ImmutableList;
+import com.gtnewhorizons.modularui.api.screen.ModularWindow;
+import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
+import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.interfaces.ITexture;
@@ -26,6 +28,7 @@ import gregtech.api.util.GT_Utility;
public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilter {
+ private static final String REPRESENTATION_SLOT_TOOLTIP = "GT5U.type_filter.representation_slot.tooltip";
public int mRotationIndex = 0;
public OrePrefixes mPrefix = OrePrefixes.ore;
@@ -50,8 +53,7 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilte
aName,
aNameRegional,
aTier,
- new String[] { "Filters 1 Item Type", "Use Screwdriver to regulate output stack size",
- "Does not consume energy to move Item" });
+ new String[] { "Filters 1 Item Type", "Use Screwdriver to regulate output stack size" });
}
public GT_MetaTileEntity_TypeFilter(String aName, int aTier, int aInvSlotCount, String aDescription,
@@ -87,34 +89,44 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilte
@Override
public void clickTypeIcon(boolean aRightClick, ItemStack aHandStack) {
if (getBaseMetaTileEntity().isServerSide()) {
- ItemData data = GT_OreDictUnificator.getAssociation(aHandStack);
- if (data != null && data.hasValidPrefixData()) {
- this.mPrefix = data.mPrefix;
- this.mRotationIndex = -1;
- return;
+ if (aHandStack != null) {
+ copyHeldItemPrefix(aHandStack);
+ } else {
+ cyclePrefix(aRightClick);
}
- for (int i = 0; i < OrePrefixes.values().length; i++) {
- if (this.mPrefix == OrePrefixes.values()[i]) {
- for (this.mPrefix = null; this.mPrefix == null; this.mPrefix = OrePrefixes.values()[i]) {
- if (aRightClick) {
- do {
- i--;
- if (i < 0) {
- i = OrePrefixes.values().length - 1;
- }
- } while (OrePrefixes.values()[i].mPrefixedItems.isEmpty());
- } else {
- do {
- i++;
- if (i >= OrePrefixes.values().length) {
- i = 0;
- }
- } while (OrePrefixes.values()[i].mPrefixedItems.isEmpty());
- }
- if (!OrePrefixes.values()[i].mPrefixedItems.isEmpty()
- && OrePrefixes.values()[i].mPrefixInto == OrePrefixes.values()[i])
- mPrefix = OrePrefixes.values()[i];
+ }
+ }
+
+ private void copyHeldItemPrefix(ItemStack handStack) {
+ ItemData data = GT_OreDictUnificator.getAssociation(handStack);
+ if (data != null && data.hasValidPrefixData()) {
+ this.mPrefix = data.mPrefix;
+ this.mRotationIndex = -1;
+ }
+ }
+
+ private void cyclePrefix(boolean aRightClick) {
+ for (int i = 0; i < OrePrefixes.values().length; i++) {
+ if (this.mPrefix == OrePrefixes.values()[i]) {
+ for (this.mPrefix = null; this.mPrefix == null; this.mPrefix = OrePrefixes.values()[i]) {
+ if (aRightClick) {
+ do {
+ i--;
+ if (i < 0) {
+ i = OrePrefixes.values().length - 1;
+ }
+ } while (OrePrefixes.values()[i].mPrefixedItems.isEmpty());
+ } else {
+ do {
+ i++;
+ if (i >= OrePrefixes.values().length) {
+ i = 0;
+ }
+ } while (OrePrefixes.values()[i].mPrefixedItems.isEmpty());
}
+ if (!OrePrefixes.values()[i].mPrefixedItems.isEmpty()
+ && OrePrefixes.values()[i].mPrefixInto == OrePrefixes.values()[i])
+ mPrefix = OrePrefixes.values()[i];
}
}
this.mRotationIndex = -1;
@@ -126,16 +138,15 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilte
super.onPreTick(aBaseMetaTileEntity, aTick);
if ((!getBaseMetaTileEntity().isServerSide()) || ((aTick % 8L != 0L) && mRotationIndex != -1)) return;
if (this.mPrefix.mPrefixedItems.isEmpty()) {
- this.mInventory[SPECIAL_SLOT_INDEX] = null;
+ this.mInventory[FILTER_SLOT_INDEX] = null;
return;
}
- this.mInventory[SPECIAL_SLOT_INDEX] = GT_Utility.copyAmount(
+ this.mInventory[FILTER_SLOT_INDEX] = GT_Utility.copyAmount(
1L,
this.mPrefix.mPrefixedItems
.get(this.mRotationIndex = (this.mRotationIndex + 1) % this.mPrefix.mPrefixedItems.size()));
- if (this.mInventory[SPECIAL_SLOT_INDEX] == null) return;
- if (this.mInventory[SPECIAL_SLOT_INDEX].getItemDamage() == W) this.mInventory[9].setItemDamage(0);
- this.mInventory[SPECIAL_SLOT_INDEX].setStackDisplayName(this.mPrefix.toString());
+ if (this.mInventory[FILTER_SLOT_INDEX] == null) return;
+ if (this.mInventory[FILTER_SLOT_INDEX].getItemDamage() == W) this.mInventory[9].setItemDamage(0);
}
@Override
@@ -162,11 +173,23 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilte
}
@Override
- protected List<String> getItemExtraTooltip() {
- return Arrays.asList(
- EnumChatFormatting.DARK_GRAY
- + StatCollector.translateToLocal("GT5U.type_filter.representation_slot.tooltip.0"),
- EnumChatFormatting.DARK_GRAY
- + StatCollector.translateToLocal("GT5U.type_filter.representation_slot.tooltip.1"));
+ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
+ super.addUIWidgets(builder, buildContext);
+ builder.widget(
+ new FakeSyncWidget.StringSyncer(
+ () -> this.mPrefix.toString(),
+ (prefix) -> this.mPrefix = OrePrefixes.getPrefix(prefix, this.mPrefix)));
+ }
+
+ @Override
+ protected Function<List<String>, List<String>> getItemStackReplacementTooltip() {
+ return (itemTooltip) -> {
+ List<String> replacementTooltip = new ArrayList<>();
+ replacementTooltip.add("Filter set to " + mPrefix.mRegularLocalName);
+ replacementTooltip.add("Ore prefix: §e" + mPrefix + "§r");
+ replacementTooltip.add("Filter size: §e" + mPrefix.mPrefixedItems.size() + "§r");
+ replacementTooltip.addAll(mTooltipCache.getData(REPRESENTATION_SLOT_TOOLTIP).text);
+ return replacementTooltip;
+ };
}
}
diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang
index 837641d937..53c226fe83 100644
--- a/src/main/resources/assets/gregtech/lang/en_US.lang
+++ b/src/main/resources/assets/gregtech/lang/en_US.lang
@@ -308,10 +308,33 @@ GT5U.machines.advdebugstructurewriter.gui.highlight.tooltip=Show Bounding Box
GT5U.machines.advdebugstructurewriter.gui.transpose.tooltip=Transpose
GT5U.machines.nei_transfer.steam.tooltip=%s steam recipes
GT5U.machines.nei_transfer.voltage.tooltip=Recipes available in %s
+GT5U.machines.emit_energy.tooltip=Emit energy to output side
+GT5U.machines.emit_energy.tooltip.1=§7Voltage: %1$s
+GT5U.machines.emit_energy.tooltip.2=§7Amperage: §e%2$d
+GT5U.machines.emit_redstone_if_full.tooltip=Emit redstone if no slot is free
+GT5U.machines.emit_redstone_if_full.tooltip.1=§7Free slots: §9%1$s
+GT5U.machines.emit_redstone_if_full.tooltip.2=§7Emitting: §c%2$d
+GT5U.machines.emit_redstone_gradually.tooltip=Emit redstone for each slot in use
+GT5U.machines.emit_redstone_gradually.tooltip.1=§7Free slots: §9%1$d
+GT5U.machines.emit_redstone_gradually.tooltip.2=§7Emitting: §c%2$d
+GT5U.machines.invert_redstone.tooltip=Invert redstone
+GT5U.machines.buffer_stocking_mode.tooltip=Enable stocking mode
+GT5U.machines.buffer_stocking_mode.tooltip.extended=§7Keeps this many items in destination rather than transfer items in batches of this amount.
+GT5U.machines.buffer_stocking_mode.tooltip.extended.1=§7This mode can be server unfriendly.
+GT5U.machines.sorting_mode.tooltip=Sort stacks
+GT5U.machines.one_stack_limit.tooltip=Limit insertion
+GT5U.machines.one_stack_limit.tooltip.extended=§7Up to 1 stack of each item can be inserted
+GT5U.machines.invert_filter.tooltip=Invert Filter
+GT5U.machines.allow_nbt.tooltip=Allow items with NBT
+GT5U.machines.allow_nbt.tooltip.extended=§7By default, all items with NBT are blocked.
+GT5U.machines.ignore_nbt.tooltip=Ignore item NBT
+GT5U.machines.ignore_nbt.tooltip.extended=§7By default, item NBT must match.
-GT5U.recipe_filter.representation_slot.tooltip=Click with a machine to set filter
-GT5U.type_filter.representation_slot.tooltip.0=left click to forward
-GT5U.type_filter.representation_slot.tooltip.1=right click to back
+GT5U.recipe_filter.empty_representation_slot.tooltip=§7Click with a machine to set filter
+GT5U.recipe_filter.representation_slot.tooltip=§7Click to clear
+GT5U.type_filter.representation_slot.tooltip=§7Left click to cycle forward
+GT5U.type_filter.representation_slot.tooltip.1=§7Right click to cycle back
+GT5U.type_filter.representation_slot.tooltip.2=§7Click with an item to set filter
GT5U.gui.select.current=Current:
GT5U.gui.button.power_switch=Power Switch
diff --git a/src/main/resources/assets/gregtech/textures/gui/overlay_button/one_stack_limit.png b/src/main/resources/assets/gregtech/textures/gui/overlay_button/one_stack_limit.png
new file mode 100644
index 0000000000..8ebbb994eb
--- /dev/null
+++ b/src/main/resources/assets/gregtech/textures/gui/overlay_button/one_stack_limit.png
Binary files differ
diff --git a/src/main/resources/assets/gregtech/textures/gui/overlay_button/sorting_mode.png b/src/main/resources/assets/gregtech/textures/gui/overlay_button/sorting_mode.png
new file mode 100644
index 0000000000..5f505ebfe7
--- /dev/null
+++ b/src/main/resources/assets/gregtech/textures/gui/overlay_button/sorting_mode.png
Binary files differ