Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
- name: setup jdk
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'microsoft'
java-version: '25'
distribution: microsoft
- name: make gradle wrapper executable
run: chmod +x ./gradlew
- name: build
Expand All @@ -27,4 +27,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
path: build/libs/
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
<h3 align="center">TooltipToggles</h3>

## Features

Provides toggles for a couple of tooltips and tooltip features.

### Toggles

- Hide Components in Advanced Tooltips*
- Hide Components in Advanced Tooltips\*
- Hide Item ID in Advanced Tooltips
- Remove italics*
- Sort Attribute Modifiers alphabetically*
- Remove italics\*
- Sort Attribute Modifiers alphabetically\*

\* Enabled by default.

### Dependencies

[Mod Menu](https://modrinth.com/mod/modmenu) and [Cloth Config](https://modrinth.com/mod/cloth-config) optionally required to change config.
[Mod Menu](https://modrinth.com/mod/modmenu) and [Cloth Config](https://modrinth.com/mod/cloth-config) optionally required to change config.
23 changes: 8 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'net.fabricmc.fabric-loom' version "${loom_version}"
id 'maven-publish'
}

version = project.mod_version
version = "${project.mod_version}+${project.minecraft_version}"
group = project.maven_group

base {
Expand All @@ -18,13 +18,12 @@ repositories {
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
implementation "net.fabricmc:fabric-loader:${project.loader_version}"

modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
api("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
compileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
}

processResources {
Expand All @@ -35,14 +34,8 @@ processResources {
}
}

configurations.all {
resolutionStrategy {
force("net.fabricmc:fabric-loader:$loader_version")
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.release = 25
}

java {
Expand All @@ -51,8 +44,8 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}

jar {
Expand Down
15 changes: 9 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# IntelliJ IDEA is not yet fully compatible with configuration cache, see: https://github.com/FabricMC/fabric-loom/issues/1349
org.gradle.configuration-cache=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.5
yarn_mappings=1.21.5+build.1
loader_version=0.16.13
minecraft_version=26.1
loader_version=0.18.4
loom_version=1.15-SNAPSHOT

# Mod Properties
mod_version=1.2.3
mod_version=1.2.4
maven_group=yungand.tooltiptoggles
archives_base_name=tooltiptoggles

# Dependencies
cloth_config_version=8.2.88
mod_menu_version=5.0.2
cloth_config_version=26.1.154
mod_menu_version=18.0.0-alpha.8
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
39 changes: 19 additions & 20 deletions src/main/java/yungando/tooltiptoggles/TooltipToggles.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.registry.Registries;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import yungando.tooltiptoggles.config.TooltipTogglesConfig;
import yungando.tooltiptoggles.config.TooltipTogglesConfig.TooltipTogglesAutoConfig;

Expand All @@ -32,21 +32,21 @@ public void onInitializeClient() {
}
}

private static void removeItalics(Text tooltip) {
if (tooltip instanceof MutableText tooltipText) {
private static void removeItalics(Component tooltip) {
if (tooltip instanceof MutableComponent tooltipText) {
if (tooltipText.getStyle().isItalic()) {
tooltipText.setStyle(tooltipText.getStyle().withItalic(false));
}

for (Text siblingTooltip : tooltipText.getSiblings()) {
for (Component siblingTooltip : tooltipText.getSiblings()) {
removeItalics(siblingTooltip);
}
}
}

private static List<Text> sortAttributes(int modifiersIndex, List<Text> list) {
ArrayList<Text> attributeModifiers = new ArrayList<>();
for (Text tooltip : list) {
private static List<Component> sortAttributes(int modifiersIndex, List<Component> list) {
ArrayList<Component> attributeModifiers = new ArrayList<>();
for (Component tooltip : list) {
if (tooltip.toString().contains("attribute.modifier")) {
attributeModifiers.add(tooltip);
if (attributeModifiers.size() > 2) {
Expand All @@ -62,16 +62,16 @@ private static List<Text> sortAttributes(int modifiersIndex, List<Text> list) {
return list;
}

public static List<Text> tooltipEditor(ItemStack itemStack, TooltipType type, List<Text> list) {
public static List<Component> tooltipEditor(ItemStack itemStack, TooltipFlag type, List<Component> list) {
if (TooltipToggles.config.removeItalics()) {
for (Text tooltip : list) {
for (Component tooltip : list) {
removeItalics(tooltip);
}
}

if (TooltipToggles.config.sortAttributes()) {
int modifiersIndex = -1;
for (Text tooltip : list) {
for (Component tooltip : list) {
if (tooltip.toString().contains("item.modifiers")) {
modifiersIndex = list.indexOf(tooltip);
break;
Expand All @@ -86,18 +86,17 @@ public static List<Text> tooltipEditor(ItemStack itemStack, TooltipType type, Li
if (!type.isAdvanced()) { return list; }

if (TooltipToggles.config.hideComponents() && !itemStack.getComponents().isEmpty()) {
ArrayList<Text> components = new ArrayList<>();
assert itemStack.getComponents() != null;
components.add(Text.translatable("item.components", itemStack.getComponents().size()).formatted(Formatting.DARK_GRAY));
ArrayList<Component> components = new ArrayList<>();
components.add(Component.translatable("item.components", itemStack.getComponents().size()).withStyle(ChatFormatting.DARK_GRAY));
int componentsIndex = list.indexOf(components.getFirst());
if (componentsIndex >= 0) {
list.remove(componentsIndex);
}
}

if (TooltipToggles.config.hideID()) {
ArrayList<Text> id = new ArrayList<>();
id.add(Text.literal(Registries.ITEM.getId(itemStack.getItem()).toString()).formatted(Formatting.DARK_GRAY));
ArrayList<Component> id = new ArrayList<>();
id.add(Component.literal(BuiltInRegistries.ITEM.getKey(itemStack.getItem()).toString()).withStyle(ChatFormatting.DARK_GRAY));
int idIndex = list.indexOf(id.getFirst());

if (idIndex >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.AutoConfigClient;
import yungando.tooltiptoggles.config.TooltipTogglesConfig.TooltipTogglesAutoConfig;

public class ModMenuEntrypoint implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> AutoConfig.getConfigScreen(TooltipTogglesAutoConfig.class, parent).get();
return parent -> AutoConfigClient.getConfigScreen(TooltipTogglesAutoConfig.class, parent).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class TooltipTogglesConfig {
public boolean removeItalics() { return true; }
public boolean sortAttributes() { return true; }

/** Config class requiring AutoConfig */
@SuppressWarnings("FieldMayBeFinal")
@Config(name = TooltipToggles.MODID)
public static class TooltipTogglesAutoConfig extends TooltipTogglesConfig implements ConfigData {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/yungando/tooltiptoggles/mixin/GuiMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package yungando.tooltiptoggles.mixin;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.Gui;
import net.minecraft.network.chat.MutableComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import yungando.tooltiptoggles.TooltipToggles;

@Mixin(Gui.class)
public class GuiMixin {
@WrapWithCondition(method = "extractSelectedItemName", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/chat/MutableComponent;withStyle(Lnet/minecraft/ChatFormatting;)Lnet/minecraft/network/chat/MutableComponent;", ordinal = 1))
private boolean TooltipToggles$removeItalics(MutableComponent instance, ChatFormatting formatting) {
return !TooltipToggles.config.removeItalics();
}
}
18 changes: 0 additions & 18 deletions src/main/java/yungando/tooltiptoggles/mixin/InGameHudMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package yungando.tooltiptoggles.mixin;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.*;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import yungando.tooltiptoggles.TooltipToggles;

import java.util.List;
Expand All @@ -15,9 +15,9 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ItemStack.class)
public class TooltipMixin {
@Inject(method = "getTooltip", at = @At("RETURN"), cancellable = true)
protected void TooltipToggles$editTooltip(Item.TooltipContext context, PlayerEntity player, TooltipType type, CallbackInfoReturnable<List<Text>> cir) {
public class ItemStackMixin {
@Inject(method = "getTooltipLines", at = @At("RETURN"), cancellable = true)
protected void TooltipToggles$editTooltip(Item.TooltipContext context, Player player, TooltipFlag type, CallbackInfoReturnable<List<Component>> cir) {
cir.setReturnValue(TooltipToggles.tooltipEditor((ItemStack) (Object) this, type, cir.getReturnValue()));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/tooltiptoggles/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"text.autoconfig.tooltiptoggles.option.removeItalics.@Tooltip": "Unitalicises all tooltips.",
"text.autoconfig.tooltiptoggles.option.sortAttributes": "Sort Attributes Alphabetically",
"text.autoconfig.tooltiptoggles.option.sortAttributes.@Tooltip": "Sorts the armor attribute (e.g. Armor Toughness, Knockback Resistance) tooltips alphabetically."
}
}
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"tooltiptoggles.mixins.json"
],
"depends": {
"minecraft": ">=1.21",
"fabricloader": ">=0.16.13",
"java": ">=21"
"fabricloader": ">=0.18.4",
"minecraft": ">=26.1",
"java": ">=25"
},
"suggests": {
"modmenu": "*",
Expand Down
17 changes: 10 additions & 7 deletions src/main/resources/tooltiptoggles.mixins.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"required": true,
"package": "yungando.tooltiptoggles.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"InGameHudMixin",
"TooltipMixin"
],
"compatibilityLevel": "JAVA_25",
"injectors": {
"defaultRequire": 1
}
}
},
"overwrites": {
"requireAnnotations": true
},
"client": [
"GuiMixin",
"ItemStackMixin"
]
}
Loading