Skip to content

Commit

Permalink
Minor Changes
Browse files Browse the repository at this point in the history
- Use Midnight Config (Fork of TinyConfig)
- Code cleanup and minor refactors
- Fix Lang Files
- Add static MODID field used everywhere
  • Loading branch information
Dragon-Seeker committed Aug 16, 2023
1 parent ef958dc commit 10a9b99
Show file tree
Hide file tree
Showing 22 changed files with 572 additions and 354 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ repositories {
maven {
url "https://maven.terraformersmc.com/releases/"
}
maven {
url = "https://api.modrinth.com/maven"
}
}

dependencies {
Expand All @@ -30,6 +33,8 @@ dependencies {
modImplementation ("com.terraformersmc:modmenu:${project.modmenu_version}") {
exclude module: "fabric-api"
}

//modImplementation include("maven.modrinth:midnightlib:${project.midnightlib_version}-fabric")
}

loom {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ org.gradle.jvmargs=-Xmx4G
fabric_version=0.76.1+1.19.2

# Mod Properties
mod_version = 1.4.0+1.18.2
mod_version = 1.4.0+1.18.2-midnight-lib-internal
maven_group = com.minenash
archives_base_name = seamless-loading-screen

# Libs
midnightlib_version = 1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.minenash.seamless_loading_screen.config.Config;
import com.mojang.logging.LogUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.util.ScreenshotRecorder;
import net.minecraft.util.Util;
Expand All @@ -13,7 +14,10 @@
import java.text.SimpleDateFormat;
import java.util.Date;

public class OnQuitHelper {
/**
* Class used as a helper to deal with taking the screenshot after leaving
*/
public class OnLeaveHelper {

private static final Logger LOGGER = LogUtils.getLogger();

Expand All @@ -24,6 +28,11 @@ public class OnQuitHelper {
private static int old_FrameBufferWidth = 0;
private static int old_FrameBufferHeight = 0;

/**
* Method to start the screenshot Task and setup the screen for the screenshot
*
* @param runnable Tasks to be performed after taking the screenshot
*/
public static void beginScreenshotTask(Runnable runnable){
//ScreenshotLoader.replacebg = false;

Expand All @@ -42,6 +51,9 @@ public static void beginScreenshotTask(Runnable runnable){
MinecraftClient.getInstance().onResolutionChanged();
}

/**
* Inject after World Rendering within {@link GameRenderer#render(float, long, boolean)} method before {@link MinecraftClient#getWindow()}
*/
public static void takeScreenShot(){
var client = MinecraftClient.getInstance();

Expand Down Expand Up @@ -74,17 +86,23 @@ public static void takeScreenShot(){

attemptScreenShot = false;

//--

var window = MinecraftClient.getInstance().getWindow();

window.setFramebufferWidth(old_FrameBufferWidth);
window.setFramebufferHeight(old_FrameBufferHeight);

client.onResolutionChanged();

finished();
//--

onceFinished.run();

onceFinished = () -> {};
}

public static void updateIcon(File iconFile, NativeImage nativeImage) {
private static void updateIcon(File iconFile, NativeImage nativeImage) {
Util.getIoWorkerExecutor().execute(() -> {
int i = nativeImage.getWidth();
int j = nativeImage.getHeight();
Expand All @@ -106,13 +124,6 @@ public static void updateIcon(File iconFile, NativeImage nativeImage) {
} finally {
nativeImage.close();
}

});
}

public static void finished(){
onceFinished.run();

onceFinished = () -> {};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.minenash.seamless_loading_screen.config.Config;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.logging.LogUtils;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
Expand All @@ -16,6 +18,7 @@
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;

import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -24,7 +27,9 @@

public class ScreenshotLoader {

public static Identifier SCREENSHOT = new Identifier("visualconnect", "screenshot");
private static final Logger LOGGER = LogUtils.getLogger();

public static Identifier SCREENSHOT = new Identifier(SeamlessLoadingScreen.MODID, "screenshot");
public static double imageRatio = 1;
public static boolean loaded = false;
public static boolean allowCustomScreenshot = false;
Expand All @@ -40,24 +45,29 @@ public static String getFileName() {
}

public static void setScreenshot(String address, int port) {
fileName = "screenshots/worlds/servers/" + address + "_" + port + ".png";
setScreenshot();
setFileName("screenshots/worlds/servers/" + cleanFileName(address) + "_" + port + ".png");
}

public static void setScreenshot(String worldName) {
fileName = "screenshots/worlds/singleplayer/" + worldName + ".png";
setScreenshot();
setFileName("screenshots/worlds/singleplayer/" + worldName + ".png");
}

public static void setRealmScreenshot(String realmName) {
fileName = "screenshots/worlds/realms/" + cleanFileName(realmName) + ".png";
setFileName("screenshots/worlds/realms/" + cleanFileName(realmName) + ".png");
}

private static void setFileName(String newFileName){
fileName = newFileName;
setScreenshot();
}

private static void setScreenshot() {
loaded = false;
try (InputStream in = new FileInputStream(ScreenshotLoader.fileName)) {
System.out.println("Name: " + ScreenshotLoader.fileName);
if(FabricLoader.getInstance().isDevelopmentEnvironment()){
LOGGER.info("Name: " + ScreenshotLoader.fileName);
}

NativeImageBackedTexture image = new NativeImageBackedTexture(NativeImage.read(in));
MinecraftClient.getInstance().getTextureManager().registerTexture(SCREENSHOT, image);
imageRatio = image.getImage().getWidth() / (double) image.getImage().getHeight();
Expand All @@ -70,14 +80,11 @@ private static void setScreenshot() {

private static final Pattern RESERVED_FILENAMES_PATTERN = Pattern.compile(".*\\.|(?:COM|CLOCK\\$|CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\\..*)?", Pattern.CASE_INSENSITIVE);
private static String cleanFileName(String fileName) {
for (char c : SharedConstants.INVALID_CHARS_LEVEL_NAME)
fileName = fileName.replace(c, '_');
for (char c : SharedConstants.INVALID_CHARS_LEVEL_NAME) fileName = fileName.replace(c, '_');

if (RESERVED_FILENAMES_PATTERN.matcher(fileName).matches())
fileName = "_" + fileName + "_";
if (RESERVED_FILENAMES_PATTERN.matcher(fileName).matches()) fileName = "_" + fileName + "_";

if (fileName.length() > 255 - 4)
fileName = fileName.substring(0, 255 - 4);
if (fileName.length() > 255 - 4) fileName = fileName.substring(0, 255 - 4);

return fileName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.minenash.seamless_loading_screen.config.Config;
import com.mojang.logging.LogUtils;
import com.minenash.seamless_loading_screen.config.MidnightConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
Expand All @@ -19,10 +20,11 @@

public class SeamlessLoadingScreen implements ClientModInitializer {

public static final String MODID = "seamless_loading_screen";

private static final Logger LOGGER = LogUtils.getLogger();

public static boolean changeWorldJoinScreen = false;
public static boolean isDisconnecting = false; //Fapi 0.30.0 Compat

public static final KeyBinding OPEN_SETTINGS = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"seamless_loading_screen.keybind.config",
Expand All @@ -31,7 +33,7 @@ public class SeamlessLoadingScreen implements ClientModInitializer {

@Override
public void onInitializeClient() {
Config.init("seamless_loading_screen", Config.class);
MidnightConfig.init(MODID, Config.class);

try {
Path path = FabricLoader.getInstance().getGameDir().resolve("screenshots/worlds");
Expand All @@ -44,7 +46,7 @@ public void onInitializeClient() {
}

ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (OPEN_SETTINGS.wasPressed()) client.setScreen(Config.getScreen(client.currentScreen));
while (OPEN_SETTINGS.wasPressed()) client.setScreen(Config.getScreen(client.currentScreen, MODID));
});

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.minenash.seamless_loading_screen;

public interface ServerInfoExtras {
public interface ServerInfoExtension {

void setAllowCustomScreenshots(boolean b);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.minenash.seamless_loading_screen.config;

public class Config extends TinyConfig {
public class Config extends MidnightConfig {

@Entry(min = 0)
public static int time = 80;
Expand Down
Loading

0 comments on commit 10a9b99

Please sign in to comment.