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
|
|
|
|
2018-06-27 09:23:55 +02:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2015-12-22 14:55:10 +01:00
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2016-11-10 19:50:01 +01:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2017-07-28 03:17:50 +02:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2018-06-27 09:23:55 +02:00
|
|
|
import net.minecraft.util.text.translation.LanguageMap;
|
2016-07-04 20:15:41 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-08-01 00:40:29 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public final class StringUtil {
|
2015-03-29 15:29:05 +02:00
|
|
|
|
|
|
|
public static final int DECIMAL_COLOR_WHITE = 16777215;
|
2015-04-19 01:50:02 +02:00
|
|
|
public static final int DECIMAL_COLOR_GRAY_TEXT = 4210752;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static final String BUGGED_ITEM_NAME = ActuallyAdditions.MODID + ".lolWutHowUDoDis";
|
2015-11-23 19:06:07 +01:00
|
|
|
|
2015-08-01 00:40:29 +02:00
|
|
|
/**
|
2017-07-28 03:17:50 +02:00
|
|
|
* Localizes a given String
|
2015-08-01 00:40:29 +02:00
|
|
|
*/
|
2017-07-28 03:17:50 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static String localize(String text) {
|
2017-07-28 03:17:50 +02:00
|
|
|
return I18n.format(text);
|
2015-08-01 00:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Localizes a given formatted String with the given Replacements
|
|
|
|
*/
|
2017-07-28 03:17:50 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static String localizeFormatted(String text, Object... replace) {
|
2017-07-28 03:17:50 +02:00
|
|
|
return I18n.format(text, replace);
|
2015-08-01 00:40:29 +02:00
|
|
|
}
|
2015-08-24 17:57:11 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
@SuppressWarnings("deprecation") //TODO: delete this shit and move ItemPotionRing's getItemStackDisplayName into getUnlocalizedName
|
2017-07-28 03:17:50 +02:00
|
|
|
public static String localizeIllegallyOnTheServerDontUseMePls(String langKey) {
|
2019-02-27 19:53:05 +01:00
|
|
|
return net.minecraft.util.text.translation.I18n.translateToLocal(langKey);
|
2017-07-28 03:17:50 +02:00
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
|
2016-07-04 20:15:41 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void drawSplitString(FontRenderer renderer, String strg, int x, int y, int width, int color, boolean shadow) {
|
2017-07-28 03:17:50 +02:00
|
|
|
List<String> list = renderer.listFormattedStringToWidth(strg, width);
|
2019-05-02 09:10:29 +02:00
|
|
|
for (int i = 0; i < list.size(); i++) {
|
2019-02-27 19:53:05 +01:00
|
|
|
String s1 = list.get(i);
|
2019-05-02 09:10:29 +02:00
|
|
|
renderer.drawString(s1, x, y + i * renderer.FONT_HEIGHT, color, shadow);
|
2015-12-22 14:55:10 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-27 21:56:32 +01:00
|
|
|
|
2016-11-10 19:50:01 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public static void renderScaledAsciiString(FontRenderer font, String text, float x, float y, int color, boolean shadow, float scale) {
|
2016-11-10 19:50:01 +01:00
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.scale(scale, scale, scale);
|
|
|
|
boolean oldUnicode = font.getUnicodeFlag();
|
|
|
|
font.setUnicodeFlag(false);
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
font.drawString(text, x / scale, y / scale, color, shadow);
|
2016-11-10 19:50:01 +01:00
|
|
|
|
|
|
|
font.setUnicodeFlag(oldUnicode);
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
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.FONT_HEIGHT * scale + 3), color, shadow, scale);
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
|
2018-06-27 09:23:55 +02:00
|
|
|
//TODO: Remove
|
|
|
|
static LanguageMap cancerino;
|
|
|
|
|
|
|
|
static void setupLangMap() {
|
|
|
|
try {
|
|
|
|
Method m = LanguageMap.class.getDeclaredMethod("inject", LanguageMap.class, InputStream.class);
|
|
|
|
m.setAccessible(true);
|
|
|
|
m.invoke(null, cancerino = new LanguageMap(), ActuallyAdditions.class.getResourceAsStream("/assets/actuallyadditions/lang/en_US.lang"));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new RuntimeException("Actually Additions failed to access LanguageMap.inject. Report this!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String badTranslate(String someUnlocAAItemName) {
|
|
|
|
if (cancerino == null) {
|
|
|
|
cancerino = new LanguageMap();
|
|
|
|
setupLangMap();
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
return cancerino.translateKey("item.actuallyadditions." + someUnlocAAItemName + ".name");
|
2018-06-27 09:23:55 +02:00
|
|
|
}
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|