Skip to content

Commit

Permalink
TextComponentTranslation
Browse files Browse the repository at this point in the history
  • Loading branch information
strubium committed Jan 13, 2025
1 parent bd0fab2 commit f2412bc
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.item.ItemTool;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;

Expand Down Expand Up @@ -94,15 +95,21 @@ static void showHarvestInfo(IProbeInfo probeInfo, World world, BlockPos pos, Blo

if (harvestTool != null) {
int harvestLevel = block.getHarvestLevel(blockState);
TextComponentTranslation harvestNameComponent;

if (harvestLevel < 0) {
// If harvest level is out of bounds, set the name manually
} else if (harvestLevel >= Config.getHarvestLevels().length) {
harvestName = I18n.translateToLocal(Config.getHarvestLevels()[Config.getHarvestLevels().length - 1]);
harvestNameComponent = new TextComponentTranslation(Config.getHarvestLevels()[Config.getHarvestLevels().length - 1]);
} else {
harvestName = I18n.translateToLocal(Config.getHarvestLevels()[harvestLevel]);
harvestNameComponent = new TextComponentTranslation(Config.getHarvestLevels()[harvestLevel]);
}

// Optionally convert to a string if necessary
harvestName = harvestNameComponent.getUnformattedText();
}


boolean harvestStyleVanilla = Config.getHarvestStyleVanilla();
int offs = harvestStyleVanilla ? 16 : 0;
int dim = harvestStyleVanilla ? 13 : 16;
Expand All @@ -116,11 +123,20 @@ static void showHarvestInfo(IProbeInfo probeInfo, World world, BlockPos pos, Blo
} else {
if (harvestName == null || harvestName.isEmpty()) {
horizontal.icon(ICONS, 16, offs, dim, dim, iconStyle)
.text(WARNING + ((harvestTool != null) ? Tools.capitalize(harvestTool) : "{*theoneprobe.probe.notool_indicator*}"));
.text(WARNING + (harvestTool != null
? Tools.capitalize(harvestTool)
: new TextComponentTranslation("theoneprobe.probe.notool_indicator").getUnformattedText()));
} else {
String toolName = harvestTool != null
? Tools.capitalize(harvestTool)
: new TextComponentTranslation("theoneprobe.probe.notool_indicator").getUnformattedText();

String levelIndicator = new TextComponentTranslation("theoneprobe.probe.level_indicator").getUnformattedText();

horizontal.icon(ICONS, 16, offs, dim, dim, iconStyle)
.text(WARNING + ((harvestTool != null) ? Tools.capitalize(harvestTool) : I18n.translateToLocal("theoneprobe.probe.notool_indicator")) + " (" + I18n.translateToLocal("theoneprobe.probe.level_indicator") + " " + harvestName + ")");
.text(WARNING + toolName + " (" + levelIndicator + " " + harvestName + ")");
}
}

}
}

0 comments on commit f2412bc

Please sign in to comment.