Skip to content

Commit

Permalink
Modules and a LOT of things
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Jun 9, 2024
1 parent 0653c53 commit 65fc4ca
Show file tree
Hide file tree
Showing 337 changed files with 15,991 additions and 2,486 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"


include modImplementation("com.github.0x3C50:Renderer:master-SNAPSHOT")
//Renderer 1.20.4 library
//TODO: Move to 1.20.6
include modImplementation("com.github.0x3C50:Renderer:aa67e1c")


// Baritone API
modCompileOnly "com.github.wagyourtail:baritone:${project.baritone_version}"
Expand Down
70 changes: 0 additions & 70 deletions examples/itemframedupe.lua

This file was deleted.

81 changes: 39 additions & 42 deletions src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import dev.heliosclient.scripting.LuaScriptManager;
import dev.heliosclient.system.*;
import dev.heliosclient.ui.clickgui.ConsoleScreen;
import dev.heliosclient.ui.clickgui.gui.Quadtree;
import dev.heliosclient.ui.notification.notifications.InfoNotification;
import dev.heliosclient.util.*;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.SoundUtils;
import dev.heliosclient.util.TimerUtils;
import dev.heliosclient.util.fontutils.FontRenderers;
import dev.heliosclient.util.player.DamageUtils;
import dev.heliosclient.util.player.RotationSimulator;
import dev.heliosclient.util.render.Renderer2D;
import me.x150.renderer.font.FontRenderer;
import net.fabricmc.api.ModInitializer;
Expand All @@ -31,6 +33,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

import static dev.heliosclient.managers.FontManager.fontSize;
import static dev.heliosclient.managers.FontManager.fonts;

