From af39caa0684dd086907b70dce54fbbfef429027c Mon Sep 17 00:00:00 2001 From: cewiko1x <62911010+cewiko1x@users.noreply.github.com> Date: Wed, 6 May 2020 19:14:29 +0200 Subject: [PATCH] Added sorting modes and changing names --- .../impl/command/RenameModuleCommand.java | 48 +++++++++++++++++++ .../seppuku/impl/config/ModuleConfig.java | 6 +++ .../gui/hud/component/ArrayListComponent.java | 29 ++++++++++- .../impl/management/CommandManager.java | 1 + .../impl/module/movement/ElytraFlyModule.java | 8 ++-- .../seppuku/impl/module/render/HudModule.java | 6 +++ 6 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 src/main/java/me/rigamortis/seppuku/impl/command/RenameModuleCommand.java diff --git a/src/main/java/me/rigamortis/seppuku/impl/command/RenameModuleCommand.java b/src/main/java/me/rigamortis/seppuku/impl/command/RenameModuleCommand.java new file mode 100644 index 0000000..51d16aa --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/impl/command/RenameModuleCommand.java @@ -0,0 +1,48 @@ +package me.rigamortis.seppuku.impl.command; + +import me.rigamortis.seppuku.Seppuku; +import me.rigamortis.seppuku.api.command.Command; +import me.rigamortis.seppuku.api.module.Module; +import net.minecraft.client.Minecraft; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.play.client.CPacketCreativeInventoryAction; + +/** + * Author Ice + * 5/06/2020 @ 18:14 PM. + */ +public final class RenameModuleCommand extends Command { + + public RenameModuleCommand() { + super("RenameModule", new String[]{"rm", "renamemod", "renamemodule"}, "Rename modules.", "Enchant ([true/false] Disable Curses)"); + } + + @Override + public void exec(String input) { + if (!this.clamp(input, 3, 3)) { + this.printUsage(); + return; + } + + final String[] split = input.split(" "); + + final String originalModuleName = split[1]; + final String newModuleName = split[2]; + + if(Seppuku.INSTANCE.getModuleManager().find(originalModuleName) != null) { + Module mod = Seppuku.INSTANCE.getModuleManager().find(originalModuleName); + + mod.setDisplayName(newModuleName); + Seppuku.INSTANCE.logChat("Set " + originalModuleName + " custom alias to " + newModuleName); + } else { + Seppuku.INSTANCE.logChat(originalModuleName + " does not exist!"); + } + + + + } +} + diff --git a/src/main/java/me/rigamortis/seppuku/impl/config/ModuleConfig.java b/src/main/java/me/rigamortis/seppuku/impl/config/ModuleConfig.java index 44086fc..d0ca6cb 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/config/ModuleConfig.java +++ b/src/main/java/me/rigamortis/seppuku/impl/config/ModuleConfig.java @@ -36,6 +36,11 @@ public class ModuleConfig extends Configurable { if (entry.getKey().equalsIgnoreCase("Keybind")) { module.setKey(entry.getValue().getAsString()); } + + if (entry.getKey().equalsIgnoreCase("Alias")) { + module.setDisplayName(entry.getValue().getAsString()); + } + // Check if we are already enabled if (entry.getKey().equalsIgnoreCase("Enabled") && !module.isEnabled() && module.getType() != Module.ModuleType.HIDDEN) { if (entry.getValue().getAsBoolean()) { @@ -67,6 +72,7 @@ public class ModuleConfig extends Configurable { public void onSave() { JsonObject moduleJsonObject = new JsonObject(); moduleJsonObject.addProperty("Name", module.getDisplayName()); + moduleJsonObject.addProperty("Alias", module.getCustomAlias()); moduleJsonObject.addProperty("Color", Integer.toHexString(module.getColor()).toUpperCase()); moduleJsonObject.addProperty("Hidden", module.isHidden()); moduleJsonObject.addProperty("Keybind", (module.getKey() != null) ? module.getKey() : "NONE"); diff --git a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/ArrayListComponent.java b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/ArrayListComponent.java index 12d300f..cb871d8 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/ArrayListComponent.java +++ b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/ArrayListComponent.java @@ -4,12 +4,15 @@ import com.mojang.realmsclient.gui.ChatFormatting; import me.rigamortis.seppuku.Seppuku; import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent; import me.rigamortis.seppuku.api.module.Module; +import me.rigamortis.seppuku.impl.module.render.HudModule; import net.minecraft.client.Minecraft; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import static me.rigamortis.seppuku.impl.module.render.HudModule.Mode.*; + /** * Author Seth * 7/25/2019 @ 7:24 AM. @@ -39,7 +42,28 @@ public final class ArrayListComponent extends DraggableHudComponent { return dif != 0 ? (int) dif : secondName.compareTo(firstName); }; - mods.sort(comparator); + final Comparator lengthComparator = (first, second) -> { + final String firstName = first.getDisplayName() + (first.getMetaData() != null ? " " + ChatFormatting.GRAY + "[" + ChatFormatting.WHITE + first.getMetaData().toLowerCase() + ChatFormatting.GRAY + "]" : ""); + final String secondName = second.getDisplayName() + (second.getMetaData() != null ? " " + ChatFormatting.GRAY + "[" + ChatFormatting.WHITE + second.getMetaData().toLowerCase() + ChatFormatting.GRAY + "]" : ""); + final float dif = Minecraft.getMinecraft().fontRenderer.getStringWidth(secondName) - Minecraft.getMinecraft().fontRenderer.getStringWidth(firstName); + return dif != 0 ? (int) dif : secondName.compareTo(firstName); + }; + + final Comparator alphabeticalComparator = (first, second) -> { + final String firstName = first.getDisplayName() + (first.getMetaData() != null ? " " + ChatFormatting.GRAY + "[" + ChatFormatting.WHITE + first.getMetaData().toLowerCase() + ChatFormatting.GRAY + "]" : ""); + final String secondName = second.getDisplayName() + (second.getMetaData() != null ? " " + ChatFormatting.GRAY + "[" + ChatFormatting.WHITE + second.getMetaData().toLowerCase() + ChatFormatting.GRAY + "]" : ""); + return firstName.compareToIgnoreCase(secondName); + }; + + + Object sorting_mode = Seppuku.INSTANCE.getModuleManager().find(HudModule.class).find("Sorting Mode").getValue(); + if (LENGTH.equals(sorting_mode)) { + mods.sort(lengthComparator); + } else if (ALPHABET.equals(sorting_mode)) { + mods.sort(alphabeticalComparator); + } else if (UNSORTED.equals(sorting_mode)) { + + } float xOffset = 0; float yOffset = 0; @@ -47,7 +71,8 @@ public final class ArrayListComponent extends DraggableHudComponent { for (Module mod : mods) { if (mod != null && mod.getType() != Module.ModuleType.HIDDEN && mod.isEnabled() && !mod.isHidden()) { - final String name = mod.getDisplayName() + (mod.getMetaData() != null ? " " + ChatFormatting.GRAY + "[" + ChatFormatting.WHITE + mod.getMetaData().toLowerCase() + ChatFormatting.GRAY + "]" : ""); + + String name = (Boolean)Seppuku.INSTANCE.getModuleManager().find(HudModule.class).find("Custom Aliases").getValue() ? mod.getCustomAlias() != null ? mod.getCustomAlias() : mod.getDisplayName() + (mod.getMetaData() != null ? " " + ChatFormatting.GRAY + "[" + ChatFormatting.WHITE + mod.getMetaData().toLowerCase() + ChatFormatting.GRAY + "]" : "") : mod.getDisplayName() + (mod.getMetaData() != null ? " " + ChatFormatting.GRAY + "[" + ChatFormatting.WHITE + mod.getMetaData().toLowerCase() + ChatFormatting.GRAY + "]" : ""); final float width = Minecraft.getMinecraft().fontRenderer.getStringWidth(name); diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java index 6137d20..db09cad 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/CommandManager.java @@ -60,6 +60,7 @@ public final class CommandManager { this.commandList.add(new JoinDateCommand()); this.commandList.add(new EnchantCommand()); this.commandList.add(new RenameCommand()); + this.commandList.add(new RenameModuleCommand()); this.commandList.add(new SpawnEggCommand()); this.commandList.add(new StackSizeCommand()); this.commandList.add(new CrashSlimeCommand()); diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/movement/ElytraFlyModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/movement/ElytraFlyModule.java index 2552c5c..5799c2c 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/movement/ElytraFlyModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/movement/ElytraFlyModule.java @@ -163,13 +163,15 @@ public final class ElytraFlyModule extends Module { break; case CONTROL: final double[] directionSpeedControl = MathUtil.directionSpeed(this.speed.getValue()); - mc.player.motionY = -this.idlefall.getValue(); + + // TODO + // mc.player.motionY = -this.idlefall.getValue(); mc.player.motionX = 0; mc.player.motionZ = 0; if (mc.player.movementInput.jump) { - mc.player.motionY = this.upspd.getValue(); + // mc.player.motionY = this.upspd.getValue(); } else if (mc.player.movementInput.sneak) { - mc.player.motionY = -this.downspd.getValue(); + // mc.player.motionY = -this.downspd.getValue(); } if (mc.player.movementInput.moveStrafe != 0 || mc.player.movementInput.moveForward != 0) { mc.player.motionX = directionSpeedControl[0]; diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java index fce1f96..a532920 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java @@ -9,6 +9,7 @@ import me.rigamortis.seppuku.api.module.Module; import me.rigamortis.seppuku.api.value.Value; import me.rigamortis.seppuku.impl.gui.hud.GuiHudEditor; import me.rigamortis.seppuku.impl.gui.hud.anchor.AnchorPoint; +import me.rigamortis.seppuku.impl.module.movement.FlightModule; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; @@ -19,6 +20,7 @@ import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; */ public final class HudModule extends Module { + public final Value mode = new Value("Sorting Mode", new String[]{"Sorting", "sort"}, "Changes arraylist sorting.", HudModule.Mode.LENGTH); public final Value hidePotions = new Value("HidePotions", new String[]{"HidePotions", "HidePots", "Hide_Potions"}, "Hides the Vanilla potion hud (at the top right of the screen).", true); public HudModule() { @@ -68,4 +70,8 @@ public final class HudModule extends Module { event.setCanceled(true); } } + + public enum Mode { + LENGTH, ALPHABET, UNSORTED; + } }