finished first version of the mod
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
package com.vaporvee.enoughmemory;
|
||||
|
||||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public class EnoughMemoryClient implements ClientModInitializer {
|
||||
public static EMConfig config;
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
AutoConfig.register(EMConfig.class, Toml4jConfigSerializer::new);
|
||||
config = AutoConfig.getConfigHolder(EMConfig.class).getConfig();
|
||||
float allocatedMemoryInGB = Runtime.getRuntime().totalMemory() / 1073741824f; // Hardcoded value for GB
|
||||
EnoughMemory.logger.info(String.format("Allocated Memory: %.1f GB", allocatedMemoryInGB));
|
||||
if(config.minMemory > allocatedMemoryInGB){
|
||||
System.setProperty("java.awt.headless", "false"); // Hacky stupid thing but it works I guess...
|
||||
ScreenEvents.BEFORE_INIT.register(EnoughMemoryClient::beforeWindowInit);
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] getWarningMessage(){
|
||||
return new String[]{config.errorTitle, config.errorDescription.replace("{minMemory}", String.valueOf(config.minMemory))};
|
||||
};
|
||||
|
||||
private static void beforeWindowInit(MinecraftClient minecraftClient, Screen screen, int i, int i1) {
|
||||
EMWindow.createWindow(minecraftClient, screen);
|
||||
}
|
||||
}
|
@@ -1,11 +1,12 @@
|
||||
package com.vaporvee.enoughmemory;
|
||||
package com.vaporvee.loadsupport;
|
||||
|
||||
import me.shedaniel.autoconfig.ConfigData;
|
||||
import me.shedaniel.autoconfig.annotation.Config;
|
||||
|
||||
@Config(name = EnoughMemory.MOD_ID)
|
||||
public class EMConfig implements ConfigData {
|
||||
@Config(name = LoadSupport.MOD_ID)
|
||||
public class LSConfig implements ConfigData {
|
||||
boolean startSound = true;
|
||||
float minMemory = 4.0f;
|
||||
String errorTitle = "Error: Not enough Java memory!";
|
||||
String errorDescription = "Please allocate at least {minMemory} GB of Java memory to your Minecraft Instance!";
|
||||
String errorDescription = "Please allocate at least {minMemory} GB of Java memory to your Minecraft Instance! You have currently {currentMemory} GB allocated.";
|
||||
}
|
@@ -1,9 +1,10 @@
|
||||
package com.vaporvee.enoughmemory;
|
||||
package com.vaporvee.loadsupport;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.AccessibilityOnboardingScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
@@ -14,12 +15,12 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class EMWindow {
|
||||
public class LSWindow {
|
||||
static boolean windowOpen = false;
|
||||
private static JFrame window;
|
||||
|
||||
public static void createWindow(MinecraftClient minecraftClient, Screen screen) {
|
||||
if(screen instanceof TitleScreen){
|
||||
if(screen instanceof TitleScreen || screen instanceof AccessibilityOnboardingScreen){
|
||||
minecraftClient.setScreen(new BlockedScreen());
|
||||
if(window != null){
|
||||
window.dispose();
|
||||
@@ -30,17 +31,17 @@ public class EMWindow {
|
||||
if (!windowOpen) {
|
||||
windowOpen = true;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
window = new JFrame(EnoughMemoryClient.getWarningMessage()[0]);
|
||||
window = new JFrame(LoadSupportClient.getWarningMessage()[0]);
|
||||
window.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
window.setSize(400, 200);
|
||||
window.setLocationRelativeTo(null);
|
||||
|
||||
JLabel message = new JLabel("<html><p style=\"width:200px\">"+EnoughMemoryClient.getWarningMessage()[1]+"</p></html>", JLabel.CENTER);
|
||||
JLabel message = new JLabel("<html><p style=\"width:200px\">"+ LoadSupportClient.getWarningMessage()[1]+"</p></html>", JLabel.CENTER);
|
||||
JButton exitButton = new JButton("OK");
|
||||
|
||||
exitButton.addActionListener(e -> {
|
||||
window.dispose();
|
||||
minecraftClient.scheduleStop();
|
||||
minecraftClient.stop();
|
||||
});
|
||||
|
||||
window.setLayout(new BorderLayout());
|
||||
@@ -50,10 +51,9 @@ public class EMWindow {
|
||||
});
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
EnoughMemory.logger.error(String.valueOf(e));
|
||||
LoadSupport.logger.error(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static class BlockedScreen extends Screen {
|
||||
protected BlockedScreen() {
|
||||
@@ -74,8 +74,8 @@ public class EMWindow {
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
|
||||
String title = EnoughMemoryClient.getWarningMessage()[0];
|
||||
String body = EnoughMemoryClient.getWarningMessage()[1];
|
||||
String title = LoadSupportClient.getWarningMessage()[0];
|
||||
String body = LoadSupportClient.getWarningMessage()[1];
|
||||
|
||||
int lineHeight = textRenderer.fontHeight + 5;
|
||||
int maxTextWidth = width - 40;
|
||||
@@ -94,6 +94,5 @@ public class EMWindow {
|
||||
context.drawCenteredTextWithShadow(textRenderer, line, width / 2, bodyStartY + (i * lineHeight), 0xffffff);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.vaporvee.loadsupport;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.sound.PositionedSoundInstance;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
|
||||
public class LoadNotifier {
|
||||
static boolean wasPlayed = false;
|
||||
public static void notifySound(MinecraftClient client){
|
||||
if(LoadSupportClient.config.startSound && !wasPlayed) {
|
||||
wasPlayed = true;
|
||||
client.getSoundManager().play(
|
||||
PositionedSoundInstance.master(SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 1.0F) // Use any sound event you like
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.vaporvee.loadsupport;
|
||||
|
||||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.AccessibilityOnboardingScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
|
||||
public class LoadSupportClient implements ClientModInitializer {
|
||||
public static LSConfig config;
|
||||
private static float allocatedMemoryInGB;
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new);
|
||||
config = AutoConfig.getConfigHolder(LSConfig.class).getConfig();
|
||||
allocatedMemoryInGB = Runtime.getRuntime().totalMemory() / 1073741824f; // Hardcoded value for GB
|
||||
LoadSupport.logger.info(String.format("Allocated Memory: %.1f GB", allocatedMemoryInGB));
|
||||
ScreenEvents.BEFORE_INIT.register(LoadSupportClient::beforeWindowInit);
|
||||
}
|
||||
|
||||
public static String[] getWarningMessage(){
|
||||
return new String[]{config.errorTitle, config.errorDescription
|
||||
.replace("{minMemory}", String.valueOf(config.minMemory))
|
||||
.replace("{currentMemory}", String.format("%.1f", allocatedMemoryInGB))};
|
||||
};
|
||||
private static void beforeWindowInit(MinecraftClient minecraftClient, Screen screen, int i, int i1) {
|
||||
if(config.minMemory > allocatedMemoryInGB){
|
||||
System.setProperty("java.awt.headless", "false"); // Hacky stupid thing but it works I guess...
|
||||
LSWindow.createWindow(minecraftClient, screen);
|
||||
}
|
||||
if (screen instanceof TitleScreen || screen instanceof AccessibilityOnboardingScreen){
|
||||
LoadNotifier.notifySound(minecraftClient);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.vaporvee.enoughmemory;
|
||||
package com.vaporvee.loadsupport;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
@@ -7,10 +7,10 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class EnoughMemory implements ModInitializer {
|
||||
public static final String MOD_ID = "enoughmemory";
|
||||
public class LoadSupport implements ModInitializer {
|
||||
public static final String MOD_ID = "loadsupport";
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger("EnoughMemory");
|
||||
public static final Logger logger = LoggerFactory.getLogger("Load Support");
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
@@ -18,6 +18,6 @@ public class EnoughMemory implements ModInitializer {
|
||||
logger.info(MOD_ID + " is a client mod only!");
|
||||
return;
|
||||
}
|
||||
logger.info("Loading EnoughMemory mod.");
|
||||
logger.info("Loading Load Support mod.");
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
@@ -1,46 +1,42 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "enoughmemory",
|
||||
"version": "${version}",
|
||||
"name": "Enough Memory",
|
||||
"description": "It will show the user when they have set too less Java Memory. The amount of required memory can be adjusted with the config.",
|
||||
"authors": [
|
||||
{
|
||||
"name": "vaporvee",
|
||||
"contact": {
|
||||
"homepage" : "https://vaporvee.com"
|
||||
}
|
||||
}
|
||||
],
|
||||
"contact": {
|
||||
"sources": "https://github.com/vaporvee/EnoughMemory",
|
||||
"issues": "https://github.com/vaporvee/EnoughMemory/issues"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"links": {
|
||||
"modmenu.discord": "https://discord.gg/StMHnsC9s2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"license": "Apache License 2.0",
|
||||
"icon": "assets/enoughmemory/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"com.vaporvee.enoughmemory.EnoughMemory"
|
||||
],
|
||||
"client": [
|
||||
"com.vaporvee.enoughmemory.EnoughMemoryClient"
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.5",
|
||||
"minecraft": "~1.21.1",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
||||
"schemaVersion": 1,
|
||||
"id": "loadsupport",
|
||||
"version": "${version}",
|
||||
"name": "Load Support",
|
||||
"description": "Shows when the user has to less Java memory allocated, and plays a sound when the game has loaded.",
|
||||
"authors": [
|
||||
{
|
||||
"name": "vaporvee",
|
||||
"contact": {
|
||||
"homepage": "https://vaporvee.com"
|
||||
}
|
||||
}
|
||||
],
|
||||
"contact": {
|
||||
"sources": "https://github.com/vaporvee/EnoughMemory",
|
||||
"issues": "https://github.com/vaporvee/EnoughMemory/issues"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"links": {
|
||||
"modmenu.discord": "https://discord.gg/StMHnsC9s2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"license": "Apache License 2.0",
|
||||
"icon": "assets/loadsupport/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": ["com.vaporvee.loadsupport.LoadSupport"],
|
||||
"client": ["com.vaporvee.loadsupport.LoadSupportClient"]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.5",
|
||||
"minecraft": "~1.21.1",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "com.vaporvee.enoughmemory.mixin",
|
||||
"package": "com.vaporvee.loadsupport.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
Reference in New Issue
Block a user