From 9fe5a4ee013c7769467cc1fee5d3b694b47b5ad8 Mon Sep 17 00:00:00 2001 From: Querns Date: Sat, 5 Oct 2024 17:12:11 -0500 Subject: [PATCH] Refactors shift tooltips on MetaBaseItem a bit --- .../java/gregtech/api/interfaces/IItemBehaviour.java | 5 +++-- src/main/java/gregtech/api/items/MetaBaseItem.java | 11 +++++++++-- .../items/behaviors/BehaviourSprayColorInfinite.java | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/api/interfaces/IItemBehaviour.java b/src/main/java/gregtech/api/interfaces/IItemBehaviour.java index 3526fc716bb..7a4286f638d 100644 --- a/src/main/java/gregtech/api/interfaces/IItemBehaviour.java +++ b/src/main/java/gregtech/api/interfaces/IItemBehaviour.java @@ -1,6 +1,7 @@ package gregtech.api.interfaces; import java.util.List; +import java.util.Optional; import net.minecraft.dispenser.IBlockSource; import net.minecraft.entity.Entity; @@ -61,8 +62,8 @@ boolean onItemUseFirst(E aItem, ItemStack aStack, EntityPlayer aPlayer, World aW List getAdditionalToolTips(E aItem, List aList, ItemStack aStack); - default List getAdditionalToolTipsWhileSneaking(E aItem, List aList, ItemStack aStack) { - return aList; + default Optional> getAdditionalToolTipsWhileSneaking(E aItem, List aList, ItemStack aStack) { + return Optional.empty(); } void onUpdate(E aItem, ItemStack aStack, World aWorld, Entity aPlayer, int aTimer, boolean aIsInHand); diff --git a/src/main/java/gregtech/api/items/MetaBaseItem.java b/src/main/java/gregtech/api/items/MetaBaseItem.java index 7369d5d1b26..c6751adb96d 100644 --- a/src/main/java/gregtech/api/items/MetaBaseItem.java +++ b/src/main/java/gregtech/api/items/MetaBaseItem.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; @@ -269,8 +270,14 @@ public final void addInformation(ItemStack aStack, EntityPlayer aPlayer, List> behaviours = mItemBehaviors.get((short) getDamage(aStack)); if (behaviours != null) { for (IItemBehaviour behavior : behaviours) { - aList = !KeyboardUtil.isShiftKeyDown() ? behavior.getAdditionalToolTips(this, aList, aStack) - : behavior.getAdditionalToolTipsWhileSneaking(this, aList, aStack); + final Optional> shiftTooltips = KeyboardUtil.isShiftKeyDown() + ? behavior.getAdditionalToolTipsWhileSneaking(this, aList, aStack) + : Optional.empty(); + if (shiftTooltips.isPresent()) { + aList = shiftTooltips.get(); + } else { + aList = behavior.getAdditionalToolTips(this, aList, aStack); + } } } diff --git a/src/main/java/gregtech/common/items/behaviors/BehaviourSprayColorInfinite.java b/src/main/java/gregtech/common/items/behaviors/BehaviourSprayColorInfinite.java index ad22dcb958b..47b81674b5d 100644 --- a/src/main/java/gregtech/common/items/behaviors/BehaviourSprayColorInfinite.java +++ b/src/main/java/gregtech/common/items/behaviors/BehaviourSprayColorInfinite.java @@ -4,6 +4,7 @@ import static net.minecraft.util.MovingObjectPosition.MovingObjectType.BLOCK; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; import net.minecraft.entity.player.EntityPlayer; @@ -117,8 +118,10 @@ public List getAdditionalToolTips(final MetaBaseItem aItem, final List getAdditionalToolTipsWhileSneaking(final MetaBaseItem aItem, final List aList, + public Optional> getAdditionalToolTipsWhileSneaking(final MetaBaseItem aItem, final List aList, final ItemStack aStack) { + aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.infinite")); + aList.add(mTooltipChain); aList.add(SEPARATOR); aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.switch")); aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.gui")); @@ -127,7 +130,7 @@ public List getAdditionalToolTipsWhileSneaking(final MetaBaseItem aItem, aList.add(SEPARATOR); aList.add(AuthorQuerns); - return aList; + return Optional.of(aList); } // endregion