Skip to content

Commit

Permalink
Added ability to translate criteria (#165)
Browse files Browse the repository at this point in the history
* Added ability to translate criteria

* Bumped version to 0.4.2
  • Loading branch information
GoryMoon authored Jun 17, 2024
1 parent 3ec8e86 commit fb12af2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void refreshHover() {
}
int titleWidth = 29 + mc.font.width(this.title) + k;
BetterAdvancementsScreen screen = betterAdvancementTabGui.getScreen();
this.criterionGrid = CriterionGrid.findOptimalCriterionGrid(this.advancementNode.advancement(), advancementProgress, screen.width / 2, mc.font);
this.criterionGrid = CriterionGrid.findOptimalCriterionGrid(this.advancementNode.holder(), this.advancementNode.advancement(), advancementProgress, screen.width / 2, mc.font);
int maxWidth;

if (!CriterionGrid.requiresShift || Screen.hasShiftDown()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouse
this.isHovered = mouseX >= this.getX() && mouseY >= this.getY() && mouseX < this.getX() + this.getWidth() && mouseY < this.getY() + this.getHeight();
guiGraphics.blit(Resources.Gui.TABS, this.getX(), this.getY(), 56, 0, 28, 32);
if (this.isHovered) {
guiGraphics.renderTooltip(mc.font, Component.literal("Advancements"), mouseX, mouseY);
guiGraphics.renderTooltip(mc.font, Component.translatable("gui.advancements"), mouseX, mouseY);
}
RenderSystem.defaultBlendFunc();
guiGraphics.renderFakeItem(new ItemStack(Items.BOOK), this.getX() + 6, this.getY() + 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.ChatFormatting;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.advancements.Criterion;
import net.minecraft.advancements.CriterionProgress;
Expand Down Expand Up @@ -81,7 +82,7 @@ public Column(List<String> cells, int width) {

// Of all the possible grids whose aspect ratio is less than the maximum, this method returns the one with the smallest number of rows.
// If there is no such grid, this method returns a single-column grid.
public static CriterionGrid findOptimalCriterionGrid(Advancement advancement, AdvancementProgress progress, int maxWidth, Font font) {
public static CriterionGrid findOptimalCriterionGrid(AdvancementHolder holder, Advancement advancement, AdvancementProgress progress, int maxWidth, Font font) {
if (progress == null || progress.isDone() || detailLevel.equals(CriteriaDetail.OFF)) {
return CriterionGrid.empty;
}
Expand All @@ -93,18 +94,19 @@ public static CriterionGrid findOptimalCriterionGrid(Advancement advancement, Ad
List<String> cellContents = new ArrayList<>();
for (String criterion : criteria.keySet()) {
CriterionProgress criterionProgress = progress.getCriterion(criterion);
String criterionKey = "betteradvancements.criterion." + holder.id() + "." + criterion;
if (criterionProgress != null && criterionProgress.isDone()) {
if (detailLevel.showObtained()) {
MutableComponent text = Component.literal(" + ").withStyle(ChatFormatting.GREEN);
MutableComponent text2 = Component.literal(criterion).withStyle(ChatFormatting.WHITE);
MutableComponent text2 = Component.translatableWithFallback(criterionKey, criterion).withStyle(ChatFormatting.WHITE);
text.append(text2);
cellContents.add(text.getString());
}
}
else {
if (detailLevel.showUnobtained()) {
MutableComponent text = Component.literal(" x ").withStyle(ChatFormatting.DARK_RED);
MutableComponent text2 = Component.literal(criterion).withStyle(ChatFormatting.WHITE);
MutableComponent text2 = Component.translatableWithFallback(criterionKey, criterion).withStyle(ChatFormatting.WHITE);
text.append(text2);
cellContents.add(text.getString());
}
Expand All @@ -114,7 +116,7 @@ public static CriterionGrid findOptimalCriterionGrid(Advancement advancement, Ad

if (!detailLevel.showUnobtained()) {
MutableComponent text = Component.literal(" x ").withStyle(ChatFormatting.DARK_RED);
MutableComponent text2 = Component.literal(numUnobtained + " remaining").withStyle(ChatFormatting.WHITE, ChatFormatting.ITALIC);
MutableComponent text2 = Component.translatable("betteradvancements.remaining", numUnobtained).withStyle(ChatFormatting.WHITE, ChatFormatting.ITALIC);
text.append(text2);
cellContents.add(text.getString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"betteradvancements.remaining": "%d remaining"
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ curseHomepageLink=https://www.curseforge.com/minecraft/mc-mods/better-advancemen
modrinthProjectId=Q2OqKxDG

# Version
specificationVersion=0.4.1
specificationVersion=0.4.2

0 comments on commit fb12af2

Please sign in to comment.