Fixed player rotator and added a follow patern.

This commit is contained in:
trouper
2024-05-09 07:28:32 -05:00
parent 0b7bae081c
commit 1c1568c037
3 changed files with 116 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import io.netty.util.concurrent.CompleteFuture;
import me.trouper.butler.modules.SwarmPlusMaster; import me.trouper.butler.modules.SwarmPlusMaster;
import me.trouper.butler.server.Connection; import me.trouper.butler.server.Connection;
import me.trouper.butler.utils.MathUtils; import me.trouper.butler.utils.MathUtils;
@@ -25,6 +26,7 @@ import net.minecraft.util.math.BlockPos;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.*;
import static com.mojang.brigadier.Command.SINGLE_SUCCESS; import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
@@ -33,6 +35,8 @@ public class SwarmManager extends Command {
super("manager", "Sends a message."); super("manager", "Sends a message.");
} }
private static boolean circling = false;
@Override @Override
public void build(LiteralArgumentBuilder<CommandSource> builder) { public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("chat") builder.then(literal("chat")
@@ -84,6 +88,7 @@ public class SwarmManager extends Command {
} }
Module m = ModuleArgumentType.get(context); Module m = ModuleArgumentType.get(context);
SwarmPlusMaster.swarmServer.broadcast("[METEOR] toggle " + m.name); SwarmPlusMaster.swarmServer.broadcast("[METEOR] toggle " + m.name);
this.info("Toggled (highlight)%s(default) for all swarm members.",m.name);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
}).then(literal("on") }).then(literal("on")
.executes(context -> { .executes(context -> {
@@ -93,6 +98,7 @@ public class SwarmManager extends Command {
} }
Module m = ModuleArgumentType.get(context); Module m = ModuleArgumentType.get(context);
SwarmPlusMaster.swarmServer.broadcast("[METEOR] toggle " + m.name + " on"); SwarmPlusMaster.swarmServer.broadcast("[METEOR] toggle " + m.name + " on");
this.info("Toggled (highlight)%s(default) on for all swarm members.",m.name);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
})) }))
.then(literal("off") .then(literal("off")
@@ -103,6 +109,7 @@ public class SwarmManager extends Command {
} }
Module m = ModuleArgumentType.get(context); Module m = ModuleArgumentType.get(context);
SwarmPlusMaster.swarmServer.broadcast("[METEOR] toggle " + m.name + " off"); SwarmPlusMaster.swarmServer.broadcast("[METEOR] toggle " + m.name + " off");
this.info("Toggled (highlight)%s(default) off for all swarm members.",m.name);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
})) }))
) )
@@ -121,7 +128,7 @@ public class SwarmManager extends Command {
String value = SettingValueArgumentType.get(context); String value = SettingValueArgumentType.get(context);
SwarmPlusMaster.swarmServer.broadcast("[METEOR] settings %s %s %s".formatted(module.name,setting.name,value)); SwarmPlusMaster.swarmServer.broadcast("[METEOR] settings %s %s %s".formatted(module.name,setting.name,value));
ModuleArgumentType.get(context).info("Setting %s changed in %s to %s for all swarm members.", module.title, setting.title, value); ModuleArgumentType.get(context).info("Setting (highlight)%s(default) changed in (highlight)%s(default) to (highlight)%s(default) for all swarm members.", module.title, setting.title, value);
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
})) }))
@@ -135,6 +142,10 @@ public class SwarmManager extends Command {
info("How did we get here?"); info("How did we get here?");
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
} }
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
int rad = context.getArgument("radius",Integer.class); int rad = context.getArgument("radius",Integer.class);
int n = SwarmPlusMaster.swarmServer.connectionCount(); int n = SwarmPlusMaster.swarmServer.connectionCount();
Point2D.Double[] distribution = MathUtils.distributePoints(MeteorClient.mc.player.getX(),MeteorClient.mc.player.getZ(),rad,n); Point2D.Double[] distribution = MathUtils.distributePoints(MeteorClient.mc.player.getX(),MeteorClient.mc.player.getZ(),rad,n);
@@ -151,6 +162,10 @@ public class SwarmManager extends Command {
) )
.then(literal("here") .then(literal("here")
.executes(context -> { .executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
int roundX = (int) Math.round(MeteorClient.mc.player.getX()); int roundX = (int) Math.round(MeteorClient.mc.player.getX());
int roundY = (int) Math.round(MeteorClient.mc.player.getY()); int roundY = (int) Math.round(MeteorClient.mc.player.getY());
int roundZ = (int) Math.round(MeteorClient.mc.player.getZ()); int roundZ = (int) Math.round(MeteorClient.mc.player.getZ());
@@ -164,6 +179,10 @@ public class SwarmManager extends Command {
}) })
.then(argument("target",StringArgumentType.string()) .then(argument("target",StringArgumentType.string())
.executes(context -> { .executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
String target = StringArgumentType.getString(context,"target"); String target = StringArgumentType.getString(context,"target");
int roundX = (int) Math.round(MeteorClient.mc.player.getX()); int roundX = (int) Math.round(MeteorClient.mc.player.getX());
int roundY = (int) Math.round(MeteorClient.mc.player.getY()); int roundY = (int) Math.round(MeteorClient.mc.player.getY());
@@ -184,6 +203,10 @@ public class SwarmManager extends Command {
) )
.then(literal("goto") .then(literal("goto")
.then(argument("y", IntegerArgumentType.integer()).executes(context -> { .then(argument("y", IntegerArgumentType.integer()).executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoy %s".formatted( SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoy %s".formatted(
IntegerArgumentType.getInteger(context,"y") IntegerArgumentType.getInteger(context,"y")
)); ));
@@ -195,6 +218,10 @@ public class SwarmManager extends Command {
.then(argument("x",IntegerArgumentType.integer()) .then(argument("x",IntegerArgumentType.integer())
.then(argument("z",IntegerArgumentType.integer()) .then(argument("z",IntegerArgumentType.integer())
.executes(context -> { .executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoxz %s %s".formatted( SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoxz %s %s".formatted(
IntegerArgumentType.getInteger(context,"x"), IntegerArgumentType.getInteger(context,"x"),
IntegerArgumentType.getInteger(context,"z") IntegerArgumentType.getInteger(context,"z")
@@ -208,6 +235,10 @@ public class SwarmManager extends Command {
.then(argument("y",IntegerArgumentType.integer()) .then(argument("y",IntegerArgumentType.integer())
.then(argument("z",IntegerArgumentType.integer()) .then(argument("z",IntegerArgumentType.integer())
.executes(context -> { .executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoxyz %s %s %s".formatted( SwarmPlusMaster.swarmServer.broadcast("[BARITONE] gotoxyz %s %s %s".formatted(
IntegerArgumentType.getInteger(context,"x"), IntegerArgumentType.getInteger(context,"x"),
IntegerArgumentType.getInteger(context,"y"), IntegerArgumentType.getInteger(context,"y"),
@@ -226,6 +257,10 @@ public class SwarmManager extends Command {
.then(argument("pitch", DoubleArgumentType.doubleArg(0,360)) .then(argument("pitch", DoubleArgumentType.doubleArg(0,360))
.then(argument("yaw", DoubleArgumentType.doubleArg(0,360)) .then(argument("yaw", DoubleArgumentType.doubleArg(0,360))
.executes(context -> { .executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
SwarmPlusMaster.swarmServer.broadcast("[LOOK] absolute %s %s".formatted( SwarmPlusMaster.swarmServer.broadcast("[LOOK] absolute %s %s".formatted(
context.getArgument("pitch",double.class), context.getArgument("pitch",double.class),
context.getArgument("yaw",double.class))); context.getArgument("yaw",double.class)));
@@ -239,8 +274,12 @@ public class SwarmManager extends Command {
.then(literal("player") .then(literal("player")
.then(argument("target",PlayerArgumentType.create()) .then(argument("target",PlayerArgumentType.create())
.executes(context -> { .executes(context -> {
SwarmPlusMaster.swarmServer.broadcast("[LOOK] player %s".formatted(context.getArgument("target",String.class))); if (SwarmPlusMaster.swarmServer == null) {
SwarmManager.this.info("Bots now targeting (highlight)%s",context.getArgument("target",String.class)); error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
SwarmPlusMaster.swarmServer.broadcast("[LOOK] player %s".formatted(context.getArgument("target",PlayerEntity.class).getName().getString()));
SwarmManager.this.info("Bots now targeting (highlight)%s",context.getArgument("target",PlayerEntity.class).getName().getString());
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
})) }))
) )
@@ -248,12 +287,66 @@ public class SwarmManager extends Command {
.then(literal("follow") .then(literal("follow")
.then(argument("player", PlayerArgumentType.create()) .then(argument("player", PlayerArgumentType.create())
.executes(context -> { .executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
PlayerEntity pe = PlayerArgumentType.get(context); PlayerEntity pe = PlayerArgumentType.get(context);
SwarmPlusMaster.swarmServer.broadcast("[BARITONE] follow %s".formatted(pe.getName().getString())); SwarmPlusMaster.swarmServer.broadcast("[BARITONE] follow %s".formatted(pe.getName().getString()));
SwarmManager.this.info("Bots now following (highlight)%s(default).",pe.getName().getString()); SwarmManager.this.info("Bots now following (highlight)%s(default).",pe.getName().getString());
return SINGLE_SUCCESS; return SINGLE_SUCCESS;
})) })
.then(literal("circle")
.then(argument("radius",IntegerArgumentType.integer(1))
.then(argument("update-freq", IntegerArgumentType.integer(0,10000))
.executes(context -> {
if (SwarmPlusMaster.swarmServer == null) {
error("SwarmPlusMaster module is disabled. Start a swarm server to send commands to it!");
return SINGLE_SUCCESS;
}
PlayerEntity pe = PlayerArgumentType.get(context);
circling = !circling;
SwarmManager.this.info("Bots are %s circling (highlight)%s(default).",circling ? "now" : "no longer", pe.getName().getString());
if (circling) {
int delay = IntegerArgumentType.getInteger(context,"update-freq");
if (delay <= 0){
SwarmManager.this.error("CHECK YOUR CONSOLE BOI + INVALID INTEGER INPUT");
return SINGLE_SUCCESS;
}
Thread thread = new Thread(() -> {
while (circling) {
try {
int rad = context.getArgument("radius",Integer.class);
int n = SwarmPlusMaster.swarmServer.connectionCount();
Point2D.Double[] distribution = MathUtils.distributePoints(MeteorClient.mc.player.getX(),MeteorClient.mc.player.getZ(),rad,n);
int index = 0;
for (Connection connection : SwarmPlusMaster.swarmServer.getConnections()) {
int x = (int) Math.round(distribution[index].x);
int z = (int) Math.round(distribution[index].y);
connection.sendMessage("[BARITONE] gotoxz %s %s".formatted(x,z));
index++;
}
Thread.sleep(delay);
} catch (Exception ex) {
ex.printStackTrace();
SwarmManager.this.error("CHECK YOUR CONSOLE BOI");
}
}
});
thread.start();
}
return SINGLE_SUCCESS;
}))
)
)
)
) )
.then(literal("leaveserver").executes(context -> {
SwarmPlusMaster.swarmServer.broadcast("[LEAVE]");
return SINGLE_SUCCESS;
}))
.then(literal("closegame").executes(context -> { .then(literal("closegame").executes(context -> {
SwarmPlusMaster.swarmServer.broadcast("[CLOSEGAME]"); SwarmPlusMaster.swarmServer.broadcast("[CLOSEGAME]");
return SINGLE_SUCCESS; return SINGLE_SUCCESS;

View File

@@ -6,6 +6,7 @@ import me.trouper.butler.server.Client;
import me.trouper.butler.server.Response; import me.trouper.butler.server.Response;
import me.trouper.butler.utils.MathUtils; import me.trouper.butler.utils.MathUtils;
import me.trouper.butler.utils.Text; import me.trouper.butler.utils.Text;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Module;
@@ -79,14 +80,19 @@ public class SwarmPlusWorker extends Module {
switch (largs[0]) { switch (largs[0]) {
case "player" -> { case "player" -> {
String target = largs[1]; String target = largs[1];
for (Entity entity : mc.player.clientWorld.getEntities()) { try {
if (!(entity instanceof PlayerEntity)) continue; for (Entity entity : mc.player.clientWorld.getEntities()) {
if (!entity.getName().getString().equalsIgnoreCase(target)) continue; if (!(entity instanceof PlayerEntity)) continue;
Vec3d vec = entity.getEyePos().subtract(mc.player.getEyePos()).normalize(); if (!entity.getName().getString().equalsIgnoreCase(target)) continue;
float[] rot = MathUtils.toPolar(vec.x,vec.y,vec.z); Vec3d vec = entity.getEyePos().subtract(mc.player.getEyePos()).normalize();
mc.player.setPitch(rot[0]); float[] rot = MathUtils.toPolar(vec.x,vec.y,vec.z);
mc.player.setYaw(rot[1]); mc.player.setPitch(rot[0]);
return; mc.player.setYaw(rot[1]);
return;
}
} catch (Exception ex) {
ex.printStackTrace();
this.sendToServer("An error occurred whilst trying to rotate to %s!".formatted(target));
} }
} }
case "absolute" -> { case "absolute" -> {
@@ -131,6 +137,10 @@ public class SwarmPlusWorker extends Module {
} }
} }
} }
case "LEAVE" -> {
SwarmPlusWorker.this.info("Quit Server call from host!");
MeteorClient.mc.disconnect();
}
case "CLOSEGAME" -> { case "CLOSEGAME" -> {
SwarmPlusWorker.this.info("Close game call from host!"); SwarmPlusWorker.this.info("Close game call from host!");
System.exit(0); System.exit(0);

View File

@@ -7,6 +7,6 @@ public class ConnectionThread extends Thread {
} }
protected void info(String str, Object... args) { protected void info(String str, Object... args) {
System.out.println(getName() + " Info: " + str.formatted(args)); //System.out.println(getName() + " Info: " + str.formatted(args));
} }
} }