From a742536948d78eb9eaefcd8ee606261becac86f5 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sun, 17 Jan 2021 13:45:29 +0000 Subject: [PATCH] Improved Help, ClientHelp, number formatting, lang stuff --- src/generated/resources/.cache/cache | 2 +- .../assets/actuallyadditions/lang/en_us.json | 5 ++- .../common/utilities/ClientHelp.java | 9 +++++ .../common/utilities/Help.java | 40 ++++++++++++++++++- .../data/GeneratorLanguage.java | 10 +++-- 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/utilities/ClientHelp.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 37a8e6fc4..0c3e24e51 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -122,7 +122,7 @@ e2c81adfe240117fa0ce2e3dfcfd04f4e1034153 assets/actuallyadditions/blockstates/wh 3670535838b4c26d01afe7ee4807c53a6cbaba12 assets/actuallyadditions/blockstates/white_wall_block.json 78e89628e3c6e891f2994b2a1794672f69826516 assets/actuallyadditions/blockstates/wood_casing_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 fa8ed5a44ee7475368eaa6c8afcd2fdcc0342a4f assets/actuallyadditions/models/block/black_brick_quartz_slab_block_top.json 00fe865b4ff89f2a82cc40bf11c806fd5ef22130 assets/actuallyadditions/models/block/black_brick_quartz_stair_block.json diff --git a/src/generated/resources/assets/actuallyadditions/lang/en_us.json b/src/generated/resources/assets/actuallyadditions/lang/en_us.json index 6c97185ea..88797901f 100644 --- a/src/generated/resources/assets/actuallyadditions/lang/en_us.json +++ b/src/generated/resources/assets/actuallyadditions/lang/en_us.json @@ -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.info.gui.animals": "%s Animals", "actuallyadditions.info.gui.enoughToBreed": "Enough to breed!", "actuallyadditions.info.gui.notEnough": "Not enough 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.charging": "Charging other item in inventory", "actuallyadditions.tooltip.battery.not-charging": "Not charging other items in inventory", diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/utilities/ClientHelp.java b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/ClientHelp.java new file mode 100644 index 000000000..444868cee --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/ClientHelp.java @@ -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); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java index fa4ab4eee..e92112180 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java @@ -2,6 +2,9 @@ package de.ellpeck.actuallyadditions.common.utilities; import de.ellpeck.actuallyadditions.common.ActuallyAdditions; 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... @@ -14,7 +17,40 @@ public class Help { * @return pretty prefixed translated string */ 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 * @return a pretty string */ - public static String compressedValue(int value) { + public static String humanReadableValue(int value) { if (value < 1000) return String.valueOf(value); diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java index 3952c03b3..ce311360d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java @@ -4,6 +4,7 @@ import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import de.ellpeck.actuallyadditions.common.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.common.items.ActuallyItems; import de.ellpeck.actuallyadditions.common.items.ToolSet; +import de.ellpeck.actuallyadditions.common.utilities.Help; import net.minecraft.data.DataGenerator; 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.notEnough","Not enough to breed!"); - // Storage - addPrefixed("storage.crystal-flux", "%s/%s Crystal Flux"); + // Storage / energy text + 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"); @@ -360,7 +364,7 @@ public class GeneratorLanguage extends LanguageProvider { * having to input it manually */ 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) {