From cd7e29a3813463a557753bf83e5179beeff622ae Mon Sep 17 00:00:00 2001 From: Andrew Grant Date: Sat, 7 Jan 2023 20:02:24 -0500 Subject: [PATCH] data-drive tooltip text customization also clean up some stuff --- README.md | 13 ++++++++- .../tiered/api/AttributeTemplate.java | 6 ++-- .../Andrew6rant/tiered/api/TooltipClass.java | 21 ++++++++++++++ .../mixin/client/ItemStackClientMixin.java | 28 +++++++++++-------- .../resources/assets/tiered/lang/en_us.json | 3 +- .../item_attributes/armor/common/test.json | 5 ---- .../armor/epic/architects.json | 10 ++++++- .../armor/epic/architects_boots.json | 14 ++++++++-- .../item_attributes/armor/junk/dented.json | 3 +- 9 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 src/main/java/Andrew6rant/tiered/api/TooltipClass.java diff --git a/README.md b/README.md index 786a6bc2..ffd22673 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ There is also a Reforging station added to reroll item attributes: Show Reforging Station ![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. Tiered was originally made by Draylar, and is being updated and maintained by Andrew6rant. @@ -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" @@ -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): diff --git a/src/main/java/Andrew6rant/tiered/api/AttributeTemplate.java b/src/main/java/Andrew6rant/tiered/api/AttributeTemplate.java index 3cf9c3b4..6ef2058e 100644 --- a/src/main/java/Andrew6rant/tiered/api/AttributeTemplate.java +++ b/src/main/java/Andrew6rant/tiered/api/AttributeTemplate.java @@ -38,9 +38,9 @@ public class AttributeTemplate { private final EquipmentSlot[] optionalEquipmentSlots; @SerializedName("tooltip") - private final List tooltip; + private final TooltipClass tooltip; - public AttributeTemplate(String attributeTypeID, EntityAttributeModifier entityAttributeModifier, EquipmentSlot[] requiredEquipmentSlots, EquipmentSlot[] optionalEquipmentSlots, List tooltip) { + public AttributeTemplate(String attributeTypeID, EntityAttributeModifier entityAttributeModifier, EquipmentSlot[] requiredEquipmentSlots, EquipmentSlot[] optionalEquipmentSlots, TooltipClass tooltip) { this.attributeTypeID = attributeTypeID; this.entityAttributeModifier = entityAttributeModifier; this.requiredEquipmentSlots = requiredEquipmentSlots; @@ -60,7 +60,7 @@ public String getAttributeTypeID() { return attributeTypeID; } - public List getTooltip() { + public TooltipClass getTooltip() { return tooltip; } diff --git a/src/main/java/Andrew6rant/tiered/api/TooltipClass.java b/src/main/java/Andrew6rant/tiered/api/TooltipClass.java new file mode 100644 index 00000000..95ef58b1 --- /dev/null +++ b/src/main/java/Andrew6rant/tiered/api/TooltipClass.java @@ -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; + } +} diff --git a/src/main/java/Andrew6rant/tiered/mixin/client/ItemStackClientMixin.java b/src/main/java/Andrew6rant/tiered/mixin/client/ItemStackClientMixin.java index 220a3804..183a5e0e 100644 --- a/src/main/java/Andrew6rant/tiered/mixin/client/ItemStackClientMixin.java +++ b/src/main/java/Andrew6rant/tiered/mixin/client/ItemStackClientMixin.java @@ -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; @@ -108,6 +109,8 @@ private void getNameMixin(CallbackInfoReturnable info) { at = @At(value = "RETURN", target = "Ljava/util/List;add(Ljava/lang/Object;)Z")) private void test(PlayerEntity player, TooltipContext context, CallbackInfoReturnable> 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 list = cir.getReturnValue(); List badlyFormattedList = new ArrayList<>(); Set modifierSet = new HashSet<>(); @@ -116,6 +119,10 @@ private void test(PlayerEntity player, TooltipContext context, CallbackInfoRetur Set 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)); @@ -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()) { @@ -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 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())); + } } } } } - */ } } \ No newline at end of file diff --git a/src/main/resources/assets/tiered/lang/en_us.json b/src/main/resources/assets/tiered/lang/en_us.json index c92c7017..6ac1d3b2 100644 --- a/src/main/resources/assets/tiered/lang/en_us.json +++ b/src/main/resources/assets/tiered/lang/en_us.json @@ -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" } \ No newline at end of file diff --git a/src/main/resources/data/tiered/item_attributes/armor/common/test.json b/src/main/resources/data/tiered/item_attributes/armor/common/test.json index d968232f..e72f5e07 100644 --- a/src/main/resources/data/tiered/item_attributes/armor/common/test.json +++ b/src/main/resources/data/tiered/item_attributes/armor/common/test.json @@ -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" diff --git a/src/main/resources/data/tiered/item_attributes/armor/epic/architects.json b/src/main/resources/data/tiered/item_attributes/armor/epic/architects.json index b8cc1cf9..38e4aa9f 100644 --- a/src/main/resources/data/tiered/item_attributes/armor/epic/architects.json +++ b/src/main/resources/data/tiered/item_attributes/armor/epic/architects.json @@ -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", diff --git a/src/main/resources/data/tiered/item_attributes/armor/epic/architects_boots.json b/src/main/resources/data/tiered/item_attributes/armor/epic/architects_boots.json index aff40df8..33ab69df 100644 --- a/src/main/resources/data/tiered/item_attributes/armor/epic/architects_boots.json +++ b/src/main/resources/data/tiered/item_attributes/armor/epic/architects_boots.json @@ -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 }, diff --git a/src/main/resources/data/tiered/item_attributes/armor/junk/dented.json b/src/main/resources/data/tiered/item_attributes/armor/junk/dented.json index f4b7e4cd..c38455d5 100644 --- a/src/main/resources/data/tiered/item_attributes/armor/junk/dented.json +++ b/src/main/resources/data/tiered/item_attributes/armor/junk/dented.json @@ -3,8 +3,7 @@ "verifiers": [ { "tag": "c:helmets" }, { "tag": "c:chestplates" }, - { "tag": "c:leggings" }, - { "tag": "c:boots" } + { "tag": "c:leggings" } ], "style": { "color": "gray"