Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors shift tooltips on MetaBaseItem a bit #3333

Merged
merged 7 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/gregtech/api/interfaces/IItemBehaviour.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -61,8 +62,8 @@ boolean onItemUseFirst(E aItem, ItemStack aStack, EntityPlayer aPlayer, World aW

List<String> getAdditionalToolTips(E aItem, List<String> aList, ItemStack aStack);

default List<String> getAdditionalToolTipsWhileSneaking(E aItem, List<String> aList, ItemStack aStack) {
return aList;
default Optional<List<String>> getAdditionalToolTipsWhileSneaking(E aItem, List<String> aList, ItemStack aStack) {
return Optional.empty();
}

void onUpdate(E aItem, ItemStack aStack, World aWorld, Entity aPlayer, int aTimer, boolean aIsInHand);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/gregtech/api/items/MetaBaseItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -269,8 +270,14 @@ public final void addInformation(ItemStack aStack, EntityPlayer aPlayer, List<St
ArrayList<IItemBehaviour<MetaBaseItem>> behaviours = mItemBehaviors.get((short) getDamage(aStack));
if (behaviours != null) {
for (IItemBehaviour<MetaBaseItem> behavior : behaviours) {
aList = !KeyboardUtil.isShiftKeyDown() ? behavior.getAdditionalToolTips(this, aList, aStack)
: behavior.getAdditionalToolTipsWhileSneaking(this, aList, aStack);
final Optional<List<String>> shiftTooltips = KeyboardUtil.isShiftKeyDown()
? behavior.getAdditionalToolTipsWhileSneaking(this, aList, aStack)
: Optional.empty();
if (shiftTooltips.isPresent()) {
aList = shiftTooltips.get();
} else {
aList = behavior.getAdditionalToolTips(this, aList, aStack);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,16 +115,19 @@ public List<String> getAdditionalToolTips(final MetaBaseItem aItem, final List<S
}

@Override
public List<String> getAdditionalToolTipsWhileSneaking(final MetaBaseItem aItem, final List<String> aList,
public Optional<List<String>> getAdditionalToolTipsWhileSneaking(final MetaBaseItem aItem, final List<String> aList,
final ItemStack aStack) {
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.infinite"));
aList.add(mTooltipChain);
aList.add(" ");
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.switch"));
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.gui"));
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.pick"));
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.lock"));
aList.add(" ");
aList.add(AuthorQuerns);
return aList;

return Optional.of(aList);
}
// endregion

Expand Down