better reporting
This commit is contained in:
@@ -121,3 +121,4 @@ task proguard(type: ProguardTask) {
|
||||
task createDist(type: CreateDistTask, dependsOn: proguard)
|
||||
|
||||
build.finalizedBy(createDist)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public enum ConstructingDeserializer implements MessageDeserializer {
|
||||
// imagine doing something in reflect but it's actually concise and you don't need to catch 42069 different exceptions. huh.
|
||||
for (Method m : IMessageListener.class.getDeclaredMethods()) {
|
||||
if (m.getName().equals("handle")) {
|
||||
MSGS.add((Class<? extends iMessage>) m.getParameterTypes()[0]);
|
||||
MSGS.add(0, (Class<? extends iMessage>) m.getParameterTypes()[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,13 @@ import cabaletta.comms.iMessage;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageStatus implements iMessage {
|
||||
|
||||
public final String playerUUID;
|
||||
public final String serverIP;
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
@@ -35,6 +39,7 @@ public class MessageStatus implements iMessage {
|
||||
public final float health;
|
||||
public final float saturation;
|
||||
public final int foodLevel;
|
||||
public final int dimension;
|
||||
public final int pathStartX;
|
||||
public final int pathStartY;
|
||||
public final int pathStartZ;
|
||||
@@ -46,8 +51,13 @@ public class MessageStatus implements iMessage {
|
||||
public final boolean safeToCancel;
|
||||
public final String currentGoal;
|
||||
public final String currentProcess;
|
||||
public final List<String> mainInventory;
|
||||
public final List<String> armor;
|
||||
public final String offHand;
|
||||
|
||||
public MessageStatus(DataInputStream in) throws IOException {
|
||||
this.playerUUID = in.readUTF();
|
||||
this.serverIP = in.readUTF();
|
||||
this.x = in.readDouble();
|
||||
this.y = in.readDouble();
|
||||
this.z = in.readDouble();
|
||||
@@ -57,6 +67,7 @@ public class MessageStatus implements iMessage {
|
||||
this.health = in.readFloat();
|
||||
this.saturation = in.readFloat();
|
||||
this.foodLevel = in.readInt();
|
||||
this.dimension = in.readInt();
|
||||
this.pathStartX = in.readInt();
|
||||
this.pathStartY = in.readInt();
|
||||
this.pathStartZ = in.readInt();
|
||||
@@ -68,9 +79,14 @@ public class MessageStatus implements iMessage {
|
||||
this.safeToCancel = in.readBoolean();
|
||||
this.currentGoal = in.readUTF();
|
||||
this.currentProcess = in.readUTF();
|
||||
this.mainInventory = readList(36, in);
|
||||
this.armor = readList(4, in);
|
||||
this.offHand = 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) {
|
||||
public MessageStatus(String playerUUID, String serverIP, double x, double y, double z, float yaw, float pitch, boolean onGround, float health, float saturation, int foodLevel, int dimension, int pathStartX, int pathStartY, int pathStartZ, boolean hasCurrentSegment, boolean hasNextSegment, boolean calcInProgress, double ticksRemainingInCurrent, boolean calcFailedLastTick, boolean safeToCancel, String currentGoal, String currentProcess, List<String> mainInventory, List<String> armor, String offHand) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.serverIP = serverIP;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
@@ -80,6 +96,7 @@ public class MessageStatus implements iMessage {
|
||||
this.health = health;
|
||||
this.saturation = saturation;
|
||||
this.foodLevel = foodLevel;
|
||||
this.dimension = dimension;
|
||||
this.pathStartX = pathStartX;
|
||||
this.pathStartY = pathStartY;
|
||||
this.pathStartZ = pathStartZ;
|
||||
@@ -91,10 +108,18 @@ public class MessageStatus implements iMessage {
|
||||
this.safeToCancel = safeToCancel;
|
||||
this.currentGoal = currentGoal;
|
||||
this.currentProcess = currentProcess;
|
||||
this.mainInventory = mainInventory;
|
||||
this.armor = armor;
|
||||
this.offHand = offHand;
|
||||
if (mainInventory.size() != 36 || armor.size() != 4) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException {
|
||||
out.writeUTF(playerUUID);
|
||||
out.writeUTF(serverIP);
|
||||
out.writeDouble(x);
|
||||
out.writeDouble(y);
|
||||
out.writeDouble(z);
|
||||
@@ -104,6 +129,7 @@ public class MessageStatus implements iMessage {
|
||||
out.writeFloat(health);
|
||||
out.writeFloat(saturation);
|
||||
out.writeInt(foodLevel);
|
||||
out.writeInt(dimension);
|
||||
out.writeInt(pathStartX);
|
||||
out.writeInt(pathStartY);
|
||||
out.writeInt(pathStartZ);
|
||||
@@ -115,6 +141,23 @@ public class MessageStatus implements iMessage {
|
||||
out.writeBoolean(safeToCancel);
|
||||
out.writeUTF(currentGoal);
|
||||
out.writeUTF(currentProcess);
|
||||
write(mainInventory, out);
|
||||
write(armor, out);
|
||||
out.writeUTF(offHand);
|
||||
}
|
||||
|
||||
private static List<String> readList(int length, DataInputStream in) throws IOException {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(in.readUTF());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void write(List<String> list, DataOutputStream out) throws IOException {
|
||||
for (String str : list) {
|
||||
out.writeUTF(str);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,10 +35,16 @@ import cabaletta.comms.downward.MessageComputationRequest;
|
||||
import cabaletta.comms.iMessage;
|
||||
import cabaletta.comms.upward.MessageComputationResponse;
|
||||
import cabaletta.comms.upward.MessageStatus;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ControllerBehavior extends Behavior implements IMessageListener {
|
||||
|
||||
@@ -60,8 +66,11 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
|
||||
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().getUniqueID().toString(),
|
||||
ctx.player().connection.getNetworkManager().getRemoteAddress().toString(),
|
||||
ctx.player().posX,
|
||||
ctx.player().posY,
|
||||
ctx.player().posZ,
|
||||
@@ -71,6 +80,7 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
|
||||
ctx.player().getHealth(),
|
||||
ctx.player().getFoodStats().getSaturationLevel(),
|
||||
ctx.player().getFoodStats().getFoodLevel(),
|
||||
ctx.world().provider.getDimensionType().getId(),
|
||||
pathStart.getX(),
|
||||
pathStart.getY(),
|
||||
pathStart.getZ(),
|
||||
@@ -81,7 +91,10 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
|
||||
baritone.getPathingBehavior().calcFailedLastTick(),
|
||||
baritone.getPathingBehavior().isSafeToCancel(),
|
||||
baritone.getPathingBehavior().getGoal() + "",
|
||||
baritone.getPathingControlManager().mostRecentInControl().map(IBaritoneProcess::displayName).orElse("")
|
||||
baritone.getPathingControlManager().mostRecentInControl().map(IBaritoneProcess::displayName).orElse(""),
|
||||
describeAll(ctx.player().inventory.mainInventory),
|
||||
describeAll(ctx.player().inventory.armorInventory),
|
||||
describe(ctx.player().inventory.offHandInventory.get(0))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -123,6 +136,43 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
|
||||
conn = null;
|
||||
}
|
||||
|
||||
public static List<String> describeAll(List<ItemStack> list) {
|
||||
return list.stream().map(ControllerBehavior::describe).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static String describe(ItemStack stack) {
|
||||
return describe(stack, true);
|
||||
}
|
||||
|
||||
public static String describe(ItemStack stack, boolean name) {
|
||||
if (stack.isEmpty()) {
|
||||
return "empty";
|
||||
}
|
||||
String description = "";
|
||||
if (name) {
|
||||
if (!stack.getDisplayName().contains("$")) { // who knows what's in there
|
||||
description += stack.getDisplayName();
|
||||
}
|
||||
description += "$";
|
||||
}
|
||||
description += stack.getTranslationKey() + ";" + stack.getItemDamage() + ";" + stack.getCount() + ";";
|
||||
NBTTagCompound data = stack.getTagCompound();
|
||||
if (data != null && data.hasKey("BlockEntityTag", 10)) {
|
||||
NBTTagCompound blockdata = data.getCompoundTag("BlockEntityTag");
|
||||
if (blockdata.hasKey("Items", 9)) {
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.withSize(27, ItemStack.EMPTY);
|
||||
ItemStackHelper.loadAllItems(blockdata, nonnulllist);
|
||||
|
||||
description += ";";
|
||||
for (ItemStack itemstack : nonnulllist) {
|
||||
description += describe(itemstack, false) + ",";
|
||||
}
|
||||
description = description.substring(0, description.length() - 1);
|
||||
}
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageChat msg) { // big brain
|
||||
ChatEvent event = new ChatEvent(ctx.player(), msg.msg);
|
||||
|
||||
Reference in New Issue
Block a user