Skip to content

Commit

Permalink
Now with less bugs! and common reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Jul 3, 2024
1 parent 5dad609 commit ae88443
Show file tree
Hide file tree
Showing 106 changed files with 779 additions and 996 deletions.
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

//Should we remove this?
//I mean we do use it for saving configs but it can be easily replaced

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"


//Renderer 1.20.4 library
//TODO: Move to 1.20.6
include modImplementation("com.github.0x3C50:Renderer:aa67e1c979")
Expand All @@ -70,17 +72,12 @@ dependencies {
// LuaJ library
modInclude("org.luaj:luaj-jse:3.0.1")

// TOML parser
modInclude('com.moandjiezana.toml:toml4j:0.7.2')

// ModMenu
modApi "com.terraformersmc:modmenu:${project.modmenu_version}"

// Discord GameSDK
modInclude('com.github.JnCrMx:discord-game-sdk4j:v0.5.5')

// shadow project(":launch")
// library "de.florianmichael:WaybackAuthLib:1.0.0"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public static void loadConfig() {
load(config -> {
CONFIG.loadEverything();
LOGGER.info("Loading Config complete in: {}s", configTimer.getElapsedTime());

String configSelectedbefore = (String) CONFIG.otherConfigManager.getCurrentConfig().getReadData().get(CLICKGUI.switchConfigs.getSaveName());
if (configSelectedbefore != null) {
CONFIG.getModuleConfigManager().switchConfig(configSelectedbefore, false);
loadModulesOnly();
}
});
}

Expand All @@ -80,7 +86,7 @@ private static void load(Consumer<Config> consumer) {
public static void loadModulesOnly() {
load(config -> {
CONFIG.getModuleConfigManager().load();
CONFIG.load();
CONFIG.loadModules();

LOGGER.info("Loading Module config complete in: {}s", configTimer.getElapsedTime());
});
Expand Down Expand Up @@ -166,6 +172,8 @@ public void onInitialize() {
DiscordRPC.INSTANCE.stopPresence();
}
});
//Saving is also handled in MixinCrashReport and ClickGUI.java


