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.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.util.Formatter; 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", "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(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; }))); } }