Port to 1.21 & Improve Performance

- Only the required textures are now loaded on startup -> Faster startup, less RAM usage
- Removed Boss Bar loading bar design, as it became a huge maintenance burden
- Added unifiedPublishing to streamline update deployment
This commit is contained in:
Martin Prokoph
2024-06-17 12:49:52 +02:00
parent 9181ed02ee
commit 7a900716a8
11 changed files with 221 additions and 171 deletions

View File

@@ -2,7 +2,9 @@ package eu.midnightdust.customsplashscreen;
import eu.midnightdust.customsplashscreen.config.CustomSplashScreenConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.Identifier;
import java.io.*;
import java.nio.file.*;
@@ -14,6 +16,7 @@ public class CustomSplashScreenClient implements ClientModInitializer {
public static final Path SquareLogoTexture = Paths.get(CONFIG_PATH + "/square_logo.png");
public static final Path ProgressBarTexture = Paths.get(CONFIG_PATH + "/progressbar.png");
public static final Path ProgressBarBackgroundTexture = Paths.get(CONFIG_PATH + "/progressbar_background.png");
public static float spinningProgress;
@Override
public void onInitializeClient() {
@@ -38,5 +41,13 @@ public class CustomSplashScreenClient implements ClientModInitializer {
} catch (Exception e) {
e.printStackTrace();
}
ClientTickEvents.END_CLIENT_TICK.register((client -> {
if (spinningProgress > 1) spinningProgress = 0f;
spinningProgress = spinningProgress + 0.01f;
}));
}
public static Identifier id(String path) {
return Identifier.of("customsplashscreen", path);
}
}

View File

@@ -43,14 +43,6 @@ public class CustomSplashScreenConfig extends MidnightConfig {
@Entry(category = loading)
public static ProgressBarMode customProgressBarMode = ProgressBarMode.Linear;
//"Change the color of the boss loading bar")
@Entry(category = loading)
public static BossBarColor bossBarColor = BossBarColor.MAGENTA;
//"Change the style of the boss loading bar")
@Entry(category = loading)
public static BossBarType bossBarType = BossBarType.NOTCHED_6;
@Entry(category = loading, isSlider = true, min = 15, max = 100)
public static int bossBarSize = 85;
@Entry(category = loading, isSlider = true, min = 1, max = 10)
public static int spinningCircleSize = 2;
@Entry(category = loading, isSlider = true, min = 1, max = 10)
@@ -59,7 +51,7 @@ public class CustomSplashScreenConfig extends MidnightConfig {
public static int spinningCircleTrail = 5;
public enum ProgressBarType {
Vanilla, BossBar, Custom, SpinningCircle, Hidden;
Vanilla, Custom, SpinningCircle, Hidden;
}
public enum LogoStyle {
Mojang, Aspect1to1, Hidden;
@@ -67,10 +59,4 @@ public class CustomSplashScreenConfig extends MidnightConfig {
public enum ProgressBarMode {
Linear, Stretch, Slide;
}
public enum BossBarColor {
MAGENTA, CYAN, RED, LIME, YELLOW, PURPLE, WHITE;
}
public enum BossBarType {
PROGRESS, NOTCHED_6, NOTCHED_10, NOTCHED_12, NOTCHED_20;
}
}

View File

@@ -35,7 +35,7 @@ public class MixinMidnightConfig extends Screen {
(Objects.requireNonNull(this.client)).setOverlay(
new SplashOverlay(client, SimpleResourceReload.create(ResourceManager.Empty.INSTANCE, List.of()
,Object::notify,Object::notify,new CompletableFuture<>()), throwable -> {}, true));
}).dimensions(this.width / 2 + 157, this.height - 28, 50, 20).build());
}).dimensions(this.width / 2 + 157, this.height - 26, 50, 20).build());
}
}
}

View File