MC.execute(() -> {
while (MC.getWindow() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
}
}

ChatUtils.sendHeliosMsg(ColorUtils.red + "Script of name {"+ scriptname +"} not found");
ChatUtils.sendHeliosMsg(ColorUtils.red + "Script of name {" + scriptname + "} not found");
return SINGLE_SUCCESS;
}));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/event/events/TickEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static class PLAYER extends TickEvent {

private PlayerEntity player;

public static PLAYER get(PlayerEntity player){
public static PLAYER get(PlayerEntity player) {
INSTANCE.player = player;
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import dev.heliosclient.event.Cancelable;
import dev.heliosclient.event.Event;
import dev.heliosclient.event.LuaEvent;
import net.minecraft.block.BlockState;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;

/**
* Event fired on block interaction.
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/dev/heliosclient/hud/HudElement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.heliosclient.hud;

import com.moandjiezana.toml.Toml;
import dev.heliosclient.HeliosClient;
import dev.heliosclient.event.SubscribeEvent;
import dev.heliosclient.event.events.TickEvent;
Expand All @@ -14,6 +13,7 @@
import dev.heliosclient.ui.clickgui.gui.HudBox;
import dev.heliosclient.ui.clickgui.hudeditor.HudEditorScreen;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.MathUtils;
import dev.heliosclient.util.interfaces.ISaveAndLoad;
import dev.heliosclient.util.interfaces.ISettingChange;
import dev.heliosclient.util.render.Renderer2D;
Expand Down Expand Up @@ -59,20 +59,18 @@ public class HudElement implements ISettingChange, ISaveAndLoad, Listener {
public SettingGroup sgUI = new SettingGroup("UI");
public boolean isInHudEditor = false;
public UniqueID id;
int startX, startY, snapSize = 120;


// Default settings
// This is a lot of complete customisation.
// Todo: Add radius setting for rounded background

public BooleanSetting renderBg = sgUI.add(new BooleanSetting.Builder()
.name("Render background")
.description("Render the background for the element")
.value(false)
.defaultValue(false)
.onSettingChange(this)
.build());


// Default settings
// This is a lot of complete customisation.
// Todo: Add radius setting for rounded background
public BooleanSetting rounded = sgUI.add(new BooleanSetting.Builder()
.name("Rounded background")
.description("Rounds the background of the element for better visuals")
Expand Down Expand Up @@ -124,7 +122,6 @@ public class HudElement implements ISettingChange, ISaveAndLoad, Listener {
.shouldRender(() -> shadow.value && renderBg.value)
.onSettingChange(this)
.build());

public BooleanSetting syncShadowColorAsBackground = sgUI.add(new BooleanSetting.Builder()
.name("Sync Background color to shadow")
.description("Syncs shadow color with background color")
Expand All @@ -140,6 +137,7 @@ public class HudElement implements ISettingChange, ISaveAndLoad, Listener {
.shouldRender(() -> shadow.value && !syncShadowColorAsBackground.value && renderBg.value)
.onSettingChange(this)
.build());
int startX, startY, snapSize = 120;


public HudElement(HudElementData<?> hudElementInfo) {
Expand Down Expand Up @@ -327,13 +325,13 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
private void drawBackground(DrawContext drawContext, Color bgStart, Color bgEnd, Color finalShadowColor) {
if (rounded.value) {
if (shadow.value) {
Renderer2D.drawRoundedGradientRectangleWithShadow(drawContext.getMatrices(), hudBox.getX(), hudBox.getY(), hudBox.getWidth() - 1.9f, hudBox.getHeight(), bgStart, bgEnd, bgEnd, bgStart, 2, (int)shadowRadius.value, finalShadowColor);
Renderer2D.drawRoundedGradientRectangleWithShadow(drawContext.getMatrices(), hudBox.getX(), hudBox.getY(), hudBox.getWidth() - 1.9f, hudBox.getHeight(), bgStart, bgEnd, bgEnd, bgStart, 2, (int) shadowRadius.value, finalShadowColor);
} else {
Renderer2D.drawRoundedGradientRectangle(drawContext.getMatrices().peek().getPositionMatrix(), bgStart, bgEnd, bgEnd, bgStart, hudBox.getX(), hudBox.getY(), hudBox.getWidth() - 1.9f, hudBox.getHeight(), 2);
}
} else {
if (shadow.value) {
Renderer2D.drawGradientWithShadow(drawContext.getMatrices(), hudBox.getX(), hudBox.getY(), hudBox.getWidth() - 1.9f, hudBox.getHeight(), (int)shadowRadius.value, bgStart.getRGB(), bgEnd.getRGB(), finalShadowColor, Renderer2D.Direction.LEFT_RIGHT);
Renderer2D.drawGradientWithShadow(drawContext.getMatrices(), hudBox.getX(), hudBox.getY(), hudBox.getWidth() - 1.9f, hudBox.getHeight(), (int) shadowRadius.value, bgStart.getRGB(), bgEnd.getRGB(), finalShadowColor, Renderer2D.Direction.LEFT_RIGHT);
} else {
Renderer2D.drawGradient(drawContext.getMatrices().peek().getPositionMatrix(), hudBox.getX(), hudBox.getY(), hudBox.getWidth() - 1.9f, hudBox.getHeight(), bgStart.getRGB(), bgEnd.getRGB(), Renderer2D.Direction.LEFT_RIGHT);
}
Expand All @@ -360,6 +358,7 @@ public void onTick(TickEvent.CLIENT e) {
public void addSettingGroup(SettingGroup settingGroup) {
settingGroups.add(settingGroup);
}

/**
* Removes a setting group to the setting groups list
*
Expand Down Expand Up @@ -464,12 +463,12 @@ public Object saveToFile(List<Object> objects) {
objects.add(width);
objects.add(height);

map.put("positions", objects);
map.put("dimensions", objects);

for (SettingGroup settingGroup : settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (setting.name != null) {
map.put(setting.name.replace(" ", ""), setting.saveToFile(new ArrayList<>()));
map.put(setting.getSaveName(), setting.saveToFile(new ArrayList<>()));
}
}
}
Expand All @@ -479,11 +478,11 @@ public Object saveToFile(List<Object> objects) {

@Override
public void loadFromFile(Map<String, Object> MAP) {
List<Object> obj = (List<Object>) MAP.get("positions");
this.x = Integer.parseInt(obj.get(0).toString());
this.y = Integer.parseInt(obj.get(1).toString());
this.width = Integer.parseInt(obj.get(2).toString());
this.height = Integer.parseInt(obj.get(3).toString());
List<Double> obj = (List<Double>) MAP.get("dimensions");
this.x = MathUtils.d2iSafe(obj.get(0));
this.y = MathUtils.d2iSafe(obj.get(1));
this.width = MathUtils.d2iSafe(obj.get(2));
this.height = MathUtils.d2iSafe(obj.get(3));
this.distanceX = x;
this.distanceY = y;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/dev/heliosclient/hud/HudElementList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.heliosclient.hud.hudelements.*;
import dev.heliosclient.ui.clickgui.hudeditor.HudCategoryPane;
import net.minecraft.screen.GenericContainerScreenHandler;

import java.util.Map;
import java.util.TreeMap;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/dev/heliosclient/hud/hudelements/Bps.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@


public class Bps extends HudElement {
public static HudElementData<Bps> DATA = new HudElementData<>("Player Speed", "Shows player speed in blocks per second", Bps::new);

public Bps() {
super(DATA);
this.width = 40;
this.height = Math.round(Renderer2D.getStringHeight());
}
} public static HudElementData<Bps> DATA = new HudElementData<>("Player Speed", "Shows player speed in blocks per second", Bps::new);

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
Expand All @@ -41,5 +39,4 @@ private double moveSpeed() {




}
11 changes: 5 additions & 6 deletions src/main/java/dev/heliosclient/hud/hudelements/ClientTag.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.heliosclient.hud.hudelements;

import dev.heliosclient.HeliosClient;
import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.hud.HudElement;
import dev.heliosclient.hud.HudElementData;
import dev.heliosclient.managers.ColorManager;
Expand All @@ -11,16 +10,13 @@

public class ClientTag extends HudElement {

public static HudElementData<ClientTag> DATA = new HudElementData<>("Client Tag", "Shows client watermark", ClientTag::new);


public ClientTag() {
super(DATA);
this.width = 20;
this.height = Math.round(Renderer2D.getStringHeight());
this.draggable = false;
this.renderOutLineBox = false;
}
} public static HudElementData<ClientTag> DATA = new HudElementData<>("Client Tag", "Shows client watermark", ClientTag::new);

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
Expand All @@ -31,4 +27,7 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {

super.renderElement(drawContext, textRenderer);
Renderer2D.drawString(drawContext.getMatrices(), text, this.x, this.y, ColorManager.INSTANCE.hudColor);
}}
}


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.heliosclient.hud.hudelements;

import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.hud.HudElement;
import dev.heliosclient.hud.HudElementData;
import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.system.TickRate;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.MathUtils;
Expand Down Expand Up @@ -97,15 +97,15 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {

}

public static HudElementData<CompactData> DATA = new HudElementData<>("CompactData", "Displays data in compact manner", CompactData::new);

private double moveSpeed() {
if (mc.player == null) {
return 0;
}
Vec3d move = new Vec3d(mc.player.getX() - mc.player.prevX, 0, mc.player.getZ() - mc.player.prevZ).multiply(20);

return Math.abs(MathUtils.length2D(move));
}
} public static HudElementData<CompactData> DATA = new HudElementData<>("CompactData", "Displays data in compact manner", CompactData::new);



}
30 changes: 15 additions & 15 deletions src/main/java/dev/heliosclient/hud/hudelements/CompassHud.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.heliosclient.hud.hudelements;

import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.hud.HudElement;
import dev.heliosclient.hud.HudElementData;
import dev.heliosclient.managers.ColorManager;
import dev.heliosclient.module.settings.BooleanSetting;
import dev.heliosclient.module.settings.DoubleSetting;
import dev.heliosclient.module.settings.RGBASetting;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class CompassHud extends HudElement {
.roundingPlace(1)
.defaultValue(0.7d)
.onSettingChange(this)
.shouldRender(()->renderEllipse.value)
.shouldRender(() -> renderEllipse.value)
.build()
);
public RGBASetting compassColor = sgGeneral.add(new RGBASetting.Builder()
Expand All @@ -71,7 +71,7 @@ public class CompassHud extends HudElement {
.defaultValue(Color.WHITE)
.value(Color.WHITE)
.onSettingChange(this)
.shouldRender(()->renderEllipse.value)
.shouldRender(() -> renderEllipse.value)
.build()
);

Expand All @@ -88,28 +88,28 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
this.width = (int) (xRad.value * 2 + Renderer2D.getStringHeight());
this.height = (int) (yRad.value * 2 + Renderer2D.getStringHeight() + 1);

if(snapToCrosshair.value){
this.x = mc.getWindow().getScaledWidth()/2 - this.width/2;
this.y = mc.getWindow().getScaledHeight()/2 - this.height/2 ;
if (snapToCrosshair.value) {
this.x = mc.getWindow().getScaledWidth() / 2 - this.width / 2;
this.y = mc.getWindow().getScaledHeight() / 2 - this.height / 2;
}

super.renderElement(drawContext, textRenderer);

// Calculate player orientation (yaw) in radians
double yawRadians = Math.toRadians(90);
if(mc.player != null){
if (mc.player != null) {
yawRadians = Math.toRadians(mc.player.getYaw(mc.getTickDelta()));
}

int centerX = this.x + this.width / 2;
int centerY = this.y + this.height / 2;

// Draw a circular radar around the cross-hair
if(renderEllipse.value)
Renderer2d.renderEllipseOutline(drawContext.getMatrices(), compassColor.value,centerX,centerY,xRad.value,yRad.value,outlineWidth.value,outlineWidth.value,360);
if (renderEllipse.value)
Renderer2d.renderEllipseOutline(drawContext.getMatrices(), compassColor.value, centerX, centerY, xRad.value, yRad.value, outlineWidth.value, outlineWidth.value, 360);

// Draw cardinal direction indicators
double quarterPI = Math.PI / 2.0;
double quarterPI = Math.PI / 2.0;
for (int i = 0; i < 4; i++) {
double angle = yawRadians + i * quarterPI; // Rotate by 90 degrees
float x = (float) (centerX + xRad.value * Math.cos(angle)) - 3;
Expand All @@ -121,11 +121,11 @@ public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
}

private String getCardinalDirection(int i) {
return switch (i){
case 0-> "E";
case 1-> "N";
case 2-> "W";
case 3-> "S";
return switch (i) {
case 0 -> "E";
case 1 -> "N";
case 2 -> "W";
case 3 -> "S";
default -> "N";
};
}
Expand Down
Loading

0 comments on commit ae88443

Please sign in to comment.