Skip to content

Commit

Permalink
Fixed duplicate module groups, cape renderer and ModuleList color. A …
Browse files Browse the repository at this point in the history
…small addition to TimerUtils.every
  • Loading branch information
tanishisherewithhh committed Apr 26, 2024
1 parent 63c8b5c commit 68b6965
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 39 deletions.
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.modules
private static final Collection<String> EXAMPLES = ModuleManager.INSTANCE.getModules()
.stream()
.limit(3)
.map(module -> addQuotes(module.name))
Expand Down Expand Up @@ -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.modules.stream().map(module -> addQuotes(module.name)), builder);
return CommandSource.suggestMatching(ModuleManager.INSTANCE.getModules().stream().map(module -> addQuotes(module.name)), builder);
}

@Override
Expand Down
54 changes: 37 additions & 17 deletions src/main/java/dev/heliosclient/hud/hudelements/ModuleList.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.Module_;
import dev.heliosclient.util.ColorUtils;
import dev.heliosclient.util.TimerUtils;
import dev.heliosclient.util.render.Renderer2D;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -22,49 +24,67 @@
public class ModuleList extends HudElement implements Listener {

private ArrayList<Module_> enabledModules = ModuleManager.INSTANCE.getEnabledModules();
private Color rainbow = new Color(255, 255, 255);
private double rainbowHue1;
private double rainbowHue2;

public ModuleList() {
super(DATA);
this.width = 50;
EventManager.register(this);
} public static HudElementData<ModuleList> DATA = new HudElementData<>("Module List", "Shows enabled modules", ModuleList::new);
}

public static HudElementData<ModuleList> DATA = new HudElementData<>("Module List", "Shows enabled modules", ModuleList::new);

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
int yOffset = 0;
int totalY = 0;
int maxWidth = 0;

// Calculate the maximum width of the module names
for (Module_ m : ModuleManager.INSTANCE.modules) {
// Calculate the maximum width of the module names for enabled modules only
for (Module_ m : enabledModules) {
if (!m.showInModulesList.value) continue;
int nameWidth = Math.round(Renderer2D.getStringWidth(m.name));
maxWidth = Math.max(maxWidth, nameWidth);
totalY += Math.round(Renderer2D.getStringHeight()) + 2;
}
rainbowHue1 += 0.01f * mc.getTickDelta();
if (rainbowHue1 > 1) rainbowHue1 -= 1;
else if (rainbowHue1 < -1) rainbowHue1 += 1;

Collections.sort(enabledModules, Comparator.comparing(module -> module.name.length(), Comparator.reverseOrder()));
this.width = maxWidth + 5;
this.height = totalY + 2;

super.renderElement(drawContext, textRenderer);
rainbowHue2 = rainbowHue1;

// Render each module with a different color
this.width = maxWidth + 5;
int yOffset = this.y; // Start rendering from this.y
for (Module_ m : enabledModules) {
if (!m.showInModulesList.value) continue;

float nameWidth = Renderer2D.getStringWidth(m.name);
Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x - 7 + width - nameWidth, this.y + yOffset, nameWidth + 3, Math.round(Renderer2D.getStringHeight()) + 2, 0x66222222);

Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x - 3 + width, this.y, 2, yOffset + Math.round(Renderer2D.getStringHeight()) + 3, HeliosClient.uiColor);
// Draw a background rectangle for each module
Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(),
x - 6 + width - nameWidth, yOffset, nameWidth + 3,
Math.round(Renderer2D.getStringHeight()) + 2, 0x66222222);

// Draw a vertical separator line
Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(),
x - 2 + width, yOffset, 2,
Math.round(Renderer2D.getStringHeight()) + 3, HeliosClient.uiColor);

rainbowHue2 += 2f;
rainbow = new Color(Color.HSBtoRGB((float) rainbowHue2, 1f, 1f));
// Draw the module name
Renderer2D.drawString(drawContext.getMatrices(), m.name,
x - 4 + width - nameWidth, 1 + yOffset,
rainbow.getRGB());

Renderer2D.drawString(drawContext.getMatrices(), m.name, x - 5 + width - nameWidth, this.y + 1 + yOffset, ColorUtils.rgbaToInt(255, 255, 255, 255));
yOffset += Math.round(Renderer2D.getStringHeight()) + 2;
}
this.height =Math.max(yOffset - this.y + 2,40);
}

