mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-20 03:59:49 +00:00
Add \n support for tooltips in our items
This commit is contained in:
1 parent
f5497bbce3
commit
f1d45e8bb4
3 files changed
+41
-8
No files matched your search
@@ -48,12 +48,12 @@ public class ItemBlockMeta extends ItemColored {
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
|
||||
if(I18n.canTranslate(this.getUnlocalizedName(stack) + ".tooltip")) {
|
||||
tooltip.add(TextFormatting.GRAY.toString() +
|
||||
LocUtils.translateRecursive(this.getUnlocalizedName(stack) + ".tooltip"));
|
||||
tooltip.addAll(LocUtils.getTooltips(TextFormatting.GRAY.toString() +
|
||||
LocUtils.translateRecursive(this.getUnlocalizedName(stack) + ".tooltip")));
|
||||
}
|
||||
else if(I18n.canTranslate(super.getUnlocalizedName(stack) + ".tooltip")) {
|
||||
tooltip.add(
|
||||
TextFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip"));
|
||||
tooltip.addAll(LocUtils.getTooltips(
|
||||
TextFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip")));
|
||||
}
|
||||
super.addInformation(stack, playerIn, tooltip, advanced);
|
||||
}
|
||||
|
||||
@@ -123,12 +123,12 @@ public class ItemMetaDynamic extends Item {
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
|
||||
if(I18n.canTranslate(this.getUnlocalizedName(stack) + ".tooltip")) {
|
||||
tooltip.add(TextFormatting.GRAY.toString() +
|
||||
LocUtils.translateRecursive(this.getUnlocalizedName(stack) + ".tooltip"));
|
||||
tooltip.addAll(LocUtils.getTooltips(TextFormatting.GRAY.toString() +
|
||||
LocUtils.translateRecursive(this.getUnlocalizedName(stack) + ".tooltip")));
|
||||
}
|
||||
else if(I18n.canTranslate(super.getUnlocalizedName(stack) + ".tooltip")) {
|
||||
tooltip.add(
|
||||
TextFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip"));
|
||||
tooltip.addAll(LocUtils.getTooltips(
|
||||
TextFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip")));
|
||||
}
|
||||
super.addInformation(stack, playerIn, tooltip, advanced);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package slimeknights.mantle.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
// localization utils
|
||||
@@ -20,4 +23,34 @@ public abstract class LocUtils {
|
||||
public static String translateRecursive(String key, Object... params) {
|
||||
return I18n.translateToLocal(I18n.translateToLocalFormatted(key, params));
|
||||
}
|
||||
|
||||
public static List<String> getTooltips(String text) {
|
||||
List<String> list = Lists.newLinkedList();
|
||||
if(text == null)
|
||||
return list;
|
||||
int j = 0;
|
||||
int k;
|
||||
while((k = text.indexOf("\\n", j)) >= 0)
|
||||
{
|
||||
list.add(text.substring(j, k));
|
||||
j = k+2;
|
||||
}
|
||||
|
||||
list.add(text.substring(j, text.length()));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static String convertNewlines(String line) {
|
||||
if(line == null)
|
||||
return null;
|
||||
int j;
|
||||
while((j = line.indexOf("\\n")) >= 0)
|
||||
{
|
||||
line = line.substring(0, j) + '\n' + line.substring(j+2);
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user