Expand All @@ -42,62 +46,61 @@ public class HeliosClient implements ModInitializer, Listener {
public static final String versionTag = ColorUtils.gray + "v0.dev";
public static final String MODID = "heliosclient";
private static final TimerUtils configTimer = new TimerUtils();
public static Quadtree quadTree;
public static Config CONFIG = new Config();
public static int uiColorA = 0xFF55FFFF;
public static int uiColor = 0x55FFFF;
public static AddonManager addonManager = new AddonManager();
public static AddonManager ADDONMANAGER = new AddonManager();
public static ClickGUI CLICKGUI = new ClickGUI();
public volatile static ConsoleScreen CONSOLE = new ConsoleScreen();
public static File SAVE_FOLDER = new File(MC.runDirectory.getPath() + "/heliosclient");

public static void loadConfig() {
configTimer.startTimer();
CommandManager.prefix = (String) CONFIG.getClientConfigMap().get("prefix");
CONFIG.loadConfig();
CONFIG.loadClientConfigModules();

// Font event is posted to allow the GUI to reset its calculation for the new font by the config.
if (FontManager.fonts != null)
EventManager.postEvent(new FontChangeEvent(FontManager.fonts));

CONFIG.loadHudElements();
CONFIG.loadModules();
LOGGER.info("Loading Config complete in: {}s", configTimer.getElapsedTime());
if(NotificationModule.get().clientNotification.value && shouldSendNotification()){
if (ModuleManager.get(NotificationModule.class).clientNotification.value && shouldSendNotification()) {
NotificationManager.addNotification(new InfoNotification("Loading Done", "in: " + configTimer.getElapsedTime() + "s", 1000, SoundUtils.TING_SOUNDEVENT));
}
if (HeliosClient.MC.getWindow() != null) {
FontManager.INSTANCE.registerFonts();
FontRenderers.fontRenderer = new FontRenderer(fonts, fontSize);
EventManager.postEvent(new FontChangeEvent(fonts));
}
configTimer.resetTimer();

// Font event is posted to allow the GUI to reset its calculation for the new font by the config.
if (fonts != null)
EventManager.postEvent(new FontChangeEvent(fonts));
}

public static void saveConfig() {
HeliosExecutor.execute(HeliosClient::saveConfigHook);
}

public static void saveConfigHook() {
LOGGER.info("Saving config... \t Module Config being saved: {}", Config.MODULES);
configTimer.startTimer();
CONFIG.getModuleConfig();
CONFIG.getClientConfig();
CONFIG.save();
configTimer.startTimer();
CONFIG.getModuleConfig();
CONFIG.getClientConfig();
CONFIG.save();
LOGGER.info("Saving Config complete in: {}s", configTimer.getElapsedTime());
if(NotificationModule.get().clientNotification.value && shouldSendNotification()){
NotificationManager.addNotification(new InfoNotification("Saving Done", "in: " + configTimer.getElapsedTime() + "s", 1000, SoundUtils.TING_SOUNDEVENT));
}
configTimer.resetTimer();
if (ModuleManager.get(NotificationModule.class).clientNotification.value && shouldSendNotification()) {
NotificationManager.addNotification(new InfoNotification("Saving Done", "in: " + configTimer.getElapsedTime() + "s", 1000, SoundUtils.TING_SOUNDEVENT));
}
configTimer.resetTimer();
}


public static boolean shouldSendNotification() {
return (NotificationManager.INSTANCE != null && NotificationModule.get() != null && MC.getWindow() != null);
return (NotificationManager.INSTANCE != null && ModuleManager.get(NotificationModule.class) != null && MC.getWindow() != null);
}

public static boolean shouldUpdate() {
return MC != null && MC.getWindow() != null && MC.player != null;
}

@SubscribeEvent
public void tick(TickEvent.CLIENT client){
public void tick(TickEvent.CLIENT client) {
if (MC.getWindow() != null) {
quadTree = new Quadtree(0);
FontManager.INSTANCE.registerFonts();
EventManager.postEvent(new FontChangeEvent(fonts));
EventManager.unregister(this);
}
}
Expand Down Expand Up @@ -125,46 +128,41 @@ public void onInitialize() {


FontManager.INSTANCE.refresh();
addonManager.loadAddons();
ADDONMANAGER.loadAddons();
AddonManager.initializeAddons();

Categories.registerCategories();
SoundUtils.registerSounds();
HudElementList.INSTANCE = new HudElementList();


CapeManager.capes = CapeManager.loadCapes();
CapeManager.CAPE_NAMES = CapeManager.loadCapes();

HeliosExecutor.execute(HeliosClient::loadConfig);

// Save
ServerLifecycleEvents.SERVER_STOPPING.register(server -> HeliosClient.saveConfig());
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((a,b,c) -> HeliosClient.saveConfig());
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((a, b, c) -> HeliosClient.saveConfig());
ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> HeliosClient.saveConfig());
ClientLifecycleEvents.CLIENT_STOPPING.register((client) -> {
saveConfigHook();
if (DiscordRPC.INSTANCE.isRunning) {
DiscordRPC.INSTANCE.stopPresence();
}
HeliosExecutor.shutdown();
});

MC.execute(()->{
while(MC.getWindow() == null){
MC.execute(() -> {
while (MC.getWindow() == null) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// Cope
}
}
HeliosClient.CLICKGUI.onLoad();
HeliosClient.CLICKGUI.onLoad();
});
}

public static boolean shouldUpdate() {
return MC != null && MC.getWindow() != null && MC.player != null;
}

public void registerEvents() {
EventManager.register(FontManager.INSTANCE);
EventManager.register(NotificationManager.INSTANCE);
Expand All @@ -173,8 +171,7 @@ public void registerEvents() {
EventManager.register(ColorManager.INSTANCE);
EventManager.register(TickRate.INSTANCE);
EventManager.register(DamageUtils.INSTANCE);
}
public static void openConsoleScreen(){
MC.setScreen(CONSOLE);
EventManager.register(RotationSimulator.INSTANCE);

}
}
11 changes: 2 additions & 9 deletions src/main/java/dev/heliosclient/addon/AddonManager.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package dev.heliosclient.addon;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import dev.heliosclient.HeliosClient;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.fabricmc.loader.api.metadata.Person;

import java.io.File;
import java.io.FileReader;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class AddonManager {
public static final List<HeliosAddon> HELIOS_ADDONS = new ArrayList<>();
Expand Down Expand Up @@ -44,12 +37,12 @@ public void loadAddons() {
try {
addon = entrypoint.getEntrypoint();
} catch (Throwable e) {
throw new RuntimeException("An error has occured during loading addon \"%s\"".formatted(metadata.getName()), e);
throw new RuntimeException("An error has occurred during loading addon \"%s\"".formatted(metadata.getName()), e);
}

addon.name = metadata.getName();

if (metadata.getAuthors().isEmpty()){
if (metadata.getAuthors().isEmpty()) {
throw new RuntimeException("The authors field in fabric.mod.json must contain at least one author for addon \"%s\"".formatted(addon.name));
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/heliosclient/addon/HeliosAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class HeliosAddon {

// Register stuff
public abstract void registerCategories();

public abstract void registerHudElementData();

public abstract void registerModules();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.stream.Collectors;

public class ModuleArgumentType implements ArgumentType<Module_> {
private static final Collection<String> EXAMPLES = ModuleManager.INSTANCE.getModules()
private static final Collection<String> EXAMPLES = ModuleManager.getModules()
.stream()
.limit(3)
.map(module -> addQuotes(module.name))
Expand Down Expand Up @@ -45,7 +45,7 @@ private static String addQuotes(String input) {
@Override
public Module_ parse(StringReader reader) throws CommandSyntaxException {
String argument = reader.readString();
Module_ module = ModuleManager.INSTANCE.getModuleByName(argument.replace("\"", ""));
Module_ module = ModuleManager.getModuleByName(argument.replace("\"", ""));

if (module == null) throw NO_SUCH_MODULE.create(argument);

Expand All @@ -54,7 +54,7 @@ public Module_ parse(StringReader reader) throws CommandSyntaxException {

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return CommandSource.suggestMatching(ModuleManager.INSTANCE.getModules().stream().map(module -> addQuotes(module.name)), builder);
return CommandSource.suggestMatching(ModuleManager.getModules().stream().map(module -> addQuotes(module.name)), builder);
}

@Override
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/dev/heliosclient/command/commands/LoadScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import dev.heliosclient.HeliosClient;
import dev.heliosclient.command.Command;
import dev.heliosclient.scripting.LuaFile;
import dev.heliosclient.scripting.LuaScriptManager;
Expand All @@ -12,24 +11,24 @@

public class LoadScript extends Command {
public LoadScript() {
super("loadScript","Loads a lua script");
super("loadScript", "Loads a lua script");
}

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(argument("scriptname", StringArgumentType.word())
.executes(context -> {
String scriptname = StringArgumentType.getString(context, "scriptname");
for(LuaFile file: LuaScriptManager.luaFiles){
if(file.getScriptName().equalsIgnoreCase(scriptname)){
for (LuaFile file : LuaScriptManager.luaFiles) {
if (file.getScriptName().equalsIgnoreCase(scriptname)) {
LuaScriptManager.INSTANCE.loadScript(file);
ChatUtils.sendHeliosMsg(ColorUtils.green + "Loaded script " + ColorUtils.darkGray + "[" +ColorUtils.aqua + file.getFile().getName() + ColorUtils.darkGray +"]");
ChatUtils.sendHeliosMsg(ColorUtils.green + "Loaded script " + ColorUtils.darkGray + "[" + ColorUtils.aqua + file.getFile().getName() + ColorUtils.darkGray + "]");
return SINGLE_SUCCESS;
}
}

ChatUtils.sendHeliosMsg(ColorUtils.red + "Script of name not found");
ChatUtils.sendHeliosMsg(ColorUtils.red + "Script of name {"+ scriptname +"} not found");
return SINGLE_SUCCESS;
}));
}));
}
}
23 changes: 0 additions & 23 deletions src/main/java/dev/heliosclient/command/commands/OpenConsole.java

This file was deleted.

Loading

0 comments on commit 65fc4ca

Please sign in to comment.