-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #750 from kevinthegreat1/potion-level-slot-text
Refactor Tooltips and Slot Texts
- Loading branch information
Showing
29 changed files
with
209 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CollectionAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package de.hysky.skyblocker.skyblock.item.slottext.adders; | ||
|
||
import de.hysky.skyblocker.skyblock.item.slottext.SlotText; | ||
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; | ||
import de.hysky.skyblocker.utils.RomanNumerals; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class CollectionAdder extends SlotTextAdder { | ||
private static final Pattern COLLECTION = Pattern.compile("^[\\w ]+ (?<level>[IVXLCDM]+)$"); | ||
|
||
public CollectionAdder() { | ||
super("^\\w+ Collections"); | ||
} | ||
|
||
@Override | ||
public @NotNull List<SlotText> getText(Slot slot) { | ||
final ItemStack stack = slot.getStack(); | ||
Matcher matcher = COLLECTION.matcher(stack.getName().getString()); | ||
if (matcher.matches()) { | ||
int level = RomanNumerals.romanToDecimal(matcher.group("level")); | ||
return List.of(SlotText.bottomRight(Text.literal(String.valueOf(level)).formatted(Formatting.YELLOW))); | ||
} | ||
return List.of(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PotionLevelAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.hysky.skyblocker.skyblock.item.slottext.adders; | ||
|
||
import de.hysky.skyblocker.skyblock.item.slottext.SlotText; | ||
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; | ||
import de.hysky.skyblocker.utils.ItemUtils; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class PotionLevelAdder extends SlotTextAdder { | ||
@Override | ||
public @NotNull List<SlotText> getText(Slot slot) { | ||
final ItemStack stack = slot.getStack(); | ||
NbtCompound customData = ItemUtils.getCustomData(stack); | ||
if (customData.contains("potion_level", NbtElement.INT_TYPE)) { | ||
int level = customData.getInt("potion_level"); | ||
return List.of(SlotText.bottomRight(Text.literal(String.valueOf(level)).formatted(Formatting.AQUA))); | ||
} | ||
return List.of(); | ||
} | ||
} |
21 changes: 9 additions & 12 deletions
21
src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,45 @@ | ||
package de.hysky.skyblocker.skyblock.item.tooltip; | ||
|
||
import de.hysky.skyblocker.skyblock.ChestValue; | ||
import de.hysky.skyblocker.utils.render.gui.AbstractContainerMatcher; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Text; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Extend this class and add it to {@link TooltipManager#adders} to add additional text to tooltips. | ||
*/ | ||
public abstract class TooltipAdder { | ||
/** | ||
* The title of the screen must match this pattern for this adder to be applied. Null means it will be applied to all screens. | ||
* @implNote Don't end your regex with a {@code $} as {@link ChestValue} appends text to the end of the title, | ||
* so the regex will stop matching if the player uses it. | ||
*/ | ||
public final Pattern titlePattern; | ||
public abstract class TooltipAdder extends AbstractContainerMatcher { | ||
/** | ||
* The priority of this adder. Lower priority means it will be applied first. | ||
* @apiNote Consider taking this value on your class' constructor and setting it from {@link TooltipManager#adders} to make it easy to read and maintain. | ||
*/ | ||
public final int priority; | ||
|
||
protected TooltipAdder(String titlePattern, int priority) { | ||
this(Pattern.compile(titlePattern), priority); | ||
super(titlePattern); | ||
this.priority = priority; | ||
} | ||
|
||
protected TooltipAdder(Pattern titlePattern, int priority) { | ||
this.titlePattern = titlePattern; | ||
super(titlePattern); | ||
this.priority = priority; | ||
} | ||
|
||
/** | ||
* Creates a TooltipAdder that will be applied to all screens. | ||
*/ | ||
protected TooltipAdder(int priority) { | ||
this.titlePattern = null; | ||
super(); | ||
this.priority = priority; | ||
} | ||
|
||
/** | ||
* @implNote The first element of the lines list holds the item's display name, | ||
* as it's a list of all lines that will be displayed in the tooltip. | ||
*/ | ||
public abstract void addToTooltip(List<Text> lines, Slot focusedSlot); | ||
public abstract void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.