diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index b6bac31..5d671f5 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -16,7 +16,6 @@ import org.apache.commons.lang3.RandomStringUtils; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java index efca633..6e00706 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java @@ -135,7 +135,7 @@ public class CorePlugin extends PositionPlugin.Listener { } public void runPlaceBlock (String command) { - if (!ready) return; + if (!ready || !bot.options().useCore()) return; final CompoundTag tag = new CompoundTag(""); final CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag"); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MabePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MabePlugin.java new file mode 100644 index 0000000..770a2a2 --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MabePlugin.java @@ -0,0 +1,43 @@ +package land.chipmunk.chayapak.chomens_bot.plugins; + +import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosRotPacket; +import land.chipmunk.chayapak.chomens_bot.Bot; +import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry; +import land.chipmunk.chayapak.chomens_bot.data.Rotation; +import org.cloudburstmc.math.vector.Vector3f; + +public class MabePlugin extends PositionPlugin.Listener { + private final Bot bot; + + public MabePlugin (Bot bot) { + this.bot = bot; + bot.position().addListener(this); + } + + @Override + public void playerMoved (MutablePlayerListEntry player, Vector3f position, Rotation rotation) { + // final String name = player.profile().getName(); + + // if (!name.equals("chayapak")) return; + + // Author: ChatGPT + final double dx = bot.position().position().getX() - position.getX(); + final double dy = bot.position().position().getY() - position.getY(); + final double dz = bot.position().position().getZ() - position.getZ(); + final double distance = Math.sqrt(dx * dx + dy * dy + dz * dz); + + final double pitchRadians = Math.asin(dy / distance); + final double pitchDegrees = Math.toDegrees(pitchRadians); + + bot.session().send( + new ServerboundMovePlayerPosRotPacket( + false, + bot.position().position().getX(), + bot.position().position().getY(), + bot.position().position().getZ(), + rotation.yaw - 180, + (float) pitchDegrees + ) + ); + } +} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java index a38d7da..8c112fe 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java @@ -84,7 +84,11 @@ public class PositionPlugin extends Bot.Listener { if (player == null) return; - rotationMap.put(packet.getEntityId(), new Rotation(packet.getYaw(), packet.getPitch())); + final Rotation rotation = new Rotation(packet.getYaw(), packet.getPitch()); + + rotationMap.put(packet.getEntityId(), rotation); + + for (Listener listener : listeners) listener.playerMoved(player, getPlayerPosition(player.profile().getName()), rotation); } public void packetReceived (ClientboundMoveEntityPosPacket packet) { @@ -103,6 +107,8 @@ public class PositionPlugin extends Bot.Listener { ); positionMap.put(packet.getEntityId(), position); + + for (Listener listener : listeners) listener.playerMoved(player, position, getPlayerRotation(player.profile().getName())); } public void packetReceived (ClientboundMoveEntityPosRotPacket packet) { @@ -121,8 +127,12 @@ public class PositionPlugin extends Bot.Listener { packet.getMoveZ() + lastPosition.getZ() ); + final Rotation rotation = new Rotation(packet.getYaw(), packet.getPitch()); + positionMap.put(packet.getEntityId(), position); - rotationMap.put(packet.getEntityId(), new Rotation(packet.getYaw(), packet.getPitch())); + rotationMap.put(packet.getEntityId(), rotation); + + for (Listener listener : listeners) listener.playerMoved(player, position, rotation); } public Vector3f getPlayerPosition (String playerName) { @@ -159,5 +169,6 @@ public class PositionPlugin extends Bot.Listener { public static class Listener { public void positionChange (Vector3i position) {} + public void playerMoved (MutablePlayerListEntry player, Vector3f position, Rotation rotation) {} } }