aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/chrisoft/trashyaddon/commands/MapLocateCommand.java
blob: c965b1a0e225afc046d4aba6dfc60ea93d1a41ac (plain) (blame)
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
package org.chrisoft.trashyaddon.commands;

import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import meteordevelopment.meteorclient.commands.Command;
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 java.text.Format;
import java.util.Formatter;
import java.util.OptionalInt;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

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.");
    }

    @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());
            }
            return SINGLE_SUCCESS;
        }));
    }
}