Make the bot work

This commit is contained in:
Astatin3
2024-05-02 16:12:00 -06:00
parent 7b5e763327
commit f64d8dbcde
7 changed files with 202 additions and 73 deletions
@@ -1,6 +1,7 @@
package com.astatin3.meteorbot.commands;
import com.astatin3.meteorbot.modules.ModuleExample;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import meteordevelopment.meteorclient.commands.Command;
@@ -23,8 +24,11 @@ public class CommandExample extends Command {
".mb help - Print this help info\n" +
".mb chat <msg> - Send chat message\n" +
".mb cmd <cmd> - Send command (No '/')\n" +
".mb stop - Stop bot\n" +
".mb rawsend <type> <content> - Send raw message to bot\n");
".mb goto <x> <y> <z> - Go to xyz choord\n" +
".mb follow - Follow player\n" +
".mb stop - Stop current action\n" +
".mb rawsend <type> <content> - Send raw message to bot\n" +
".mb quit - Make bot leave the game");
}
@Override
@@ -59,11 +63,39 @@ public class CommandExample extends Command {
builder.then(literal("stop").executes(context -> {
module.stopBot();
module.writeSTDIN("Stop");
if(module.followMode){
module.followMode = false;
}
return SINGLE_SUCCESS;
}));
builder.then(literal("quit").executes(context -> {
module.quitBot();
return SINGLE_SUCCESS;
}));
builder.then(literal("goto")
.then(
argument(
"x", IntegerArgumentType.integer())
.then(
argument(
"y", IntegerArgumentType.integer())
.then(
argument(
"z", IntegerArgumentType.integer())
.executes(context -> {
module.writeSTDIN(
"goto:" + context.getArgument("x", Integer.class) + "," +
context.getArgument("y", Integer.class) + "," +
context.getArgument("z", Integer.class));
return SINGLE_SUCCESS;
})))));
builder.then(literal("rawsend")
.then(
argument(
@@ -76,5 +108,11 @@ public class CommandExample extends Command {
return SINGLE_SUCCESS;
}))));
builder.then(literal("follow")
.executes(context -> {
module.startFollowMode();
return SINGLE_SUCCESS;
}));
}
}
@@ -9,6 +9,7 @@ import meteordevelopment.meteorclient.systems.modules.Module;
import net.minecraft.util.math.Vec3d;
import java.io.*;
import java.util.concurrent.TimeUnit;
public class ModuleExample extends Module {
@@ -58,7 +59,7 @@ public class ModuleExample extends Module {
cmdThread = new Thread(new Runnable() {
public void run() {
readCMD();
stopBot();
quitBot();
}
});
cmdThread.start();
@@ -75,8 +76,7 @@ public class ModuleExample extends Module {
String line;
while ((line = stdout.readLine()) != null) {
if(verboseMode.get())
info(line);
parseSTDOUT(line);
}
int exitCode = process.waitFor();
@@ -89,20 +89,36 @@ public class ModuleExample extends Module {
}
}
private void parseSTDOUT(String str){
if(verboseMode.get())
info(str);
if(str.equals("Get Player Pos")){
assert mc.player != null;
Vec3d vel = mc.player.getVelocity();
writeSTDIN("PlayerPos:" +
mc.player.getX() + "," +
mc.player.getY() + "," +
mc.player.getZ() + "," +
vel.getX() + "," +
vel.getZ() + "," +
vel.getZ() + ",");
}
}
private Thread cmdThread = null;
public void onActivate() {
stopBot();
quitBot();
startCMD();
}
@Override
public void onDeactivate() {
stopBot();
quitBot();
}
public void stopBot(){
public void quitBot(){
if (cmdThread != null) {
writeSTDIN("Disconnect");
cmdThread.interrupt();
@@ -134,17 +150,22 @@ public class ModuleExample extends Module {
}
}
private void parseResponse(String response){
if(response.equals("Get Player Pos")){
Vec3d vel = mc.player.getVelocity();
writeSTDIN("PlayerPos:" +
mc.player.getX() + "," +
mc.player.getY() + "," +
mc.player.getZ() + "," +
vel.getX() + "," +
vel.getZ() + "," +
vel.getZ() + ",");
}
public boolean followMode = false;
public void startFollowMode(){
writeSTDIN("startGotoSteamMode");
followMode = true;
new Thread(new Runnable() {
public void run() {
while(followMode){
writeSTDIN("goto:"+mc.player.getX()+","+mc.player.getY()+","+mc.player.getZ());
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
}
}
}).start();
}
}