stonecutter: support 1.21.1

This commit is contained in:
Martin Prokoph
2025-11-19 20:50:38 +01:00
parent 8ed02fef87
commit 6e270b1a4d
7 changed files with 127 additions and 49 deletions

View File

@@ -250,4 +250,16 @@ stonecutter {
direction = eval(current.version, ">=1.21.8")
replace("context.renderComponentTooltip(", "context.setComponentTooltipForNextFrame(")
}
replacements.string {
direction = eval(current.version, ">=1.21.5")
replace("getTextureImage", "loadContents")
}
replacements.string {
direction = eval(current.version, ">=1.21.5")
replace("TextureImage", "TextureContents")
}
replacements.string {
direction = eval(current.version, ">=1.21.5")
replace("SimpleTexture", "ReloadableTexture")
}
}

View File

@@ -1,7 +1,5 @@
package net.puzzlemc.core;
import net.minecraft.resources.ResourceLocation;
import net.puzzlemc.gui.screen.PuzzleOptionsScreen;
@@ -58,8 +56,13 @@ import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModList;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.AddClientReloadListenersEvent;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
//? if >= 1.21.5 {
import net.neoforged.neoforge.client.event.AddClientReloadListenersEvent;
//?} else {
/^import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
^///?}
@Mod(value = MOD_ID, dist = Dist.CLIENT)
public class PuzzleClient {
@@ -70,10 +73,17 @@ public class PuzzleClient {
@EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT /^? if <= 1.21.5 {^/ /^, bus = EventBusSubscriber.Bus.MOD ^//^?}^/)
public static class MidnightLibBusEvents {
//? if >= 1.21.5 {
@SubscribeEvent
public static void onResourceReload(AddClientReloadListenersEvent event) {
event.addListener(ResourceLocation.fromNamespaceAndPath(MOD_ID, "splash_screen"), PuzzleSplashScreen.ReloadListener.INSTANCE);
}
//?} else {
/^@SubscribeEvent
public static void onResourceReload(RegisterClientReloadListenersEvent event) {
event.registerReloadListener(PuzzleSplashScreen.ReloadListener.INSTANCE);
}
^///?}
}
}
*///?}

View File

@@ -30,7 +30,7 @@ public class PuzzleGui {
PuzzleConfig.resourcepackSplashScreen = !PuzzleConfig.resourcepackSplashScreen;
PuzzleSplashScreen.resetColors();
PuzzleConfig.write(MOD_ID);
Minecraft.getInstance().getTextureManager().registerAndLoad(PuzzleSplashScreen.LOGO, new PuzzleSplashScreen.LogoTexture(PuzzleSplashScreen.LOGO));
Minecraft.getInstance().getTextureManager()./*? if >= 1.21.5 {*/ registerAndLoad /*?} else {*//*register*//*?}*/(PuzzleSplashScreen.LOGO, new PuzzleSplashScreen.LogoTexture(PuzzleSplashScreen.LOGO));
}));
PuzzleApi.addToResourceOptions(new PuzzleWidget(Component.translatable("puzzle.option.unlimited_model_rotations"), (button) -> button.setMessage(PuzzleConfig.unlimitedRotations ? YES : NO), (button) -> {
PuzzleConfig.unlimitedRotations = !PuzzleConfig.unlimitedRotations;

View File

@@ -1,6 +1,5 @@
package net.puzzlemc.gui.screen.widget;
import net.minecraft.client.gui.components.AbstractTextAreaWidget;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;

View File

@@ -1,18 +1,13 @@
package net.puzzlemc.splashscreen;
import com.mojang.blaze3d.pipeline.BlendFunction;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.platform.DepthTestFunction;
import com.mojang.blaze3d.platform.DestFactor;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.platform.SourceFactor;
import eu.midnightdust.lib.util.MidnightColorUtil;
import eu.midnightdust.lib.util.PlatformFunctions;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.ReloadableTexture;
import net.minecraft.client.renderer.texture.TextureContents;
import net.minecraft.client.resources.metadata.texture.TextureMetadataSection;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
@@ -20,7 +15,6 @@ import net.minecraft.server.packs.VanillaPackResources;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
import net.puzzlemc.core.config.PuzzleConfig;
import net.puzzlemc.splashscreen.mixin.RenderPipelinesAccessor;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@@ -34,7 +28,16 @@ import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
//? if <= 1.21.5 {
//? if >= 1.21.5 {
import com.mojang.blaze3d.pipeline.BlendFunction;
import com.mojang.blaze3d.platform.DepthTestFunction;
import com.mojang.blaze3d.platform.DestFactor;
import com.mojang.blaze3d.platform.SourceFactor;
import net.minecraft.client.renderer.texture.TextureContents;
import net.puzzlemc.splashscreen.mixin.RenderPipelinesAccessor;
//?}
//? if = 1.21.5 {
/*import net.minecraft.client.gui.screens.LoadingOverlay;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
@@ -53,7 +56,7 @@ public class PuzzleSplashScreen {
private static Minecraft client = Minecraft.getInstance();
private static boolean keepBackground = false;
public static RenderPipeline CUSTOM_LOGO_PIPELINE;
//? if <= 1.21.5
//? if = 1.21.5
/*public static RenderType CUSTOM_LOGO_LAYER;*/
public static void init() {
@@ -65,9 +68,11 @@ public class PuzzleSplashScreen {
}
}
}
//? if >= 1.21.5
buildRenderLayer();
}
//? if >= 1.21.5 {
public static void buildRenderLayer() {
if (PuzzleConfig.resourcepackSplashScreen) {
BlendFunction blendFunction = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE);
@@ -100,6 +105,7 @@ public class PuzzleSplashScreen {
*///?}
}
}
//?}
public static class ReloadListener implements ResourceManagerReloadListener {
public static final ReloadListener INSTANCE = new ReloadListener();
@@ -111,8 +117,8 @@ public class PuzzleSplashScreen {
client = Minecraft.getInstance();
if (PuzzleConfig.resourcepackSplashScreen) {
PuzzleSplashScreen.resetColors();
client.getTextureManager().registerAndLoad(LOGO, new LogoTexture(LOGO));
client.getTextureManager().registerAndLoad(BACKGROUND, new LogoTexture(BACKGROUND));
client.getTextureManager()./*? if >= 1.21.5 {*/ registerAndLoad /*?} else {*//*register*//*?}*/(LOGO, new LogoTexture(LOGO));
client.getTextureManager()./*? if >= 1.21.5 {*/ registerAndLoad /*?} else {*//*register*//*?}*/(BACKGROUND, new LogoTexture(BACKGROUND));
manager.listResources("optifine", path -> path.getPath().contains("color.properties")).forEach((id, resource) -> {
try (InputStream stream = resource.open()) {
@@ -150,7 +156,7 @@ public class PuzzleSplashScreen {
manager.listResources("textures", path -> path.getPath().contains("mojangstudios.png")).forEach((id, resource) -> {
try (InputStream stream = resource.open()) {
Files.copy(stream, LOGO_TEXTURE, StandardCopyOption.REPLACE_EXISTING);
client.getTextureManager().registerAndLoad(LOGO, new DynamicLogoTexture());
client.getTextureManager()./*? if >= 1.21.5 {*/ registerAndLoad /*?} else {*//*register*//*?}*/(LOGO, new DynamicLogoTexture());
if (logoCount.get() > 0) PuzzleConfig.hasCustomSplashScreen = true;
logoCount.getAndIncrement();
} catch (Exception e) {
@@ -161,7 +167,7 @@ public class PuzzleSplashScreen {
try (InputStream stream = resource.open()) {
Files.copy(stream, BACKGROUND_TEXTURE, StandardCopyOption.REPLACE_EXISTING);
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.BACKGROUND_TEXTURE));
client.getTextureManager().register(BACKGROUND, new DynamicTexture(() -> "splash_screen_background", NativeImage.read(input)));
client.getTextureManager().register(BACKGROUND, new DynamicTexture(/*? if >= 1.21.5 {*/() -> "splash_screen_background",/*?}*/ NativeImage.read(input)));
keepBackground = true;
PuzzleConfig.hasCustomSplashScreen = true;
} catch (Exception e) {
@@ -175,6 +181,7 @@ public class PuzzleSplashScreen {
}
keepBackground = false;
PuzzleConfig.write(MOD_ID);
//? if >= 1.21.5
buildRenderLayer();
}
}
@@ -190,24 +197,20 @@ public class PuzzleSplashScreen {
PuzzleConfig.hasCustomSplashScreen = false;
}
public static class LogoTexture extends ReloadableTexture {
public LogoTexture(ResourceLocation logo) { super(logo); }
public LogoTexture(ResourceLocation logo) {
super(logo);
}
@Override
public @NotNull TextureContents loadContents(ResourceManager resourceManager) {
Minecraft client = Minecraft.getInstance();
VanillaPackResources defaultResourcePack = client.getVanillaPackResources();
try {
InputStream inputStream = Objects.requireNonNull(defaultResourcePack.getResource(PackType.CLIENT_RESOURCES, LOGO)).get();
TextureContents tex;
try {
tex = new TextureContents(NativeImage.read(inputStream), new TextureMetadataSection(true, true));
} finally {
inputStream.close();
}
return tex;
} catch (IOException var18) {
return TextureContents.createMissing();
try (InputStream input = Objects.requireNonNull(defaultResourcePack.getResource(PackType.CLIENT_RESOURCES, LOGO)).get()) {
return /*? if >= 1.21.5 {*/ new TextureContents(NativeImage.read(input), new TextureMetadataSection(true, true)) /*?} else {*/ /*new TextureContents(new TextureMetadataSection(true, true), NativeImage.read(input)) *//*?}*/;
} catch (IOException ex) {
return /*? if >= 1.21.5 {*/ TextureContents.createMissing() /*?} else {*/ /*new TextureContents(ex) *//*?}*/;
}
}
}
@@ -218,16 +221,19 @@ public class PuzzleSplashScreen {
}
@Override
public @NotNull TextureContents loadContents(ResourceManager resourceManager) {
try {
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.LOGO_TEXTURE));
return new TextureContents(NativeImage.read(input), new TextureMetadataSection(true, true));
try (InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.LOGO_TEXTURE))) {
return /*? if >= 1.21.5 {*/ new TextureContents(NativeImage.read(input), new TextureMetadataSection(true, true)) /*?} else {*/ /*new TextureContents(new TextureMetadataSection(true, true), NativeImage.read(input)) *//*?}*/;
} catch (IOException e) {
LOGGER.error("Encountered an error during logo loading: ", e);
//? if >= 1.21.5 {
try {
return TextureContents.load(resourceManager, LOGO);
} catch (IOException ex) {
return TextureContents.createMissing();
}
//?} else {
/*return TextureContents.load(resourceManager, LOGO);
*///?}
}
}
}

View File

@@ -1,7 +1,5 @@
package net.puzzlemc.splashscreen.mixin;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
@@ -11,7 +9,6 @@ import net.minecraft.client.gui.screens.Overlay;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ARGB;
import net.minecraft.util.Mth;
import net.puzzlemc.core.config.PuzzleConfig;
import net.puzzlemc.splashscreen.PuzzleSplashScreen;
@@ -25,21 +22,34 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.function.Function;
import java.util.function.IntSupplier;
//? if >= 1.21.8 {
import net.minecraft.util.ARGB;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import net.minecraft.client.renderer.RenderPipelines;
//?} else {
/*import net.minecraft.client.renderer.RenderType;
//?} else if >= 1.21.5 {
/*import net.minecraft.util.ARGB;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.renderer.RenderType;
import java.util.function.Function;
*///?} else {
/*import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.renderer.GameRenderer;
import static net.puzzlemc.core.PuzzleCore.LOGGER;
*///?}
import static net.puzzlemc.splashscreen.PuzzleSplashScreen.BACKGROUND;
//? if >= 1.21.5
import static net.minecraft.client.gui.screens.LoadingOverlay.MOJANG_STUDIOS_LOGO_LOCATION;
@Mixin(value = LoadingOverlay.class, priority = 2000)
public abstract class MixinSplashScreen extends Overlay {
@Shadow @Final public static ResourceLocation MOJANG_STUDIOS_LOGO_LOCATION;
@Shadow private long fadeInStart;
@Shadow @Final private Minecraft minecraft;
@Shadow @Final private boolean fadeIn;
@@ -48,17 +58,24 @@ public abstract class MixinSplashScreen extends Overlay {
private static int replaceAlpha(int color, int alpha) {
return 0;
}
//? if < 1.21.5
/*@Shadow @Final static ResourceLocation MOJANG_STUDIOS_LOGO_LOCATION;*/
@Inject(method = "registerTextures", at = @At("TAIL"))
private static void puzzle$initSplashscreen(TextureManager textureManager, CallbackInfo ci) { // Load our custom textures at game start //
@Inject(method = "registerTextures", at = @At("TAIL")) // Load our custom textures at game start //
//? if >= 1.21.5 {
private static void puzzle$initSplashscreen(TextureManager textureManager, CallbackInfo ci) {
//?} else {
/*private static void puzzle$initSplashscreen(Minecraft client, CallbackInfo ci) {
TextureManager textureManager = client.getTextureManager();
*///?}
if (PuzzleConfig.resourcepackSplashScreen) {
if (PuzzleSplashScreen.LOGO_TEXTURE.toFile().exists()) {
textureManager.registerAndLoad(MOJANG_STUDIOS_LOGO_LOCATION, new PuzzleSplashScreen.DynamicLogoTexture());
textureManager./*? if >= 1.21.5 {*/ registerAndLoad /*?} else {*//*register*//*?}*/(MOJANG_STUDIOS_LOGO_LOCATION, new PuzzleSplashScreen.DynamicLogoTexture());
}
if (PuzzleSplashScreen.BACKGROUND_TEXTURE.toFile().exists()) {
try {
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.BACKGROUND_TEXTURE));
textureManager.register(BACKGROUND, new DynamicTexture(() -> "splash_screen_background", NativeImage.read(input)));
textureManager.register(BACKGROUND, new DynamicTexture(/*? if >= 1.21.5 {*/ () -> "splash_screen_background", /*?}*/ NativeImage.read(input)));
} catch (IOException ignored) {}
}
}
@@ -76,13 +93,31 @@ public abstract class MixinSplashScreen extends Overlay {
context.blit(PuzzleSplashScreen.CUSTOM_LOGO_PIPELINE, sprite, x, y, u, v, width, height, regionWidth, regionHeight, textureWidth, textureHeight, color);
else context.blit(pipeline, sprite, x, y, u, v, width, height, textureWidth, textureHeight, color);
}
//?} else {
//?} else if >= 1.21.5 {
/*@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blit(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIFFIIIIIII)V"))
private void puzzle$modifyRenderLayer(GuiGraphics context, Function<ResourceLocation, RenderType> renderType, ResourceLocation sprite, int x, int y, float u, float v, int width, int height, int regionWidth, int regionHeight, int textureWidth, int textureHeight, int color, Operation<Void> original) {
if (PuzzleConfig.resourcepackSplashScreen)
context.blit(id -> PuzzleSplashScreen.CUSTOM_LOGO_LAYER, sprite, x, y, u, v, width, height, regionWidth, regionHeight, textureWidth, textureHeight, color);
else context.blit(renderType, sprite, x, y, u, v, width, height, textureWidth, textureHeight, color);
}
*///?} else {
/*@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;blendFunc(II)V", shift = At.Shift.AFTER), remap = false)
private void puzzle$betterBlend(GuiGraphics context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (PuzzleConfig.resourcepackSplashScreen) {
if (PuzzleConfig.disableBlend) RenderSystem.disableBlend();
else if (PuzzleConfig.customBlendFunction.size() == 4) {
try {
RenderSystem.blendFuncSeparate(
GlStateManager.SourceFactor.valueOf(PuzzleConfig.customBlendFunction.get(0)),
GlStateManager.DestFactor.valueOf(PuzzleConfig.customBlendFunction.get(1)),
GlStateManager.SourceFactor.valueOf(PuzzleConfig.customBlendFunction.get(2)),
GlStateManager.DestFactor.valueOf(PuzzleConfig.customBlendFunction.get(3)));
} catch (Exception e) {
LOGGER.error("Incorrect blend function defined in color.properties: {}{}", PuzzleConfig.customBlendFunction, e.getMessage());
}
}
}
}
*///?}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;guiWidth()I", ordinal = 2))
@@ -97,12 +132,19 @@ public abstract class MixinSplashScreen extends Overlay {
if (f >= 1.0F) s = 1.0F - Mth.clamp(f - 1.0F, 0.0F, 1.0F);
else if (fadeIn) s = Mth.clamp(g, 0.0F, 1.0F);
else s = 1.0F;
//? if >= 1.21.8 {
context.blit(RenderPipelines.GUI_TEXTURED
//?} else {
/*context.blit(RenderType::guiTextured
context.blit(RenderPipelines.GUI_TEXTURED, BACKGROUND, 0, 0, 0, 0, width, height, width, height, ARGB.white(s));
//?} else if >= 1.21.5 {
/*context.blit(RenderType::guiTextured, BACKGROUND, 0, 0, 0, 0, width, height, width, height, ARGB.white(s));
*///?} else {
/*RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, s);
context.blit(BACKGROUND, 0, 0, 0, 0, width, height, width, height);
RenderSystem.disableBlend();
*///?}
, BACKGROUND, 0, 0, 0, 0, width, height, width, height, ARGB.white(s));
}
}

View File

@@ -1,5 +1,6 @@
package net.puzzlemc.splashscreen.mixin;
//? if > 1.21.1 {
import com.mojang.blaze3d.pipeline.RenderPipeline;
import net.minecraft.client.renderer.RenderPipelines;
import org.spongepowered.asm.mixin.Mixin;
@@ -12,3 +13,11 @@ public interface RenderPipelinesAccessor {
return null;
}
}
//?} else {
/*import eu.midnightdust.core.MidnightLib;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(MidnightLib.class)
public interface RenderPipelinesAccessor {} // TODO: Properly disable this mixin when on 1.21.1 and lower
*///?}