Skip to content

Commit

Permalink
data-drive tooltip text customization
Browse files Browse the repository at this point in the history
also clean up some stuff
  • Loading branch information
Andrew6rant committed Jan 8, 2023
1 parent 7cb83dd commit cd7e29a
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 28 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ There is also a Reforging station added to reroll item attributes:
<summary>Show Reforging Station</summary>

![Tiered Reforging Station](https://user-images.githubusercontent.com/57331134/172750885-5ba9668d-51db-43ff-ba63-d5c177210462.png)
The Reforging Station holds a small inventory, click on the drawer to open it.
</details>

Tiered was originally made by Draylar, and is being updated and maintained by Andrew6rant.
Expand Down Expand Up @@ -39,6 +40,15 @@ Tiered is almost entirely data-driven, which means you can add, modify, and remo
"operation": "MULTIPLY_BASE",
"amount": 0.10
},
"tooltip": {
"style": {
"color": "gray"
},
"text": [
"tiered:hasteful.tooltip",
"tiered:hasteful.tooltip_2"
]
},
"optional_equipment_slots": [
"MAINHAND",
"OFFHAND"
Expand Down Expand Up @@ -78,12 +88,13 @@ Reforging an item's modifier costs experience points (not levels). Each item's c

### Tooltips

Tiered provides five customization options regarding tooltips.
Tiered provides six customization options regarding tooltips.

- `color` changes the text color
- `tooltip_image` specifies the border style (see below)
- `tooltip_border` determines the line colors of the border. It is an array of 0xAARRGGBB hexadecimal formatted strings. Use one value to color the entire border, or two to specify the start and end colors.
- `no_tooltip` can be used in the `name` section of an attribute to prevent it from showing. For example, this can be useful for the `reach` and `attack_range` modifier types, as they are often used together and can clutter a tooltip.
- `tooltip` is an optional section in the `attributes` array. It allows you to add additional text to the tooltip. The `text` array is for translation keys, and there is an optional `style` section as well (otherwise, the text is colored to the above `style`)

Here is the formatting for the border style. This image allows for up to 16 styles (0-15):

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/Andrew6rant/tiered/api/AttributeTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class AttributeTemplate {
private final EquipmentSlot[] optionalEquipmentSlots;

@SerializedName("tooltip")
private final List<Object> tooltip;
private final TooltipClass tooltip;

public AttributeTemplate(String attributeTypeID, EntityAttributeModifier entityAttributeModifier, EquipmentSlot[] requiredEquipmentSlots, EquipmentSlot[] optionalEquipmentSlots, List<Object> tooltip) {
public AttributeTemplate(String attributeTypeID, EntityAttributeModifier entityAttributeModifier, EquipmentSlot[] requiredEquipmentSlots, EquipmentSlot[] optionalEquipmentSlots, TooltipClass tooltip) {
this.attributeTypeID = attributeTypeID;
this.entityAttributeModifier = entityAttributeModifier;
this.requiredEquipmentSlots = requiredEquipmentSlots;
Expand All @@ -60,7 +60,7 @@ public String getAttributeTypeID() {
return attributeTypeID;
}

public List<Object> getTooltip() {
public TooltipClass getTooltip() {
return tooltip;
}

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/Andrew6rant/tiered/api/TooltipClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Andrew6rant.tiered.api;

import net.minecraft.text.Style;

public class TooltipClass {
private final Style style;
private final String[] text;

public TooltipClass(Style style, String[] text) {
this.style = style;
this.text = text;
}

public Style getStyle() {
return style;
}

public String[] getTooltipText() {
return text;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Andrew6rant.tiered.mixin.client;

import Andrew6rant.tiered.api.AttributeTemplate;
import Andrew6rant.tiered.api.TooltipClass;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import Andrew6rant.tiered.Tiered;
Expand Down Expand Up @@ -108,6 +109,8 @@ private void getNameMixin(CallbackInfoReturnable<Text> info) {
at = @At(value = "RETURN", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"))
private void test(PlayerEntity player, TooltipContext context, CallbackInfoReturnable<List<Text>> cir) {
if (isTiered && this.hasNbt() && this.getSubNbt(Tiered.NBT_SUBTAG_KEY) != null) { // only run on tiered items
Identifier tier = new Identifier(this.getOrCreateSubNbt(Tiered.NBT_SUBTAG_KEY).getString(Tiered.NBT_SUBTAG_DATA_KEY));
PotentialAttribute attribute = Tiered.ATTRIBUTE_DATA_LOADER.getItemAttributes().get(tier);
List<Text> list = cir.getReturnValue();
List<Text> badlyFormattedList = new ArrayList<>();
Set<TranslatableText> modifierSet = new HashSet<>();
Expand All @@ -116,6 +119,10 @@ private void test(PlayerEntity player, TooltipContext context, CallbackInfoRetur
Set<TranslatableText> noDuplicates = new HashSet<>();
String heldOrArmor = "";

//for (Text text : list) {
// System.out.println(text);
//}

// remove blank tooltip lines
list.removeIf(text -> (!(text instanceof TranslatableText) && text.getSiblings().size() == 0));

Expand Down Expand Up @@ -193,8 +200,6 @@ private void test(PlayerEntity player, TooltipContext context, CallbackInfoRetur
String val1Str = trailZeros(val1);
String val2Str = trailZeros(val2);
if (key.getKey().equals(key_compare.getKey())) {
Identifier tier = new Identifier(this.getOrCreateSubNbt(Tiered.NBT_SUBTAG_KEY).getString(Tiered.NBT_SUBTAG_DATA_KEY));
PotentialAttribute attribute = Tiered.ATTRIBUTE_DATA_LOADER.getItemAttributes().get(tier);
list.remove(noDuplicates.toArray()[i]);
list.remove(noDuplicates.toArray()[j]);
switch (text.getKey() + text_compare.getKey()) {
Expand All @@ -218,19 +223,18 @@ private void test(PlayerEntity player, TooltipContext context, CallbackInfoRetur
}
}

}
/*
Identifier tier = new Identifier(getOrCreateSubNbt(Tiered.NBT_SUBTAG_KEY).getString(Tiered.NBT_SUBTAG_DATA_KEY));
PotentialAttribute potentialAttribute = Tiered.ATTRIBUTE_DATA_LOADER.getItemAttributes().get(tier);
for (AttributeTemplate attribute : potentialAttribute.getAttributes()) {
if (attribute.getTooltip() != null) {
List<Object> tooltips = attribute.getTooltip();
for (Object tooltip : tooltips.subList(1, tooltips.size())) {
list.add(new TranslatableText((String) tooltip).setStyle((Style) tooltips.get(0)));
for (AttributeTemplate attributeTemplate : attribute.getAttributes()) {
if (attributeTemplate.getTooltip() != null) {
TooltipClass tooltips = attributeTemplate.getTooltip();
for (String tooltipText : tooltips.getTooltipText()) {
if (tooltips.getStyle() != null) {
list.add(new TranslatableText(tooltipText).setStyle(tooltips.getStyle()));
} else {
list.add(new TranslatableText(tooltipText).setStyle(attribute.getStyle()));
}
}
}
}
}
*/
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/tiered/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"///": "Epic",
"tiered:resilient.name": "Resilient",
"tiered:architects.name": "Architect's",
"tiered:architects.tooltip": "Only affects Reach, not Attack Range",
"tiered:architects.tooltip": "Only affects Reach,",
"tiered:architects.tooltip_2": "not Attack Range",

"///": "Legendary"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"id": "okay:test",
"verifiers": [
{ "tag": "c:helmets" },
{ "tag": "c:chestplates" },
{ "tag": "c:leggings" },
{ "tag": "c:boots" },
{ "tag": "c:shields" }
],
"style": {
"color": "gray"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
"attributes": [
{
"type": "reach-entity-attributes:reach",
"tooltip": ["tiered:architects.tooltip"],
"tooltip": {
"style": {
"color": "gray"
},
"text": [
"tiered:architects.tooltip",
"tiered:architects.tooltip_2"
]
},
"modifier": {
"name": "tiered:architects",
"operation": "ADDITION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
"style": {
"color": "light_purple"
},
"weight": 2,
"weight": 3,
"tooltip_image": [4],
"tooltip_border": ["FF996922"],
"reforge_cost": 21,
"attributes": [
{
"type": "reach-entity-attributes:reach",
"tooltip": ["light_purple", "tiered:architects.tooltip"],
"tooltip": {
"style": {
"color": "gray"
},
"text": [
"tiered:architects.tooltip",
"tiered:architects.tooltip_2"
]
},
"modifier": {
"name": "no_tooltip",
"name": "tiered:architects_boots",
"operation": "ADDITION",
"amount": 2
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"verifiers": [
{ "tag": "c:helmets" },
{ "tag": "c:chestplates" },
{ "tag": "c:leggings" },
{ "tag": "c:boots" }
{ "tag": "c:leggings" }
],
"style": {
"color": "gray"
Expand Down

0 comments on commit cd7e29a

Please sign in to comment.