mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 19:49:41 +00:00
Add the ability to have dynamic tooltips in the loc file for the dynamic items
This commit is contained in:
1 parent
c798d616d7
commit
6c06ee151a
2 files changed
+36
-1
No files matched your search
@@ -6,8 +6,11 @@ import gnu.trove.procedure.TIntObjectProcedure;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -16,6 +19,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import slimeknights.mantle.util.LocUtils;
|
||||
|
||||
/**
|
||||
* Item representing a dynamic amount of different items represented by meta.
|
||||
* Only returns valid metadatas. The validity is determined by a bitmask.
|
||||
@@ -58,7 +63,7 @@ public class ItemMetaDynamic extends Item {
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
int meta = stack.getMetadata(); // should call getMetadata below
|
||||
return super.getUnlocalizedName(stack) + "." + names.get(meta).toLowerCase(Locale.US).replaceAll(" ", "");
|
||||
return super.getUnlocalizedName(stack) + "." + LocUtils.makeLocString(names.get(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,4 +107,13 @@ public class ItemMetaDynamic extends Item {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) {
|
||||
if(StatCollector.canTranslate(this.getUnlocalizedName(stack) + ".tooltip")) {
|
||||
tooltip.add(EnumChatFormatting.GRAY.toString() +
|
||||
LocUtils.translateRecursive(this.getUnlocalizedName(stack) + ".tooltip"));
|
||||
}
|
||||
super.addInformation(stack, playerIn, tooltip, advanced);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package slimeknights.mantle.util;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
// localization utils
|
||||
public abstract class LocUtils {
|
||||
private LocUtils() {}
|
||||
|
||||
/**
|
||||
* Removes all whitespaces from the string and makes it lowercase.
|
||||
*/
|
||||
public static String makeLocString(String unclean) {
|
||||
return unclean.toLowerCase(Locale.US).replaceAll(" ", "");
|
||||
}
|
||||
|
||||
public static String translateRecursive(String key, Object... params) {
|
||||
return StatCollector.translateToLocal(StatCollector.translateToLocalFormatted(key, params));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user