a few more packets, and consistent indexing
This commit is contained in:
@@ -17,10 +17,16 @@
|
||||
|
||||
package cabaletta.comms;
|
||||
|
||||
import cabaletta.comms.downward.MessageChat;
|
||||
import cabaletta.comms.downward.MessageClickSlot;
|
||||
import cabaletta.comms.downward.MessageComputationRequest;
|
||||
import cabaletta.comms.upward.MessageComputationResponse;
|
||||
import cabaletta.comms.upward.MessageEchestConfirmed;
|
||||
import cabaletta.comms.upward.MessageStatus;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,12 +36,12 @@ public enum ConstructingDeserializer implements MessageDeserializer {
|
||||
|
||||
ConstructingDeserializer() {
|
||||
MSGS = new ArrayList<>();
|
||||
// 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(0, (Class<? extends iMessage>) m.getParameterTypes()[0]);
|
||||
}
|
||||
}
|
||||
MSGS.add(MessageStatus.class);
|
||||
MSGS.add(MessageChat.class);
|
||||
MSGS.add(MessageComputationRequest.class);
|
||||
MSGS.add(MessageComputationResponse.class);
|
||||
MSGS.add(MessageEchestConfirmed.class);
|
||||
MSGS.add(MessageClickSlot.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
package cabaletta.comms;
|
||||
|
||||
import cabaletta.comms.downward.MessageChat;
|
||||
import cabaletta.comms.downward.MessageClickSlot;
|
||||
import cabaletta.comms.downward.MessageComputationRequest;
|
||||
import cabaletta.comms.upward.MessageComputationResponse;
|
||||
import cabaletta.comms.upward.MessageEchestConfirmed;
|
||||
import cabaletta.comms.upward.MessageStatus;
|
||||
|
||||
public interface IMessageListener {
|
||||
@@ -39,6 +41,14 @@ public interface IMessageListener {
|
||||
unhandled(message);
|
||||
}
|
||||
|
||||
default void handle(MessageEchestConfirmed message) {
|
||||
unhandled(message);
|
||||
}
|
||||
|
||||
default void handle(MessageClickSlot 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
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 MessageClickSlot implements iMessage {
|
||||
public final int windowId;
|
||||
public final int slotId;
|
||||
public final int mouseButton;
|
||||
public final int clickType; // index into ClickType.values()
|
||||
|
||||
public MessageClickSlot(DataInputStream in) throws IOException {
|
||||
this.windowId = in.readInt();
|
||||
this.slotId = in.readInt();
|
||||
this.mouseButton = in.readInt();
|
||||
this.clickType = in.readInt();
|
||||
}
|
||||
|
||||
public MessageClickSlot(int windowId, int slotId, int mouseButton, int clickType) {
|
||||
this.windowId = windowId;
|
||||
this.slotId = slotId;
|
||||
this.mouseButton = mouseButton;
|
||||
this.clickType = clickType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException {
|
||||
out.writeInt(windowId);
|
||||
out.writeInt(slotId);
|
||||
out.writeInt(mouseButton);
|
||||
out.writeInt(clickType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(IMessageListener listener) {
|
||||
listener.handle(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 MessageEchestConfirmed implements iMessage {
|
||||
public final int slot;
|
||||
public final String item;
|
||||
|
||||
public MessageEchestConfirmed(DataInputStream in) throws IOException {
|
||||
this.slot = in.readInt();
|
||||
this.item = in.readUTF();
|
||||
}
|
||||
|
||||
public MessageEchestConfirmed(int slot, String item) {
|
||||
this.slot = slot;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream out) throws IOException {
|
||||
out.writeInt(slot);
|
||||
out.writeUTF(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(IMessageListener listener) {
|
||||
listener.handle(this);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,8 @@ public class MessageStatus implements iMessage {
|
||||
public final List<String> mainInventory;
|
||||
public final List<String> armor;
|
||||
public final String offHand;
|
||||
public final int windowId;
|
||||
public final boolean eChestOpen;
|
||||
|
||||
public MessageStatus(DataInputStream in) throws IOException {
|
||||
this.playerUUID = in.readUTF();
|
||||
@@ -82,9 +84,11 @@ public class MessageStatus implements iMessage {
|
||||
this.mainInventory = readList(36, in);
|
||||
this.armor = readList(4, in);
|
||||
this.offHand = in.readUTF();
|
||||
this.windowId = in.readInt();
|
||||
this.eChestOpen = in.readBoolean();
|
||||
}
|
||||
|
||||
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) {
|
||||
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, int windowId, boolean eChestOpen) {
|
||||
this.playerUUID = playerUUID;
|
||||
this.serverIP = serverIP;
|
||||
this.x = x;
|
||||
@@ -111,6 +115,8 @@ public class MessageStatus implements iMessage {
|
||||
this.mainInventory = mainInventory;
|
||||
this.armor = armor;
|
||||
this.offHand = offHand;
|
||||
this.windowId = windowId;
|
||||
this.eChestOpen = eChestOpen;
|
||||
if (mainInventory.size() != 36 || armor.size() != 4) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
@@ -144,6 +150,8 @@ public class MessageStatus implements iMessage {
|
||||
write(mainInventory, out);
|
||||
write(armor, out);
|
||||
out.writeUTF(offHand);
|
||||
out.writeInt(windowId);
|
||||
out.writeBoolean(eChestOpen);
|
||||
}
|
||||
|
||||
private static List<String> readList(int length, DataInputStream in) throws IOException {
|
||||
|
||||
@@ -31,10 +31,12 @@ import cabaletta.comms.BufferedConnection;
|
||||
import cabaletta.comms.IConnection;
|
||||
import cabaletta.comms.IMessageListener;
|
||||
import cabaletta.comms.downward.MessageChat;
|
||||
import cabaletta.comms.downward.MessageClickSlot;
|
||||
import cabaletta.comms.downward.MessageComputationRequest;
|
||||
import cabaletta.comms.iMessage;
|
||||
import cabaletta.comms.upward.MessageComputationResponse;
|
||||
import cabaletta.comms.upward.MessageStatus;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -94,7 +96,9 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
|
||||
baritone.getPathingControlManager().mostRecentInControl().map(IBaritoneProcess::displayName).orElse(""),
|
||||
describeAll(ctx.player().inventory.mainInventory),
|
||||
describeAll(ctx.player().inventory.armorInventory),
|
||||
describe(ctx.player().inventory.offHandInventory.get(0))
|
||||
describe(ctx.player().inventory.offHandInventory.get(0)),
|
||||
ctx.player().openContainer.windowId,
|
||||
baritone.getMemoryBehavior().eChestOpen()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,6 +210,14 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageClickSlot msg) {
|
||||
if (ctx.player().openContainer.windowId != msg.windowId) {
|
||||
return; // stale
|
||||
}
|
||||
ctx.playerController().windowClick(msg.windowId, msg.slotId, msg.mouseButton, ClickType.values()[msg.clickType], ctx.player());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unhandled(iMessage msg) {
|
||||
Helper.HELPER.logDebug("Unhandled message received by ControllerBehavior " + msg);
|
||||
|
||||
@@ -26,15 +26,18 @@ import baritone.cache.ContainerMemory;
|
||||
import baritone.cache.Waypoint;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import cabaletta.comms.upward.MessageEchestConfirmed;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockBed;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.client.CPacketClickWindow;
|
||||
import net.minecraft.network.play.client.CPacketCloseWindow;
|
||||
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
|
||||
import net.minecraft.network.play.server.SPacketCloseWindow;
|
||||
import net.minecraft.network.play.server.SPacketOpenWindow;
|
||||
import net.minecraft.network.play.server.SPacketSetSlot;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityLockable;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -101,6 +104,11 @@ public final class MemoryBehavior extends Behavior {
|
||||
updateInventory();
|
||||
getCurrent().save();
|
||||
}
|
||||
|
||||
if (p instanceof CPacketClickWindow) {
|
||||
CPacketClickWindow c = event.cast();
|
||||
System.out.println("CLICK " + c.getWindowId() + " " + c.getSlotId() + " " + c.getUsedButton() + " " + c.getClickType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,9 +146,28 @@ public final class MemoryBehavior extends Behavior {
|
||||
updateInventory();
|
||||
getCurrent().save();
|
||||
}
|
||||
|
||||
// apparently doesn't happen
|
||||
/*if (p instanceof SPacketWindowItems) {
|
||||
SPacketWindowItems meme = (SPacketWindowItems) p;
|
||||
if (meme.getWindowId() == ctx.player().openContainer.windowId && enderChestWindowId != null && meme.getWindowId() == enderChestWindowId) {
|
||||
System.out.println("RECEIVED GUARANTEED ECHEST CONTENTS" + meme.getItemStacks());
|
||||
}
|
||||
}*/
|
||||
|
||||
if (p instanceof SPacketSetSlot) {
|
||||
SPacketSetSlot slot = (SPacketSetSlot) p;
|
||||
if (enderChestWindowId != null && slot.getWindowId() == enderChestWindowId) {
|
||||
baritone.getControllerBehavior().trySend(new MessageEchestConfirmed(slot.getSlot(), ControllerBehavior.describe(slot.getStack())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean eChestOpen() {
|
||||
return enderChestWindowId != null && ctx.player().openContainer.windowId == enderChestWindowId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockInteract(BlockInteractEvent event) {
|
||||
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BlockBed) {
|
||||
|
||||
Reference in New Issue
Block a user