mirror of
https://github.com/PuzzleMC/Puzzle.git
synced 2025-12-16 11:55:09 +01:00
Puzzle 0.3.0 - 1.17
Modulized into: puzzle-base (update checker + config) puzzle-gui (unified config gui) puzzle-models (remove limitations) puzzle-blocks (custom render layers) puzzle-splashscreen (resourcepack-provided spash screen) Updated to 1.17
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
package net.puzzlemc.splashscreen;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
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;
|
||||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.hud.BackgroundHelper;
|
||||
import net.minecraft.client.resource.metadata.TextureResourceMetadata;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.texture.ResourceTexture;
|
||||
import net.minecraft.resource.DefaultResourcePack;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Properties;
|
||||
|
||||
public class PuzzleSplashScreen implements ClientModInitializer {
|
||||
public static final Identifier LOGO = new Identifier("textures/gui/title/mojangstudios.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");
|
||||
private static final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
public static void resetColors() {
|
||||
PuzzleConfig.backgroundColor = 15675965;
|
||||
PuzzleConfig.progressBarColor = 16777215;
|
||||
PuzzleConfig.progressFrameColor = 16777215;
|
||||
PuzzleConfig.write("puzzle");
|
||||
}
|
||||
|
||||
public void onInitializeClient() {
|
||||
if (!CONFIG_PATH.exists()) { // Run when config directory is nonexistant //
|
||||
if (CONFIG_PATH.mkdir()) { // Create our custom config directory //
|
||||
try {
|
||||
Files.setAttribute(CONFIG_PATH.toPath(), "dos:hidden", true);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
||||
@Override
|
||||
public Identifier getFabricId() {
|
||||
return new Identifier("puzzle", "splash_screen");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(ResourceManager manager) {
|
||||
if (PuzzleConfig.resourcepackSplashScreen) {
|
||||
PuzzleSplashScreen.resetColors();
|
||||
client.getTextureManager().registerTexture(LOGO, new LogoTexture());
|
||||
|
||||
for (Identifier id : manager.findResources("optifine", path -> path.contains("color.properties"))) {
|
||||
try (InputStream stream = manager.getResource(id).getInputStream()) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(stream);
|
||||
|
||||
if (properties.get("screen.loading") != null) {
|
||||
Color backgroundColorRGB = ColorUtil.hex2Rgb(properties.get("screen.loading").toString());
|
||||
PuzzleConfig.backgroundColor = BackgroundHelper.ColorMixer.getArgb(backgroundColorRGB.getAlpha(), backgroundColorRGB.getRed(), backgroundColorRGB.getGreen(), backgroundColorRGB.getGreen());
|
||||
}
|
||||
if (properties.get("screen.loading.bar") != null) {
|
||||
Color progressFrameColorRGB = ColorUtil.hex2Rgb(properties.get("screen.loading.bar").toString());
|
||||
PuzzleConfig.progressFrameColor = BackgroundHelper.ColorMixer.getArgb(progressFrameColorRGB.getAlpha(), progressFrameColorRGB.getRed(), progressFrameColorRGB.getGreen(), progressFrameColorRGB.getGreen());
|
||||
}
|
||||
if (properties.get("screen.loading.progress") != null) {
|
||||
Color progressBarColorRGB = ColorUtil.hex2Rgb(properties.get("screen.loading.progress").toString());
|
||||
PuzzleConfig.progressBarColor = BackgroundHelper.ColorMixer.getArgb(progressBarColorRGB.getAlpha(), progressBarColorRGB.getRed(), progressBarColorRGB.getGreen(), progressBarColorRGB.getGreen());
|
||||
}
|
||||
if (properties.get("screen.loading") != null) {
|
||||
PuzzleConfig.write("puzzle");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogManager.getLogger("Puzzle").error("Error occurred while loading color.properties " + id.toString(), e);
|
||||
}
|
||||
}
|
||||
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));
|
||||
} catch (Exception e) {
|
||||
LogManager.getLogger("Puzzle").error("Error occurred while loading custom minecraft logo " + id.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class LogoTexture extends ResourceTexture {
|
||||
public LogoTexture() { super(LOGO); }
|
||||
|
||||
protected TextureData loadTextureData(ResourceManager resourceManager) {
|
||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||
DefaultResourcePack defaultResourcePack = minecraftClient.getResourcePackProvider().getPack();
|
||||
try {
|
||||
InputStream inputStream = defaultResourcePack.open(ResourceType.CLIENT_RESOURCES, LOGO);
|
||||
TextureData var6;
|
||||
try {
|
||||
var6 = new TextureData(new TextureResourceMetadata(true, true), NativeImage.read(inputStream));
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
return var6;
|
||||
} catch (IOException var18) {
|
||||
return new TextureData(var18);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.puzzlemc.splashscreen.mixin;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.SplashScreen;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = SplashScreen.class, priority = 2000)
|
||||
public class MixinSplashScreen {
|
||||
@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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@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)
|
||||
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)
|
||||
private int modifyProgressColor(int color) { // Set the Progress Bar Color to our configured value //
|
||||
return PuzzleConfig.progressBarColor | 255 << 24;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BIN
puzzle-splashscreen/src/main/resources/assets/puzzle/icon.png
Executable file
BIN
puzzle-splashscreen/src/main/resources/assets/puzzle/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
40
puzzle-splashscreen/src/main/resources/fabric.mod.json
Executable file
40
puzzle-splashscreen/src/main/resources/fabric.mod.json
Executable file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "puzzle-splashscreen",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "Puzzle Splash Screen",
|
||||
"description": "Allows resourcepacks to define a custom splash screen",
|
||||
"authors": [
|
||||
"Motschen",
|
||||
"TeamMidnightDust"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://www.midnightdust.eu/",
|
||||
"sources": "https://github.com/TeamMidnightDust/Puzzle",
|
||||
"issues": "https://github.com/TeamMidnightDust/Puzzle/issues"
|
||||
},
|
||||
|
||||
"license": "MIT",
|
||||
"icon": "assets/puzzle/icon.png",
|
||||
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"net.puzzlemc.splashscreen.PuzzleSplashScreen"
|
||||
]
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"parent": "puzzle"
|
||||
}
|
||||
},
|
||||
|
||||
"mixins": [
|
||||
"puzzle-splashscreen.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabric": "*"
|
||||
}
|
||||
}
|
||||
11
puzzle-splashscreen/src/main/resources/puzzle-splashscreen.mixins.json
Executable file
11
puzzle-splashscreen/src/main/resources/puzzle-splashscreen.mixins.json
Executable file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "net.puzzlemc.splashscreen.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"MixinSplashScreen"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user