Skip to content

Commit

Permalink
finished first version of the mod
Browse files Browse the repository at this point in the history
  • Loading branch information
vaporvee committed Oct 5, 2024
1 parent 3cf8a0d commit 7f9fb5a
Show file tree
Hide file tree
Showing 29 changed files with 1,082 additions and 126 deletions.
File renamed without changes.
25 changes: 25 additions & 0 deletions .github/workflows/build-neoforge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"

- name: Build with Gradle
uses: gradle/actions/setup-gradle@v3
working-directory: ./neoforge
with:
arguments: build
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Enoug Memory
A Minecraft mod which displays a warning when too less Java memory was allocated.<br>
# Load Support
Shows when the user has to less Java memory allocated, and plays a sound when the game has loaded.<br>
It is fully configurable in `config/enoughmemory.toml`
## Directly Shows a warning message
![image](https://github.com/user-attachments/assets/7f3b152c-a744-4570-91b4-5d005ac6f94b)
Expand Down
7 changes: 7 additions & 0 deletions debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[1004/203846.550:ERROR:crashpad_client_win.cc(810)] not connected
[1004/210622.059:ERROR:crashpad_client_win.cc(810)] not connected
[1004/210622.163:ERROR:crashpad_client_win.cc(810)] not connected
[1004/223616.841:ERROR:crashpad_client_win.cc(810)] not connected
[1004/233021.354:ERROR:crashpad_client_win.cc(810)] not connected
[1004/233021.469:ERROR:crashpad_client_win.cc(810)] not connected
[1004/233120.351:ERROR:crashpad_client_win.cc(810)] not connected

This file was deleted.

12 changes: 12 additions & 0 deletions fabric/src/client/java/com/vaporvee/loadsupport/LSConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.vaporvee.loadsupport;

import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;

@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! You have currently {currentMemory} GB allocated.";
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,12 +15,12 @@
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();
Expand All @@ -30,17 +31,17 @@ public static void createWindow(MinecraftClient minecraftClient, Screen screen)
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());
Expand All @@ -50,10 +51,9 @@ public static void createWindow(MinecraftClient minecraftClient, Screen screen)
});
}
} 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() {
Expand All @@ -74,8 +74,8 @@ public void init(){
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;
Expand All @@ -94,6 +94,5 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
context.drawCenteredTextWithShadow(textRenderer, line, width / 2, bodyStartY + (i * lineHeight), 0xffffff);
}
}

}
}
16 changes: 16 additions & 0 deletions fabric/src/client/java/com/vaporvee/loadsupport/LoadNotifier.java
Original file line number Diff line number Diff line change
@@ -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
);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vaporvee.enoughmemory;
package com.vaporvee.loadsupport;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
Expand All @@ -7,17 +7,17 @@
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() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
logger.info(MOD_ID + " is a client mod only!");
return;
}
logger.info("Loading EnoughMemory mod.");
logger.info("Loading Load Support mod.");
}
}
86 changes: 41 additions & 45 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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": "*"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"required": true,
"package": "com.vaporvee.enoughmemory.mixin",
"package": "com.vaporvee.loadsupport.mixin",
"compatibilityLevel": "JAVA_21",
"injectors": {
"defaultRequire": 1
Expand Down
5 changes: 5 additions & 0 deletions neoforge/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disable autocrlf on generated files, they always generate with LF
# Add any extra files or paths here to make git stop saying they
# are changed when only line endings change.
src/generated/**/.cache/cache text eol=lf
src/generated/**/*.json text eol=lf
Loading

0 comments on commit 7f9fb5a

Please sign in to comment.