2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("StringUtil.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.util;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
|
|
import net.minecraft.client.gui.Font;
|
2024-03-03 01:20:53 +01:00
|
|
|
import net.minecraft.client.gui.GuiGraphics;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.resources.language.I18n;
|
2024-03-04 20:21:48 +01:00
|
|
|
import net.neoforged.api.distmarker.Dist;
|
|
|
|
import net.neoforged.api.distmarker.OnlyIn;
|
2015-08-01 00:40:29 +02:00
|
|
|
|
2022-06-05 22:30:25 +02:00
|
|
|
@Deprecated
|
2019-05-02 09:10:29 +02:00
|
|
|
public final class StringUtil {
|
2015-08-01 00:40:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Localizes a given formatted String with the given Replacements
|
|
|
|
*/
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static String localizeFormatted(String text, Object... replace) {
|
2021-08-22 17:09:06 +02:00
|
|
|
return I18n.get(text, replace);
|
2015-08-01 00:40:29 +02:00
|
|
|
}
|
2015-08-24 17:57:11 +02:00
|
|
|
|
2021-11-13 19:30:58 +01:00
|
|
|
// TODO: Move to official
|
2024-03-11 23:51:32 +01:00
|
|
|
@Deprecated
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2024-03-02 21:23:08 +01:00
|
|
|
public static void drawSplitString(Font renderer, String strg, int x, int y, int width, int color, boolean shadow) {
|
2021-11-13 19:30:58 +01:00
|
|
|
// ResourcePackList <- holds the correct way
|
|
|
|
// List<String> list = renderer.listFormattedStringToWidth(strg, width);
|
|
|
|
// for (int i = 0; i < list.size(); i++) {
|
|
|
|
// String s1 = list.get(i);
|
|
|
|
// renderer.draw(s1, x, y + i * renderer.lineHeight, color, shadow);
|
|
|
|
// }
|
2015-12-22 14:55:10 +01:00
|
|
|
}
|
2015-12-27 21:56:32 +01:00
|
|
|
|
2021-11-13 19:30:58 +01:00
|
|
|
// @OnlyIn(Dist.CLIENT)
|
|
|
|
// public static void renderSplitScaledAsciiString(FontRenderer font, String text, int x, int y, int color, boolean shadow, float scale, int length) {
|
|
|
|
// List<String> lines = font.listFormattedStringToWidth(text, (int) (length / scale));
|
|
|
|
// for (int i = 0; i < lines.size(); i++) {
|
|
|
|
// renderScaledAsciiString(font, lines.get(i), x, y + i * (int) (font.lineHeight * scale + 3), color, shadow, scale);
|
|
|
|
// }
|
|
|
|
// }
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2024-03-03 01:20:53 +01:00
|
|
|
public static void renderScaledString(GuiGraphics guiGraphics, Font font, String text, float x, float y, int color, boolean shadow, float scale) {
|
|
|
|
PoseStack matrices = guiGraphics.pose();
|
2022-04-02 23:56:22 +02:00
|
|
|
matrices.pushPose();
|
|
|
|
matrices.translate(x, y, 0);
|
|
|
|
matrices.scale(scale, scale, 1.0F);
|
|
|
|
if (shadow)
|
2024-03-03 01:20:53 +01:00
|
|
|
guiGraphics.drawString(font, text, 0, 0, color);
|
2022-04-02 23:56:22 +02:00
|
|
|
else
|
2024-03-03 01:20:53 +01:00
|
|
|
guiGraphics.drawString(font, text, x, y, color, false);
|
2022-04-02 23:56:22 +02:00
|
|
|
matrices.popPose();
|
2018-06-27 09:23:55 +02:00
|
|
|
}
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|