Topic category: Help with Minecraft modding (Java Edition)
Hello everyone I ran into the problem that it is not possible to add additional lines to the Tooltip in the GUI. As I noticed, many people have tried to do this, but there is still no answer to this on the forum, and I decided to help solve this issue.
I found a way to implement this.
To begin with, this cannot be done without editing the GUI code.
1) Create a Tooltip in your GUI
2) Set it a display function that will return the text.
Use New Line for the separator (well, or /n inside the code)
3) Create a Custom Element and add the separator function there.import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSequence;
import java.util.ArrayList;
import java.util.List;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class TooltipUtils {
public static List<FormattedCharSequence> StringToComponent(String text) {
String[] lines = text.split("\n");
List<FormattedCharSequence> result = new ArrayList<>();
for (String line : lines) {
result.add(Component.literal(line).getVisualOrderText());
}
return result;
}
}
4) Replace the code in your GUI Screen.java on:
Don't forget to add Custom element import :)
Well, the result: