Improved Help, ClientHelp, number formatting, lang stuff

This commit is contained in:
Michael Hillcox 2021-01-17 13:45:29 +00:00
parent 610a1ca61c
commit a742536948
5 changed files with 59 additions and 7 deletions

View file

@ -122,7 +122,7 @@ e2c81adfe240117fa0ce2e3dfcfd04f4e1034153 assets/actuallyadditions/blockstates/wh
3670535838b4c26d01afe7ee4807c53a6cbaba12 assets/actuallyadditions/blockstates/white_wall_block.json 3670535838b4c26d01afe7ee4807c53a6cbaba12 assets/actuallyadditions/blockstates/white_wall_block.json
78e89628e3c6e891f2994b2a1794672f69826516 assets/actuallyadditions/blockstates/wood_casing_block.json 78e89628e3c6e891f2994b2a1794672f69826516 assets/actuallyadditions/blockstates/wood_casing_block.json
207adf3d139369e983100a6002f6f77d36d40916 assets/actuallyadditions/blockstates/xp_solidifier_block.json 207adf3d139369e983100a6002f6f77d36d40916 assets/actuallyadditions/blockstates/xp_solidifier_block.json
05c5a950e54b4a1640a8afc2f596b6a636577761 assets/actuallyadditions/lang/en_us.json 59ee3cf6d1199a2a84ea3e03c89fc3f20dde913f assets/actuallyadditions/lang/en_us.json
997ea09e934d491608895093fc7ba8d2022a50f5 assets/actuallyadditions/models/block/black_brick_quartz_slab_block.json 997ea09e934d491608895093fc7ba8d2022a50f5 assets/actuallyadditions/models/block/black_brick_quartz_slab_block.json
fa8ed5a44ee7475368eaa6c8afcd2fdcc0342a4f assets/actuallyadditions/models/block/black_brick_quartz_slab_block_top.json fa8ed5a44ee7475368eaa6c8afcd2fdcc0342a4f assets/actuallyadditions/models/block/black_brick_quartz_slab_block_top.json
00fe865b4ff89f2a82cc40bf11c806fd5ef22130 assets/actuallyadditions/models/block/black_brick_quartz_stair_block.json 00fe865b4ff89f2a82cc40bf11c806fd5ef22130 assets/actuallyadditions/models/block/black_brick_quartz_stair_block.json

View file

@ -1,10 +1,13 @@
{ {
"actuallyadditions.energy.crystal-flux-double": "%s / %s Crystal Flux",
"actuallyadditions.energy.crystal-flux-long": "Crystal Flux",
"actuallyadditions.energy.crystal-flux-short": "CF",
"actuallyadditions.energy.crystal-flux-single": "%s Crystal Flux",
"actuallyadditions.gui.name.drill": "Drill", "actuallyadditions.gui.name.drill": "Drill",
"actuallyadditions.info.gui.animals": "%s Animals", "actuallyadditions.info.gui.animals": "%s Animals",
"actuallyadditions.info.gui.enoughToBreed": "Enough to breed!", "actuallyadditions.info.gui.enoughToBreed": "Enough to breed!",
"actuallyadditions.info.gui.notEnough": "Not enough to breed!", "actuallyadditions.info.gui.notEnough": "Not enough to breed!",
"actuallyadditions.info.gui.tooMany": "Too many to breed!", "actuallyadditions.info.gui.tooMany": "Too many to breed!",
"actuallyadditions.storage.crystal-flux": "%s/%s Crystal Flux",
"actuallyadditions.tooltip.battery.charge-help": "Sneak-right-click to toggle", "actuallyadditions.tooltip.battery.charge-help": "Sneak-right-click to toggle",
"actuallyadditions.tooltip.battery.charging": "Charging other item in inventory", "actuallyadditions.tooltip.battery.charging": "Charging other item in inventory",
"actuallyadditions.tooltip.battery.not-charging": "Not charging other items in inventory", "actuallyadditions.tooltip.battery.not-charging": "Not charging other items in inventory",

View file

@ -0,0 +1,9 @@
package de.ellpeck.actuallyadditions.common.utilities;
import net.minecraft.client.resources.I18n;
public class ClientHelp {
public static String i18n(String key, Object... args) {
return I18n.format(Help.prefixActuallyId(key), args);
}
}

View file

@ -2,6 +2,9 @@ package de.ellpeck.actuallyadditions.common.utilities;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.energy.IEnergyStorage;
import java.text.NumberFormat;
/** /**
* HELP! FIRE!... I mean, this class should stop fires cure my ocd... * HELP! FIRE!... I mean, this class should stop fires cure my ocd...
@ -14,7 +17,40 @@ public class Help {
* @return pretty prefixed translated string * @return pretty prefixed translated string
*/ */
public static TranslationTextComponent trans(String key, Object... args) { public static TranslationTextComponent trans(String key, Object... args) {
return new TranslationTextComponent(String.format("%s.%s", ActuallyAdditions.MOD_ID, key), args); return new TranslationTextComponent(prefixActuallyId(key), args);
}
/**
* Prefixes any string with a {@link ActuallyAdditions#MOD_ID} then a (dot) with the remaining text
* @param text suffix of mod id
*/
public static String prefixActuallyId(String text) {
return String.format("%s.%s", ActuallyAdditions.MOD_ID, text);
}
/**
* Cleans up any values into either a short variant {1M / 1M} or a long variant
* like {1,000,000 / 1,000,000}
*
* @return a cleaned and formatting version of any energy values.
*/
public static String cleanEnergyValues(int energy, int maxEnergy, boolean small) {
String cleanEnergy, cleanMaxEnergy;
if (small) {
cleanEnergy = humanReadableValue(energy);
cleanMaxEnergy = humanReadableValue(maxEnergy);
} else {
NumberFormat format = NumberFormat.getInstance();
cleanEnergy = format.format(energy);
cleanMaxEnergy = format.format(maxEnergy);
}
return String.format("%s / %s", cleanEnergy, cleanMaxEnergy);
}
public static String cleanEnergyValues(IEnergyStorage energy, boolean small) {
return cleanEnergyValues(energy.getEnergyStored(), energy.getMaxEnergyStored(), small);
} }
/** /**
@ -23,7 +59,7 @@ public class Help {
* @param value value you need prettified * @param value value you need prettified
* @return a pretty string * @return a pretty string
*/ */
public static String compressedValue(int value) { public static String humanReadableValue(int value) {
if (value < 1000) if (value < 1000)
return String.valueOf(value); return String.valueOf(value);

View file

@ -4,6 +4,7 @@ import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.common.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.common.items.ActuallyItems; import de.ellpeck.actuallyadditions.common.items.ActuallyItems;
import de.ellpeck.actuallyadditions.common.items.ToolSet; import de.ellpeck.actuallyadditions.common.items.ToolSet;
import de.ellpeck.actuallyadditions.common.utilities.Help;
import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.LanguageProvider; import net.minecraftforge.common.data.LanguageProvider;
@ -346,8 +347,11 @@ public class GeneratorLanguage extends LanguageProvider {
addPrefixed("info.gui.tooMany","Too many to breed!"); addPrefixed("info.gui.tooMany","Too many to breed!");
addPrefixed("info.gui.notEnough","Not enough to breed!"); addPrefixed("info.gui.notEnough","Not enough to breed!");
// Storage // Storage / energy text
addPrefixed("storage.crystal-flux", "%s/%s Crystal Flux"); addPrefixed("energy.crystal-flux-double", "%s / %s Crystal Flux");
addPrefixed("energy.crystal-flux-single", "%s Crystal Flux");
addPrefixed("energy.crystal-flux-long", "Crystal Flux");
addPrefixed("energy.crystal-flux-short", "CF");
add("itemGroup.actuallyadditions", "Actually Additions"); add("itemGroup.actuallyadditions", "Actually Additions");
@ -360,7 +364,7 @@ public class GeneratorLanguage extends LanguageProvider {
* having to input it manually * having to input it manually
*/ */
private void addPrefixed(String key, String text) { private void addPrefixed(String key, String text) {
add(String.format("%s.%s", ActuallyAdditions.MOD_ID, key), text); add(Help.prefixActuallyId(key), text);
} }
private void addToolSet(ToolSet set) { private void addToolSet(ToolSet set) {