Skip to content

Commit

Permalink
Console Screen and appender. Some more comments. FontRenderer error f…
Browse files Browse the repository at this point in the history
…ix. Some Refactoring. MultiLineInputBox changes. ClickGUI and Console keybinds. Make sure to delete config for this commit. Plenty other changes.
  • Loading branch information
tanishisherewithhh committed Apr 27, 2024
1 parent c65b802 commit b11b785
Show file tree
Hide file tree
Showing 23 changed files with 254 additions and 129 deletions.
49 changes: 25 additions & 24 deletions src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@
import dev.heliosclient.module.Categories;
import dev.heliosclient.module.modules.misc.NotificationModule;
import dev.heliosclient.module.sysmodules.ClickGUI;
import dev.heliosclient.scripting.LuaExecutor;
import dev.heliosclient.scripting.LuaScriptManager;
import dev.heliosclient.system.Config;
import dev.heliosclient.system.DiscordRPC;
import dev.heliosclient.system.HeliosExecutor;
import dev.heliosclient.system.TickRate;
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.fontutils.FontRenderers;
import dev.heliosclient.util.player.DamageUtils;
import dev.heliosclient.util.render.Renderer2D;
import me.x150.renderer.font.FontRenderer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import org.luaj.vm2.lib.jse.CoerceLuaToJava;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,7 +37,7 @@
public class HeliosClient implements ModInitializer, Listener {
public static final HeliosClient INSTANCE = new HeliosClient();
public static final MinecraftClient MC = MinecraftClient.getInstance();
public static final Logger LOGGER = LoggerFactory.getLogger("Helios Client");
public static final Logger LOGGER = LoggerFactory.getLogger("HeliosClient");
public static final String clientTag = ColorUtils.yellow + "Helios" + ColorUtils.white + "Client";
public static final String versionTag = ColorUtils.gray + "v0.dev";
public static final String MODID = "heliosclient";
Expand All @@ -50,7 +48,7 @@ public class HeliosClient implements ModInitializer, Listener {
public static int uiColor = 0x55FFFF;
public static AddonManager addonManager = new AddonManager();
public static ClickGUI CLICKGUI = new ClickGUI();
public static ConsoleScreen CONSOLE = new ConsoleScreen();
public volatile static ConsoleScreen CONSOLE = new ConsoleScreen();

public static void loadConfig() {
configTimer.startTimer();
Expand All @@ -64,7 +62,7 @@ public static void loadConfig() {

CONFIG.loadHudElements();
CONFIG.loadModules();
LOGGER.info("Loading Config complete in: " + configTimer.getElapsedTime() + "s");
LOGGER.info("Loading Config complete in: {}s", configTimer.getElapsedTime());
if(NotificationModule.get().clientNotification.value && shouldSendNotification()){
NotificationManager.addNotification(new InfoNotification("Loading Done", "in: " + configTimer.getElapsedTime() + "s", 1000, SoundUtils.TING_SOUNDEVENT));
}
Expand All @@ -80,12 +78,12 @@ public static void saveConfig() {
HeliosExecutor.execute(HeliosClient::saveConfigHook);
}
public static void saveConfigHook() {
LOGGER.info("Saving config... \t Module Config being saved: " + Config.MODULES);
LOGGER.info("Saving config... \t Module Config being saved: {}", Config.MODULES);
configTimer.startTimer();
CONFIG.getModuleConfig();
CONFIG.getClientConfig();
CONFIG.save();
LOGGER.info("Saving Config complete in: " + configTimer.getElapsedTime() + "s");
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));
}
Expand All @@ -106,6 +104,14 @@ public void tick(TickEvent.CLIENT client){

@Override
public void onInitialize() {
ConsoleAppender consoleAppender = new ConsoleAppender(CONSOLE);

LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
config.addAppender(consoleAppender);
config.getRootLogger().addAppender(consoleAppender, null, null);
ctx.updateLoggers(config);

LOGGER.info("Initialising Helios Client...");

EventManager.register(this);
Expand Down Expand Up @@ -135,23 +141,15 @@ public void onInitialize() {
ServerLifecycleEvents.SERVER_STOPPING.register(server -> HeliosClient.saveConfig());
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register((a,b,c) -> HeliosClient.saveConfig());
ServerPlayConnectionEvents.DISCONNECT.register((handler, packetSender) -> HeliosClient.saveConfig());
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
ClientLifecycleEvents.CLIENT_STOPPING.register((client) -> {
saveConfigHook();
if (DiscordRPC.INSTANCE.isRunning) {
DiscordRPC.INSTANCE.stopPresence();
}
HeliosExecutor.shutdown();
}));

/* ConsoleAppender consoleAppender = new ConsoleAppender(CONSOLE);
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
config.addAppender(consoleAppender);
config.getRootLogger().addAppender(consoleAppender, null, null);
ctx.updateLoggers(config);
});
MC.getSession().getUsername();

*/
MC.execute(()->{
while(MC.getWindow() == null){
try {
Expand All @@ -177,4 +175,7 @@ public void registerEvents() {
EventManager.register(TickRate.INSTANCE);
EventManager.register(DamageUtils.INSTANCE);
}
public static void openConsoleScreen(){
MC.setScreen(CONSOLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public OpenConsole() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
mc.setScreen(HeliosClient.CONSOLE);
HeliosClient.openConsoleScreen();
return SINGLE_SUCCESS;
});
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/heliosclient/event/Cancelable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* This annotation indicates that an event can be canceled
* To be used over Event Class declaration
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.awt.*;

public class FontChangeEvent extends Event {

private final Font[] fonts;

public FontChangeEvent(Font[] fonts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public KeyHeldEvent(long window, int key, int scancode, int action, int modifier
this.scancode = scancode;
this.action = action;
this.modifiers = modifiers;

}

public int getKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dev.heliosclient.hud.HudElement;
import dev.heliosclient.hud.HudElementData;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.DamageUtils;
import dev.heliosclient.util.player.DamageUtils;
import dev.heliosclient.util.EntityUtils;
import dev.heliosclient.util.render.Renderer2D;
import net.minecraft.client.font.TextRenderer;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/managers/CapeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private static void saveCapeFromBase64(String UUID, String url) throws Exception
}

if (jsonElement.isJsonNull()) {
HeliosClient.LOGGER.error("UUID does not contain any capes: " + UUID + " If you are sure that this UUID should contain a cape then try other service (i.e Craftar or Minecraft capes");
HeliosClient.LOGGER.error("UUID does not contain any capes: {} If you are sure that this UUID should contain a cape then try other service (i.e Craftar or Minecraft capes", UUID);
AnimationUtils.addErrorToast("UUID does not contain any capes, Check Logs for details", true, 1500);
connection.disconnect();
throw new NullPointerException("UUID does not contain any capes");
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/dev/heliosclient/managers/KeybindManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.scripting.LuaFile;
import dev.heliosclient.scripting.LuaScriptManager;
import dev.heliosclient.ui.clickgui.ClickGUIScreen;
import dev.heliosclient.ui.notification.notifications.InfoNotification;
import dev.heliosclient.util.SoundUtils;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen;
import org.lwjgl.glfw.GLFW;

public class KeybindManager implements Listener {
Expand All @@ -30,9 +34,18 @@ public KeybindManager() {

@SubscribeEvent(priority = SubscribeEvent.Priority.HIGHEST)
public void keyPressedEvent(KeyPressedEvent event) {
if (HeliosClient.MC.currentScreen != null) return;
int key = event.getKey();

if (key == HeliosClient.CLICKGUI.clickGUIKeyBind.value && !(HeliosClient.MC.currentScreen instanceof ChatScreen) && !(HeliosClient.MC.currentScreen instanceof AbstractInventoryScreen)
&& !(HeliosClient.MC.currentScreen instanceof GameMenuScreen)) {
ClickGUIScreen.INSTANCE.onLoad();
HeliosClient.MC.setScreen(ClickGUIScreen.INSTANCE);
}
if (key == HeliosClient.CLICKGUI.consoleScreen.value) {
HeliosClient.MC.setScreen(HeliosClient.CONSOLE);
}
if (HeliosClient.MC.currentScreen != null) return;

for (Module_ module : ModuleManager.INSTANCE.modules) {
if (module.getKeybind() != null && module.getKeybind() != -1 && key == module.getKeybind()) {
if (module.toggleOnBindRelease.value) {
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/dev/heliosclient/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ public void onKey(long window, int key, int scancode, int action, int modifiers,
info.cancel();
}
}
if (key == GLFW.GLFW_KEY_RIGHT_SHIFT && !(HeliosClient.MC.currentScreen instanceof ChatScreen) && !(mc.currentScreen instanceof AbstractInventoryScreen)
&& !(mc.currentScreen instanceof GameMenuScreen)) {
ClickGUIScreen.INSTANCE.onLoad();
MinecraftClient.getInstance().setScreen(ClickGUIScreen.INSTANCE);
}
KeyHeldEvent event = new KeyHeldEvent(window, key, scancode, action, modifiers);
EventManager.postEvent(event, TimeUnit.NANOSECONDS.toMillis(1));
EventManager.postEvent(event);
if (event.isCanceled()) {
info.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.*;
import dev.heliosclient.util.InputBox;
import dev.heliosclient.util.PlayerUtils;
import dev.heliosclient.util.player.PlayerUtils;
import dev.heliosclient.util.render.Renderer2D;
import dev.heliosclient.util.render.Renderer3D;
import dev.heliosclient.util.render.color.LineColor;
import dev.heliosclient.util.render.color.QuadColor;
import me.x150.renderer.render.Renderer3d;
import net.fabricmc.loader.impl.lib.sat4j.core.Vec;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

import java.awt.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, TextRenderer
Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width - 4, 14, 2, 0.7f, borderColor);

// Render button text
float textX = x + (width/2.0f) - (Renderer2D.getFxStringWidth(text)/2.0f);
double textX = x + ((width/2.0d) - (Renderer2D.getFxStringWidth(text)/2.0d)) - 0.2f;

float textHeight = Renderer2D.getFxStringHeight();
float textY = y + (14 - textHeight) / 2; // Center the text vertically
if (Renderer2D.isVanillaRenderer()) {
textY += 1;
}
Renderer2D.drawFixedString(drawContext.getMatrices(), text, textX, textY, Color.WHITE.getRGB());
Renderer2D.drawFixedString(drawContext.getMatrices(), text,(float) textX, textY, Color.WHITE.getRGB());
}

private boolean hovered(int mouseX, int mouseY) {
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import dev.heliosclient.util.fontutils.FontUtils;
import me.x150.renderer.font.FontRenderer;
import net.minecraft.client.MinecraftClient;
import org.lwjgl.glfw.GLFW;

import java.awt.*;
import java.io.File;
Expand All @@ -33,12 +34,16 @@
import static dev.heliosclient.managers.FontManager.fonts;

/**
* Setting for ClickGUI.
* Settings for the client and ClickGUI.
*/
public class ClickGUI extends Module_ {
public static boolean pause = false;
public static boolean keybinds = false;
public SettingGroup sgMisc = new SettingGroup("Misc");
private final SettingGroup sgConfig = new SettingGroup("Config");
public SettingGroup sgTooltip = new SettingGroup("ToolTip");
public SettingGroup sgGeneral = new SettingGroup("General");
public SettingGroup sgSound = new SettingGroup("Sound");

public CycleSetting ScrollType = sgMisc.add(new CycleSetting.Builder()
.name("Scrolling System")
Expand Down Expand Up @@ -109,7 +114,19 @@ public class ClickGUI extends Module_ {
.roundingPlace(0)
.build()
);
private final SettingGroup sgConfig = new SettingGroup("Config");
public KeyBind clickGUIKeyBind = sgConfig.add(new KeyBind.Builder()
.name("ClickGUI bind")
.description("The key to open the ClickGUI screen")
.value(GLFW.GLFW_KEY_RIGHT_SHIFT)
.defaultValue(GLFW.GLFW_KEY_RIGHT_SHIFT)
.build()
);
public KeyBind consoleScreen = sgConfig.add(new KeyBind.Builder()
.name("Console Screen bind")
.description("The key to open the console / minecraft terminal screen")
.value(-1)
.build()
);
public StringSetting configPath = sgConfig.add(new StringSetting.Builder()
.name("Save Config Path")
.description("Saves current config to that path. It only saves there for temporary purposes, otherwise it selects the default HeliosClient directory")
Expand All @@ -133,7 +150,6 @@ public class ClickGUI extends Module_ {
.description("Reload or save Configs")
.build()
);
public SettingGroup sgSound = new SettingGroup("Sound");
public BooleanSetting clickGUISound = sgSound.add(new BooleanSetting.Builder()
.name("Play module toggle sound")
.description("Play ClickGUI button sound on toggling modules")
Expand All @@ -143,8 +159,6 @@ public class ClickGUI extends Module_ {
.build()
);

public SettingGroup sgTooltip = new SettingGroup("ToolTip");
public SettingGroup sgGeneral = new SettingGroup("General");
public CycleSetting TooltipMode = sgTooltip.add(new CycleSetting.Builder()
.name("Tooltip mode")
.description("Mode in what tooltips should be shown.")
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dev/heliosclient/scripting/LuaExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import dev.heliosclient.scripting.libraries.PacketLib;
import dev.heliosclient.scripting.libraries.PlayerLib;
import dev.heliosclient.util.*;
import dev.heliosclient.util.player.DamageUtils;
import dev.heliosclient.util.player.InventoryUtils;
import dev.heliosclient.util.player.PlayerUtils;
import dev.heliosclient.util.player.RotationUtils;
import dev.heliosclient.util.render.Renderer2D;
import dev.heliosclient.util.render.Renderer3D;
import net.minecraft.block.Blocks;
Expand All @@ -23,10 +27,7 @@
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
import org.luaj.vm2.lib.jse.JsePlatform;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

/**
* This class provides an execution environment for Lua scripts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import dev.heliosclient.HeliosClient;
import dev.heliosclient.module.settings.Option;
import dev.heliosclient.util.InventoryUtils;
import dev.heliosclient.util.RotationUtils;
import dev.heliosclient.util.player.InventoryUtils;
import dev.heliosclient.util.player.RotationUtils;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
Expand Down
Loading

0 comments on commit b11b785

Please sign in to comment.