aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java')
-rw-r--r--src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java69
1 files changed, 49 insertions, 20 deletions
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 <id> [color] : highlight item frames with map #<id> 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<? extends Entity> l1 = esIF.getClientSideEntityMatches(mc.world, mc.player.getPos());
+ List<? extends Entity> 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<CommandSource> 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;
- }));
+ })));
}
}