From 0848a6afe87245f1b2b802c9058e38cf50fb7cab Mon Sep 17 00:00:00 2001 From: Jerozgen Date: Mon, 9 Dec 2024 14:55:23 +0300 Subject: [PATCH] Update to Minecraft 1.21.4 --- gradle.properties | 10 +-- .../languagereload/gui/LanguageEntry.java | 2 +- .../gui/LanguageListWidget.java | 74 ++++++++----------- .../mixin/EntryListWidgetAccessor.java | 11 --- .../mixin/LanguageOptionsScreenMixin.java | 6 +- src/main/resources/fabric.mod.json | 2 +- src/main/resources/languagereload.mixins.json | 1 - 7 files changed, 41 insertions(+), 65 deletions(-) delete mode 100644 src/main/java/jerozgen/languagereload/mixin/EntryListWidgetAccessor.java diff --git a/gradle.properties b/gradle.properties index effec00..9e92356 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.21.3 -yarn_mappings=1.21.3+build.2 -loader_version=0.16.7 -fabric_version=0.107.0+1.21.3 +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.1 +loader_version=0.16.9 +fabric_version=0.110.5+1.21.4 # Mod Properties mod_version=1.7.2 @@ -16,4 +16,4 @@ archives_base_name=language-reload # Dependencies # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu # https://modrinth.com/mod/modmenu/versions -modmenu_version=12.0.0-beta.1 +modmenu_version=13.0.0-beta.1 diff --git a/src/main/java/jerozgen/languagereload/gui/LanguageEntry.java b/src/main/java/jerozgen/languagereload/gui/LanguageEntry.java index fa5cb5b..20bf39c 100644 --- a/src/main/java/jerozgen/languagereload/gui/LanguageEntry.java +++ b/src/main/java/jerozgen/languagereload/gui/LanguageEntry.java @@ -121,7 +121,7 @@ public void render(DrawContext context, int index, int y, int x, int entryWidth, x -= 2; y -= 2; if (hovered || isFocused() || client.options.getTouchscreen().getValue()) { - context.fill(x + 1, y + 1, x + entryWidth - 1, y + entryHeight + 3, + context.fill(x + 1, y + 1, parentList.getHoveredSelectionRight() - 1, y + entryHeight + 3, (hovered || isFocused()) ? 0xA0909090 : 0x50909090); buttons.forEach(button -> button.visible = false); renderButtons((button, buttonX, buttonY) -> { diff --git a/src/main/java/jerozgen/languagereload/gui/LanguageListWidget.java b/src/main/java/jerozgen/languagereload/gui/LanguageListWidget.java index a02a3bc..f788aae 100644 --- a/src/main/java/jerozgen/languagereload/gui/LanguageListWidget.java +++ b/src/main/java/jerozgen/languagereload/gui/LanguageListWidget.java @@ -1,30 +1,29 @@ package jerozgen.languagereload.gui; import jerozgen.languagereload.access.ILanguageOptionsScreen; -import jerozgen.languagereload.mixin.EntryListWidgetAccessor; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.ParentElement; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.LanguageOptionsScreen; import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; import net.minecraft.text.Text; +import net.minecraft.util.Colors; import net.minecraft.util.Formatting; -import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; -import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_DOWN; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_ENTER; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_UP; public class LanguageListWidget extends AlwaysSelectedEntryListWidget { private final Text title; private final LanguageOptionsScreen screen; public LanguageListWidget(MinecraftClient client, LanguageOptionsScreen screen, int width, int height, Text title) { - super(client, width, height - 83 - 16, 32 + 16, 24); + super(client, width, height - 83 - 16, 32 + 16, 24, (int) (9f * 1.5f)); this.title = title; this.screen = screen; - - setRenderHeader(true, (int) (9f * 1.5f)); centerListVertically = false; } @@ -33,7 +32,7 @@ protected void renderHeader(DrawContext context, int x, int y) { var headerText = title.copy().formatted(Formatting.UNDERLINE, Formatting.BOLD); int headerPosX = x + width / 2 - client.textRenderer.getWidth(headerText) / 2; int headerPosY = Math.min(this.getY() + 3, y); - context.drawText(client.textRenderer, headerText, headerPosX, headerPosY, 0xFFFFFF, false); + context.drawTextWithShadow(client.textRenderer, headerText, headerPosX, headerPosY, Colors.WHITE); } @Override @@ -62,41 +61,34 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return super.keyPressed(keyCode, scanCode, modifiers); } - // Remove focusing on entry click + // Remove hovering in scrollbar area @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - this.updateScrollingState(mouseX, mouseY, button); - if (!this.isMouseOver(mouseX, mouseY)) return false; - - var entry = this.getEntryAtPosition(mouseX, mouseY); - if (entry == null && button == 0) return true; - - if (entry != null && entry.mouseClicked(mouseX, mouseY, button)) { - var focusedEntry = this.getFocused(); - if (focusedEntry != entry && focusedEntry instanceof ParentElement parentElement) - parentElement.setFocused(null); - this.setDragging(true); - return true; - } - - return ((EntryListWidgetAccessor) this).languagereload_isScrolling(); + @Nullable + protected LanguageEntry getEntryAtPosition(double x, double y) { + var entry = super.getEntryAtPosition(x, y); + return entry != null && this.overflows() && x >= this.getScrollbarX() + ? null + : entry; } @Override - @Nullable - protected LanguageEntry getEntryAtPosition(double x, double y) { - int halfRowWidth = this.getRowWidth() / 2; - int center = this.getX() + width / 2; - int minX = center - halfRowWidth; - int maxX = center + halfRowWidth; - int m = MathHelper.floor(y - this.getY()) - headerHeight + (int) this.getScrollAmount() - 4 + 2; - int entryIndex = m / itemHeight; - var hasScrollbar = this.isScrollbarVisible(); - var scrollbarX = this.getScrollbarX(); - var entryCount = this.getEntryCount(); - return x >= minX && x <= maxX && (!hasScrollbar || x < scrollbarX) && entryIndex >= 0 && m >= 0 && entryIndex < entryCount - ? this.children().get(entryIndex) - : null; + protected void drawSelectionHighlight(DrawContext context, int y, int entryWidth, int entryHeight, int borderColor, int fillColor) { + if (this.overflows()) { + var x1 = this.getRowLeft() - 2; + var x2 = this.getScrollbarX(); + var y1 = y - 2; + var y2 = y + entryHeight + 2; + context.fill(x1, y1, x2, y2, borderColor); + context.fill(x1 + 1, y1 + 1, x2 - 1, y2 - 1, fillColor); + } else { + super.drawSelectionHighlight(context, y, entryWidth, entryHeight, borderColor, fillColor); + } + } + + public int getHoveredSelectionRight() { + return this.overflows() + ? this.getScrollbarX() + : this.getRowRight() - 2; } public LanguageOptionsScreen getScreen() { @@ -116,8 +108,4 @@ public int getRowWidth() { protected int getScrollbarX() { return this.getRight() - 6; } - - public void updateScroll() { - this.setScrollAmount(this.getScrollAmount()); - } } diff --git a/src/main/java/jerozgen/languagereload/mixin/EntryListWidgetAccessor.java b/src/main/java/jerozgen/languagereload/mixin/EntryListWidgetAccessor.java deleted file mode 100644 index 87915d8..0000000 --- a/src/main/java/jerozgen/languagereload/mixin/EntryListWidgetAccessor.java +++ /dev/null @@ -1,11 +0,0 @@ -package jerozgen.languagereload.mixin; - -import net.minecraft.client.gui.widget.EntryListWidget; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(EntryListWidget.class) -public interface EntryListWidgetAccessor { - @Accessor("scrolling") - boolean languagereload_isScrolling(); -} diff --git a/src/main/java/jerozgen/languagereload/mixin/LanguageOptionsScreenMixin.java b/src/main/java/jerozgen/languagereload/mixin/LanguageOptionsScreenMixin.java index 9de1975..a8ed7f6 100644 --- a/src/main/java/jerozgen/languagereload/mixin/LanguageOptionsScreenMixin.java +++ b/src/main/java/jerozgen/languagereload/mixin/LanguageOptionsScreenMixin.java @@ -92,8 +92,8 @@ protected void onRefreshWidgetPositions(CallbackInfo ci) { selectedLanguageList.position(listWidth, layout); availableLanguageList.setX(width / 2 - 4 - listWidth); selectedLanguageList.setX(width / 2 + 4); - availableLanguageList.updateScroll(); - selectedLanguageList.updateScroll(); + availableLanguageList.refreshScroll(); + selectedLanguageList.refreshScroll(); ci.cancel(); } @@ -140,7 +140,7 @@ private void refreshList(LanguageListWidget list, Stream=0.15.10", - "minecraft": ">=1.21.2" + "minecraft": ">=1.21.4" }, "suggests": { "modmenu": "*" diff --git a/src/main/resources/languagereload.mixins.json b/src/main/resources/languagereload.mixins.json index ff457cb..6d128d3 100644 --- a/src/main/resources/languagereload.mixins.json +++ b/src/main/resources/languagereload.mixins.json @@ -10,7 +10,6 @@ "BookScreenAccessor", "ClientChunkManagerAccessor", "ClientChunkMapAccessor", - "EntryListWidgetAccessor", "GameOptionsMixin", "KeyboardMixin", "LanguageManagerMixin",