Skip to content

Commit

Permalink
Update to Minecraft 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerozgen committed Dec 9, 2024
1 parent a639294 commit 0848a6a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 65 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {
Expand Down
74 changes: 31 additions & 43 deletions src/main/java/jerozgen/languagereload/gui/LanguageListWidget.java
Original file line number Diff line number Diff line change
@@ -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<LanguageEntry> {
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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -116,8 +108,4 @@ public int getRowWidth() {
protected int getScrollbarX() {
return this.getRight() - 6;
}

public void updateScroll() {
this.setScrollAmount(this.getScrollAmount());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -140,7 +140,7 @@ private void refreshList(LanguageListWidget list, Stream<? extends LanguageEntry
list.setSelected(entry);
}
});
list.updateScroll();
list.refreshScroll();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"depends": {
"fabric-resource-loader-v0": "*",
"fabricloader": ">=0.15.10",
"minecraft": ">=1.21.2"
"minecraft": ">=1.21.4"
},
"suggests": {
"modmenu": "*"
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/languagereload.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"BookScreenAccessor",
"ClientChunkManagerAccessor",
"ClientChunkMapAccessor",
"EntryListWidgetAccessor",
"GameOptionsMixin",
"KeyboardMixin",
"LanguageManagerMixin",
Expand Down

0 comments on commit 0848a6a

Please sign in to comment.