Skip to content

Commit

Permalink
feat: Support 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
magicus committed Apr 20, 2024
1 parent f296bd7 commit b3e2973
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.17
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.15.10

# Mod Properties
project_name=Mod Settings
mod_version=1.1.0+1.19.3
mod_version=1.1.0+1.19.4
maven_group=se.icus.mag
archives_base_name=modsettings

# Fabric api
fabric_version=0.76.0+1.19.3
fabric_version=0.87.2+1.19.4
26 changes: 7 additions & 19 deletions src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package se.icus.mag.modsettings.gui;

import java.util.Optional;
import java.util.List;
import net.fabricmc.fabric.api.client.screen.v1.Screens;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;

import java.util.List;
import se.icus.mag.modsettings.mixin.GridWidgetAccessor;

public abstract class MenuScreensChanger {
private static final int TITLE_FULL_BUTTON_WIDTH = 200;
Expand All @@ -22,17 +14,14 @@ public abstract class MenuScreensChanger {
private static final int BUTTON_HEIGHT = 20;
private static final int BUTTON_VERICAL_SPACING = 24;

public static void postTitleScreenInit(TitleScreen screen) {
public static void postTitleScreenInit(Screen screen) {
List<ClickableWidget> buttons = Screens.getButtons(screen);
injectModSettingsButton(screen, buttons, TITLE_FULL_BUTTON_WIDTH, 2, BUTTON_VERICAL_SPACING / 2);
injectModSettingsButton(screen, buttons, TITLE_FULL_BUTTON_WIDTH, 2, BUTTON_VERICAL_SPACING / 2);
}

public static void postGameMenuScreenInit(GameMenuScreen screen) {
Optional<ClickableWidget> gridWidgetOpt = Screens.getButtons(screen).stream().filter(w -> w instanceof GridWidget).findFirst();
if (gridWidgetOpt.isEmpty()) return;

List<ClickableWidget> buttons = ((GridWidgetAccessor) gridWidgetOpt.get()).getChildren();
injectModSettingsButton(screen, buttons, INGAME_FULL_BUTTON_WIDTH, 4, 0);
public static void postGameMenuScreenInit(Screen screen) {
List<ClickableWidget> buttons = Screens.getButtons(screen);
injectModSettingsButton(screen, buttons, INGAME_FULL_BUTTON_WIDTH, 4, 0);
}

private static void injectModSettingsButton(Screen screen, List<ClickableWidget> buttons, int fullButtonWidth,
Expand Down Expand Up @@ -85,8 +74,7 @@ private static void injectModSettingsButton(Screen screen, List<ClickableWidget>

private static boolean buttonHasText(ClickableWidget button, String translationKey) {
Text text = button.getMessage();
return text instanceof MutableText mutableText &&
mutableText.getContent().equals(new TranslatableTextContent(translationKey));
return text.getContent().equals(Text.translatable(translationKey).getContent());
}

public static class ModSettingsButton extends Button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private ModSettingsOption[] getAllModConfigOptions() {
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
this.list.render(matrices, mouseX, mouseY, delta);
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 5, TITLE_COLOR);
drawCenteredTextWithShadow(matrices, this.textRenderer, this.title, this.width / 2, 5, TITLE_COLOR);
super.render(matrices, mouseX, mouseY, delta);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/se/icus/mag/modsettings/mixin/ScreenMixin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package se.icus.mag.modsettings.mixin;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.AbstractParentElement;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
Expand All @@ -12,11 +10,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import se.icus.mag.modsettings.gui.MenuScreensChanger;

// Set priority so we run after ModMenu (1000) and MinimalMenu (1100)
// Set priority so we run after Fabric API, used by ModMenu, which uses
// the default priority (1000). We also avoid conflict with MinimalMenu
// which hooks into TitleScreen.init(), which is called as part of Screen.init()
@Mixin(value = Screen.class, priority = 1500)
public abstract class ScreenMixin extends AbstractParentElement implements Drawable {
public abstract class ScreenMixin {

@Inject(method = "init(Lnet/minecraft/client/MinecraftClient;II)V", at = @At("RETURN"))
@Inject(method = "init(Lnet/minecraft/client/MinecraftClient;II)V", at = @At("TAIL"))
private void init(MinecraftClient client, int width, int height, CallbackInfo info) {
Screen screen = (Screen) (Object) this;

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 @@ -33,6 +33,6 @@
"fabricloader": ">=0.7.4",
"fabric-screen-api-v1": ">=1.0.4",
"fabric-key-binding-api-v1": ">=1.0.1",
"minecraft": "~1.19"
"minecraft": "1.19.4"
}
}

0 comments on commit b3e2973

Please sign in to comment.