stonecutter: support Fabric 1.20.1

This commit is contained in:
Martin Prokoph
2025-11-19 21:33:47 +01:00
parent 6e270b1a4d
commit 15ab623edb
6 changed files with 50 additions and 15 deletions

View File

@@ -262,4 +262,8 @@ stonecutter {
direction = eval(current.version, ">=1.21.5") direction = eval(current.version, ">=1.21.5")
replace("SimpleTexture", "ReloadableTexture") replace("SimpleTexture", "ReloadableTexture")
} }
replacements.string {
direction = eval(current.version, ">=1.21")
replace("new ResourceLocation", "ResourceLocation.fromNamespaceAndPath")
}
} }

View File

@@ -2,17 +2,14 @@ package net.puzzlemc.gui.mixin;
import eu.midnightdust.core.config.MidnightLibConfig; import eu.midnightdust.core.config.MidnightLibConfig;
import eu.midnightdust.lib.util.PlatformFunctions; import eu.midnightdust.lib.util.PlatformFunctions;
import net.minecraft.client.gui.components.SpriteIconButton;
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.options.OptionsScreen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.puzzlemc.core.config.PuzzleConfig; import net.puzzlemc.core.config.PuzzleConfig;
import net.puzzlemc.gui.PuzzleGui;
import net.puzzlemc.gui.screen.PuzzleOptionsScreen; import net.puzzlemc.gui.screen.PuzzleOptionsScreen;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -20,16 +17,32 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Objects; import java.util.Objects;
//? if >= 1.21 {
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Shadow;
import net.minecraft.client.gui.screens.options.OptionsScreen;
import net.minecraft.client.gui.components.SpriteIconButton;
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
import net.puzzlemc.gui.PuzzleGui;
//?} else {
/*import net.minecraft.client.gui.screens.OptionsScreen;
import net.minecraft.client.gui.components.TextAndImageButton;
import net.minecraft.resources.ResourceLocation;
import static net.puzzlemc.core.PuzzleCore.MOD_ID;
*///?}
@Mixin(OptionsScreen.class) @Mixin(OptionsScreen.class)
public abstract class MixinOptionsScreen extends Screen { public abstract class MixinOptionsScreen extends Screen {
private MixinOptionsScreen(Component title) {super(title);}
//? if >= 1.21 {
@Shadow @Final private HeaderAndFooterLayout layout; @Shadow @Final private HeaderAndFooterLayout layout;
@Unique @Unique
SpriteIconButton puzzle$button = SpriteIconButton.builder(Component.translatable("puzzle.screen.title"), (buttonWidget) -> SpriteIconButton puzzle$button = SpriteIconButton.builder(Component.translatable("puzzle.screen.title"), (buttonWidget) ->
(Objects.requireNonNull(this.minecraft)).setScreen(new PuzzleOptionsScreen(this)), true) (Objects.requireNonNull(this.minecraft)).setScreen(new PuzzleOptionsScreen(this)), true)
.size(20, 20).sprite(PuzzleGui.PUZZLE_BUTTON, 20, 20).build(); .size(20, 20).sprite(PuzzleGui.PUZZLE_BUTTON, 20, 20).build();
private MixinOptionsScreen(Component title) {super(title);}
@Inject(at = @At("HEAD"), method = "init") @Inject(at = @At("HEAD"), method = "init")
public void puzzle$onInit(CallbackInfo ci) { public void puzzle$onInit(CallbackInfo ci) {
if (PuzzleConfig.enablePuzzleButton) { if (PuzzleConfig.enablePuzzleButton) {
@@ -52,4 +65,22 @@ public abstract class MixinOptionsScreen extends Screen {
} }
puzzle$button.setPosition(this.width / 2 - 178 + i, layout.getY() + layout.getFooterHeight() - 4); puzzle$button.setPosition(this.width / 2 - 178 + i, layout.getY() + layout.getFooterHeight() - 4);
} }
//?} else {
/*@Unique TextAndImageButton puzzle$button = TextAndImageButton.builder(Component.translatable("midnightlib.overview.title"), ResourceLocation.fromNamespaceAndPath(MOD_ID, "icon/button.png"),
button -> Objects.requireNonNull(minecraft).setScreen(new PuzzleOptionsScreen(this))).textureSize(19, 19).usedTextureSize(16, 16).offset(-2, 0).build();
@Inject(at = @At("HEAD"), method = "init")
private void midnightlib$init(CallbackInfo ci) {
if (PuzzleConfig.enablePuzzleButton) {
puzzle$button.setWidth(20);
int i = 0;
if (PlatformFunctions.isModLoaded("lod")) {
i = i + 358;
if (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.FALSE)) i = i - 25;
}
puzzle$button.setPosition(this.width / 2 - 178 + i, this.height / 6 - 12);
this.addRenderableWidget(puzzle$button);
}
}
*///?}
} }

View File

@@ -63,8 +63,8 @@ public class PuzzleOptionListWidget extends MidnightConfigListWidget {
var entry = new ButtonEntry(buttons, text, info); var entry = new ButtonEntry(buttons, text, info);
this.addEntry(entry); this.addEntry(entry);
} }
public void renderWidget(GuiGraphics context, int mouseX, int mouseY, float delta) { public void /*? if >= 1.21 {*/ renderWidget /*?} else {*/ /*renderList*/ /*?}*/(GuiGraphics context, int mouseX, int mouseY, float delta) {
super.renderWidget(context, mouseX, mouseY, delta); super./*? if >= 1.21 {*/ renderWidget /*?} else {*/ /*renderList*/ /*?}*/(context, mouseX, mouseY, delta);
ButtonEntry e = this.getHovered(); ButtonEntry e = this.getHovered();
if (minecraft.screen instanceof PuzzleOptionsScreen page && e != null && !e.buttons.isEmpty() && if (minecraft.screen instanceof PuzzleOptionsScreen page && e != null && !e.buttons.isEmpty() &&
e.text.getContents() instanceof TranslatableContents content) { e.text.getContents() instanceof TranslatableContents content) {
@@ -95,4 +95,4 @@ public class PuzzleOptionListWidget extends MidnightConfigListWidget {
public ButtonEntry getHovered() { public ButtonEntry getHovered() {
return super.getHovered(); return super.getHovered();
} }
} }

View File

@@ -48,8 +48,8 @@ import static net.puzzlemc.core.PuzzleCore.LOGGER;
import static net.puzzlemc.core.PuzzleCore.MOD_ID; import static net.puzzlemc.core.PuzzleCore.MOD_ID;
public class PuzzleSplashScreen { public class PuzzleSplashScreen {
public static final ResourceLocation LOGO = ResourceLocation.withDefaultNamespace("textures/gui/title/mojangstudios.png"); public static final ResourceLocation LOGO = ResourceLocation.fromNamespaceAndPath("minecraft", "textures/gui/title/mojangstudios.png");
public static final ResourceLocation BACKGROUND = ResourceLocation.withDefaultNamespace("puzzle/splash_background.png"); public static final ResourceLocation BACKGROUND = ResourceLocation.fromNamespaceAndPath("minecraft", "puzzle/splash_background.png");
public static File CONFIG_PATH = new File(String.valueOf(PlatformFunctions.getConfigDirectory().resolve(".puzzle_cache"))); public static File CONFIG_PATH = new File(String.valueOf(PlatformFunctions.getConfigDirectory().resolve(".puzzle_cache")));
public static Path LOGO_TEXTURE = Paths.get(CONFIG_PATH + "/mojangstudios.png"); public static Path LOGO_TEXTURE = Paths.get(CONFIG_PATH + "/mojangstudios.png");
public static Path BACKGROUND_TEXTURE = Paths.get(CONFIG_PATH + "/splash_background.png"); public static Path BACKGROUND_TEXTURE = Paths.get(CONFIG_PATH + "/splash_background.png");

View File

@@ -37,6 +37,6 @@
"depends": { "depends": {
"fabric": "*", "fabric": "*",
"minecraft": ">=1.21" "minecraft": ">=1.20"
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B