From 767d0c8ec148f93c88db4dda7ee849c767f8dd7e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 14 Dec 2018 21:57:20 -0800 Subject: [PATCH 1/8] better reporting --- build.gradle | 1 + .../comms/ConstructingDeserializer.java | 2 +- .../cabaletta/comms/upward/MessageStatus.java | 45 +++++++++++++++- .../baritone/behavior/ControllerBehavior.java | 52 ++++++++++++++++++- 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index cdc236466..37f312b56 100755 --- a/build.gradle +++ b/build.gradle @@ -121,3 +121,4 @@ task proguard(type: ProguardTask) { task createDist(type: CreateDistTask, dependsOn: proguard) build.finalizedBy(createDist) + diff --git a/src/comms/java/cabaletta/comms/ConstructingDeserializer.java b/src/comms/java/cabaletta/comms/ConstructingDeserializer.java index eb15bdf09..f972ad904 100644 --- a/src/comms/java/cabaletta/comms/ConstructingDeserializer.java +++ b/src/comms/java/cabaletta/comms/ConstructingDeserializer.java @@ -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) m.getParameterTypes()[0]); + MSGS.add(0, (Class) m.getParameterTypes()[0]); } } } diff --git a/src/comms/java/cabaletta/comms/upward/MessageStatus.java b/src/comms/java/cabaletta/comms/upward/MessageStatus.java index f7727fc1f..465046da6 100644 --- a/src/comms/java/cabaletta/comms/upward/MessageStatus.java +++ b/src/comms/java/cabaletta/comms/upward/MessageStatus.java @@ -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 mainInventory; + public final List 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 mainInventory, List 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 readList(int length, DataInputStream in) throws IOException { + ArrayList result = new ArrayList<>(); + for (int i = 0; i < length; i++) { + result.add(in.readUTF()); + } + return result; + } + + private static void write(List list, DataOutputStream out) throws IOException { + for (String str : list) { + out.writeUTF(str); + } } @Override diff --git a/src/main/java/baritone/behavior/ControllerBehavior.java b/src/main/java/baritone/behavior/ControllerBehavior.java index 340310681..1eb912ad7 100644 --- a/src/main/java/baritone/behavior/ControllerBehavior.java +++ b/src/main/java/baritone/behavior/ControllerBehavior.java @@ -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 describeAll(List 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 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); From 8cd8a957639ba9fd07775670c23795e37c0906b1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 16 Dec 2018 20:14:07 -0800 Subject: [PATCH 2/8] little fix --- src/main/java/baritone/process/MineProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 9347dba24..2d5d18bed 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -39,7 +39,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.chunk.EmptyChunk; import java.util.*; import java.util.stream.Collectors; @@ -255,7 +254,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro .distinct() // remove any that are within loaded chunks that aren't actually what we want - .filter(pos -> ctx.world().getChunk(pos) instanceof EmptyChunk || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) + + .filter(pos -> !ctx.bsi().isLoaded(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)) // remove any that are implausible to mine (encased in bedrock, or touching lava) .filter(pos -> MineProcess.plausibleToBreak(ctx.bsi(), pos)) From 0249bd5dd76fa188c7ecc9213c502a35597dd26f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 17 Dec 2018 15:10:55 -0800 Subject: [PATCH 3/8] a few more packets, and consistent indexing --- .../comms/ConstructingDeserializer.java | 20 ++++--- .../cabaletta/comms/IMessageListener.java | 10 ++++ .../comms/downward/MessageClickSlot.java | 59 +++++++++++++++++++ .../comms/upward/MessageEchestConfirmed.java | 51 ++++++++++++++++ .../cabaletta/comms/upward/MessageStatus.java | 10 +++- .../baritone/behavior/ControllerBehavior.java | 14 ++++- .../baritone/behavior/MemoryBehavior.java | 27 +++++++++ 7 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 src/comms/java/cabaletta/comms/downward/MessageClickSlot.java create mode 100644 src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java diff --git a/src/comms/java/cabaletta/comms/ConstructingDeserializer.java b/src/comms/java/cabaletta/comms/ConstructingDeserializer.java index f972ad904..fe7a3bf2f 100644 --- a/src/comms/java/cabaletta/comms/ConstructingDeserializer.java +++ b/src/comms/java/cabaletta/comms/ConstructingDeserializer.java @@ -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) 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 diff --git a/src/comms/java/cabaletta/comms/IMessageListener.java b/src/comms/java/cabaletta/comms/IMessageListener.java index 2829f2671..7d6b09c98 100644 --- a/src/comms/java/cabaletta/comms/IMessageListener.java +++ b/src/comms/java/cabaletta/comms/IMessageListener.java @@ -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 diff --git a/src/comms/java/cabaletta/comms/downward/MessageClickSlot.java b/src/comms/java/cabaletta/comms/downward/MessageClickSlot.java new file mode 100644 index 000000000..5357cee59 --- /dev/null +++ b/src/comms/java/cabaletta/comms/downward/MessageClickSlot.java @@ -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 . + */ + +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); + } +} diff --git a/src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java b/src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java new file mode 100644 index 000000000..8dc3797a7 --- /dev/null +++ b/src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java @@ -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 . + */ + +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); + } +} diff --git a/src/comms/java/cabaletta/comms/upward/MessageStatus.java b/src/comms/java/cabaletta/comms/upward/MessageStatus.java index 465046da6..a8ea5e3ab 100644 --- a/src/comms/java/cabaletta/comms/upward/MessageStatus.java +++ b/src/comms/java/cabaletta/comms/upward/MessageStatus.java @@ -54,6 +54,8 @@ public class MessageStatus implements iMessage { public final List mainInventory; public final List 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 mainInventory, List 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 mainInventory, List 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 readList(int length, DataInputStream in) throws IOException { diff --git a/src/main/java/baritone/behavior/ControllerBehavior.java b/src/main/java/baritone/behavior/ControllerBehavior.java index 1eb912ad7..763889ac3 100644 --- a/src/main/java/baritone/behavior/ControllerBehavior.java +++ b/src/main/java/baritone/behavior/ControllerBehavior.java @@ -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); diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 06627d7e1..41db9559d 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -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) { From 380a645a6c20b47b46b79b2716137cfb504da9c5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 17 Dec 2018 19:51:24 -0800 Subject: [PATCH 4/8] only report items that are actually in the echest --- src/main/java/baritone/behavior/MemoryBehavior.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 41db9559d..ed63ee7c9 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -157,7 +157,7 @@ public final class MemoryBehavior extends Behavior { if (p instanceof SPacketSetSlot) { SPacketSetSlot slot = (SPacketSetSlot) p; - if (enderChestWindowId != null && slot.getWindowId() == enderChestWindowId) { + if (slot.getSlot() < 27 && enderChestWindowId != null && slot.getWindowId() == enderChestWindowId) { baritone.getControllerBehavior().trySend(new MessageEchestConfirmed(slot.getSlot(), ControllerBehavior.describe(slot.getStack()))); } } From 9dfcef6356e421c510463989f35d7fad30757584 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 15 Jan 2019 17:21:50 -0800 Subject: [PATCH 5/8] crucial performance optimization --- src/main/java/baritone/utils/ToolSet.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index ab8d2e403..fa71a6b0f 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -154,11 +154,10 @@ public class ToolSet { speed /= hardness; if (state.getMaterial().isToolNotRequired() || (!item.isEmpty() && item.canHarvestBlock(state))) { - speed /= 30; + return speed / 30; } else { - speed /= 100; + return speed / 100; } - return speed; } /** From 59320d9b85672f079d3b14ea8a1ed00e67d90fcd Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 16 Jan 2019 13:37:39 -0600 Subject: [PATCH 6/8] Auto test class javadoc --- src/main/java/baritone/utils/BaritoneAutoTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index 2e4a5706a..b7ae5fbb3 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -32,6 +32,15 @@ import net.minecraft.world.GameType; import net.minecraft.world.WorldSettings; import net.minecraft.world.WorldType; +/** + * Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific + * seed, setting a specified goal, and only allowing a certain amount of ticks to pass before the pathing test is + * considered a failure. In order to test locally, docker may be used, or through an IDE: Create a run config which runs + * in a separate directory from the primary one (./run), and set the enrivonmental variable {@code BARITONE_AUTO_TEST} + * to {@code true}. + * + * @author leijurv, Brady + */ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { public static final BaritoneAutoTest INSTANCE = new BaritoneAutoTest(); From db24822d2f908f839a4e1fc2a1808451d19f1045 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 16 Jan 2019 13:50:15 -0600 Subject: [PATCH 7/8] Fix cursed exception --- src/api/java/baritone/api/utils/PathCalculationResult.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/api/java/baritone/api/utils/PathCalculationResult.java b/src/api/java/baritone/api/utils/PathCalculationResult.java index 20aef9de7..a71c31a6b 100644 --- a/src/api/java/baritone/api/utils/PathCalculationResult.java +++ b/src/api/java/baritone/api/utils/PathCalculationResult.java @@ -19,6 +19,7 @@ package baritone.api.utils; import baritone.api.pathing.calc.IPath; +import java.util.Objects; import java.util.Optional; public class PathCalculationResult { @@ -31,11 +32,9 @@ public class PathCalculationResult { } public PathCalculationResult(Type type, IPath path) { + Objects.requireNonNull(type); this.path = path; this.type = type; - if (type == null) { - throw new IllegalArgumentException("come on"); - } } public final Optional getPath() { From 2daedecf9233c07d3dcf415b9ecbe2a8559ac3c4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 16 Jan 2019 17:42:43 -0800 Subject: [PATCH 8/8] maybe fix --- src/main/java/baritone/behavior/MemoryBehavior.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 499860185..696e107d5 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; +import baritone.api.event.events.TickEvent; import baritone.api.event.events.type.EventState; import baritone.cache.ContainerMemory; import baritone.cache.Waypoint; @@ -60,6 +61,14 @@ public final class MemoryBehavior extends Behavior { super(baritone); } + @Override + public synchronized void onTick(TickEvent event) { + if (event.getType() == TickEvent.Type.OUT) { + enderChestWindowId = null; + futureInventories.clear(); + } + } + @Override public synchronized void onPlayerUpdate(PlayerUpdateEvent event) { if (event.getState() == EventState.PRE) {