First steps to 1.0.0

- Fix modmenu compat
- Better Puzzle settings button based on MidnightLib
- Partially fix puzzle-splashscreen
This commit is contained in:
Motschen
2021-11-14 18:25:23 +01:00
parent c9b0e81f77
commit 92439549cc
22 changed files with 279 additions and 258 deletions

View File

@@ -1,9 +1,9 @@
package net.puzzlemc.splashscreen;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.puzzlemc.core.config.PuzzleConfig;
import net.puzzlemc.core.util.ColorUtil;
import net.puzzlemc.splashscreen.util.ConfigTexture;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.LogManager;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -90,9 +91,13 @@ public class PuzzleSplashScreen implements ClientModInitializer {
}
for (Identifier id : manager.findResources("textures", path -> path.contains("mojangstudios.png"))) {
try (InputStream stream = manager.getResource(id).getInputStream()) {
//LogManager.getLogger().info("Logo copied to cache!");
Files.copy(stream, LOGO_TEXTURE, StandardCopyOption.REPLACE_EXISTING);
client.getTextureManager().registerTexture(LOGO, new ConfigTexture(LOGO));
DefaultResourcePack defaultResourcePack = client.getResourcePackProvider().getPack();
InputStream defaultLogo = defaultResourcePack.open(ResourceType.CLIENT_RESOURCES, LOGO);
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.LOGO_TEXTURE));
if (input != defaultLogo)
client.getTextureManager().registerTexture(LOGO, new NativeImageBackedTexture(NativeImage.read(input)));
else Files.delete(LOGO_TEXTURE);
} catch (Exception e) {
LogManager.getLogger("Puzzle").error("Error occurred while loading custom minecraft logo " + id.toString(), e);
}

View File

@@ -1,13 +1,17 @@
package net.puzzlemc.splashscreen.mixin;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Overlay;
import net.minecraft.client.gui.screen.SplashOverlay;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import net.puzzlemc.core.config.PuzzleConfig;
import net.puzzlemc.splashscreen.PuzzleSplashScreen;
import net.puzzlemc.splashscreen.util.ConfigTexture;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -16,37 +20,66 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@Mixin(value = SplashOverlay.class, priority = 2000)
public class MixinSplashScreen {
public abstract class MixinSplashScreen extends Overlay {
@Shadow @Final static Identifier LOGO;
@Shadow @Final private boolean reloading;
@Shadow private long reloadStartTime;
@Shadow private long reloadCompleteTime;
@Inject(method = "init(Lnet/minecraft/client/MinecraftClient;)V", at = @At("TAIL"), cancellable=true)
private static void init(MinecraftClient client, CallbackInfo ci) { // Load our custom textures at game start //
if (PuzzleConfig.resourcepackSplashScreen && PuzzleSplashScreen.LOGO_TEXTURE.toFile().exists()) client.getTextureManager().registerTexture(LOGO, new ConfigTexture(LOGO));
}
//@ModifyArg(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashScreen;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"), index = 5)
private int modifyBackgroundColor(int color) { // Set the Background Color to our configured value //
long l = Util.getMeasuringTimeMs();
if (this.reloading && this.reloadStartTime == -1L) {
this.reloadStartTime = l;
}
@Shadow @Final private MinecraftClient client;
@Shadow private long reloadStartTime;
@Inject(method = "init(Lnet/minecraft/client/MinecraftClient;)V", at = @At("TAIL"))
private static void init(MinecraftClient client, CallbackInfo ci) { // Load our custom textures at game start //
if (PuzzleConfig.resourcepackSplashScreen && PuzzleSplashScreen.LOGO_TEXTURE.toFile().exists()) {
try {
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.LOGO_TEXTURE));
client.getTextureManager().registerTexture(LOGO, new NativeImageBackedTexture(NativeImage.read(input)));
} catch (IOException ignored) {}
}
}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V", shift = At.Shift.AFTER, ordinal = 0))
private void modifyBackgroundColor(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) { // Set the Background Color to our configured value //
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);
return PuzzleConfig.backgroundColor | m << 24;
if (PuzzleConfig.resourcepackSplashScreen && PuzzleConfig.backgroundColor != 15675965)
fill(matrices, 0, 0, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight(), withAlpha(PuzzleConfig.backgroundColor, m));
}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V", shift = At.Shift.AFTER, ordinal = 1))
private void modifyBackgroundColor2(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) { // Set the Background Color to our configured value //
long l = Util.getMeasuringTimeMs();
float g = this.reloadStartTime > -1L ? (float)(l - this.reloadStartTime) / 500.0F : -1.0F;
int m = MathHelper.ceil(MathHelper.clamp((double)g, 0.15D, 1.0D) * 255.0D);
if (PuzzleConfig.resourcepackSplashScreen && PuzzleConfig.backgroundColor != 15675965)
fill(matrices, 0, 0, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight(), withAlpha(PuzzleConfig.backgroundColor, m));
}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;_clear(IZ)V", shift = At.Shift.AFTER))
private void modifyBackgroundColor3(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) { // Set the Background Color to our configured value //
if (PuzzleConfig.resourcepackSplashScreen && PuzzleConfig.backgroundColor != 15675965) {
int m = PuzzleConfig.backgroundColor;
float p = (float) (m >> 16 & 255) / 255.0F;
float q = (float) (m >> 8 & 255) / 255.0F;
float r = (float) (m & 255) / 255.0F;
GlStateManager._clearColor(p, q, r, 1.0F);
GlStateManager._clear(16384, MinecraftClient.IS_SYSTEM_MAC);
}
}
//@ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashScreen;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"), index = 5)
@ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V"), index = 5)
private int modifyProgressFrame(int color) { // Set the Progress Bar Frame Color to our configured value //
return PuzzleConfig.progressFrameColor | 255 << 24;
}
//@ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashScreen;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V", ordinal = 4), index = 5)
@ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V", ordinal = 4), index = 5)
private int modifyProgressColor(int color) { // Set the Progress Bar Color to our configured value //
return PuzzleConfig.progressBarColor | 255 << 24;
}
private static int withAlpha(int color, int alpha) {
return color & 16777215 | alpha << 24;
}
}

View File

@@ -1,38 +0,0 @@
package net.puzzlemc.splashscreen.util;
import net.minecraft.client.resource.metadata.TextureResourceMetadata;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.puzzlemc.splashscreen.PuzzleSplashScreen;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class ConfigTexture extends ResourceTexture {
// Load textures from the config directory //
public ConfigTexture(Identifier location) {
super(location);
}
protected TextureData loadTextureData(ResourceManager resourceManager) {
try {
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.LOGO_TEXTURE));
TextureData texture;
try {
texture = new TextureData(new TextureResourceMetadata(false, true), NativeImage.read(input));
} finally {
input.close();
}
return texture;
} catch (IOException var18) {
return new TextureData(var18);
}
}
}

View File

@@ -6,8 +6,8 @@
"name": "Puzzle Splash Screen",
"description": "Allows resourcepacks to define a custom splash screen",
"authors": [
"Motschen",
"TeamMidnightDust"
"PuzzleMC",
"Motschen"
],
"contact": {
"homepage": "https://www.midnightdust.eu/",