Skip to content

Commit

Permalink
Puzzle 1.3.4 - Custom splashscreen background & fixes
Browse files Browse the repository at this point in the history
- Add the ability to use custom splash screen background images placed in a resourcepack under "assets/minecraft/puzzle/splash_background.png"
- Some more fixes regarding splash screen
  • Loading branch information
Motschen committed Jul 6, 2022
1 parent 2410b8f commit 795759b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ dependencies {
modImplementation ("maven.modrinth:lambdynamiclights:${project.ldl_version}")
modImplementation ("maven.modrinth:lambdabettergrass:${project.lbg_version}")
modImplementation ("maven.modrinth:iris:${project.iris_version}")
modImplementation ("maven.modrinth:cit-resewn:${project.cit_resewn_version}")
modCompileOnly ("maven.modrinth:cit-resewn:${project.cit_resewn_version}")
modImplementation ("maven.modrinth:continuity:${project.continuity_version}")
modImplementation ("maven.modrinth:animatica:${project.animatica_version}")
modImplementation ("maven.modrinth:entitytexturefeatures:${project.entitytexturefeatures_version}")
Expand Down
26 changes: 13 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6
yarn_mappings=1.19+build.4
loader_version=0.14.8

# Mod Properties
mod_version = 1.3.3
mod_version = 1.3.4
maven_group = net.puzzlemc
archives_base_name = puzzle

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.55.1+1.19
mod_menu_version = 2.0.13
fabric_version=0.57.0+1.19
mod_menu_version = 4.0.0

cull_leaves_version = 2.3.3
ldl_version = 2.1.0+1.17
lbg_version = 1.2.3+1.18
iris_version = 1.18.x-v1.2.4
continuity_version = 1.0.3+1.18
animatica_version = 0.2+1.18
ldl_version = 2.1.2+1.19
lbg_version = 1.3.0+1.19
iris_version = 1.19.x-v1.2.5
continuity_version = 2.0.0+1.19
animatica_version = 0.5+1.19
cit_resewn_version = 1.0.1+1.18.2
cem_version = 0.7.1
cem_version = 0.7.1-1.19
complete_config_version = 1.0.0
spruceui_version=3.3.3+1.18
spruceui_version=4.0.0+1.19
midnightlib_version=0.5.2
entitytexturefeatures_version=3.0.0
entitytexturefeatures_version=3.1.5
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onInitializeClient() {
PuzzleConfig.resourcepackSplashScreen = !PuzzleConfig.resourcepackSplashScreen;
PuzzleConfig.write(id);
PuzzleSplashScreen.resetColors();
MinecraftClient.getInstance().getTextureManager().registerTexture(PuzzleSplashScreen.LOGO, new PuzzleSplashScreen.LogoTexture());
MinecraftClient.getInstance().getTextureManager().registerTexture(PuzzleSplashScreen.LOGO, new PuzzleSplashScreen.LogoTexture(PuzzleSplashScreen.LOGO));
}));
}
if (FabricLoader.getInstance().isModLoaded("puzzle-models") && !PuzzleConfig.disabledIntegrations.contains("puzzle-models")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@

public class PuzzleSplashScreen implements ClientModInitializer {
public static final Identifier LOGO = new Identifier("textures/gui/title/mojangstudios.png");
public static final Identifier BACKGROUND = new Identifier("optifine/splash_background.png");
public static File CONFIG_PATH = new File(String.valueOf(FabricLoader.getInstance().getConfigDir().resolve(".puzzle_cache")));
public static Path LOGO_TEXTURE = Paths.get(CONFIG_PATH + "/mojangstudios.png");
public static Path BACKGROUND_TEXTURE = Paths.get(CONFIG_PATH + "/splash_background.png");
private static final MinecraftClient client = MinecraftClient.getInstance();
private static boolean keepBackground = true;

public static void resetColors() {
PuzzleConfig.backgroundColor = 15675965;
Expand Down Expand Up @@ -71,7 +74,8 @@ public void method_14491(ResourceManager manager) {
public void reload(ResourceManager manager) {
if (PuzzleConfig.resourcepackSplashScreen) {
PuzzleSplashScreen.resetColors();
client.getTextureManager().registerTexture(LOGO, new LogoTexture());
client.getTextureManager().registerTexture(LOGO, new LogoTexture(LOGO));
client.getTextureManager().registerTexture(BACKGROUND, new LogoTexture(BACKGROUND));

manager.findResources("optifine", path -> path.getPath().contains("color.properties")).forEach((id, resource) -> {
try (InputStream stream = manager.getResource(id).get().getInputStream()) {
Expand Down Expand Up @@ -102,23 +106,35 @@ public void reload(ResourceManager manager) {
manager.findResources("textures", path -> path.getPath().contains("mojangstudios.png")).forEach((id, resource) -> {
try (InputStream stream = manager.getResource(id).get().getInputStream()) {
Files.copy(stream, LOGO_TEXTURE, StandardCopyOption.REPLACE_EXISTING);
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);
}
});
manager.findResources("puzzle", path -> path.getPath().contains("splash_background.png")).forEach((id, resource) -> {
try (InputStream stream = manager.getResource(id).get().getInputStream()) {
Files.copy(stream, BACKGROUND_TEXTURE, StandardCopyOption.REPLACE_EXISTING);
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.BACKGROUND_TEXTURE));
client.getTextureManager().registerTexture(BACKGROUND, new NativeImageBackedTexture(NativeImage.read(input)));
keepBackground = true;
} catch (Exception e) {
LogManager.getLogger("Puzzle").error("Error occurred while loading custom splash background " + id.toString(), e);
}
});
if (!keepBackground) {
try {
Files.delete(BACKGROUND_TEXTURE);
} catch (Exception ignored) {}
}
keepBackground = false;
}
}
});
}
@Environment(EnvType.CLIENT)
public static class LogoTexture extends ResourceTexture {
public LogoTexture() { super(LOGO); }
public LogoTexture(Identifier logo) { super(logo); }

protected TextureData loadTextureData(ResourceManager resourceManager) {
MinecraftClient minecraftClient = MinecraftClient.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Overlay;
import net.minecraft.client.gui.screen.SplashOverlay;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -21,6 +22,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.function.IntSupplier;

@Mixin(value = SplashOverlay.class, priority = 2000)
Expand All @@ -33,13 +35,29 @@ private static int withAlpha(int color, int alpha) {
return 0;
}

@Shadow @Final private MinecraftClient client;

@Shadow @Final private boolean reloading;

@Shadow private long reloadStartTime;

@Inject(method = "init(Lnet/minecraft/client/MinecraftClient;)V", at = @At("TAIL"))
private static void puzzle$initSplashscreen(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) {}
if (PuzzleConfig.resourcepackSplashScreen) {
if (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) {
}
}
if (PuzzleSplashScreen.BACKGROUND_TEXTURE.toFile().exists()) {
try {
InputStream input = new FileInputStream(String.valueOf(PuzzleSplashScreen.BACKGROUND_TEXTURE));
client.getTextureManager().registerTexture(PuzzleSplashScreen.BACKGROUND, new NativeImageBackedTexture(NativeImage.read(input)));
} catch (IOException ignored) {
}
}
}
}
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Ljava/util/function/IntSupplier;getAsInt()I"))
Expand All @@ -50,6 +68,32 @@ private static int withAlpha(int color, int alpha) {
private void puzzle$betterBlend(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (PuzzleConfig.disableBlend) RenderSystem.defaultBlendFunc();
}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;getScaledWidth()I", shift = At.Shift.BEFORE))
private void puzzle$renderSplashBackground(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (Files.exists(PuzzleSplashScreen.BACKGROUND_TEXTURE)) {
int width = client.getWindow().getScaledWidth();
int height = client.getWindow().getScaledHeight();
long l = Util.getMeasuringTimeMs();
float f = this.reloadCompleteTime > -1L ? (float)(l - this.reloadCompleteTime) / 1000.0F : -1.0F;
float g = this.reloadStartTime> -1L ? (float)(l - this.reloadStartTime) / 500.0F : -1.0F;
float s;
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;
RenderSystem.setShaderTexture(0, PuzzleSplashScreen.BACKGROUND);
RenderSystem.enableBlend();
RenderSystem.blendEquation(32774);
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, s);
drawTexture(matrices, 0, 0, 0, 0, 0, width, height, width, height);
RenderSystem.defaultBlendFunc();
RenderSystem.disableBlend();
}
}
@Inject(method = "renderProgressBar", at = @At("HEAD"))
private void puzzle$addProgressBarBackground(MatrixStack matrices, int minX, int minY, int maxX, int maxY, float opacity, CallbackInfo ci) {
RenderSystem.disableBlend();
Expand All @@ -59,20 +103,12 @@ private static int withAlpha(int color, int alpha) {
int m = MathHelper.ceil((1.0F - MathHelper.clamp(f - 1.0F, 0.0F, 1.0F)) * 255.0F);
fill(matrices, minX, minY, maxX, maxY, withAlpha(PuzzleConfig.progressBarBackgroundColor, m));
}
@Inject(method = "renderProgressBar", at = @At("TAIL"))
private void puzzle$fixProgressBarEnd(MatrixStack matrices, int minX, int minY, int maxX, int maxY, float opacity, CallbackInfo ci) { // For some reason the end of the progressbar is colored wrong
if (!PuzzleConfig.resourcepackSplashScreen || PuzzleConfig.progressFrameColor == 16777215) return;
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);
fill(matrices, maxX-1, minY, maxX, maxY, withAlpha(PuzzleConfig.progressFrameColor, m));
}

@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 puzzle$modifyProgressFrame(int color) { // Set the Progress Bar Frame Color to our configured value //
return (!PuzzleConfig.resourcepackSplashScreen || PuzzleConfig.progressFrameColor == 16777215) ? color : PuzzleConfig.progressFrameColor | 255 << 24;
}
@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)
@ModifyArg(method = "renderProgressBar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/SplashOverlay;fill(Lnet/minecraft/client/util/math/MatrixStack;IIIII)V", ordinal = 0), index = 5)
private int puzzle$modifyProgressColor(int color) { // Set the Progress Bar Color to our configured value //
return (!PuzzleConfig.resourcepackSplashScreen || PuzzleConfig.progressBarColor == 16777215) ? color : PuzzleConfig.progressBarColor | 255 << 24;
}
Expand Down
Binary file added puzzle-splashscreen_example_pack.zip
Binary file not shown.

0 comments on commit 795759b

Please sign in to comment.