Merge pull request #1552 from leagris/patch-3
feature(i18n): itemlist withname locale
This commit is contained in:
commit
2f813f77d2
1 changed files with 23 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
package gregtech.api.enums;
|
package gregtech.api.enums;
|
||||||
|
|
||||||
import gregtech.api.interfaces.IItemContainer;
|
import gregtech.api.interfaces.IItemContainer;
|
||||||
|
import gregtech.api.util.GT_LanguageManager;
|
||||||
import gregtech.api.util.GT_ModHandler;
|
import gregtech.api.util.GT_ModHandler;
|
||||||
import gregtech.api.util.GT_OreDictUnificator;
|
import gregtech.api.util.GT_OreDictUnificator;
|
||||||
import gregtech.api.util.GT_Utility;
|
import gregtech.api.util.GT_Utility;
|
||||||
|
@ -9,7 +10,9 @@ import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
|
||||||
import static gregtech.api.enums.GT_Values.W;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static gregtech.api.enums.GT_Values.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class containing all non-OreDict Items of GregTech.
|
* Class containing all non-OreDict Items of GregTech.
|
||||||
|
@ -750,8 +753,24 @@ public enum ItemList implements IItemContainer {
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getWithName(long aAmount, String aDisplayName, Object... aReplacements) {
|
public ItemStack getWithName(long aAmount, String aDisplayName, Object... aReplacements) {
|
||||||
ItemStack rStack = get(1, aReplacements);
|
ItemStack rStack = get(1, aReplacements);
|
||||||
if (GT_Utility.isStackInvalid(rStack)) return null;
|
if (GT_Utility.isStackInvalid(rStack)) return NI;
|
||||||
rStack.setStackDisplayName(aDisplayName);
|
|
||||||
|
// CamelCase alphanumeric words from aDisplayName
|
||||||
|
StringBuilder tCamelCasedDisplayNameBuilder = new StringBuilder();
|
||||||
|
final String[] tDisplayNameWords = aDisplayName.split("\\W");
|
||||||
|
for (String tWord : tDisplayNameWords){
|
||||||
|
if (tWord.length() > 0) tCamelCasedDisplayNameBuilder.append(tWord.substring(0, 1).toUpperCase(Locale.US));
|
||||||
|
if (tWord.length() > 1) tCamelCasedDisplayNameBuilder.append(tWord.substring(1).toLowerCase(Locale.US));
|
||||||
|
}
|
||||||
|
if (tCamelCasedDisplayNameBuilder.length() == 0) {
|
||||||
|
// CamelCased DisplayName is empty, so use hash of aDisplayName
|
||||||
|
tCamelCasedDisplayNameBuilder.append(((Long) (long)aDisplayName.hashCode()).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a translation key from UnlocalizedName and CamelCased DisplayName
|
||||||
|
final String tKey = rStack.getUnlocalizedName() + ".with." + tCamelCasedDisplayNameBuilder.toString() + ".name";
|
||||||
|
|
||||||
|
rStack.setStackDisplayName(GT_LanguageManager.addStringLocalization(tKey, aDisplayName));
|
||||||
return GT_Utility.copyAmount(aAmount, rStack);
|
return GT_Utility.copyAmount(aAmount, rStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,4 +805,4 @@ public enum ItemList implements IItemContainer {
|
||||||
for (Object tOreName : aOreNames) GT_OreDictUnificator.registerOre(tOreName, getWildcard(1));
|
for (Object tOreName : aOreNames) GT_OreDictUnificator.registerOre(tOreName, getWildcard(1));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue