Skip to content

Commit

Permalink
Use locale formatting where possible in WAILA and The One Probe (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
josiah-roberts authored Dec 29, 2023
1 parent e8e3c70 commit dec3f76
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.capability.FeCompat;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.util.GTUtility;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.converter.ConverterTrait;

import net.minecraft.client.resources.I18n;
Expand Down Expand Up @@ -67,19 +68,21 @@ protected NBTTagCompound getNBTData(ConverterTrait capability, NBTTagCompound ta
tooltip.add(I18n.format("gregtech.top.convert_fe"));
if (accessor.getSide() == frontFacing) {
tooltip.add(I18n.format("gregtech.top.transform_output") + " " + voltageName +
TextFormatting.RESET + " (" + amperage + "A)");
TextFormatting.RESET + " (" + TextFormattingUtil.formatNumbers(amperage) + "A)");
} else {
tooltip.add(I18n.format("gregtech.top.transform_input") + " " +
FeCompat.toFe(voltage * amperage, FeCompat.ratio(true)) + " FE");
TextFormattingUtil.formatNumbers(FeCompat.toFe(voltage * amperage, FeCompat.ratio(true))) +
" FE");
}
} else {
tooltip.add(I18n.format("gregtech.top.convert_eu"));
if (accessor.getSide() == frontFacing) {
tooltip.add(I18n.format("gregtech.top.transform_output") + " " +
FeCompat.toFe(voltage * amperage, FeCompat.ratio(false)) + " FE");
TextFormattingUtil.formatNumbers(FeCompat.toFe(voltage * amperage, FeCompat.ratio(false))) +
" FE");
} else {
tooltip.add(I18n.format("gregtech.top.transform_input") + " " + voltageName + TextFormatting.RESET +
" (" + amperage + "A)");
" (" + TextFormattingUtil.formatNumbers(amperage) + "A)");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gregtech.api.GTValues;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.electric.MetaTileEntityDiode;

import net.minecraft.client.resources.I18n;
Expand Down Expand Up @@ -59,9 +60,11 @@ protected NBTTagCompound getNBTData(IEnergyContainer capability, NBTTagCompound
final EnumFacing frontFacing = EnumFacing.byIndex(tag.getInteger("FrontFacing"));

if (accessor.getSide() == frontFacing) { // output side
tooltip.add(I18n.format("gregtech.top.transform_output") + " " + outputAmperage + " A");
tooltip.add(I18n.format("gregtech.top.transform_output") + " " +
TextFormattingUtil.formatNumbers(outputAmperage) + " A");
} else {
tooltip.add(I18n.format("gregtech.top.transform_input") + " " + inputAmperage + " A");
tooltip.add(I18n.format("gregtech.top.transform_input") + " " +
TextFormattingUtil.formatNumbers(inputAmperage) + " A");
}
}
return tooltip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gregtech.api.GTValues;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IPrimitivePump;
import gregtech.api.util.TextFormattingUtil;

