1.2.0 #2

Merged
vaporvee merged 8 commits from 1.2.0 into main 2025-06-23 00:58:41 +00:00
66 changed files with 953 additions and 1375 deletions
Showing only changes of commit ed26add885 - Show all commits

View File

@@ -8,9 +8,11 @@ The config in `config/loadsupport.toml` is pretty self explainatory:
startSound = true
minMemory = 4.0
errorTitle = "Error: Not enough Java memory!"
errorDescription = "Please allocate at least {minMemory} GB of Java memory to your Minecraft Instance! You have currently {currentMemory} GB allocated."
errorMinMemory = "Please allocate at least {minMemory} GB of Java memory to your Minecraft instance!"
errorCurrentMemory = "You have currently {currentMemory} GB allocated."
memoryInfoLink = "https://github.com/vaporvee/LoadSupport/wiki/How-to-allocate-more-memory-to-your-Minecraft-instance"
```
The errorDescription does automatic line breaks. `{minMemory}` and `{currentMemory}` get replaced by their actual values.
`{minMemory}` and `{currentMemory}` get replaced by their actual values.
## Planned Features 👀
- 🔊 Customizable startup sound
@@ -23,11 +25,9 @@ The player doesn't need to wait just to know that they selected the wrong amount
![Screenshot](https://cdn.modrinth.com/data/cached_images/0b148e2023ca586cc64f821a2ce0ca8b87402ce5.png)
#### Blocks the title screen🚧
#### Blocks the game window🚧
Make sure the player gets the correct performance experience.
<img src="https://cdn.modrinth.com/data/bnO15g6H/images/881f15c2413795ba1ba0bebd2baf4c0f4862336c.png" width="600px">
---
### Play a sound when Minecraft finished loading 🔊

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

@@ -1,6 +1,6 @@
package com.vaporvee.loadsupport.mixin;
import com.vaporvee.loadsupport.Allocated;
import com.vaporvee.loadsupport.modules.Allocated;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

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": {

View File

@@ -15,7 +15,7 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
modApi("me.shedaniel.cloth:cloth-config-fabric:18.0.145") {
modApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
}

View File

@@ -0,0 +1,11 @@
package com.vaporvee.loadsupport;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
public class ClientScreenHandler {
public static void register() {
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
ScreenEventHandler.eventTrigger(screen);
});
}
}

View File

@@ -6,6 +6,9 @@ public class LoadSupport implements ModInitializer {
@Override
public void onInitialize() {
CommonClass.init();
boolean initiated = CommonClass.init();
if(initiated) {
ClientScreenHandler.register();
}
}
}

View File

@@ -1,24 +0,0 @@
package com.vaporvee.loadsupport.mixin;
import com.vaporvee.loadsupport.Allocated;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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;
@Environment(EnvType.CLIENT)
@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,26 +0,0 @@
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.Allocated;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.lwjgl.glfw.GLFW;
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;
@Environment(EnvType.CLIENT)
@Mixin(Window.class)
public class WindowHideMixin {
@Inject(method = "<init>", at = @At("RETURN"))
private void onWindowInit(WindowEventHandler eventHandler, ScreenManager screenManager, DisplayData displayData, String preferredFullscreenVideoMode, String title, CallbackInfo ci) {
if (!Allocated.enoughMemory) {
long w = ((Window)(Object)this).getWindow();
GLFW.glfwHideWindow(w);
}
}
}

View File

@@ -1,21 +0,0 @@
package com.vaporvee.loadsupport.platform;
import com.vaporvee.loadsupport.CommonClass;
import com.vaporvee.loadsupport.Config;
import com.vaporvee.loadsupport.platform.services.IConfig;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
public class LSConfigFabric implements IConfig {
public static Config config;
@Override
public void InitConfig() {
AutoConfig.register(Config.class, Toml4jConfigSerializer::new);
config = AutoConfig.getConfigHolder(Config.class).getConfig();
CommonClass.checkConfig(config);
}
@Override
public Config getConfig() {
return config;
}
}

View File

@@ -1 +0,0 @@
com.vaporvee.loadsupport.platform.LSConfigFabric

View File

@@ -5,10 +5,7 @@
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"MinecraftPauseMixin",
"WindowHideMixin"
],
"client": [],
"server": [],
"injectors": {
"defaultRequire": 1

View File

@@ -7,30 +7,33 @@ group=com.vaporvee.loadsupport
java_version=21
# Common
minecraft_version=1.21.5
minecraft_version=1.21.1
mod_name=Load Support
mod_author=vaporvee
mod_id=loadsupport
license=Apache License 2.0
credits=
description=Shows when the user has too less Java memory allocated, and plays a sound when the game has loaded.
minecraft_version_range=[1.21.5, 1.22)
minecraft_version_range=[1.21.1, 1.21.6)
## This is the version of minecraft that the 'common' project uses, you can find a list of all versions here
## https://projects.neoforged.net/neoforged/neoform
neo_form_version=1.21.5-20250325.162830
neo_form_version=1.21.1-20240808.144430
# The version of ParchmentMC that is used, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
parchment_minecraft=1.21.4
parchment_version=2025.03.23
parchment_minecraft=1.21.1
parchment_version=2024.11.17
# Fabric
fabric_version=0.119.5+1.21.5
fabric_version=0.116.3+1.21.1
fabric_loader_version=0.16.10
# NeoForge
neoforge_version=21.5.4-beta
neoforge_version=21.1.184
neoforge_loader_version_range=[4,)
# Dependencies
cloth_version=15.0.140
# Gradle
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

View File

@@ -10,7 +10,7 @@ repositories {
dependencies {
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
implementation "me.shedaniel.cloth:cloth-config-neoforge:18.0.145"
implementation "me.shedaniel.cloth:cloth-config-neoforge:${cloth_version}"
}
neoForge {
@@ -32,9 +32,6 @@ neoForge {
client {
client()
}
data {
clientData()
}
server {
server()
}

View File

@@ -0,0 +1,16 @@
package com.vaporvee.loadsupport;
import net.minecraft.client.gui.screens.Screen;
import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.common.NeoForge;
public class ClientScreenHandler {
public static void register() {
NeoForge.EVENT_BUS.addListener(ClientScreenHandler::onScreenInit);
}
private static void onScreenInit(ScreenEvent.Init.Post event) {
Screen screen = event.getScreen();
ScreenEventHandler.eventTrigger(screen);
}
}

View File

@@ -1,8 +1,5 @@
package com.vaporvee.loadsupport;
import com.vaporvee.loadsupport.platform.Services;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
@@ -10,6 +7,9 @@ import net.neoforged.fml.common.Mod;
public class LoadSupport {
public LoadSupport(IEventBus eventBus) {
CommonClass.init();
boolean initiated = CommonClass.init();
if (initiated) {
ClientScreenHandler.register();
}
}
}

View File

@@ -1,23 +0,0 @@
package com.vaporvee.loadsupport.mixin;
import com.mojang.blaze3d.platform.Window;
import com.vaporvee.loadsupport.Allocated;
import org.lwjgl.glfw.GLFW;
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.CallbackInfoReturnable;
@Mixin(Window.class)
public class WindowHideMixin {
@Inject(
method = "takeOverWindow",
at = @At("RETURN")
)
private void onTakeOverWindow(CallbackInfoReturnable<Long> cir) {
if (!Allocated.enoughMemory) {
long w = cir.getReturnValue();
GLFW.glfwHideWindow(w);
}
}
}

View File

@@ -1,23 +0,0 @@
package com.vaporvee.loadsupport.platform;
import com.vaporvee.loadsupport.CommonClass;
import com.vaporvee.loadsupport.Config;
import com.vaporvee.loadsupport.platform.services.IConfig;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.neoforged.neoforge.client.event.ScreenEvent;
public class LSConfigNeoForge implements IConfig {
public static Config config;
@Override
public void InitConfig() {
AutoConfig.register(Config.class, Toml4jConfigSerializer::new);
config = AutoConfig.getConfigHolder(Config.class).getConfig();
CommonClass.checkConfig(config);
}
@Override
public Config getConfig() {
return config;
}
}

View File

@@ -10,13 +10,11 @@ public class NeoForgePlatformHelper implements IPlatformHelper {
@Override
public String getPlatformName() {
return "NeoForge";
}
@Override
public boolean isModLoaded(String modId) {
return ModList.get().isLoaded(modId);
}
@@ -27,7 +25,6 @@ public class NeoForgePlatformHelper implements IPlatformHelper {
@Override
public boolean isDevelopmentEnvironment() {
return !FMLLoader.isProduction();
}
}

View File

@@ -1 +0,0 @@
com.vaporvee.loadsupport.platform.LSConfigNeoForge

View File

@@ -4,10 +4,7 @@
"package": "com.vaporvee.loadsupport.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"MinecraftPauseMixin",
"WindowHideMixin"
],
"client": [],
"server": [],
"injectors": {
"defaultRequire": 1