From 04b4941e65693f8d6b55f924781d7dd7cd26b1d5 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 18 May 2024 01:24:05 -0400 Subject: commands: EntityHighlight, improved MapLocate. --- .../trashyaddon/commands/MapLocateCommand.java | 69 +++++++++++++++------- 1 file changed, 49 insertions(+), 20 deletions(-) (limited to 'src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java') diff --git a/src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java b/src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java index c965b1a..a96b52b 100644 --- a/src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java +++ b/src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java @@ -1,43 +1,72 @@ package org.chrisoft.trashyaddon.commands; +import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; import meteordevelopment.meteorclient.commands.Command; +import meteordevelopment.meteorclient.utils.render.color.Color; import net.minecraft.command.CommandSource; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import org.chrisoft.trashyaddon.commands.argument.CEntityArgumentType; +import org.chrisoft.trashyaddon.commands.argument.ColorCodeArgumentType; -import java.text.Format; import java.util.Formatter; -import java.util.OptionalInt; +import java.util.List; +import java.util.stream.Stream; import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +/* +Usage: +ml [color] : highlight item frames with map # using [color] (defaults to bright magenta) +Note: Use .eh clear to remove highlight from all item frames. + */ + public class MapLocateCommand extends Command { private final MinecraftClient mc = MinecraftClient.getInstance(); public MapLocateCommand() { - super("ml", "Find item frames with a certain map in them. Will eventually be replaced with an enhanced ESP module."); + super("ml", "Locate item frames with a specific map."); + } + + private void exec(int id, Color color) { + try { + CEntityArgumentType dummyArgIF = CEntityArgumentType.entities(); + CEntitySelector esIF = dummyArgIF.parse(new StringReader(new Formatter().format("@e[type=minecraft:item_frame,nbt={Item:{tag:{map:%d}}}]", id).toString())); + CEntityArgumentType dummyArgGIF = CEntityArgumentType.entities(); + CEntitySelector esGIF = dummyArgGIF.parse(new StringReader(new Formatter().format("@e[type=minecraft:glow_item_frame,nbt={Item:{tag:{map:%d}}}]", id).toString())); + List l1 = esIF.getClientSideEntityMatches(mc.world, mc.player.getPos()); + List l2 = esGIF.getClientSideEntityMatches(mc.world, mc.player.getPos()); + if (l1.isEmpty() && l2.isEmpty()) { + info(Text.literal(new Formatter().format("Map #%d not found", id).toString()).setStyle(Style.EMPTY.withColor(Formatting.RED))); + return; + } + info(new Formatter().format("Map #%d found at:", id).toString()); + Stream.concat(l1.stream(), l2.stream()).forEach(e -> { + EntityHighlightCommand.setEntityColor(e, color); + info(new Formatter().format(" %.1f %.1f %.1f", e.getPos().x, e.getPos().y, e.getPos().z).toString()); + }); + } catch (CommandSyntaxException e) { + error("This should never happen. The author of this garbage is probably an idiot."); + } } @Override public void build(LiteralArgumentBuilder builder) { - builder.then(argument("id", IntegerArgumentType.integer()).executes(context -> { - int targetID = IntegerArgumentType.getInteger(context, "id"); - for (Entity e : mc.world.getEntities()) { - if (e.getType() != EntityType.ITEM_FRAME && e.getType() != EntityType.GLOW_ITEM_FRAME) - continue; - ItemFrameEntity ife = (ItemFrameEntity) e; - OptionalInt oid = ife.getMapId(); - if (oid.isEmpty()) - continue; - int id = oid.getAsInt(); - Formatter fmt = new Formatter(); - if (id == targetID) - info(fmt.format("Map frame found at %.2f %.2f %.2f", ife.getPos().x, ife.getPos().y, ife.getPos().z).toString()); - } + builder.then(argument("id", IntegerArgumentType.integer()).executes(ctx -> { + int targetID = IntegerArgumentType.getInteger(ctx, "id"); + Color color = new Color(0xff7fff); + exec(targetID, color); + return SINGLE_SUCCESS; + }).then(argument("color", ColorCodeArgumentType.colorCode()).executes(ctx -> { + int targetID = IntegerArgumentType.getInteger(ctx, "id"); + Color color = ctx.getArgument("color", Color.class); + exec(targetID, color); return SINGLE_SUCCESS; - })); + }))); } } -- cgit v1.2.3