mirror of
https://github.com/PuzzleMC/Puzzle.git
synced 2025-12-15 19:35:10 +01:00
fix: get logo blending working again
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
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.SourceFactor;
|
||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
||||
import eu.midnightdust.lib.util.PlatformFunctions;
|
||||
import net.minecraft.client.gui.screen.SplashOverlay;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
||||
import net.minecraft.client.texture.TextureContents;
|
||||
import net.minecraft.resource.*;
|
||||
import net.minecraft.util.TriState;
|
||||
import net.minecraft.util.Util;
|
||||
import net.puzzlemc.core.config.PuzzleConfig;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@@ -12,6 +21,7 @@ import net.minecraft.client.resource.metadata.TextureResourceMetadata;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.texture.ResourceTexture;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.puzzlemc.splashscreen.mixin.RenderPipelinesAccessor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -35,6 +45,7 @@ public class PuzzleSplashScreen {
|
||||
public static Path BACKGROUND_TEXTURE = Paths.get(CONFIG_PATH + "/splash_background.png");
|
||||
private static MinecraftClient client = MinecraftClient.getInstance();
|
||||
private static boolean keepBackground = false;
|
||||
private static RenderLayer CUSTOM_LOGO_LAYER;
|
||||
|
||||
public static void init() {
|
||||
if (!CONFIG_PATH.exists()) { // Run when config directory is nonexistent //
|
||||
@@ -45,8 +56,41 @@ public class PuzzleSplashScreen {
|
||||
}
|
||||
}
|
||||
}
|
||||
buildRenderLayer();
|
||||
}
|
||||
|
||||
public static RenderLayer getCustomLogoRenderLayer() {
|
||||
return CUSTOM_LOGO_LAYER;
|
||||
}
|
||||
|
||||
public static void buildRenderLayer() {
|
||||
if (PuzzleConfig.resourcepackSplashScreen) {
|
||||
BlendFunction blendFunction = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE);
|
||||
if (PuzzleConfig.disableBlend) blendFunction = null;
|
||||
else if (PuzzleConfig.customBlendFunction.size() == 4) {
|
||||
try {
|
||||
blendFunction = new BlendFunction(
|
||||
SourceFactor.valueOf(PuzzleConfig.customBlendFunction.get(0)),
|
||||
DestFactor.valueOf(PuzzleConfig.customBlendFunction.get(1)),
|
||||
SourceFactor.valueOf(PuzzleConfig.customBlendFunction.get(2)),
|
||||
DestFactor.valueOf(PuzzleConfig.customBlendFunction.get(3)));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Incorrect blend function defined in color.properties: {}{}", PuzzleConfig.customBlendFunction, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
var CUSTOM_LOGO_PIPELINE_BUILDER = RenderPipeline.builder(RenderPipelinesAccessor.getPOSITION_TEX_COLOR_SNIPPET())
|
||||
.withLocation("pipeline/mojang_logo_puzzle")
|
||||
.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST)
|
||||
.withDepthWrite(false);
|
||||
CUSTOM_LOGO_PIPELINE_BUILDER = blendFunction != null ? CUSTOM_LOGO_PIPELINE_BUILDER.withBlend(blendFunction) : CUSTOM_LOGO_PIPELINE_BUILDER.withoutBlend();
|
||||
|
||||
CUSTOM_LOGO_LAYER = RenderLayer.of("mojang_logo_puzzle", 786432, CUSTOM_LOGO_PIPELINE_BUILDER.build(),
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture(new RenderPhase.Texture(SplashOverlay.LOGO, TriState.DEFAULT, false))
|
||||
.build(false));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReloadListener implements SynchronousResourceReloader {
|
||||
public static final ReloadListener INSTANCE = new ReloadListener();
|
||||
@@ -122,6 +166,7 @@ public class PuzzleSplashScreen {
|
||||
}
|
||||
keepBackground = false;
|
||||
PuzzleConfig.write(MOD_ID);
|
||||
buildRenderLayer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.puzzlemc.splashscreen.mixin;
|
||||
|
||||
import com.mojang.blaze3d.opengl.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Overlay;
|
||||
@@ -16,7 +16,6 @@ import net.minecraft.util.math.ColorHelper;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.puzzlemc.core.config.PuzzleConfig;
|
||||
import net.puzzlemc.splashscreen.PuzzleSplashScreen;
|
||||
import net.puzzlemc.splashscreen.util.BlendFactors;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -27,9 +26,9 @@ 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;
|
||||
|
||||
import static net.puzzlemc.core.PuzzleCore.LOGGER;
|
||||
import static net.puzzlemc.splashscreen.PuzzleSplashScreen.BACKGROUND;
|
||||
|
||||
@Mixin(value = SplashOverlay.class, priority = 2000)
|
||||
@@ -63,23 +62,14 @@ public abstract class MixinSplashScreen extends Overlay {
|
||||
private int puzzle$modifyBackground(IntSupplier instance) { // Set the Progress Bar Frame Color to our configured value //
|
||||
return (!PuzzleConfig.resourcepackSplashScreen || PuzzleConfig.progressBarBackgroundColor == 15675965) ? instance.getAsInt() : PuzzleConfig.backgroundColor | 255 << 24;
|
||||
}
|
||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/ColorHelper;getWhite(F)I", shift = At.Shift.AFTER))
|
||||
private void puzzle$betterBlend(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||
if (PuzzleConfig.resourcepackSplashScreen) {
|
||||
if (PuzzleConfig.disableBlend) GlStateManager._disableBlend();
|
||||
else if (PuzzleConfig.customBlendFunction.size() == 4) {
|
||||
try {
|
||||
GlStateManager._blendFuncSeparate(
|
||||
BlendFactors.SrcFactor.valueFromString(PuzzleConfig.customBlendFunction.get(0)),
|
||||
BlendFactors.DstFactor.valueFromString(PuzzleConfig.customBlendFunction.get(1)),
|
||||
BlendFactors.SrcFactor.valueFromString(PuzzleConfig.customBlendFunction.get(2)),
|
||||
BlendFactors.DstFactor.valueFromString(PuzzleConfig.customBlendFunction.get(3)));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Incorrect blend function defined in color.properties: {}{}", PuzzleConfig.customBlendFunction, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIIIIII)V"))
|
||||
private void puzzle$modifyRenderLayer(DrawContext instance, Function<Identifier, RenderLayer> renderLayers, Identifier 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)
|
||||
instance.drawTexture(id -> PuzzleSplashScreen.getCustomLogoRenderLayer(), sprite, x, y, u, v, width, height, regionWidth, regionHeight, textureWidth, textureHeight, color);
|
||||
else instance.drawTexture(renderLayers, sprite, x, y, u, v, width, height, textureWidth, textureHeight, color);
|
||||
}
|
||||
|
||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;getScaledWindowWidth()I", ordinal = 2))
|
||||
private void puzzle$renderSplashBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||
if (Files.exists(PuzzleSplashScreen.BACKGROUND_TEXTURE) && PuzzleConfig.resourcepackSplashScreen) {
|
||||
@@ -92,15 +82,11 @@ public abstract class MixinSplashScreen extends Overlay {
|
||||
if (f >= 1.0F) s = 1.0F - MathHelper.clamp(f - 1.0F, 0.0F, 1.0F);
|
||||
else if (reloading) s = MathHelper.clamp(g, 0.0F, 1.0F);
|
||||
else s = 1.0F;
|
||||
//GlStateManager._enableBlend();
|
||||
//GlStateManager.blendEquation(32774);
|
||||
//GlStateManager._defaultBlendFunc();
|
||||
context.getMatrices().translate(0, 0, 1f);
|
||||
context.drawTexture(RenderLayer::getGuiTextured, BACKGROUND, 0, 0, 0, 0, width, height, width, height, ColorHelper.getWhite(s));
|
||||
//RenderSystem._defaultBlendFunc();
|
||||
//RenderSystem._disableBlend();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderProgressBar", at = @At("HEAD"))
|
||||
private void puzzle$addProgressBarBackground(DrawContext context, int minX, int minY, int maxX, int maxY, float opacity, CallbackInfo ci) {
|
||||
context.getMatrices().translate(0, 0, 1f);
|
||||
@@ -108,7 +94,6 @@ public abstract class MixinSplashScreen extends Overlay {
|
||||
long l = Util.getMeasuringTimeMs();
|
||||
float f = this.reloadCompleteTime > -1L ? (float)(l - this.reloadCompleteTime) / 1000.0F : -1.0F;
|
||||
int m = MathHelper.ceil((1.0F - MathHelper.clamp(f - 1.0F, 0.0F, 1.0F)) * 255.0F);
|
||||
//RenderSystem.disableBlend();
|
||||
context.fill(minX, minY, maxX, maxY, withAlpha(PuzzleConfig.progressBarBackgroundColor, m));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.puzzlemc.splashscreen.mixin;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import net.minecraft.client.gl.RenderPipelines;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(RenderPipelines.class)
|
||||
public interface RenderPipelinesAccessor {
|
||||
@Accessor
|
||||
static RenderPipeline.Snippet getPOSITION_TEX_COLOR_SNIPPET() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package net.puzzlemc.splashscreen.util;
|
||||
|
||||
public abstract class BlendFactors {
|
||||
public enum SrcFactor {
|
||||
CONSTANT_ALPHA(32771),
|
||||
CONSTANT_COLOR(32769),
|
||||
DST_ALPHA(772),
|
||||
DST_COLOR(774),
|
||||
ONE(1),
|
||||
ONE_MINUS_CONSTANT_ALPHA(32772),
|
||||
ONE_MINUS_CONSTANT_COLOR(32770),
|
||||
ONE_MINUS_DST_ALPHA(773),
|
||||
ONE_MINUS_DST_COLOR(775),
|
||||
ONE_MINUS_SRC_ALPHA(771),
|
||||
ONE_MINUS_SRC_COLOR(769),
|
||||
SRC_ALPHA(770),
|
||||
SRC_ALPHA_SATURATE(776),
|
||||
SRC_COLOR(768),
|
||||
ZERO(0);
|
||||
|
||||
public final int value;
|
||||
|
||||
public static int valueFromString(String input) throws IllegalArgumentException {
|
||||
return SrcFactor.valueOf(input).value;
|
||||
}
|
||||
|
||||
SrcFactor(final int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DstFactor {
|
||||
CONSTANT_ALPHA(32771),
|
||||
CONSTANT_COLOR(32769),
|
||||
DST_ALPHA(772),
|
||||
DST_COLOR(774),
|
||||
ONE(1),
|
||||
ONE_MINUS_CONSTANT_ALPHA(32772),
|
||||
ONE_MINUS_CONSTANT_COLOR(32770),
|
||||
ONE_MINUS_DST_ALPHA(773),
|
||||
ONE_MINUS_DST_COLOR(775),
|
||||
ONE_MINUS_SRC_ALPHA(771),
|
||||
ONE_MINUS_SRC_COLOR(769),
|
||||
SRC_ALPHA(770),
|
||||
SRC_COLOR(768),
|
||||
ZERO(0);
|
||||
|
||||
public final int value;
|
||||
|
||||
public static int valueFromString(String input) throws IllegalArgumentException {
|
||||
return DstFactor.valueOf(input).value;
|
||||
}
|
||||
|
||||
DstFactor(final int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,7 @@
|
||||
accessWidener v1 named
|
||||
accessible class net/minecraft/client/render/model/json/ModelElement$Deserializer
|
||||
accessible class net/minecraft/client/render/model/json/ModelElement$Deserializer
|
||||
accessible method net/minecraft/client/render/RenderLayer of (Ljava/lang/String;ILcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;)Lnet/minecraft/client/render/RenderLayer$MultiPhase;
|
||||
accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters
|
||||
accessible class net/minecraft/client/render/RenderPhase$Texture
|
||||
accessible method net/minecraft/client/render/RenderLayer$MultiPhaseParameters$Builder texture (Lnet/minecraft/client/render/RenderPhase$TextureBase;)Lnet/minecraft/client/render/RenderLayer$MultiPhaseParameters$Builder;
|
||||
accessible method net/minecraft/client/render/RenderLayer$MultiPhaseParameters$Builder build (Z)Lnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;
|
||||
@@ -3,7 +3,8 @@
|
||||
"package": "net.puzzlemc.splashscreen.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"MixinSplashScreen"
|
||||
"MixinSplashScreen",
|
||||
"RenderPipelinesAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -7,7 +7,7 @@ yarn_mappings=1.21.5+build.1
|
||||
enabled_platforms=fabric,neoforge
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 2.0.6
|
||||
mod_version = 2.1.0
|
||||
maven_group = net.puzzlemc
|
||||
archives_base_name = puzzle
|
||||
release_type=release
|
||||
|
||||
Reference in New Issue
Block a user