From bb927a6715eb41be92d768dd22c7dcaaf5264292 Mon Sep 17 00:00:00 2001 From: Dedicate Date: Fri, 27 Dec 2024 14:01:52 +0100 Subject: [PATCH 1/4] Added TextCommand - Spawns a text hologram in front of you with custom text. Added new lines to it. And will also probably add that to AutoTexts --- .../java/pwn/noobs/trouserstreak/Trouser.java | 3 +- .../trouserstreak/commands/TextCommand.java | 83 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java diff --git a/src/main/java/pwn/noobs/trouserstreak/Trouser.java b/src/main/java/pwn/noobs/trouserstreak/Trouser.java index d9ec1172..871845d2 100644 --- a/src/main/java/pwn/noobs/trouserstreak/Trouser.java +++ b/src/main/java/pwn/noobs/trouserstreak/Trouser.java @@ -53,6 +53,7 @@ public void onInitialize() { Modules.get().add(new AutoDisplays()); Modules.get().add(new AutoNames()); Modules.get().add(new AutoTexts()); + Commands.add(new TextCommand()); Modules.get().add(new OPplayerTPmodule()); //Modules.get().add(new -----> Create Illegal things with Creative mode! <-----()); @@ -62,7 +63,7 @@ public void onInitialize() { Modules.get().add(new AirstrikePlus()); Modules.get().add(new BoomPlus()); Modules.get().add(new ExplosionAura()); - Modules.get().add(new FasterUse()); + // Modules.get().add(new FasterUse()); //Modules.get().add(new -----> Exploits for old versions! <-----()); Modules.get().add(new ShulkerDupe()); diff --git a/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java new file mode 100644 index 00000000..05ca0bce --- /dev/null +++ b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java @@ -0,0 +1,83 @@ +package pwn.noobs.trouserstreak.commands; + +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.commands.Command; +import net.minecraft.command.CommandSource; +import net.minecraft.component.ComponentChanges; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtDouble; +import net.minecraft.nbt.NbtList; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; + +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; + +public class TextCommand extends Command { + public TextCommand() { + super("text", "Spawns a text hologram with custom text in front of you. Use | for new lines."); + } + + @Override + public void build(LiteralArgumentBuilder builder) { + builder.then(argument("message", StringArgumentType.greedyString()).executes(context -> { + String text = context.getArgument("message", String.class); + String[] lines = text.split("\\|"); + for (int i = lines.length - 1; i >= 0; i--) { + spawnText(lines[i].trim(), ((lines.length - 1 - i) * 0.3) + 1); + } + return SINGLE_SUCCESS; + })); + } + + private void spawnText(String message, double yOffset) { + if (!mc.player.getAbilities().creativeMode) { + error("Creative mode required!"); + return; + } + + ItemStack armorStand = new ItemStack(Items.ARMOR_STAND); + ItemStack current = mc.player.getMainHandStack(); + Vec3d pos = mc.player.getPos().add(mc.player.getRotationVector().multiply(2)).add(0, yOffset, 0); + + var changes = ComponentChanges.builder() + .add(DataComponentTypes.CUSTOM_NAME, Text.literal(message).formatted(Formatting.WHITE)) + .add(DataComponentTypes.ENTITY_DATA, createEntityData(pos, message)) + .build(); + + armorStand.applyChanges(changes); + + BlockHitResult bhr = new BlockHitResult(pos, Direction.UP, BlockPos.ofFloored(pos), false); + mc.interactionManager.clickCreativeStack(armorStand, 36 + mc.player.getInventory().selectedSlot); + mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, bhr); + mc.interactionManager.clickCreativeStack(current, 36 + mc.player.getInventory().selectedSlot); + } + + private NbtComponent createEntityData(Vec3d pos, String text) { + NbtCompound entityTag = new NbtCompound(); + NbtList position = new NbtList(); + + position.add(NbtDouble.of(pos.x)); + position.add(NbtDouble.of(pos.y)); + position.add(NbtDouble.of(pos.z)); + + entityTag.putString("id", "minecraft:armor_stand"); + entityTag.put("Pos", position); + entityTag.putBoolean("Invisible", true); + entityTag.putBoolean("Marker", true); + entityTag.putBoolean("NoGravity", true); + entityTag.putBoolean("CustomNameVisible", true); + entityTag.putString("CustomName", "{\"text\":\"" + text + "\",\"color\":\"white\"}"); + + return NbtComponent.of(entityTag); + } +} From c99cd44b7a7fb7e56fa001e21627c39267603a7d Mon Sep 17 00:00:00 2001 From: Dedicate Date: Fri, 27 Dec 2024 14:28:43 +0100 Subject: [PATCH 2/4] Added Cool color system to TextCommand usable like #gold and #red all that kinda stuff --- .../trouserstreak/commands/TextCommand.java | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java index 05ca0bce..36445d93 100644 --- a/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java +++ b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java @@ -23,8 +23,14 @@ import static com.mojang.brigadier.Command.SINGLE_SUCCESS; public class TextCommand extends Command { + public enum ColorModes { + aqua, black, blue, dark_aqua, dark_blue, dark_gray, dark_green, + dark_purple, dark_red, gold, gray, green, italic, light_purple, + red, white, yellow + } + public TextCommand() { - super("text", "Spawns a text hologram with custom text in front of you. Use | for new lines."); + super("text", "Spawns a text hologram with custom text in front of you. Use | for new lines and #color for text color."); } @Override @@ -33,13 +39,32 @@ public void build(LiteralArgumentBuilder builder) { String text = context.getArgument("message", String.class); String[] lines = text.split("\\|"); for (int i = lines.length - 1; i >= 0; i--) { - spawnText(lines[i].trim(), ((lines.length - 1 - i) * 0.3) + 1); + String line = lines[i].trim(); + StringBuilder formattedText = new StringBuilder(); + String currentColor = "white"; + + String[] words = line.split(" "); + for (String word : words) { + if (word.startsWith("#")) { + try { + ColorModes.valueOf(word.substring(1).toLowerCase()); + currentColor = word.substring(1).toLowerCase(); + } catch (IllegalArgumentException ignored) { + formattedText.append(word).append(" "); + } + } else { + formattedText.append("{\"text\":\"").append(word).append(" \",\"color\":\"").append(currentColor).append("\"},"); + } + } + + String finalText = "[" + formattedText.substring(0, formattedText.length() - 1) + "]"; + spawnText(finalText, ((lines.length - 1 - i) * 0.3) + 1, true); } return SINGLE_SUCCESS; })); } - private void spawnText(String message, double yOffset) { + private void spawnText(String message, double yOffset, boolean isJson) { if (!mc.player.getAbilities().creativeMode) { error("Creative mode required!"); return; @@ -50,8 +75,7 @@ private void spawnText(String message, double yOffset) { Vec3d pos = mc.player.getPos().add(mc.player.getRotationVector().multiply(2)).add(0, yOffset, 0); var changes = ComponentChanges.builder() - .add(DataComponentTypes.CUSTOM_NAME, Text.literal(message).formatted(Formatting.WHITE)) - .add(DataComponentTypes.ENTITY_DATA, createEntityData(pos, message)) + .add(DataComponentTypes.ENTITY_DATA, createEntityData(pos, message, isJson)) .build(); armorStand.applyChanges(changes); @@ -62,7 +86,7 @@ private void spawnText(String message, double yOffset) { mc.interactionManager.clickCreativeStack(current, 36 + mc.player.getInventory().selectedSlot); } - private NbtComponent createEntityData(Vec3d pos, String text) { + private NbtComponent createEntityData(Vec3d pos, String text, boolean isJson) { NbtCompound entityTag = new NbtCompound(); NbtList position = new NbtList(); @@ -76,7 +100,7 @@ private NbtComponent createEntityData(Vec3d pos, String text) { entityTag.putBoolean("Marker", true); entityTag.putBoolean("NoGravity", true); entityTag.putBoolean("CustomNameVisible", true); - entityTag.putString("CustomName", "{\"text\":\"" + text + "\",\"color\":\"white\"}"); + entityTag.putString("CustomName", isJson ? text : "{\"text\":\"" + text + "\"}"); return NbtComponent.of(entityTag); } From 636f959b15c89af0562b5346de0b4807702160ed Mon Sep 17 00:00:00 2001 From: Dedicate Date: Fri, 27 Dec 2024 15:18:48 +0100 Subject: [PATCH 3/4] Added preset system to TextCommand You can still use the command normally like: .text But now also: .text save [PresetName] .text load [PresetName] The load command PresetName suggests saved presets so you can just press tab. added 2 default presets with the Mountains of Lava Inc. youtube. --- .../trouserstreak/commands/TextCommand.java | 134 +++++++++++++++--- 1 file changed, 112 insertions(+), 22 deletions(-) diff --git a/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java index 36445d93..4e8650d2 100644 --- a/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java +++ b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java @@ -2,6 +2,8 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; import meteordevelopment.meteorclient.commands.Command; import net.minecraft.command.CommandSource; import net.minecraft.component.ComponentChanges; @@ -12,14 +14,21 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtDouble; import net.minecraft.nbt.NbtList; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + import static com.mojang.brigadier.Command.SINGLE_SUCCESS; public class TextCommand extends Command { @@ -31,37 +40,118 @@ public enum ColorModes { public TextCommand() { super("text", "Spawns a text hologram with custom text in front of you. Use | for new lines and #color for text color."); + createDefaultPresets(); } @Override public void build(LiteralArgumentBuilder builder) { builder.then(argument("message", StringArgumentType.greedyString()).executes(context -> { String text = context.getArgument("message", String.class); - String[] lines = text.split("\\|"); - for (int i = lines.length - 1; i >= 0; i--) { - String line = lines[i].trim(); - StringBuilder formattedText = new StringBuilder(); - String currentColor = "white"; - - String[] words = line.split(" "); - for (String word : words) { - if (word.startsWith("#")) { - try { - ColorModes.valueOf(word.substring(1).toLowerCase()); - currentColor = word.substring(1).toLowerCase(); - } catch (IllegalArgumentException ignored) { - formattedText.append(word).append(" "); - } + spawnTextLines(text); + return SINGLE_SUCCESS; + })); + + builder.then(literal("save").then(argument("presetName", StringArgumentType.word()) + .then(argument("text", StringArgumentType.greedyString()).executes(context -> { + String presetName = context.getArgument("presetName", String.class); + String text = context.getArgument("text", String.class); + savePreset(presetName, text); + info("Saved preset: " + presetName); + return SINGLE_SUCCESS; + })))); + + builder.then(literal("load").then(argument("presetName", StringArgumentType.word()) + .suggests((context, suggestionsBuilder) -> suggestPresets(suggestionsBuilder)) + .executes(context -> { + String presetName = context.getArgument("presetName", String.class); + String text = loadPreset(presetName); + if (text != null) { + spawnTextLines(text); + info("Loaded preset: " + presetName); } else { - formattedText.append("{\"text\":\"").append(word).append(" \",\"color\":\"").append(currentColor).append("\"},"); + error("Preset not found: " + presetName); } + return SINGLE_SUCCESS; + }))); + } + + private CompletableFuture suggestPresets(SuggestionsBuilder builder) { + try { + Path presetsDir = Paths.get("TrouserStreak", "TextPresets"); + if (Files.exists(presetsDir)) { + try (Stream files = Files.list(presetsDir)) { + files.filter(path -> path.toString().endsWith(".txt")) + .map(path -> path.getFileName().toString().replace(".txt", "")) + .forEach(builder::suggest); } + } + } catch (IOException ignored) {} + return builder.buildFuture(); + } - String finalText = "[" + formattedText.substring(0, formattedText.length() - 1) + "]"; - spawnText(finalText, ((lines.length - 1 - i) * 0.3) + 1, true); + private void spawnTextLines(String text) { + String[] lines = text.split("\\|"); + for (int i = lines.length - 1; i >= 0; i--) { + String line = lines[i].trim(); + StringBuilder formattedText = new StringBuilder(); + String currentColor = "white"; + + String[] words = line.split(" "); + for (String word : words) { + if (word.startsWith("#")) { + try { + ColorModes.valueOf(word.substring(1).toLowerCase()); + currentColor = word.substring(1).toLowerCase(); + } catch (IllegalArgumentException ignored) { + formattedText.append(word).append(" "); + } + } else { + formattedText.append("{\"text\":\"").append(word).append(" \",\"color\":\"").append(currentColor).append("\"},"); + } } - return SINGLE_SUCCESS; - })); + + String finalText = "[" + formattedText.substring(0, formattedText.length() - 1) + "]"; + spawnText(finalText, ((lines.length - 1 - i) * 0.3) + 1, true); + } + } + + private void savePreset(String presetName, String text) { + try { + Path dirPath = Paths.get("TrouserStreak", "TextPresets"); + Files.createDirectories(dirPath); + Path filePath = dirPath.resolve(presetName + ".txt"); + Files.write(filePath, text.getBytes(StandardCharsets.UTF_8), + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING); + } catch (IOException e) { + error("Failed to save preset: " + e.getMessage()); + } + } + + private String loadPreset(String presetName) { + try { + Path filePath = Paths.get("TrouserStreak", "TextPresets", presetName + ".txt"); + if (Files.exists(filePath)) { + return Files.readString(filePath); + } + } catch (IOException e) { + error("Failed to load preset: " + e.getMessage()); + } + return null; + } + + private void createDefaultPresets() { + String[] defaultPresets = { + "trolled=#green [ #dark_red Trolled! #green ]|#gold Mountains of Lava Inc.|#red Youtube: #blue www.youtube.com/@mountainsoflavainc.6913|#green [ #dark_red Trolled! #green ]", + "mountains=#red Mountains Of Lava Inc.|#gold youtube.com/@mountainsoflavainc.6913" + }; + + for (String preset : defaultPresets) { + String[] parts = preset.split("=", 2); + if (!Files.exists(Paths.get("TrouserStreak", "TextPresets", parts[0] + ".txt"))) { + savePreset(parts[0], parts[1]); + } + } } private void spawnText(String message, double yOffset, boolean isJson) { From a180a1e0034bd83c522ccbb09e291408b082f03e Mon Sep 17 00:00:00 2001 From: Dedicate Date: Fri, 27 Dec 2024 15:44:10 +0100 Subject: [PATCH 4/4] Made the code look better in general since it looked bad. --- .../trouserstreak/commands/TextCommand.java | 112 ++++++++++-------- 1 file changed, 62 insertions(+), 50 deletions(-) diff --git a/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java index 4e8650d2..07f55b96 100644 --- a/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java +++ b/src/main/java/pwn/noobs/trouserstreak/commands/TextCommand.java @@ -32,6 +32,10 @@ import static com.mojang.brigadier.Command.SINGLE_SUCCESS; public class TextCommand extends Command { + private static final double LINE_SPACING = 0.3; + private static final double INITIAL_HEIGHT_OFFSET = 1.0; + private static final String PRESETS_DIRECTORY = "TrouserStreak/TextPresets"; + public enum ColorModes { aqua, black, blue, dark_aqua, dark_blue, dark_gray, dark_green, dark_purple, dark_red, gold, gray, green, italic, light_purple, @@ -45,39 +49,41 @@ public TextCommand() { @Override public void build(LiteralArgumentBuilder builder) { - builder.then(argument("message", StringArgumentType.greedyString()).executes(context -> { - String text = context.getArgument("message", String.class); - spawnTextLines(text); - return SINGLE_SUCCESS; - })); - - builder.then(literal("save").then(argument("presetName", StringArgumentType.word()) - .then(argument("text", StringArgumentType.greedyString()).executes(context -> { - String presetName = context.getArgument("presetName", String.class); - String text = context.getArgument("text", String.class); - savePreset(presetName, text); - info("Saved preset: " + presetName); - return SINGLE_SUCCESS; - })))); - - builder.then(literal("load").then(argument("presetName", StringArgumentType.word()) - .suggests((context, suggestionsBuilder) -> suggestPresets(suggestionsBuilder)) - .executes(context -> { - String presetName = context.getArgument("presetName", String.class); - String text = loadPreset(presetName); - if (text != null) { - spawnTextLines(text); - info("Loaded preset: " + presetName); - } else { - error("Preset not found: " + presetName); - } - return SINGLE_SUCCESS; - }))); + builder + .then(argument("message", StringArgumentType.greedyString()) + .executes(context -> { + spawnTextLines(context.getArgument("message", String.class)); + return SINGLE_SUCCESS; + })) + .then(literal("save") + .then(argument("presetName", StringArgumentType.word()) + .then(argument("text", StringArgumentType.greedyString()) + .executes(context -> { + String presetName = context.getArgument("presetName", String.class); + String text = context.getArgument("text", String.class); + savePreset(presetName, text); + info("Saved preset: " + presetName); + return SINGLE_SUCCESS; + })))) + .then(literal("load") + .then(argument("presetName", StringArgumentType.word()) + .suggests((context, suggestionsBuilder) -> suggestPresets(suggestionsBuilder)) + .executes(context -> { + String presetName = context.getArgument("presetName", String.class); + String text = loadPreset(presetName); + if (text != null) { + spawnTextLines(text); + info("Loaded preset: " + presetName); + } else { + error("Preset not found: " + presetName); + } + return SINGLE_SUCCESS; + }))); } private CompletableFuture suggestPresets(SuggestionsBuilder builder) { try { - Path presetsDir = Paths.get("TrouserStreak", "TextPresets"); + Path presetsDir = Paths.get(PRESETS_DIRECTORY); if (Files.exists(presetsDir)) { try (Stream files = Files.list(presetsDir)) { files.filter(path -> path.toString().endsWith(".txt")) @@ -93,31 +99,37 @@ private void spawnTextLines(String text) { String[] lines = text.split("\\|"); for (int i = lines.length - 1; i >= 0; i--) { String line = lines[i].trim(); - StringBuilder formattedText = new StringBuilder(); - String currentColor = "white"; - - String[] words = line.split(" "); - for (String word : words) { - if (word.startsWith("#")) { - try { - ColorModes.valueOf(word.substring(1).toLowerCase()); - currentColor = word.substring(1).toLowerCase(); - } catch (IllegalArgumentException ignored) { - formattedText.append(word).append(" "); - } - } else { - formattedText.append("{\"text\":\"").append(word).append(" \",\"color\":\"").append(currentColor).append("\"},"); + String formattedText = formatTextWithColors(line); + double heightOffset = ((lines.length - 1 - i) * LINE_SPACING) + INITIAL_HEIGHT_OFFSET; + spawnText(formattedText, heightOffset, true); + } + } + + private String formatTextWithColors(String line) { + StringBuilder formattedText = new StringBuilder(); + String currentColor = "white"; + String[] words = line.split(" "); + + for (String word : words) { + if (word.startsWith("#")) { + try { + ColorModes.valueOf(word.substring(1).toLowerCase()); + currentColor = word.substring(1).toLowerCase(); + } catch (IllegalArgumentException ignored) { + formattedText.append(word).append(" "); } + } else { + formattedText.append("{\"text\":\"").append(word).append(" \",\"color\":\"") + .append(currentColor).append("\"},"); } - - String finalText = "[" + formattedText.substring(0, formattedText.length() - 1) + "]"; - spawnText(finalText, ((lines.length - 1 - i) * 0.3) + 1, true); } + + return "[" + formattedText.substring(0, formattedText.length() - 1) + "]"; } private void savePreset(String presetName, String text) { try { - Path dirPath = Paths.get("TrouserStreak", "TextPresets"); + Path dirPath = Paths.get(PRESETS_DIRECTORY); Files.createDirectories(dirPath); Path filePath = dirPath.resolve(presetName + ".txt"); Files.write(filePath, text.getBytes(StandardCharsets.UTF_8), @@ -130,7 +142,7 @@ private void savePreset(String presetName, String text) { private String loadPreset(String presetName) { try { - Path filePath = Paths.get("TrouserStreak", "TextPresets", presetName + ".txt"); + Path filePath = Paths.get(PRESETS_DIRECTORY, presetName + ".txt"); if (Files.exists(filePath)) { return Files.readString(filePath); } @@ -143,12 +155,12 @@ private String loadPreset(String presetName) { private void createDefaultPresets() { String[] defaultPresets = { "trolled=#green [ #dark_red Trolled! #green ]|#gold Mountains of Lava Inc.|#red Youtube: #blue www.youtube.com/@mountainsoflavainc.6913|#green [ #dark_red Trolled! #green ]", - "mountains=#red Mountains Of Lava Inc.|#gold youtube.com/@mountainsoflavainc.6913" + "mountains=#red Mountains Of Lava Inc.|#gold youtube.com/@mountainsoflavainc.6913", }; for (String preset : defaultPresets) { String[] parts = preset.split("=", 2); - if (!Files.exists(Paths.get("TrouserStreak", "TextPresets", parts[0] + ".txt"))) { + if (!Files.exists(Paths.get(PRESETS_DIRECTORY, parts[0] + ".txt"))) { savePreset(parts[0], parts[1]); } }