1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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.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 <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", "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(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;
})));
}
}
|