@@ -2,6 +2,7 @@ package eu.midnightdust.customsplashscreen.mixin;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import eu.midnightdust.customsplashscreen.CustomSplashScreenClient;
import eu.midnightdust.customsplashscreen.config.CustomSplashScreenConfig;
import eu.midnightdust.customsplashscreen.texture.BlurredConfigTexture;
import eu.midnightdust.customsplashscreen.texture.ConfigTexture;
@@ -31,6 +32,8 @@ import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.IntSupplier;
import static eu.midnightdust.customsplashscreen.CustomSplashScreenClient.id;
@Mixin(value = SplashOverlay.class, priority = 3000)
public abstract class MixinSplashScreen {
@@ -47,13 +50,12 @@ public abstract class MixinSplashScreen {
}
@Shadow @Final private static IntSupplier BRAND_ARGB;
private static final Identifier EMPTY_TEXTURE = new Identifier("customsplashscreen","empty.png");
private static final Identifier MOJANG_TEXTURE = new Identifier("customsplashscreen", "wide_logo.png");
private static final Identifier ASPECT_1to1_TEXTURE = new Identifier("customsplashscreen", "square_logo.png");
private static final Identifier BOSS_BAR_TEXTURE = new Identifier("textures/gui/bars.png");
private static final Identifier CUSTOM_PROGRESS_BAR_TEXTURE = new Identifier("customsplashscreen", "progressbar.png");
private static final Identifier CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE = new Identifier("customsplashscreen", "progressbar_background.png");
private static final Identifier BACKGROUND_TEXTURE = new Identifier("customsplashscreen", "background.png");
@Unique private static final Identifier EMPTY_TEXTURE = id("empty.png");
@Unique private static final Identifier MOJANG_TEXTURE = id("wide_logo.png");
@Unique private static final Identifier ASPECT_1to1_TEXTURE = id("square_logo.png");
@Unique private static final Identifier CUSTOM_PROGRESS_BAR_TEXTURE = id("progressbar.png");
@Unique private static final Identifier CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE = id("progressbar_background.png");
@Unique private static final Identifier BACKGROUND_TEXTURE = id("background.png");
@Inject(method = "<init>", at = @At("TAIL"))
private void css$init(MinecraftClient client, ResourceReload monitor, Consumer<Optional<Throwable>> exceptionHandler, boolean reloading, CallbackInfo ci) { // Load our custom textures on screen init //
@@ -61,11 +63,15 @@ public abstract class MixinSplashScreen {
client.getTextureManager().registerTexture(LOGO, new BlurredConfigTexture(MOJANG_TEXTURE));
else client.getTextureManager().registerTexture(LOGO, new EmptyTexture(EMPTY_TEXTURE));
client.getTextureManager().registerTexture(ASPECT_1to1_TEXTURE, new ConfigTexture(ASPECT_1to1_TEXTURE));
client.getTextureManager().registerTexture(BACKGROUND_TEXTURE, new ConfigTexture(BACKGROUND_TEXTURE));
if (CustomSplashScreenConfig.logoStyle.equals(CustomSplashScreenConfig.LogoStyle.Aspect1to1)) {
client.getTextureManager().registerTexture(ASPECT_1to1_TEXTURE, new ConfigTexture(ASPECT_1to1_TEXTURE));
}
if (CustomSplashScreenConfig.backgroundImage) client.getTextureManager().registerTexture(BACKGROUND_TEXTURE, new ConfigTexture(BACKGROUND_TEXTURE));
client.getTextureManager().registerTexture(CUSTOM_PROGRESS_BAR_TEXTURE, new ConfigTexture(CUSTOM_PROGRESS_BAR_TEXTURE));
client.getTextureManager().registerTexture(CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE, new ConfigTexture(CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE));
if (CustomSplashScreenConfig.progressBarType.equals(CustomSplashScreenConfig.ProgressBarType.Custom)) {
client.getTextureManager().registerTexture(CUSTOM_PROGRESS_BAR_TEXTURE, new ConfigTexture(CUSTOM_PROGRESS_BAR_TEXTURE));
client.getTextureManager().registerTexture(CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE, new ConfigTexture(CUSTOM_PROGRESS_BAR_BACKGROUND_TEXTURE));
}
}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;getScaledWindowWidth()I", shift = At.Shift.BEFORE, ordinal = 2))
private void css$renderSplashBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
@@ -117,26 +123,6 @@ public abstract class MixinSplashScreen {
private void css$renderProgressBar(DrawContext context, int x1, int y1, int x2, int y2, float opacity, CallbackInfo ci) {
int i = MathHelper.ceil((float)(x2 - x1 - 2) * this.progress);
// Bossbar Progress Bar
if (CustomSplashScreenConfig.progressBarType == CustomSplashScreenConfig.ProgressBarType.BossBar) {
int color = CustomSplashScreenConfig.bossBarColor.ordinal() * 10;
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
int overlay = 70 + CustomSplashScreenConfig.bossBarType.ordinal()*10;
int width = (int) ((x2 - x1) * (CustomSplashScreenConfig.bossBarSize * 0.01f));
int offset = ((x2 - x1) - width) / 2;
i = MathHelper.ceil((float)(width - 2) * this.progress);
context.drawTexture(BOSS_BAR_TEXTURE, x1 + offset, y1 + 1, width, (int) ((width / 182f) * 5), 0, color, 182, 5,256, 256);
context.drawTexture(BOSS_BAR_TEXTURE, x1 + offset, y1 + 1, i, (int) ((width / 182f) * 5), 0, color+5, (int) (180 * this.progress), 5, 256, 256);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
if (overlay != 120) {
context.drawTexture(BOSS_BAR_TEXTURE, x1 + offset, y1 + 1, width, (int) ((width / 182f) * 5), 0, overlay, 182, 5,256, 256);
}
RenderSystem.disableBlend();
}
// Custom Progress Bar
if (CustomSplashScreenConfig.progressBarType == CustomSplashScreenConfig.ProgressBarType.Custom) {
int regionWidth = CustomSplashScreenConfig.customProgressBarMode == CustomSplashScreenConfig.ProgressBarMode.Stretch ? x2 - x1 : i;
@@ -156,7 +142,7 @@ public abstract class MixinSplashScreen {
int size = (y2-y1)*CustomSplashScreenConfig.spinningCircleSize;
float f = this.reloadCompleteTime > -1L ? (float) (Util.getMeasuringTimeMs() - this.reloadCompleteTime) / 1000.0F : -1.0F;
int m = MathHelper.ceil((1.0F - MathHelper.clamp(f - 1.0F, 0.0F, 1.0F)) * 255.0F);
int time = (((int) (MidnightColorUtil.hue * 24 * CustomSplashScreenConfig.spinningCircleSpeed))%24)-1;
int time = (((int) (CustomSplashScreenClient.spinningProgress * 24 * CustomSplashScreenConfig.spinningCircleSpeed))%24)-1;
int color = withAlpha(MidnightColorUtil.hex2Rgb(CustomSplashScreenConfig.splashProgressBarColor).getRGB(), m);
for (int j = 0; j<=CustomSplashScreenConfig.spinningCircleTrail; j++) {