import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
Expand Down Expand Up @@ -58,7 +59,8 @@ public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWai
if (accessor.getNBTData().hasKey("gregtech.IPrimitivePump")) {
NBTTagCompound tag = accessor.getNBTData().getCompoundTag("gregtech.IPrimitivePump");
int production = tag.getInteger("Production");
tooltip.add(I18n.format("gregtech.top.primitive_pump_production") + " " + TextFormatting.AQUA + production +
tooltip.add(I18n.format("gregtech.top.primitive_pump_production") + " " + TextFormatting.AQUA +
TextFormattingUtil.formatNumbers(production) +
TextFormatting.RESET + " L/s");
}
return tooltip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import gregtech.api.metatileentity.multiblock.RecipeMapSteamMultiblockController;
import gregtech.api.unification.material.Materials;
import gregtech.api.util.GTUtility;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.multi.MetaTileEntityLargeBoiler;

import net.minecraft.client.resources.I18n;
Expand Down Expand Up @@ -72,7 +73,7 @@ public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWai
MetaTileEntity mte = gtte.getMetaTileEntity();
if (mte instanceof SteamMetaTileEntity || mte instanceof MetaTileEntityLargeBoiler ||
mte instanceof RecipeMapSteamMultiblockController) {
endText = ": " + absEUt + TextFormatting.RESET + " L/t " +
endText = ": " + TextFormattingUtil.formatNumbers(absEUt) + TextFormatting.RESET + " L/t " +
I18n.format(Materials.Steam.getUnlocalizedName());
}
AbstractRecipeLogic arl = mte.getRecipeLogic();
Expand All @@ -81,7 +82,7 @@ public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWai
}
}
if (endText == null) {
endText = ": " + absEUt + TextFormatting.RESET + " EU/t (" +
endText = ": " + TextFormattingUtil.formatNumbers(absEUt) + TextFormatting.RESET + " EU/t (" +
GTValues.VNF[GTUtility.getTierByVoltage(absEUt)] + TextFormatting.RESET + ")";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gregtech.api.GTValues;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.unification.material.Materials;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.steam.boiler.SteamBoiler;

import net.minecraft.client.resources.I18n;
Expand Down Expand Up @@ -65,7 +66,8 @@ public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWai

// Creating steam
if (steamRate > 0 && hasWater) {
tooltip.add(I18n.format("gregtech.top.energy_production") + ": " + (steamRate / 10) + " L/t " +
tooltip.add(I18n.format("gregtech.top.energy_production") + ": " +
TextFormattingUtil.formatNumbers(steamRate / 10) + " L/t " +
I18n.format(Materials.Steam.getUnlocalizedName()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.util.GTUtility;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.electric.MetaTileEntityTransformer;

import net.minecraft.client.resources.I18n;
Expand Down Expand Up @@ -82,15 +83,15 @@ public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWai
.append(GTValues.VNF[GTUtility.getTierByVoltage(inputVoltage)])
.append(TextFormatting.RESET)
.append(" (")
.append(inputAmperage)
.append(TextFormattingUtil.formatNumbers(inputAmperage))
.append("A)");

StringBuilder output = new StringBuilder()
.append(" ")
.append(GTValues.VNF[GTUtility.getTierByVoltage(outputVoltage)])
.append(TextFormatting.RESET)
.append(" (")
.append(outputAmperage)
.append(TextFormattingUtil.formatNumbers(outputAmperage))
.append("A)");

// Step Up/Step Down line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.util.GTUtility;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.converter.ConverterTrait;

import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -45,18 +46,22 @@ protected void addProbeInfo(@NotNull ConverterTrait capability, @NotNull IProbeI
if (capability.isFeToEu()) {
if (data.getSideHit() == facing) {
probeInfo.text(TextStyleClass.INFO + "{*gregtech.top.transform_output*} " + voltageN +
TextFormatting.GREEN + " (" + amperage + "A)");
TextFormatting.GREEN + " (" + TextFormattingUtil.formatNumbers(amperage) + "A)");
} else {
probeInfo.text(TextStyleClass.INFO + "{*gregtech.top.transform_input*} " + TextFormatting.RED +
FeCompat.toFe(capability.getVoltage() * amperage, FeCompat.ratio(true)) + " FE");
TextFormattingUtil.formatNumbers(
FeCompat.toFe(capability.getVoltage() * amperage, FeCompat.ratio(true))) +
" FE");
}
} else {
if (data.getSideHit() == facing) {
probeInfo.text(TextStyleClass.INFO + "{*gregtech.top.transform_output*} " + TextFormatting.RED +
FeCompat.toFe(capability.getVoltage() * amperage, FeCompat.ratio(false)) + " FE");
TextFormattingUtil.formatNumbers(
FeCompat.toFe(capability.getVoltage() * amperage, FeCompat.ratio(false))) +
" FE");
} else {
probeInfo.text(TextStyleClass.INFO + "{*gregtech.top.transform_input*} " + voltageN +
TextFormatting.GREEN + " (" + amperage + "A)");
TextFormatting.GREEN + " (" + TextFormattingUtil.formatNumbers(amperage) + "A)");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ private static void transferRateText(@NotNull IProbeInfo probeInfo, @NotNull IIO
private static void transferModeText(@NotNull IProbeInfo probeInfo, @NotNull TransferMode mode,
@NotNull String rateUnit, int rate, boolean hasFilter) {
String text = TextStyleClass.OK + IProbeInfo.STARTLOC + mode.getName() + IProbeInfo.ENDLOC;
if (!hasFilter && mode != TransferMode.TRANSFER_ANY) text += TextStyleClass.LABEL + " " + rate + rateUnit;
if (!hasFilter && mode != TransferMode.TRANSFER_ANY)
text += TextStyleClass.LABEL + " " + TextFormattingUtil.formatNumbers(rate) + rateUnit;
probeInfo.text(text);
}

Expand All @@ -220,7 +221,7 @@ private static void transferModeText(@NotNull IProbeInfo probeInfo, @NotNull Tra
private static void voidingText(@NotNull IProbeInfo probeInfo, @NotNull VoidingMode mode, @NotNull String unit,
int amount, boolean hasFilter) {
String text = TextFormatting.RED + IProbeInfo.STARTLOC + mode.getName() + IProbeInfo.ENDLOC;
if (mode != VoidingMode.VOID_ANY && !hasFilter) text += " " + amount + unit;
if (mode != VoidingMode.VOID_ANY && !hasFilter) text += " " + TextFormattingUtil.formatNumbers(amount) + unit;
probeInfo.text(text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.util.TextFormattingUtil;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
Expand Down Expand Up @@ -36,9 +37,9 @@ protected void addProbeInfo(@NotNull IEnergyContainer capability, @NotNull IProb
long maxStorage = capability.getEnergyCapacity();
if (maxStorage == 0) return; // do not add empty max storage progress bar
probeInfo.progress(capability.getEnergyStored(), maxStorage, probeInfo.defaultProgressStyle()
.suffix(" / " + maxStorage + " EU")
.suffix(" / " + TextFormattingUtil.formatNumbers(maxStorage) + " EU")
.filledColor(0xFFEEE600)
.alternateFilledColor(0xFFEEE600)
.borderColor(0xFF555555));
.borderColor(0xFF555555).numberFormat(mcjty.theoneprobe.api.NumberFormat.COMMAS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.ILaserContainer;
import gregtech.api.util.TextFormattingUtil;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.capabilities.Capability;

import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.NumberFormat;
import org.jetbrains.annotations.NotNull;

public class LaserContainerInfoProvider extends CapabilityInfoProvider<ILaserContainer> {
Expand All @@ -31,10 +33,10 @@ protected void addProbeInfo(ILaserContainer capability, IProbeInfo probeInfo, En
long maxStorage = capability.getEnergyCapacity();
if (maxStorage == 0) return; // do not add empty max storage progress bar
probeInfo.progress(capability.getEnergyStored(), maxStorage, probeInfo.defaultProgressStyle()
.suffix(" / " + maxStorage + " EU")
.suffix(" / " + TextFormattingUtil.formatNumbers(maxStorage) + " EU")
.filledColor(0xFFEEE600)
.alternateFilledColor(0xFFEEE600)
.borderColor(0xFF555555));
.borderColor(0xFF555555).numberFormat(NumberFormat.COMMAS));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IPrimitivePump;
import gregtech.api.util.TextFormattingUtil;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -32,7 +33,9 @@ public void addProbeInfo(@NotNull ProbeMode mode, @NotNull IProbeInfo probeInfo,
if (metaTileEntity instanceof IPrimitivePump) {
probeInfo.text(
TextStyleClass.INFO + "{*gregtech.top.primitive_pump_production*} " + TextFormatting.AQUA +
((IPrimitivePump) metaTileEntity).getFluidProduction() + TextFormatting.RESET + " L/s");
TextFormattingUtil
.formatNumbers(((IPrimitivePump) metaTileEntity).getFluidProduction()) +
TextFormatting.RESET + " L/s");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gregtech.api.metatileentity.multiblock.RecipeMapSteamMultiblockController;
import gregtech.api.unification.material.Materials;
import gregtech.api.util.GTUtility;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.multi.MetaTileEntityLargeBoiler;

import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -53,14 +54,16 @@ protected void addProbeInfo(@NotNull AbstractRecipeLogic capability, @NotNull IP
MetaTileEntity mte = gtTileEntity.getMetaTileEntity();
if (mte instanceof SteamMetaTileEntity || mte instanceof MetaTileEntityLargeBoiler ||
mte instanceof RecipeMapSteamMultiblockController) {
text = TextFormatting.AQUA.toString() + absEUt + TextStyleClass.INFO + " L/t {*" +
text = TextFormatting.AQUA.toString() + TextFormattingUtil.formatNumbers(absEUt) +
TextStyleClass.INFO + " L/t {*" +
Materials.Steam.getUnlocalizedName() + "*}";
}
}
if (text == null) {
// Default behavior, if this TE is not a steam machine (or somehow not instanceof
// IGregTechTileEntity...)
text = TextFormatting.RED.toString() + absEUt + TextStyleClass.INFO + " EU/t" + TextFormatting.GREEN +
text = TextFormatting.RED.toString() + TextFormattingUtil.formatNumbers(absEUt) + TextStyleClass.INFO +
" EU/t" + TextFormatting.GREEN +
" (" + GTValues.VNF[GTUtility.getTierByVoltage(absEUt)] + TextFormatting.GREEN + ")";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.unification.material.Materials;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.steam.boiler.SteamBoiler;

import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -36,7 +37,8 @@ public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer play
// Creating steam
if (steamOutput > 0 && boiler.hasWater()) {
probeInfo.text(TextStyleClass.INFO + "{*gregtech.top.energy_production*} " +
TextFormatting.AQUA + (steamOutput / 10) + TextStyleClass.INFO + " L/t" + " {*" +
TextFormatting.AQUA + TextFormattingUtil.formatNumbers(steamOutput / 10) +
TextStyleClass.INFO + " L/t" + " {*" +
Materials.Steam.getUnlocalizedName() + "*}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.util.GTUtility;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.electric.MetaTileEntityTransformer;

import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -33,14 +34,14 @@ protected void addProbeInfo(@NotNull IEnergyContainer capability, @NotNull IProb
.append(GTValues.VNF[GTUtility.getTierByVoltage(capability.getInputVoltage())])
.append(TextFormatting.GREEN)
.append(" (")
.append(capability.getInputAmperage())
.append(TextFormattingUtil.formatNumbers(capability.getInputAmperage()))
.append("A)");

StringBuilder output = new StringBuilder()
.append(GTValues.VNF[GTUtility.getTierByVoltage(capability.getOutputVoltage())])
.append(TextFormatting.GREEN)
.append(" (")
.append(capability.getOutputAmperage())
.append(TextFormattingUtil.formatNumbers(capability.getOutputAmperage()))
.append("A)");

// Step Up/Step Down line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IWorkable;
import gregtech.api.capability.impl.ComputationRecipeLogic;
import gregtech.api.util.TextFormattingUtil;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.capabilities.Capability;

import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.NumberFormat;
import org.jetbrains.annotations.NotNull;

public class WorkableInfoProvider extends CapabilityInfoProvider<IWorkable> {
Expand Down Expand Up @@ -52,7 +54,7 @@ protected void addProbeInfo(@NotNull IWorkable capability, @NotNull IProbeInfo p
} else {
currentProgress = Math.round(currentProgress / 20.0F);
maxProgress = Math.round(maxProgress / 20.0F);
text = " / " + maxProgress + " s";
text = " / " + TextFormattingUtil.formatNumbers(maxProgress) + " s";
}

if (maxProgress > 0) {
Expand All @@ -61,7 +63,7 @@ protected void addProbeInfo(@NotNull IWorkable capability, @NotNull IProbeInfo p
.suffix(text)
.filledColor(color)
.alternateFilledColor(color)
.borderColor(0xFF555555));
.borderColor(0xFF555555).numberFormat(NumberFormat.COMMAS));
}
}
}

0 comments on commit dec3f76

Please sign in to comment.