finished 1.2.0

This commit is contained in:
2025-06-23 02:57:48 +02:00
parent d6e0ebc196
commit ed26add885
30 changed files with 174 additions and 222 deletions

View File

@@ -21,7 +21,7 @@ repositories {
}
dependencies {
compileOnly "me.shedaniel.cloth:cloth-config-neoforge:18.0.145"
compileOnly "me.shedaniel.cloth:cloth-config-neoforge:${cloth_version}"
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
// fabric and neoforge both bundle mixinextras, so it is safe to use it in common
compileOnly group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5'

View File

@@ -1,29 +1,30 @@
package com.vaporvee.loadsupport;
import com.vaporvee.loadsupport.modules.Allocated;
import com.vaporvee.loadsupport.platform.Services;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import org.lwjgl.glfw.GLFW;
public class CommonClass {
public static void init() {
public static boolean init() {
if (Services.PLATFORM.isEnvServer()) {
Constants.LOG.info(Constants.MOD_ID + " is a client mod only!");
return;
return false;
}
Constants.LOG.info("Loading Load Support mod.");
InitConfig();
Allocated.init();
Allocated.printAllocated();
Services.CONFIG.InitConfig();
return true;
}
public static void checkConfig(Config config) {
Constants.LOG.info("Config loaded!");
if (config != null) {
if(config.minMemory > Allocated.memoryInGB){
System.setProperty("java.awt.headless", "false");
Constants.LOG.error("Not enough memory! Allocated memory in GB is {} but set in config is {}",
Allocated.memoryInGB, config.minMemory);
Allocated.createMemoryError();
}
} else {
Constants.LOG.warn("Load config is null!");
}
public static Config config;
public static long window;
private static void InitConfig() {
AutoConfig.register(Config.class, Toml4jConfigSerializer::new);
config = AutoConfig.getConfigHolder(Config.class).getConfig();
}
public static void HideWindow() {
GLFW.glfwHideWindow(window);
}
}

View File

@@ -4,10 +4,10 @@ import me.shedaniel.autoconfig.ConfigData;
@me.shedaniel.autoconfig.annotation.Config(name = Constants.MOD_ID)
public class Config implements ConfigData {
boolean startSound = true;
float minMemory = 4.0f;
String errorTitle = "Error: Not enough Java memory!";
String errorMinMemory = "Please allocate at least {minMemory} GB of Java memory to your Minecraft instance!";
String errorCurrentMemory = "You have currently {currentMemory} GB allocated.";
String memoryInfoLink = "https://github.com/vaporvee/LoadSupport/wiki/How-to-allocate-more-memory-to-your-Minecraft-instance";
public boolean startSound = true;
public float minMemory = 4.0f;
public String errorTitle = "Error: Not enough Java memory!";
public String errorMinMemory = "Please allocate at least {minMemory} GB of Java memory to your Minecraft instance!";
public String errorCurrentMemory = "You have currently {currentMemory} GB allocated.";
public String memoryInfoLink = "https://github.com/vaporvee/LoadSupport/wiki/How-to-allocate-more-memory-to-your-Minecraft-instance";
}

View File

@@ -0,0 +1,14 @@
package com.vaporvee.loadsupport;
import com.vaporvee.loadsupport.modules.StartSound;
import net.minecraft.client.gui.screens.AccessibilityOnboardingScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
public class ScreenEventHandler {
public static void eventTrigger(Screen screen) {
if (screen instanceof TitleScreen || screen instanceof AccessibilityOnboardingScreen) {
StartSound.play();
}
}
}

View File

@@ -0,0 +1,21 @@
package com.vaporvee.loadsupport.mixin;
import com.vaporvee.loadsupport.modules.Allocated;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Minecraft.class)
public class MinecraftPauseMixin {
@Inject(method = "run", at = @At("HEAD"), cancellable = true)
private void onRunHead(CallbackInfo ci) {
if (!Allocated.enoughMemory) {
while (Allocated.isWindowOpen()) {
try { Thread.sleep(100); } catch (InterruptedException ignored) {}
}
ci.cancel();
}
}
}

View File

@@ -1,17 +0,0 @@
package com.vaporvee.loadsupport.mixin;
import com.vaporvee.loadsupport.Constants;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Minecraft.class)
public class MixinMinecraft {
@Inject(at = @At("TAIL"), method = "<init>")
private void init(CallbackInfo info) {
Constants.LOG.info("Mixin MC Platform: {}", Minecraft.getInstance().getVersionType());
}
}

View File

@@ -0,0 +1,35 @@
package com.vaporvee.loadsupport.mixin;
import com.mojang.blaze3d.platform.DisplayData;
import com.mojang.blaze3d.platform.ScreenManager;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.platform.WindowEventHandler;
import com.vaporvee.loadsupport.CommonClass;
import com.vaporvee.loadsupport.modules.Allocated;
import com.vaporvee.loadsupport.platform.Services;
import org.lwjgl.glfw.GLFW;
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.callback.CallbackInfo;
import java.util.Objects;
@Mixin(Window.class)
public class WindowHideMixin {
@Final
@Shadow
private long window;
@Inject(method = "<init>", at = @At("RETURN"))
private void afterInit(WindowEventHandler eventHandler, ScreenManager screenManager, DisplayData displayData, String preferredFullscreenVideoMode, String title, CallbackInfo ci) {
CommonClass.window = window;
if(Objects.equals(Services.PLATFORM.getPlatformName(), "Fabric") && !Allocated.enoughMemory){ // Fabric loads early enough to fire it here
CommonClass.HideWindow(); // Hide main Minecraft Window which gets frozen by mixin
}
}
}

View File

@@ -1,6 +1,10 @@
package com.vaporvee.loadsupport;
package com.vaporvee.loadsupport.modules;
import com.vaporvee.loadsupport.CommonClass;
import com.vaporvee.loadsupport.Config;
import com.vaporvee.loadsupport.Constants;
import com.vaporvee.loadsupport.platform.Services;
import org.lwjgl.glfw.GLFW;
import javax.swing.*;
import java.awt.*;
@@ -11,14 +15,22 @@ public class Allocated {
public static float memoryInGB;
public static void init(){
memoryInGB = Runtime.getRuntime().maxMemory() / Constants.GIGABYTE;
memoryInGB = Math.round(Allocated.memoryInGB * 10) / 10f;
}
public static void printAllocated() {
memoryInGB = Math.round(memoryInGB * 10) / 10f;
Constants.LOG.info(String.format("Allocated Memory: %.1f GB", memoryInGB));
checkMemory();
}
public static String[] getWarningMessage() {
Config config = Services.CONFIG.getConfig();
private static void checkMemory(){
if(CommonClass.config.minMemory > memoryInGB){
System.setProperty("java.awt.headless", "false");
Constants.LOG.error("Not enough memory! Allocated memory in GB is {} but set in config is {}",
memoryInGB, CommonClass.config.minMemory);
createMemoryError();
}
}
private static String[] getWarningMessage() {
Config config = CommonClass.config;
String title = stripHtml(config.errorTitle);
String minMemoryText = stripHtml(config.errorMinMemory);
@@ -38,14 +50,15 @@ public class Allocated {
return input == null ? "" : input.replaceAll("<[^>]*>", "");
}
public static boolean enoughMemory = true;
private static JFrame errorWindow;
public static boolean enoughMemory = true;
public static boolean isWindowOpen(){
return errorWindow.isDisplayable();
}
public static void createMemoryError() {
private static void createMemoryError() {
try {
if (enoughMemory) {
enoughMemory = false;
@@ -91,6 +104,9 @@ public class Allocated {
errorWindow.add(buttonPanel, BorderLayout.SOUTH);
errorWindow.setVisible(true);
});
if(Objects.equals(Services.PLATFORM.getPlatformName(), "NeoForge")){// NeoForge loads too late so we need to fire it here
CommonClass.HideWindow(); // Hide main Minecraft Window which gets frozen by mixin
}
}
} catch (RuntimeException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
Constants.LOG.error(String.valueOf(e));

View File

@@ -0,0 +1,19 @@
package com.vaporvee.loadsupport.modules;
import com.vaporvee.loadsupport.CommonClass;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.sounds.SoundEvents;
public class StartSound {
private static boolean startedOnce = false;
public static void play() {
if (!startedOnce && CommonClass.config.startSound) {
startedOnce = true;
Minecraft.getInstance().getSoundManager().play(
SimpleSoundInstance.forUI(SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 1.0F)
);
}
}
}

View File

@@ -1,7 +1,6 @@
package com.vaporvee.loadsupport.platform;
import com.vaporvee.loadsupport.Constants;
import com.vaporvee.loadsupport.platform.services.IConfig;
import com.vaporvee.loadsupport.platform.services.IPlatformHelper;
import java.util.ServiceLoader;
@@ -10,8 +9,6 @@ public class Services {
public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class);
public static final IConfig CONFIG = load(IConfig.class);
public static <T> T load(Class<T> clazz) {
final T loadedService = ServiceLoader.load(clazz)

View File

@@ -1,16 +0,0 @@
package com.vaporvee.loadsupport.platform.services;
import com.vaporvee.loadsupport.Config;
public interface IConfig {
/**
* Initializes config on available platforms
*/
void InitConfig();
/**
* Gets the populated config class with local config data when loaded correctly
* @return pupulated Config object
*/
Config getConfig();
}

View File

@@ -6,7 +6,8 @@
"compatibilityLevel": "JAVA_18",
"mixins": [],
"client": [
"MixinMinecraft"
"MinecraftPauseMixin",
"WindowHideMixin"
],
"server": [],
"injectors": {