forked from afspiegeling/NitoriBot
added the core and position
This commit is contained in:
Vendored
+4
-2
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"java.configuration.updateBuildConfiguration": "disabled",
|
||||
"java.compile.nullAnalysis.mode": "disabled",
|
||||
"java.refactoring.askBeforeRefactoring": true
|
||||
"java.refactoring.askBeforeRefactoring": true,
|
||||
"java.autobuild.enabled": false,
|
||||
"java.import.projectSelection": "manual"
|
||||
}
|
||||
+21
-18
@@ -1,7 +1,7 @@
|
||||
version = "v9.0.0"
|
||||
group = "nitoribot"
|
||||
description = "NitoriBot"
|
||||
plugins {// id 'com.gradleup.shadow' version '9.2.2'
|
||||
plugins {
|
||||
id("com.gradleup.shadow") version "9.2.2"
|
||||
kotlin("jvm") version "2.3.10"
|
||||
application
|
||||
@@ -24,26 +24,29 @@ repositories {
|
||||
maven("https://repo.opencollab.dev/main/")
|
||||
|
||||
maven("https://maven.maxhenkel.de/repository/public/")
|
||||
|
||||
maven("https://libraries.minecraft.net")
|
||||
|
||||
maven("https://code.optmstc.dev/api/packages/kso/maven")
|
||||
// maven("https://code.chipmunk.land/api/packages/kaboomstandardsorganization/maven/")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
dependencies {
|
||||
implementation("org.geysermc.mcprotocollib:protocol:1.21.11-SNAPSHOT")
|
||||
implementation("net.lenni0451:LambdaEvents:2.4.2")
|
||||
implementation("org.slf4j:slf4j-api:2.0.13")
|
||||
implementation("org.tinylog:slf4j-tinylog:2.7.0")
|
||||
implementation("org.tinylog:tinylog-impl:2.7.0")
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
implementation("net.kyori:adventure-text-serializer-ansi:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-plain:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-gson:4.26.1")
|
||||
implementation("net.lenni0451:Reflect:1.6.2")
|
||||
implementation("org.ow2.asm:asm:9.9.1")
|
||||
implementation("com.google.guava:guava:33.2.1-jre")
|
||||
}
|
||||
//kotlin {
|
||||
dependencies {
|
||||
implementation("org.geysermc.mcprotocollib:protocol:26.1-SNAPSHOT")
|
||||
implementation("org.slf4j:slf4j-api:2.0.13")
|
||||
implementation("org.tinylog:slf4j-tinylog:2.7.0")
|
||||
implementation("org.tinylog:tinylog-impl:2.7.0")
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
implementation("net.kyori:adventure-text-serializer-ansi:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-plain:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-gson:4.26.1")
|
||||
implementation("com.mojang:brigadier:1.3.10")
|
||||
//implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:mcprotocollib:3.1.1-SNAPSHOT")
|
||||
// implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:3.1.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("land.chipmunk.parker2991.nitoribot.Main")
|
||||
}
|
||||
}
|
||||
@@ -52,19 +52,23 @@ public class Bot extends SessionAdapter {
|
||||
|
||||
public SelfcareModule selfcare;
|
||||
|
||||
public PositionModule position;
|
||||
|
||||
public CommandCoreModule core;
|
||||
|
||||
public void loadModules () {
|
||||
this.chat = new ChatModule(this);
|
||||
this.console = new ConsoleModule(this);
|
||||
this.selfcare = new SelfcareModule(this);
|
||||
this.position = new PositionModule(this);
|
||||
this.core = new CommandCoreModule(this);
|
||||
}
|
||||
|
||||
public Bot (Config.Options options, List<Bot> bots, Config config) {
|
||||
this.options = options;
|
||||
this.bots = bots;
|
||||
this.config = config;
|
||||
// loadModules();
|
||||
connect();
|
||||
// loadModules();
|
||||
};
|
||||
|
||||
public void connect () {
|
||||
@@ -130,4 +134,4 @@ public class Bot extends SessionAdapter {
|
||||
public static class Listener {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,23 @@
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static class Core {
|
||||
public Area area = new Area();
|
||||
}
|
||||
|
||||
public static class Area {
|
||||
public Position start = new Position();
|
||||
public Position end = new Position();
|
||||
}
|
||||
|
||||
public static class Position {
|
||||
public int x = 0;
|
||||
public int y = 0;
|
||||
public int z = 0;
|
||||
}
|
||||
|
||||
public Core core = new Core();
|
||||
|
||||
public Options[] bots = new Options[]{};
|
||||
|
||||
public static class Options {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Main {
|
||||
|
||||
LoggerManager.INFO(host, "config not found making config now");
|
||||
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yaml");//.getResource("default_config.yaml");//.getResource("default_config.yaml");
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yaml");
|
||||
Files.copy(defaultConfig, Paths.get("config.yaml"));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
||||
public class CommandCoreAreaData {
|
||||
public Vector3i start;
|
||||
public Vector3i end;
|
||||
|
||||
public CommandCoreAreaData (Vector3i start, Vector3i end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
public record PositionData (int x, int y, int z) {}
|
||||
@@ -54,8 +54,7 @@ public class ChatModule extends SessionAdapter {
|
||||
for (Listener listener : listeners) {
|
||||
listener.playerChatReceived(unsignedContent);
|
||||
}
|
||||
}// session.sendPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0, null, 0, new BitSet(), 0));
|
||||
|
||||
}
|
||||
|
||||
public void message (String message) {
|
||||
bot.session.send(
|
||||
@@ -92,13 +91,7 @@ public class ChatModule extends SessionAdapter {
|
||||
public boolean disguisedChatReceived (Component message) { return true; };
|
||||
}
|
||||
|
||||
|
||||
//@Override
|
||||
//public void packetReceived (Session session, Packet packet) {
|
||||
|
||||
//}
|
||||
|
||||
public void addListener (Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.CommandCoreAreaData;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PositionData;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.CommandBlockMode;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
public class CommandCoreModule extends PositionModule.Listener {
|
||||
private Bot bot;
|
||||
|
||||
public CommandCoreAreaData area;
|
||||
|
||||
@Override
|
||||
public boolean botMoved () {
|
||||
move();
|
||||
return true;
|
||||
}
|
||||
|
||||
public Vector3i position;
|
||||
|
||||
public void move () {
|
||||
Vector3d botPos = bot.position.positionAsVector;
|
||||
position = Vector3i.from(
|
||||
Math.floor(botPos.getX() / 16) * 16,
|
||||
0,
|
||||
Math.floor(botPos.getZ() / 16) * 16
|
||||
);
|
||||
|
||||
refill();
|
||||
};
|
||||
|
||||
public void refill () {
|
||||
Vector3i pos = position;
|
||||
CommandCoreAreaData coreArea = area;
|
||||
|
||||
int startPosX = pos.getX() - coreArea.start.getX();
|
||||
int startPosY = pos.getY() - coreArea.start.getY();
|
||||
int startPosZ = pos.getZ() - coreArea.start.getZ();
|
||||
int endPosX = pos.getX() - coreArea.end.getX();
|
||||
int endPosY = pos.getY() - coreArea.end.getY();
|
||||
int endPosZ = pos.getZ() - coreArea.end.getZ();
|
||||
|
||||
String command = String.format(
|
||||
"minecraft:fill %s %s %s %s %s %s command_block destroy",
|
||||
startPosX,
|
||||
startPosY,
|
||||
startPosZ,
|
||||
endPosX,
|
||||
endPosY,
|
||||
endPosZ
|
||||
);
|
||||
|
||||
bot.chat.command(command);
|
||||
}
|
||||
|
||||
public Vector3i currentBlockRelative = Vector3i.from(0, 0, 0);
|
||||
|
||||
public PositionData currentBlock () {
|
||||
Vector3i relativePosition = currentBlockRelative;
|
||||
Vector3i corePosition = position;
|
||||
|
||||
return new PositionData(
|
||||
relativePosition.getX() + corePosition.getX(),
|
||||
relativePosition.getY() + corePosition.getY(),
|
||||
relativePosition.getZ() + corePosition.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
public void incrementCurrentBlock () {
|
||||
Vector3i relativePosition = currentBlockRelative;
|
||||
CommandCoreAreaData coreArea = area;
|
||||
|
||||
int posX = relativePosition.getX();
|
||||
int posY = relativePosition.getY();
|
||||
int posZ = relativePosition.getZ();
|
||||
|
||||
posX++;
|
||||
|
||||
if (posX > coreArea.end.getX()) {
|
||||
posX = coreArea.start.getX();
|
||||
posZ++;
|
||||
}
|
||||
|
||||
if (posZ > coreArea.end.getZ()) {
|
||||
posZ = coreArea.start.getZ();
|
||||
posY++;
|
||||
}
|
||||
|
||||
if (posY > coreArea.end.getY()) {
|
||||
posX = coreArea.start.getX();
|
||||
posY = coreArea.start.getY();
|
||||
posZ = coreArea.start.getZ();
|
||||
}
|
||||
}
|
||||
|
||||
public void commandBlock (String command, boolean doesTrackOutput, boolean conditional, boolean automatic) {
|
||||
bot.session.send(
|
||||
new ServerboundSetCommandBlockPacket(
|
||||
position,
|
||||
command,
|
||||
CommandBlockMode.AUTO,
|
||||
doesTrackOutput,
|
||||
conditional,
|
||||
automatic
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void run (String command) {
|
||||
commandBlock(command, true, false, true);
|
||||
|
||||
incrementCurrentBlock();
|
||||
}
|
||||
|
||||
public CommandCoreModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
System.out.println(bot.config.core.area.start.x);
|
||||
this.area = new CommandCoreAreaData(
|
||||
Vector3i.from(
|
||||
bot.config.core.area.start.x,
|
||||
bot.config.core.area.start.y,
|
||||
bot.config.core.area.start.z
|
||||
),
|
||||
Vector3i.from(
|
||||
bot.config.core.area.end.x,
|
||||
bot.config.core.area.end.y,
|
||||
bot.config.core.area.end.z
|
||||
)
|
||||
);
|
||||
|
||||
bot.position.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PositionData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
public class PositionModule extends SessionAdapter {
|
||||
private Bot bot;
|
||||
|
||||
private final List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
public Vector3d positionAsVector = null;
|
||||
|
||||
public PositionData positionAsInteger;
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundPlayerPositionPacket) packetReceived((ClientboundPlayerPositionPacket) packet);
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundPlayerPositionPacket packet) {
|
||||
Vector3d getPosition = packet.getPosition();
|
||||
|
||||
int x = (int) Math.round(getPosition.getX());
|
||||
int y = (int) Math.round(getPosition.getY());
|
||||
int z = (int) Math.round(getPosition.getZ());
|
||||
|
||||
positionAsInteger = new PositionData(x, y, z);
|
||||
positionAsVector = getPosition;
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundAcceptTeleportationPacket(
|
||||
packet.getId()
|
||||
)
|
||||
);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
listener.botMoved();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Listener {
|
||||
public boolean botMoved () { return true; };
|
||||
}
|
||||
|
||||
public void addListener (Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public PositionModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.session.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,6 @@ public class SelfcareModule extends SessionAdapter {
|
||||
GameMode.CREATIVE
|
||||
)
|
||||
);
|
||||
//else if (gamemode.gamemode != 1) bot.chat.command("minecraft:gamemode creative");
|
||||
}, 0, bot.options.selfcareInterval, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"bot": {
|
||||
"version": "v9.0.0-alpha",
|
||||
"codename": "Night of Nights",
|
||||
"build": "5210"
|
||||
"build": "5215"
|
||||
}
|
||||
},
|
||||
"owner": "Parker2991",
|
||||
|
||||
Reference in New Issue
Block a user