diff --git a/PROTOCOL.md b/PROTOCOL.md
new file mode 100644
index 00000000..8713120b
--- /dev/null
+++ b/PROTOCOL.md
@@ -0,0 +1,36 @@
+# Baritone Comms Protocol
+
+## Data Types
+
+| Name | Descriptor | Java |
+|------------|-----------------------------------------------------------|-----------------------------|
+| coordinate | Big endian 8-byte floating point number | [readDouble], [writeDouble] |
+| string | unsigned short (length) followed by UTF-8 character bytes | [readUTF], [writeUTF] |
+
+## Inbound
+
+Allows the server to execute a chat command on behalf of the client's player
+
+### Chat
+
+| Name | Type |
+|---------|--------|
+| Message | string |
+
+## Outbound
+
+Update the player position with the server
+
+### Status
+
+| Name | Type |
+|------|------------|
+| X | coordinate |
+| Y | coordinate |
+| Z | coordinate |
+
+
+[readUTF]: https://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readUTF()
+[writeUTF]: https://docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html#writeUTF(java.lang.String)
+[readDouble]: https://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readDouble()
+[writeDouble]: https://docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html#writeDouble(double)
\ No newline at end of file
diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java
index 5ca54a25..14805375 100644
--- a/src/api/java/baritone/api/IBaritone.java
+++ b/src/api/java/baritone/api/IBaritone.java
@@ -22,6 +22,7 @@ import baritone.api.behavior.IMemoryBehavior;
import baritone.api.behavior.IPathingBehavior;
import baritone.api.cache.IWorldProvider;
import baritone.api.event.listener.IEventBus;
+import baritone.api.pathing.calc.IPathingControlManager;
import baritone.api.process.ICustomGoalProcess;
import baritone.api.process.IFollowProcess;
import baritone.api.process.IGetToBlockProcess;
@@ -59,6 +60,8 @@ public interface IBaritone {
*/
IMineProcess getMineProcess();
+ IPathingControlManager getPathingControlManager();
+
/**
* @return The {@link IPathingBehavior} instance
* @see IPathingBehavior
diff --git a/src/api/java/baritone/api/pathing/calc/IPath.java b/src/api/java/baritone/api/pathing/calc/IPath.java
index 8f0cb68e..1b4650f5 100644
--- a/src/api/java/baritone/api/pathing/calc/IPath.java
+++ b/src/api/java/baritone/api/pathing/calc/IPath.java
@@ -104,7 +104,7 @@ public interface IPath {
* Returns the estimated number of ticks to complete the path from the given node index.
*
* @param pathPosition The index of the node we're calculating from
- * @return The estimated number of ticks remaining frm the given position
+ * @return The estimated number of ticks remaining from the given position
*/
default double ticksRemainingFrom(int pathPosition) {
double sum = 0;
@@ -116,6 +116,15 @@ public interface IPath {
return sum;
}
+ /**
+ * Returns the estimated amount of time needed to complete this path from start to finish
+ *
+ * @return The estimated amount of time, in ticks
+ */
+ default double totalTicks() {
+ return ticksRemainingFrom(0);
+ }
+
/**
* Cuts off this path at the loaded chunk border, and returns the resulting path. Default
* implementation just returns this path, without the intended functionality.
diff --git a/src/comms/java/comms/BufferedConnection.java b/src/comms/java/cabaletta/comms/BufferedConnection.java
similarity index 86%
rename from src/comms/java/comms/BufferedConnection.java
rename to src/comms/java/cabaletta/comms/BufferedConnection.java
index 450010e7..f21a684c 100644
--- a/src/comms/java/comms/BufferedConnection.java
+++ b/src/comms/java/cabaletta/comms/BufferedConnection.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.EOFException;
import java.io.IOException;
@@ -83,4 +83,16 @@ public class BufferedConnection implements IConnection {
}
return msgs;
}
+
+ public void handleAllPendingMessages(IMessageListener listener) throws IOException {
+ receiveMessagesNonBlocking().forEach(msg -> msg.handle(listener));
+ }
+
+ public static BufferedConnection makeBuffered(IConnection conn) {
+ if (conn instanceof BufferedConnection) {
+ return (BufferedConnection) conn;
+ } else {
+ return new BufferedConnection(conn);
+ }
+ }
}
diff --git a/src/comms/java/comms/ConstructingDeserializer.java b/src/comms/java/cabaletta/comms/ConstructingDeserializer.java
similarity index 94%
rename from src/comms/java/comms/ConstructingDeserializer.java
rename to src/comms/java/cabaletta/comms/ConstructingDeserializer.java
index c6407976..eb15bdf0 100644
--- a/src/comms/java/comms/ConstructingDeserializer.java
+++ b/src/comms/java/cabaletta/comms/ConstructingDeserializer.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.DataInputStream;
import java.io.IOException;
@@ -39,7 +39,7 @@ public enum ConstructingDeserializer implements MessageDeserializer {
}
@Override
- public iMessage deserialize(DataInputStream in) throws IOException {
+ public synchronized iMessage deserialize(DataInputStream in) throws IOException {
int type = ((int) in.readByte()) & 0xff;
try {
return MSGS.get(type).getConstructor(DataInputStream.class).newInstance(in);
diff --git a/src/comms/java/comms/IConnection.java b/src/comms/java/cabaletta/comms/IConnection.java
similarity index 97%
rename from src/comms/java/comms/IConnection.java
rename to src/comms/java/cabaletta/comms/IConnection.java
index dc54beb0..02046fe3 100644
--- a/src/comms/java/comms/IConnection.java
+++ b/src/comms/java/cabaletta/comms/IConnection.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.IOException;
diff --git a/src/comms/java/comms/IMessageListener.java b/src/comms/java/cabaletta/comms/IMessageListener.java
similarity index 72%
rename from src/comms/java/comms/IMessageListener.java
rename to src/comms/java/cabaletta/comms/IMessageListener.java
index afed4cfe..2829f267 100644
--- a/src/comms/java/comms/IMessageListener.java
+++ b/src/comms/java/cabaletta/comms/IMessageListener.java
@@ -15,10 +15,12 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
-import comms.downward.MessageChat;
-import comms.upward.MessageStatus;
+import cabaletta.comms.downward.MessageChat;
+import cabaletta.comms.downward.MessageComputationRequest;
+import cabaletta.comms.upward.MessageComputationResponse;
+import cabaletta.comms.upward.MessageStatus;
public interface IMessageListener {
default void handle(MessageStatus message) {
@@ -29,6 +31,14 @@ public interface IMessageListener {
unhandled(message);
}
+ default void handle(MessageComputationRequest message) {
+ unhandled(message);
+ }
+
+ default void handle(MessageComputationResponse message) {
+ unhandled(message);
+ }
+
default void unhandled(iMessage msg) {
// can override this to throw UnsupportedOperationException, if you want to make sure you're handling everything
// default is to silently ignore messages without handlers
diff --git a/src/comms/java/comms/MessageDeserializer.java b/src/comms/java/cabaletta/comms/MessageDeserializer.java
similarity index 97%
rename from src/comms/java/comms/MessageDeserializer.java
rename to src/comms/java/cabaletta/comms/MessageDeserializer.java
index aece828d..264a753d 100644
--- a/src/comms/java/comms/MessageDeserializer.java
+++ b/src/comms/java/cabaletta/comms/MessageDeserializer.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.DataInputStream;
import java.io.IOException;
diff --git a/src/comms/java/comms/Pipe.java b/src/comms/java/cabaletta/comms/Pipe.java
similarity index 99%
rename from src/comms/java/comms/Pipe.java
rename to src/comms/java/cabaletta/comms/Pipe.java
index c189af60..42e28899 100644
--- a/src/comms/java/comms/Pipe.java
+++ b/src/comms/java/cabaletta/comms/Pipe.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.EOFException;
import java.io.IOException;
diff --git a/src/comms/java/comms/SerializedConnection.java b/src/comms/java/cabaletta/comms/SerializedConnection.java
similarity index 94%
rename from src/comms/java/comms/SerializedConnection.java
rename to src/comms/java/cabaletta/comms/SerializedConnection.java
index 0952854d..5ac482a9 100644
--- a/src/comms/java/comms/SerializedConnection.java
+++ b/src/comms/java/cabaletta/comms/SerializedConnection.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.*;
@@ -35,7 +35,7 @@ public class SerializedConnection implements IConnection {
}
@Override
- public void sendMessage(iMessage message) throws IOException {
+ public synchronized void sendMessage(iMessage message) throws IOException {
message.writeHeader(out);
message.write(out);
}
diff --git a/src/comms/java/comms/SocketConnection.java b/src/comms/java/cabaletta/comms/SocketConnection.java
similarity index 97%
rename from src/comms/java/comms/SocketConnection.java
rename to src/comms/java/cabaletta/comms/SocketConnection.java
index e40d5a1a..95bb83d5 100644
--- a/src/comms/java/comms/SocketConnection.java
+++ b/src/comms/java/cabaletta/comms/SocketConnection.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.IOException;
import java.net.Socket;
diff --git a/src/comms/java/comms/downward/MessageChat.java b/src/comms/java/cabaletta/comms/downward/MessageChat.java
similarity index 92%
rename from src/comms/java/comms/downward/MessageChat.java
rename to src/comms/java/cabaletta/comms/downward/MessageChat.java
index b04d2a31..be6b0f3b 100644
--- a/src/comms/java/comms/downward/MessageChat.java
+++ b/src/comms/java/cabaletta/comms/downward/MessageChat.java
@@ -15,10 +15,10 @@
* along with Baritone. If not, see .
*/
-package comms.downward;
+package cabaletta.comms.downward;
-import comms.IMessageListener;
-import comms.iMessage;
+import cabaletta.comms.IMessageListener;
+import cabaletta.comms.iMessage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
diff --git a/src/comms/java/cabaletta/comms/downward/MessageComputationRequest.java b/src/comms/java/cabaletta/comms/downward/MessageComputationRequest.java
new file mode 100644
index 00000000..c1e4f51a
--- /dev/null
+++ b/src/comms/java/cabaletta/comms/downward/MessageComputationRequest.java
@@ -0,0 +1,62 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package cabaletta.comms.downward;
+
+import cabaletta.comms.IMessageListener;
+import cabaletta.comms.iMessage;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class MessageComputationRequest implements iMessage {
+ public final long computationID;
+ public final int startX;
+ public final int startY;
+ public final int startZ;
+ public final String goal; // TODO find a better way to do this lol
+
+ public MessageComputationRequest(DataInputStream in) throws IOException {
+ this.computationID = in.readLong();
+ this.startX = in.readInt();
+ this.startY = in.readInt();
+ this.startZ = in.readInt();
+ this.goal = in.readUTF();
+ }
+
+ public MessageComputationRequest(long computationID, int startX, int startY, int startZ, String goal) {
+ this.computationID = computationID;
+ this.startX = startX;
+ this.startY = startY;
+ this.startZ = startZ;
+ this.goal = goal;
+ }
+
+ @Override
+ public void write(DataOutputStream out) throws IOException {
+ out.writeLong(computationID);
+ out.writeInt(startX);
+ out.writeInt(startY);
+ out.writeUTF(goal);
+ }
+
+ @Override
+ public void handle(IMessageListener listener) {
+ listener.handle(this);
+ }
+}
diff --git a/src/comms/java/comms/iMessage.java b/src/comms/java/cabaletta/comms/iMessage.java
similarity index 98%
rename from src/comms/java/comms/iMessage.java
rename to src/comms/java/cabaletta/comms/iMessage.java
index 67ec2965..7d00ab4c 100644
--- a/src/comms/java/comms/iMessage.java
+++ b/src/comms/java/cabaletta/comms/iMessage.java
@@ -15,7 +15,7 @@
* along with Baritone. If not, see .
*/
-package comms;
+package cabaletta.comms;
import java.io.DataOutputStream;
import java.io.IOException;
diff --git a/src/comms/java/cabaletta/comms/upward/MessageComputationResponse.java b/src/comms/java/cabaletta/comms/upward/MessageComputationResponse.java
new file mode 100644
index 00000000..a6d7ac1b
--- /dev/null
+++ b/src/comms/java/cabaletta/comms/upward/MessageComputationResponse.java
@@ -0,0 +1,72 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package cabaletta.comms.upward;
+
+import cabaletta.comms.IMessageListener;
+import cabaletta.comms.iMessage;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class MessageComputationResponse implements iMessage {
+ public final long computationID;
+ public final int pathLength;
+ public final double pathCost;
+ public final boolean endsInGoal;
+ public final int endX;
+ public final int endY;
+ public final int endZ;
+
+ public MessageComputationResponse(DataInputStream in) throws IOException {
+ this.computationID = in.readLong();
+ this.pathLength = in.readInt();
+ this.pathCost = in.readDouble();
+ this.endsInGoal = in.readBoolean();
+ this.endX = in.readInt();
+ this.endY = in.readInt();
+ this.endZ = in.readInt();
+ }
+
+ public MessageComputationResponse(long computationID, int pathLength, double pathCost, boolean endsInGoal, int endX, int endY, int endZ) {
+ this.computationID = computationID;
+ this.pathLength = pathLength;
+ this.pathCost = pathCost;
+ this.endsInGoal = endsInGoal;
+ this.endX = endX;
+ this.endY = endY;
+ this.endZ = endZ;
+ }
+
+ @Override
+ public void write(DataOutputStream out) throws IOException {
+ out.writeLong(computationID);
+ out.writeInt(pathLength);
+ out.writeDouble(pathCost);
+ out.writeBoolean(endsInGoal);
+ out.writeInt(endX);
+ out.writeInt(endY);
+ out.writeInt(endZ);
+ }
+
+ @Override
+ public void handle(IMessageListener listener) {
+ listener.handle(this);
+ }
+}
+
diff --git a/src/comms/java/cabaletta/comms/upward/MessageStatus.java b/src/comms/java/cabaletta/comms/upward/MessageStatus.java
new file mode 100644
index 00000000..f7727fc1
--- /dev/null
+++ b/src/comms/java/cabaletta/comms/upward/MessageStatus.java
@@ -0,0 +1,124 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package cabaletta.comms.upward;
+
+import cabaletta.comms.IMessageListener;
+import cabaletta.comms.iMessage;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class MessageStatus implements iMessage {
+
+ public final double x;
+ public final double y;
+ public final double z;
+ public final float yaw;
+ public final float pitch;
+ public final boolean onGround;
+ public final float health;
+ public final float saturation;
+ public final int foodLevel;
+ public final int pathStartX;
+ public final int pathStartY;
+ public final int pathStartZ;
+ public final boolean hasCurrentSegment;
+ public final boolean hasNextSegment;
+ public final boolean calcInProgress;
+ public final double ticksRemainingInCurrent;
+ public final boolean calcFailedLastTick;
+ public final boolean safeToCancel;
+ public final String currentGoal;
+ public final String currentProcess;
+
+ public MessageStatus(DataInputStream in) throws IOException {
+ this.x = in.readDouble();
+ this.y = in.readDouble();
+ this.z = in.readDouble();
+ this.yaw = in.readFloat();
+ this.pitch = in.readFloat();
+ this.onGround = in.readBoolean();
+ this.health = in.readFloat();
+ this.saturation = in.readFloat();
+ this.foodLevel = in.readInt();
+ this.pathStartX = in.readInt();
+ this.pathStartY = in.readInt();
+ this.pathStartZ = in.readInt();
+ this.hasCurrentSegment = in.readBoolean();
+ this.hasNextSegment = in.readBoolean();
+ this.calcInProgress = in.readBoolean();
+ this.ticksRemainingInCurrent = in.readDouble();
+ this.calcFailedLastTick = in.readBoolean();
+ this.safeToCancel = in.readBoolean();
+ this.currentGoal = in.readUTF();
+ this.currentProcess = in.readUTF();
+ }
+
+ public MessageStatus(double x, double y, double z, float yaw, float pitch, boolean onGround, float health, float saturation, int foodLevel, int pathStartX, int pathStartY, int pathStartZ, boolean hasCurrentSegment, boolean hasNextSegment, boolean calcInProgress, double ticksRemainingInCurrent, boolean calcFailedLastTick, boolean safeToCancel, String currentGoal, String currentProcess) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.yaw = yaw;
+ this.pitch = pitch;
+ this.onGround = onGround;
+ this.health = health;
+ this.saturation = saturation;
+ this.foodLevel = foodLevel;
+ this.pathStartX = pathStartX;
+ this.pathStartY = pathStartY;
+ this.pathStartZ = pathStartZ;
+ this.hasCurrentSegment = hasCurrentSegment;
+ this.hasNextSegment = hasNextSegment;
+ this.calcInProgress = calcInProgress;
+ this.ticksRemainingInCurrent = ticksRemainingInCurrent;
+ this.calcFailedLastTick = calcFailedLastTick;
+ this.safeToCancel = safeToCancel;
+ this.currentGoal = currentGoal;
+ this.currentProcess = currentProcess;
+ }
+
+ @Override
+ public void write(DataOutputStream out) throws IOException {
+ out.writeDouble(x);
+ out.writeDouble(y);
+ out.writeDouble(z);
+ out.writeFloat(yaw);
+ out.writeFloat(pitch);
+ out.writeBoolean(onGround);
+ out.writeFloat(health);
+ out.writeFloat(saturation);
+ out.writeInt(foodLevel);
+ out.writeInt(pathStartX);
+ out.writeInt(pathStartY);
+ out.writeInt(pathStartZ);
+ out.writeBoolean(hasCurrentSegment);
+ out.writeBoolean(hasNextSegment);
+ out.writeBoolean(calcInProgress);
+ out.writeDouble(ticksRemainingInCurrent);
+ out.writeBoolean(calcFailedLastTick);
+ out.writeBoolean(safeToCancel);
+ out.writeUTF(currentGoal);
+ out.writeUTF(currentProcess);
+ }
+
+ @Override
+ public void handle(IMessageListener listener) {
+ listener.handle(this);
+ }
+}
diff --git a/src/comms/java/comms/upward/MessageStatus.java b/src/comms/java/comms/upward/MessageStatus.java
deleted file mode 100644
index 55a29828..00000000
--- a/src/comms/java/comms/upward/MessageStatus.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * This file is part of Baritone.
- *
- * Baritone is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Baritone is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Baritone. If not, see .
- */
-
-package comms.upward;
-
-import comms.IMessageListener;
-import comms.iMessage;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-public class MessageStatus implements iMessage {
-
- public final double x;
- public final double y;
- public final double z;
-
- public MessageStatus(DataInputStream in) throws IOException {
- this.x = in.readDouble();
- this.y = in.readDouble();
- this.z = in.readDouble();
- }
-
- public MessageStatus(double x, double y, double z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
-
- @Override
- public void write(DataOutputStream out) throws IOException {
- out.writeDouble(x);
- out.writeDouble(y);
- out.writeDouble(z);
- }
-
- @Override
- public void handle(IMessageListener listener) {
- listener.handle(this);
- }
-}
diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java
index 951bcaa6..523357dc 100755
--- a/src/main/java/baritone/Baritone.java
+++ b/src/main/java/baritone/Baritone.java
@@ -136,6 +136,7 @@ public class Baritone implements IBaritone {
this.gameEventHandler.registerEventListener(behavior);
}
+ @Override
public PathingControlManager getPathingControlManager() {
return this.pathingControlManager;
}
diff --git a/src/main/java/baritone/behavior/ControllerBehavior.java b/src/main/java/baritone/behavior/ControllerBehavior.java
index f1deb618..34031068 100644
--- a/src/main/java/baritone/behavior/ControllerBehavior.java
+++ b/src/main/java/baritone/behavior/ControllerBehavior.java
@@ -20,18 +20,28 @@ package baritone.behavior;
import baritone.Baritone;
import baritone.api.event.events.ChatEvent;
import baritone.api.event.events.TickEvent;
+import baritone.api.pathing.goals.Goal;
+import baritone.api.pathing.goals.GoalYLevel;
+import baritone.api.process.IBaritoneProcess;
+import baritone.api.utils.BetterBlockPos;
+import baritone.pathing.movement.CalculationContext;
import baritone.utils.Helper;
-import comms.BufferedConnection;
-import comms.IConnection;
-import comms.IMessageListener;
-import comms.downward.MessageChat;
-import comms.iMessage;
-import comms.upward.MessageStatus;
+import baritone.utils.pathing.SegmentedCalculator;
+import cabaletta.comms.BufferedConnection;
+import cabaletta.comms.IConnection;
+import cabaletta.comms.IMessageListener;
+import cabaletta.comms.downward.MessageChat;
+import cabaletta.comms.downward.MessageComputationRequest;
+import cabaletta.comms.iMessage;
+import cabaletta.comms.upward.MessageComputationResponse;
+import cabaletta.comms.upward.MessageStatus;
+import net.minecraft.util.math.BlockPos;
import java.io.IOException;
-import java.util.List;
+import java.util.Objects;
public class ControllerBehavior extends Behavior implements IMessageListener {
+
public ControllerBehavior(Baritone baritone) {
super(baritone);
}
@@ -43,17 +53,44 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
- trySend(new MessageStatus(ctx.player().posX, ctx.player().posY, ctx.player().posZ));
+ trySend(buildStatus());
readAndHandle();
}
+ public MessageStatus buildStatus() {
+ // TODO report inventory and echest contents
+ // TODO figure out who should remember echest contents when it isn't open, baritone or tenor?
+ BlockPos pathStart = baritone.getPathingBehavior().pathStart();
+ return new MessageStatus(
+ ctx.player().posX,
+ ctx.player().posY,
+ ctx.player().posZ,
+ ctx.player().rotationYaw,
+ ctx.player().rotationPitch,
+ ctx.player().onGround,
+ ctx.player().getHealth(),
+ ctx.player().getFoodStats().getSaturationLevel(),
+ ctx.player().getFoodStats().getFoodLevel(),
+ pathStart.getX(),
+ pathStart.getY(),
+ pathStart.getZ(),
+ baritone.getPathingBehavior().getCurrent() != null,
+ baritone.getPathingBehavior().getNext() != null,
+ baritone.getPathingBehavior().getInProgress().isPresent(),
+ baritone.getPathingBehavior().ticksRemainingInSegment().orElse(0D),
+ baritone.getPathingBehavior().calcFailedLastTick(),
+ baritone.getPathingBehavior().isSafeToCancel(),
+ baritone.getPathingBehavior().getGoal() + "",
+ baritone.getPathingControlManager().mostRecentInControl().map(IBaritoneProcess::displayName).orElse("")
+ );
+ }
+
private void readAndHandle() {
if (conn == null) {
return;
}
try {
- List msgs = conn.receiveMessagesNonBlocking();
- msgs.forEach(msg -> msg.handle(this));
+ conn.handleAllPendingMessages(this);
} catch (IOException e) {
e.printStackTrace();
disconnect();
@@ -76,11 +113,7 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
public void connectTo(IConnection conn) {
disconnect();
- if (conn instanceof BufferedConnection) {
- this.conn = (BufferedConnection) conn;
- } else {
- this.conn = new BufferedConnection(conn);
- }
+ this.conn = BufferedConnection.makeBuffered(conn);
}
public void disconnect() {
@@ -96,6 +129,33 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
baritone.getGameEventHandler().onSendChatMessage(event);
}
+ @Override
+ public void handle(MessageComputationRequest msg) {
+ BetterBlockPos start = new BetterBlockPos(msg.startX, msg.startY, msg.startZ);
+ // TODO this may require scanning the world for blocks of a certain type, idk how to manage that
+ Goal goal = new GoalYLevel(Integer.parseInt(msg.goal)); // im already winston
+ SegmentedCalculator.calculateSegmentsThreaded(start, goal, new CalculationContext(baritone), path -> {
+ if (!Objects.equals(path.getGoal(), goal)) {
+ throw new IllegalStateException(); // sanity check
+ }
+ try {
+ BetterBlockPos dest = path.getDest();
+ conn.sendMessage(new MessageComputationResponse(msg.computationID, path.length(), path.totalTicks(), path.getGoal().isInGoal(dest), dest.x, dest.y, dest.z));
+ } catch (IOException e) {
+ // nothing we can do about this, we just completed a computation but our tenor connection was closed in the meantime
+ // just discard the path we made for them =((
+ e.printStackTrace(); // and complain =)
+ }
+ }, () -> {
+ try {
+ conn.sendMessage(new MessageComputationResponse(msg.computationID, 0, 0, false, 0, 0, 0));
+ } catch (IOException e) {
+ // same deal
+ e.printStackTrace();
+ }
+ });
+ }
+
@Override
public void unhandled(iMessage msg) {
Helper.HELPER.logDebug("Unhandled message received by ControllerBehavior " + msg);
diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java
index bd2146b8..ff66a902 100644
--- a/src/main/java/baritone/behavior/PathingBehavior.java
+++ b/src/main/java/baritone/behavior/PathingBehavior.java
@@ -371,7 +371,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
}
if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) {
// this is plausible
- logDebug("Faking path start assuming player is standing off the edge of a block");
+ //logDebug("Faking path start assuming player is standing off the edge of a block");
return possibleSupport;
}
}
@@ -380,7 +380,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
// !onGround
// we're in the middle of a jump
if (MovementHelper.canWalkOn(ctx, feet.down().down())) {
- logDebug("Faking path start assuming player is midair and falling");
+ //logDebug("Faking path start assuming player is midair and falling");
return feet.down();
}
}
diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java
index 4b995e82..1de14596 100644
--- a/src/main/java/baritone/utils/ExampleBaritoneControl.java
+++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java
@@ -35,7 +35,7 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.Moves;
import baritone.process.CustomGoalProcess;
import baritone.utils.pathing.SegmentedCalculator;
-import comms.SocketConnection;
+import cabaletta.comms.SocketConnection;
import net.minecraft.block.Block;
import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.entity.Entity;