@SubscribeEvent
public void update(TickEvent.CLIENT event) {
enabledModules = ModuleManager.INSTANCE.getEnabledModules();
enabledModules.sort(Comparator.comparing(module -> Renderer2D.getStringWidth(module.name), Comparator.reverseOrder()));
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public PlayerModel() {
this.width = 30;
this.height = 55;
addSettingGroup(group);

}

@Override
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/heliosclient/managers/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import dev.heliosclient.module.modules.player.NoFall;
import dev.heliosclient.module.modules.render.*;
import dev.heliosclient.util.MathUtils;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;

import java.util.ArrayList;
import java.util.Set;

public class ModuleManager {
public static ModuleManager INSTANCE = new ModuleManager();

public ArrayList<Module_> modules = new ArrayList<>();
Set<Module_> modules = new ObjectArraySet<>();

public ModuleManager() {
registerModules(
Expand Down Expand Up @@ -104,4 +106,8 @@ public ArrayList<Module_> getEnabledModules() {
}
return enabledModules;
}

public Set<Module_> getModules() {
return modules;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,5 @@ public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsume
}
}
}

@ModifyVariable(method = "render*", at = @At("STORE"), ordinal = 6)
private float render(float n, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, AbstractClientPlayerEntity abstractClientPlayerEntity, float f, float g, float h, float j, float k, float l) {
return MathHelper.lerp(h, abstractClientPlayerEntity.prevBodyYaw, abstractClientPlayerEntity.bodyYaw);
}
}

11 changes: 7 additions & 4 deletions src/main/java/dev/heliosclient/module/Module_.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import dev.heliosclient.util.SoundUtils;
import dev.heliosclient.util.interfaces.ISaveAndLoad;
import dev.heliosclient.util.interfaces.ISettingChange;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import net.minecraft.client.MinecraftClient;

import java.util.*;
Expand All @@ -33,8 +34,8 @@ public abstract class Module_ implements Listener, ISettingChange, ISaveAndLoad
public String name;
public String description;
public Category category;
public List<SettingGroup> settingGroups;
public List<Setting> quickSettings;
public Set<SettingGroup> settingGroups;
public Set<Setting> quickSettings;
public boolean settingsOpen = false;
public SettingGroup sgbind = new SettingGroup("Bind");

Expand Down Expand Up @@ -98,8 +99,8 @@ public Module_(String name, String description, Category category) {
this.name = name;
this.description = description;
this.category = category;
settingGroups = new ArrayList<>(1);
quickSettings = new ArrayList<>(1);
settingGroups = new ObjectArraySet<>();
quickSettings = new ObjectArraySet<>();
}


Expand Down Expand Up @@ -251,6 +252,8 @@ public void onSettingChange(Setting<?> setting) {
public Object saveToToml(List<Object> list) {
Map<String, Object> ModuleConfig = new HashMap<>();
// Map for storing the values of each module
if(this.settingGroups == null) return ModuleConfig;

for (SettingGroup settingGroup : this.settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (!setting.shouldSaveAndLoad()) continue;
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,18 @@ public void onSettingChange(Setting setting) {
}

if (setting == switchConfigs) {
HeliosClient.saveConfig();
Config.MODULES = HeliosClient.CONFIG.MODULE_CONFIGS.get(switchConfigs.value).replace(".toml", "");
HeliosClient.loadConfig();
for (NavBarItem item : NavBarManager.INSTANCE.navBarItems) {
if (item.name.equalsIgnoreCase("ClickGUI")) {
item.target = ClickGUIScreen.INSTANCE;
//Todo: Replace with cleaner config manager
if(!HeliosClient.CONFIG.MODULE_CONFIGS.isEmpty()) {
HeliosClient.saveConfig();
Config.MODULES = HeliosClient.CONFIG.MODULE_CONFIGS.get(switchConfigs.value).replace(".toml", "");
HeliosClient.loadConfig();
for (NavBarItem item : NavBarManager.INSTANCE.navBarItems) {
if (item.name.equalsIgnoreCase("ClickGUI")) {
item.target = ClickGUIScreen.INSTANCE;
}
}
EventManager.postEvent(new FontChangeEvent(fonts));
}
EventManager.postEvent(new FontChangeEvent(fonts));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/scripting/LuaExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public LuaExecutor(MinecraftClient mc, LuaEventManager eventManager) {
globals.set("Box", CoerceJavaToLua.coerce(Box.class));
globals.set("Hand", CoerceJavaToLua.coerce(Hand.class));

for(Module_ module: ModuleManager.INSTANCE.modules){
for(Module_ module: ModuleManager.INSTANCE.getModules()){
globals.set(module.name, CoerceJavaToLua.coerce(module));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ private HudEditorScreen() {
super(Text.of("Hud editor"));
EventManager.register(this);
dragBox = new HudBox(0, 0, 0, 0);
selectedElements.clear();
}

@Override
public void onDisplayed() {
super.onDisplayed();
selectedElements.clear();
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/heliosclient/util/TimerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ public boolean every(long ms) {
resetTimer();
return getElapsedTime() >= ms / 1000.0;
}

public boolean every(long ms, Runnable task) {
if (getElapsedTime() >= ms / 1000.0) {
task.run();
resetTimer();
}
return getElapsedTime() >= ms / 1000.0;
}
}

0 comments on commit 68b6965

Please sign in to comment.