From 0e900f2c0556cd768b77d2b1a52c2e4494892af3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 19 Aug 2018 17:28:19 -0700 Subject: [PATCH] purge old MineBot --- src/main/resources/baritone/Baritone.java | 439 ---------------- .../resources/baritone/mining/MickeyMine.java | 487 ------------------ .../baritone/movement/MovementManager.java | 230 --------- .../resources/baritone/pathfinding/Path.java | 274 ---------- .../baritone/pathfinding/PathFinder.java | 268 ---------- .../baritone/pathfinding/actions/Action.java | 207 -------- .../pathfinding/actions/ActionBridge.java | 182 ------- .../pathfinding/actions/ActionClimb.java | 106 ---- .../pathfinding/actions/ActionDescend.java | 37 -- .../actions/ActionDescendThree.java | 33 -- .../pathfinding/actions/ActionDescendTwo.java | 33 -- .../pathfinding/actions/ActionFall.java | 42 -- .../pathfinding/actions/ActionPillar.java | 140 ----- .../actions/ActionPlaceOrBreak.java | 229 -------- .../actions/ActionWalkDiagonal.java | 56 -- .../baritone/schematic/Schematic.java | 96 ---- .../baritone/schematic/SchematicBuilder.java | 69 --- .../baritone/schematic/SchematicLoader.java | 76 --- .../resources/baritone/ui/LookManager.java | 371 ------------- .../resources/baritone/ui/PathRenderer.java | 178 ------- src/main/resources/baritone/util/Autorun.java | 42 -- .../resources/baritone/util/BlockPuncher.java | 43 -- .../resources/baritone/util/ChatCommand.java | 385 -------------- src/main/resources/baritone/util/MCEdit.java | 71 --- src/main/resources/baritone/util/Manager.java | 109 ---- .../resources/baritone/util/ManagerTick.java | 18 - src/main/resources/baritone/util/Memory.java | 398 -------------- src/main/resources/baritone/util/Out.java | 123 ----- 28 files changed, 4742 deletions(-) delete mode 100644 src/main/resources/baritone/Baritone.java delete mode 100644 src/main/resources/baritone/mining/MickeyMine.java delete mode 100644 src/main/resources/baritone/movement/MovementManager.java delete mode 100644 src/main/resources/baritone/pathfinding/Path.java delete mode 100644 src/main/resources/baritone/pathfinding/PathFinder.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/Action.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionBridge.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionClimb.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionDescend.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionDescendThree.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionDescendTwo.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionFall.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionPillar.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java delete mode 100644 src/main/resources/baritone/pathfinding/actions/ActionWalkDiagonal.java delete mode 100644 src/main/resources/baritone/schematic/Schematic.java delete mode 100644 src/main/resources/baritone/schematic/SchematicBuilder.java delete mode 100644 src/main/resources/baritone/schematic/SchematicLoader.java delete mode 100644 src/main/resources/baritone/ui/LookManager.java delete mode 100644 src/main/resources/baritone/ui/PathRenderer.java delete mode 100644 src/main/resources/baritone/util/Autorun.java delete mode 100644 src/main/resources/baritone/util/BlockPuncher.java delete mode 100644 src/main/resources/baritone/util/ChatCommand.java delete mode 100644 src/main/resources/baritone/util/MCEdit.java delete mode 100644 src/main/resources/baritone/util/Manager.java delete mode 100644 src/main/resources/baritone/util/ManagerTick.java delete mode 100644 src/main/resources/baritone/util/Memory.java delete mode 100644 src/main/resources/baritone/util/Out.java diff --git a/src/main/resources/baritone/Baritone.java b/src/main/resources/baritone/Baritone.java deleted file mode 100644 index 4e11745e..00000000 --- a/src/main/resources/baritone/Baritone.java +++ /dev/null @@ -1,439 +0,0 @@ -package baritone; - -import baritone.movement.MovementManager; -import baritone.pathfinding.Path; -import baritone.pathfinding.PathFinder; -import baritone.pathfinding.actions.Action; -import baritone.pathfinding.actions.ActionPlaceOrBreak; -import baritone.pathfinding.goals.Goal; -import baritone.pathfinding.goals.GoalComposite; -import baritone.schematic.SchematicBuilder; -import baritone.ui.LookManager; -import baritone.util.Autorun; -import baritone.util.Manager; -import baritone.util.ManagerTick; -import baritone.util.Memory; -import baritone.util.Out; -import baritone.util.ToolSet; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.entity.Entity; -import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; - -/** - * - * @author leijurv - */ -public class Baritone { - - public static BlockPos playerFeet = null; - public static World world = null; - public static boolean allowDiagonal = true; - public static boolean farf5 = false; - public static boolean slowPath = false; - public static boolean pause = false; - public static boolean overrideF3 = false; - public static boolean sketchytracer = false; - public static boolean allowVerticalMotion = true; - public static boolean actuallyPutMessagesInChat = false; - public static boolean isThereAnythingInProgress = false; - public static boolean fullBright = true; - public static boolean plsCancel = false; - public static int tickNumber = 0; - public static boolean ticktimer = false; - public static boolean allowBreakOrPlace = true; - public static boolean hasThrowaway = true; - public static Path currentPath = null; - public static Path nextPath = null; - public static boolean calculatingNext = false; - public static Goal goal = null; - static int numTicksInInventoryOrCrafting = 0; - public static BlockPos death; - public static long lastDeath = 0; - public static SchematicBuilder currentBuilder = null; - - public static IBlockState get(BlockPos pos) { // wrappers for future 1.13 compat - return world.getBlockState(pos); - } - - public static Block getBlock(BlockPos pos) { - return get(pos).getBlock(); - } - - public static boolean isBlockNormalCube(BlockPos pos) { - IBlockState state = get(pos); - return state.getBlock().isBlockNormalCube(state); - } - - /** - * Called by minecraft.java - */ - public static void onTick() { - try { - long start = System.currentTimeMillis(); - onTick1(); - long end = System.currentTimeMillis(); - long time = end - start; - if (ticktimer && time > 3) { - Out.gui("Tick took " + time + "ms", Out.Mode.Debug); - Out.log("Tick took " + time + "ms"); - } - } catch (Exception ex) { - Out.log("Exception"); - Logger.getLogger(Baritone.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public static void onTick1() { - if (pause) { - Manager.tick(LookManager.class, true); - MovementManager.clearMovement(); - return; - } - world = Minecraft.getMinecraft().world; - if (world == null || Minecraft.getMinecraft().player == null) { - Baritone.cancelPath(); - Baritone.plsCancel = true; - return; - } - MovementManager.leftPressTime = 0; - MovementManager.rightPressTime = 0; - if (MovementManager.isLeftClick) { - MovementManager.leftPressTime = 5; - } - if (MovementManager.isRightClick) { - MovementManager.rightPressTime = 5; - } - Manager.tick(LookManager.class, true); - - /*MovementManager.isLeftClick = false; - MovementManager.isRightClick = false; - MovementManager.jumping = false; - MovementManager.sneak = false;*/ - MovementManager.clearMovement(); - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - World theWorld = Minecraft.getMinecraft().world; - playerFeet = new BlockPos(thePlayer.posX, thePlayer.posY, thePlayer.posZ); - if (thePlayer.isDead && System.currentTimeMillis() > lastDeath + 10000) { - death = playerFeet; - lastDeath = System.currentTimeMillis(); - Out.gui("Saved death position (" + death + "). do /death to set goal.", Out.Mode.Minimal); - //impact handles this - //thePlayer.respawnPlayer(); - //Minecraft.getMinecraft().displayGuiScreen(null); - } - tickNumber++; - hasThrowaway = ActionPlaceOrBreak.hasthrowaway(); - ManagerTick.tickPath = true; - Manager.tick(LookManager.class); - BlockPos ts = whatAreYouLookingAt(); - if (ts != null) { - Memory.scanBlock(ts); - } - if (currentBuilder != null) { - currentBuilder.tick(); - } - if (currentPath != null && ManagerTick.tickPath) { - if (currentPath.tick()) { - Goal currentPathGoal = currentPath == null ? null : currentPath.goal; - if (currentPath != null && currentPath.failed) { - clearPath(); - Out.gui("Recalculating because path failed", Out.Mode.Standard); - nextPath = null; - if (isAir(playerFeet.down())) {//sometimes we are jumping and we make a path that starts in the air and then jumps up, which is impossible - Out.gui("DOING THE JANKY THING, WARNING", Out.Mode.Debug); - findPathInNewThread(playerFeet.down(), true); - } else { - findPathInNewThread(playerFeet, true); - } - return; - } else { - clearPath(); - } - currentPath = null; - if (goal.isInGoal(playerFeet)) { - Out.gui("All done. At goal", Out.Mode.Standard); - nextPath = null; - } else { - Out.gui("Done with segment", Out.Mode.Debug); - if (nextPath != null || calculatingNext) { - if (calculatingNext) { - calculatingNext = false; - Out.gui("Patiently waiting to finish", Out.Mode.Debug); - } else { - currentPath = nextPath; - nextPath = null; - if (!currentPath.start.equals(playerFeet)) { - //Out.gui("The next path starts at " + currentPath.start + " but I'm at " + playerFeet + ". not doing it", true); - currentPath = null; - findPathInNewThread(playerFeet, true); - } else { - Out.gui("Going onto next", Out.Mode.Debug); - if (!currentPath.goal.isInGoal(currentPath.end)) { - planAhead(); - } - } - } - } else { - Out.gui("Hmm. I'm not actually at the goal. Recalculating.", Out.Mode.Debug); - findPathInNewThread(playerFeet, (currentPathGoal != null && goal != null) ? !(currentPathGoal instanceof GoalComposite) && currentPathGoal.toString().equals(goal.toString()) : true); - } - } - } else { - if (Action.isWater(theWorld.getBlockState(playerFeet).getBlock())) { - //if (Movement.isWater(theWorld.getBlockState(playerFeet.down()).getBlock()) || !Movement.canWalkOn(playerFeet.down()) || Movement.isWater(theWorld.getBlockState(playerFeet.up()).getBlock())) { - //if water is deeper than one block, or we can't walk on what's below the water, or our head is in water, jump - Out.log("Jumping because in water"); - MovementManager.jumping = true; - //} - } - if (nextPath != null) { - for (int i = 1; i < 20 && i < nextPath.path.size(); i++) { - if (playerFeet.equals(nextPath.path.get(i))) { - Out.gui("Jumping to position " + i + " in nextpath", Out.Mode.Debug); - currentPath = nextPath; - currentPath.calculatePathPosition(); - nextPath = null; - if (!currentPath.goal.isInGoal(currentPath.end)) { - planAhead(); - } - break; - } - } - } - LookManager.nudgeToLevel(); - } - } - /*if (Minecraft.getMinecraft().currentScreen != null && (Minecraft.getMinecraft().currentScreen instanceof GuiCrafting || Minecraft.getMinecraft().currentScreen instanceof GuiInventory || Minecraft.getMinecraft().currentScreen instanceof GuiFurnace)) { - MovementManager.isLeftClick = false; - MovementManager.leftPressTime = -5; - numTicksInInventoryOrCrafting++; - if (numTicksInInventoryOrCrafting > 20 * 20) { - Minecraft.getMinecraft().player.closeScreen(); - numTicksInInventoryOrCrafting = 0; - } - } else { - numTicksInInventoryOrCrafting = 0; - }*/ // impact does this - if (isThereAnythingInProgress && Action.isWater(theWorld.getBlockState(playerFeet).getBlock())) { - if (Action.isWater(theWorld.getBlockState(playerFeet.down()).getBlock()) || !Action.canWalkOn(playerFeet.down()) || Action.isWater(theWorld.getBlockState(playerFeet.up()).getBlock())) { - //if water is deeper than one block, or we can't walk on what's below the water, or our head is in water, jump - Out.log("Jumping because in water and pathing"); - MovementManager.jumping = true; - } - } - Manager.tick(LookManager.class, false); - MovementManager.tick(); - } - - public static boolean isPathFinding() { - return isThereAnythingInProgress; - } - - /** - * Clears movement, clears the current path, and lets go of left click. It - * purposefully does NOT clear nextPath. - */ - public static void clearPath() { - currentPath = null; - MovementManager.letGoOfLeftClick(); - MovementManager.clearMovement(); - } - - public static String info(BlockPos bp) { - IBlockState state = get(bp); - Block block = state.getBlock(); - return bp + " " + block + " can walk on: " + Action.canWalkOn(bp) + " can walk through: " + Action.canWalkThrough(bp) + " is full block: " + block.isFullBlock(state) + " is full cube: " + block.isFullCube(state) + " is liquid: " + Action.isLiquid(block) + " is flow: " + Action.isFlowing(bp, state); - } - - /** - * Cancel the path - * - */ - public static void cancelPath() { - nextPath = null; - currentBuilder = null; - clearPath(); - } - - public static boolean isAir(BlockPos pos) { - return Baritone.get(pos).getBlock().equals(Blocks.AIR); - } - - public static void findPathInNewThread(final boolean talkAboutIt) { - findPathInNewThread(playerFeet, talkAboutIt); - } - - /** - * In a new thread, pathfind to target blockpos - * - * @param start - * @param talkAboutIt - */ - public static void findPathInNewThread(final BlockPos start, final boolean talkAboutIt) { - if (isThereAnythingInProgress) { - return; - } - isThereAnythingInProgress = true; - new Thread() { - @Override - public void run() { - if (talkAboutIt) { - Out.gui("Starting to search for path from " + start + " to " + goal, Out.Mode.Debug); - } - try { - currentPath = findPath(start); - } catch (Exception e) { - } - isThereAnythingInProgress = false; - if (!currentPath.goal.isInGoal(currentPath.end)) { - if (talkAboutIt) { - Out.gui("I couldn't get all the way to " + goal + ", but I'm going to get as close as I can. " + currentPath.numNodes + " nodes considered", Out.Mode.Standard); - } - planAhead(); - } else if (talkAboutIt) { - Out.gui("Finished finding a path from " + start + " to " + goal + ". " + currentPath.numNodes + " nodes considered", Out.Mode.Debug); - } - } - }.start(); - } - - /** - * In a new thread, pathfind from currentPath.end to goal. Store resulting - * path in nextPath (or in currentPath if calculatingNext was set to false - * in the meantime). - */ - public static void planAhead() { - if (isThereAnythingInProgress) { - return; - } - isThereAnythingInProgress = true; - new Thread() { - @Override - public void run() { - Out.gui("Planning ahead", Out.Mode.Debug); - calculatingNext = true; - Path path = findPath(currentPath.end); - isThereAnythingInProgress = false; - Out.gui("Done planning ahead " + calculatingNext, Out.Mode.Debug); - if (calculatingNext) { - nextPath = path; - } else { - currentPath = path; - if (!plsCancel) { - planAhead(); - } - } - calculatingNext = false; - Out.gui(path.numNodes + " nodes considered, calculated " + path.start + " to " + path.end, Out.Mode.Debug); - } - }.start(); - } - - /** - * Actually do the pathing - * - * @param start - * @return - */ - private static Path findPath(BlockPos start) { - if (goal == null) { - Out.gui("babe, please. there is no goal", Out.Mode.Minimal); - return null; - } - try { - PathFinder pf = new PathFinder(start, goal); - Path path = pf.calculatePath(); - return path; - } catch (Exception e) { - Logger.getLogger(Baritone.class.getName()).log(Level.SEVERE, null, e); - isThereAnythingInProgress = false; - return null; - } - } - - /** - * What block is the player looking at - * - * @return the position of it - */ - public static BlockPos whatAreYouLookingAt() { - Minecraft mc = Minecraft.getMinecraft(); - if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) { - return mc.objectMouseOver.getBlockPos(); - } - return null; - } - - public static void switchToBestTool() { - BlockPos pos = whatAreYouLookingAt(); - if (pos == null) { - return; - } - IBlockState state = Baritone.get(pos); - if (state.getBlock().equals(Blocks.AIR)) { - return; - } - switchtotool(state); - } - - public static void switchtotool(IBlockState b) { - Baritone.switchtotool(b, new ToolSet()); - } - - public static void switchtotool(IBlockState b, ToolSet ts) { - Minecraft.getMinecraft().player.inventory.currentItem = ts.getBestSlot(b); - } - - public static Entity whatEntityAreYouLookingAt() { - Minecraft mc = Minecraft.getMinecraft(); - if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.ENTITY) { - return mc.objectMouseOver.entityHit; - } - return null; - } - - public static List getDebugGui() { - if (!overrideF3) { - return null; - } - List list = new ArrayList(); - list.add("§5[§dBaritone§5]§f"); - Class c = LookManager.class; - list.add("§r[§" + (Manager.enabled(c) ? "a" : "c") + c.getSimpleName() + "§r]"); - list.add(""); - list.add("Current goal: " + goal); - list.add(""); - if (currentPath != null) { - list.add("Current path start: " + currentPath.start); - list.add("Current path end: " + currentPath.end); - list.add("Current path ends in current goal: " + (goal == null ? null : goal.isInGoal(currentPath.end))); - if (!currentPath.goal.equals(goal)) { - list.add("Current path goal: " + currentPath.goal); - } - } - if (nextPath != null) { - list.add(""); - list.add("Next path start: " + nextPath.start); - list.add("Next path end: " + nextPath.end); - list.add("Next path ends in current goal: " + (goal == null ? null : goal.isInGoal(nextPath.end))); - } - return list; - } - - public boolean isNull() throws NullPointerException { - NullPointerException up = new NullPointerException("You are disgusting"); - throw up; - //To use this surround the call to this message with a try-catch then compare the length of the NullPointerException.getMessage() - } -} diff --git a/src/main/resources/baritone/mining/MickeyMine.java b/src/main/resources/baritone/mining/MickeyMine.java deleted file mode 100644 index c77b3a47..00000000 --- a/src/main/resources/baritone/mining/MickeyMine.java +++ /dev/null @@ -1,487 +0,0 @@ -package baritone.mining; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.pathfinding.actions.Action; -import baritone.pathfinding.goals.Goal; -import baritone.pathfinding.goals.GoalBlock; -import baritone.pathfinding.goals.GoalComposite; -import baritone.pathfinding.goals.GoalTwoBlocks; -import baritone.pathfinding.goals.GoalYLevel; -import baritone.ui.LookManager; -import baritone.util.Manager; -import baritone.util.ManagerTick; -import baritone.util.Memory; -import baritone.util.Out; -import java.util.ArrayList; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.Chunk; - -/** - * - * @author galdara - */ -public class MickeyMine extends ManagerTick { - - public static final int Y_DIAMOND = 13; - public static final int Y_IRON = 36; - public static int yLevel = Y_DIAMOND; - static ArrayList goalBlocks = null; - static boolean isGoingToMine = false; - static boolean isMining = false; - public static boolean tempDisable = false; - static EnumFacing miningFacing = EnumFacing.EAST; - static ArrayList diamondChunks = new ArrayList(); - static ArrayList hasBeenMined = new ArrayList(); - static ArrayList needsToBeMined = new ArrayList(); - static ArrayList priorityNeedsToBeMined = new ArrayList(); - static ArrayList chunkHasDiamonds = new ArrayList(); - static BlockPos branchPosition = null; - static final String[] ores = {"diamond", "iron", "coal", "gold", "emerald"}; - static final boolean[] enabled = {true, true, false, true, true}; - static boolean mightNeedToGoBackToPath = false; - - public static void notifyFullness(String item, boolean isFull) { - if (item.equals("stone")) { - return; - } - boolean up = false; - for (int i = 0; i < ores.length; i++) { - if (ores[i].endsWith(item)) { - if (enabled[i] == isFull) { - Out.gui((isFull ? "is full" : "not full") + " of " + item + " so therefore " + ores[i], Out.Mode.Minimal); - enabled[i] = !isFull; - up = true; - } - } - } - if (up) { - calculateGoal(); - } - } - - public static void toggleOre(String ore) { - String lower = ore.toLowerCase(); - if (lower.trim().length() == 0) { - for (int i = 0; i < ores.length; i++) { - Out.gui(ores[i] + ": " + enabled[i], Out.Mode.Minimal); - } - return; - } - boolean m = false; - for (int i = 0; i < ores.length; i++) { - if (!ores[i].contains(lower)) { - Out.gui(ores[i] + ": " + enabled[i], Out.Mode.Minimal); - continue; - } - m = true; - enabled[i] = !enabled[i]; - Out.gui(ores[i] + ": " + enabled[i] + " (I toggled this one just now)", Out.Mode.Minimal); - } - if (m) { - goalBlocks = new ArrayList(); - calculateGoal(); - } - } - - public static void calculateGoal() { - goalBlocks = new ArrayList(); - for (int i = 0; i < ores.length; i++) { - if (!enabled[i]) { - continue; - } - String oreName = "minecraft:" + ores[i] + "_ore"; - Block block = Block.getBlockFromName(oreName); - if (block == null) { - Out.gui(oreName + " doesn't exist bb", Out.Mode.Minimal); - throw new NullPointerException(oreName + " doesn't exist bb"); - } - goalBlocks.add(block); - } - } - - public static void doMine() { - if (goalBlocks == null) { - calculateGoal(); - } - MovementManager.clearMovement(); - Out.log("Goal blocks: " + goalBlocks); - Out.log("priority: " + priorityNeedsToBeMined); - Out.log("needs to be mined: " + needsToBeMined); - updateBlocksMined(); - if (priorityNeedsToBeMined.isEmpty() && needsToBeMined.isEmpty()) { - doBranchMine(); - } else if (priorityNeedsToBeMined.isEmpty()) { - doNormalMine(); - } - if (ticksSinceBlockMined > 200) { - Out.gui("Mickey mine stops, its been like 10 seconds and nothing has happened", Out.Mode.Debug); - Manager.getManager(MickeyMine.class).cancel(); - } - } - - public static boolean torch() { - EntityPlayerSP p = Minecraft.getMinecraft().player; - NonNullList inv = p.inventory.mainInventory; - for (int i = 0; i < 9; i++) { - ItemStack item = inv.get(i); - if (item == null) { - continue; - } - if (item.getItem().equals(Item.getByNameOrId("minecraft:torch"))) { - p.inventory.currentItem = i; - return true; - } - } - return false; - } - - public static void doBranchMine() { - if (branchPosition == null) { - BlockPos player = Baritone.playerFeet; - branchPosition = new BlockPos(player.getX(), yLevel, player.getZ()); - } - if (!Memory.blockLoaded(branchPosition)) {//if this starts before chunks load, this thing just goes on forever - branchPosition = null; - return; - } - if (!branchPosition.equals(Baritone.playerFeet)) { - Out.gui("Should be at branch position " + branchPosition + " " + Baritone.playerFeet, Out.Mode.Debug); - mightNeedToGoBackToPath = true; - } else if (torch()) { - if (LookManager.lookAtBlock(branchPosition.down(), true)) { - MovementManager.rightClickMouse(); - } else { - return; - } - } - int i; - int l = 5; - for (i = 0; i < l || diamondChunks.contains(tupleFromBlockPos(branchPosition.offset(miningFacing, i))); i++) { - addNormalBlock(branchPosition.offset(miningFacing, i).up(), true); - addNormalBlock(branchPosition.offset(miningFacing, i), true); - Out.log("branche" + i); - if (i >= l) { - Out.gui("Not mining " + branchPosition.offset(miningFacing, i) + " because it's in known diamond chunk " + tupleFromBlockPos(branchPosition.offset(miningFacing, i)), Out.Mode.Debug); - } - } - i--; - Out.gui("Branch distance " + i, Out.Mode.Debug); - BlockPos futureBranchPosition = branchPosition.offset(miningFacing, i); - if (futureBranchPosition.getY() != yLevel) { - onCancel1(); - return; - } - Out.log("player reach: " + Minecraft.getMinecraft().playerController.getBlockReachDistance()); - for (int j = 1; j <= Math.ceil(Minecraft.getMinecraft().playerController.getBlockReachDistance()); j++) { - addNormalBlock(futureBranchPosition.offset(miningFacing.rotateY(), j).up(), false); - } - for (int j = 1; j <= Math.ceil(Minecraft.getMinecraft().playerController.getBlockReachDistance()); j++) { - addNormalBlock(futureBranchPosition.offset(miningFacing.rotateYCCW(), j).up(), false); - } - branchPosition = futureBranchPosition; - } - - public static void doPriorityMine() { - Goal[] toComposite = new Goal[priorityNeedsToBeMined.size()]; - for (int i = 0; i < toComposite.length; i++) { - toComposite[i] = new GoalTwoBlocks(priorityNeedsToBeMined.get(i)); - } - Baritone.goal = new GoalComposite(toComposite); - if (Baritone.currentPath == null && !Baritone.isPathFinding()) { - Baritone.findPathInNewThread(Baritone.playerFeet, false); - } else { - addNearby(); - } - } - - public static void addNearby() { - BlockPos playerFeet = Baritone.playerFeet; - int searchDist = 4;//why four? idk - for (int x = playerFeet.getX() - searchDist; x <= playerFeet.getX() + searchDist; x++) { - for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) { - for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) { - BlockPos pos = new BlockPos(x, y, z); - if (isGoalBlock(pos)) { - if (LookManager.couldIReach(pos)) {//crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught - addPriorityBlock(pos); - } - } - } - } - } - } - - public static void doNormalMine() { - if (mightNeedToGoBackToPath) { - Baritone.goal = new GoalBlock(branchPosition); - if (Baritone.currentPath == null && !Baritone.isPathFinding()) { - Baritone.findPathInNewThread(Baritone.playerFeet, false); - Out.gui("Pathing back to branch", Out.Mode.Standard); - } - if (Baritone.playerFeet.equals(branchPosition)) { - mightNeedToGoBackToPath = false; - Out.gui("I'm back", Out.Mode.Debug); - } - return; - } - addNearby(); - BlockPos toMine = needsToBeMined.get(0); - if (LookManager.lookAtBlock(toMine, true)) { - if (Action.avoidBreaking(toMine)) { - miningFacing = miningFacing.rotateY(); - Out.gui("Since I need to avoid breaking " + toMine + ", I'm rotating to " + miningFacing, Out.Mode.Debug); - needsToBeMined.clear(); - //.priorityNeedsToBeMined.clear(); - } else { - Baritone.switchToBestTool(); - MovementManager.isLeftClick = true; - Out.log("Looking"); - if (Baritone.playerFeet.equals(branchPosition)) { - Out.log("IN position"); - if (Baritone.whatAreYouLookingAt() == null) { - Out.log("Can't see, going"); - MovementManager.forward = true; - } - } else { - Out.log("Going to position"); - if (!Action.canWalkOn(Baritone.playerFeet.offset(Minecraft.getMinecraft().player.getHorizontalFacing()).down())) { - Out.gui("About to fall off", Out.Mode.Debug); - mightNeedToGoBackToPath = true; - return; - } - MovementManager.moveTowardsBlock(branchPosition, false); - if (Baritone.playerFeet.getY() != branchPosition.getY()) { - Out.gui("wrong Y coordinate", Out.Mode.Debug); - mightNeedToGoBackToPath = true; - } - } - } - } - } - static double ticksSinceBlockMined = 0; - - public static void updateBlocksMined() { - if (Baritone.currentPath == null) { - ticksSinceBlockMined++; - } else { - ticksSinceBlockMined += 0.1; - } - ArrayList shouldBeRemoved = new ArrayList(); - for (BlockPos isMined : needsToBeMined) { - Block block = Baritone.get(isMined).getBlock(); - if (isGoalBlock(isMined) || block.equals(Blocks.AIR) || block.equals(Block.getBlockFromName("minecraft:torch")) || block.equals(Blocks.BEDROCK)) { - hasBeenMined.add(isMined); - shouldBeRemoved.add(isMined); - updateBlocks(isMined); - ticksSinceBlockMined = 0; - } - } - for (BlockPos needsRemoval : shouldBeRemoved) { - needsToBeMined.remove(needsRemoval); - } - } - - public static void updatePriorityBlocksMined() { - boolean wasEmpty = priorityNeedsToBeMined.isEmpty(); - ArrayList shouldBeRemoved = new ArrayList(); - for (BlockPos isMined : priorityNeedsToBeMined) { - Block block = Baritone.get(isMined).getBlock(); - if (block.equals(Blocks.AIR) || block.equals(Block.getBlockFromName("minecraft:torch")) || block.equals(Blocks.BEDROCK)) { - hasBeenMined.add(isMined); - shouldBeRemoved.add(isMined); - updateBlocks(isMined); - ticksSinceBlockMined = 0; - } - } - for (BlockPos needsRemoval : shouldBeRemoved) { - priorityNeedsToBeMined.remove(needsRemoval); - } - if (priorityNeedsToBeMined.isEmpty() && !wasEmpty) { - mightNeedToGoBackToPath = true; - if (!chunkHasDiamonds.isEmpty()) { - for (IntegerTuple shouldAdd : chunkHasDiamonds) { - if (!diamondChunks.contains(shouldAdd)) { - diamondChunks.add(shouldAdd); - } - } - chunkHasDiamonds.clear(); - } - } - } - - public static void updateBlocks(BlockPos blockPos) { - for (int i = 0; i < 4; i++) { - Out.log(blockPos.offset(miningFacing)); - } - addPriorityBlock(blockPos); - addPriorityBlock(blockPos.north()); - addPriorityBlock(blockPos.south()); - addPriorityBlock(blockPos.east()); - addPriorityBlock(blockPos.west()); - addPriorityBlock(blockPos.up()); - addPriorityBlock(blockPos.down()); - } - - public static boolean addNormalBlock(BlockPos blockPos, boolean mainBranch) { - if (!needsToBeMined.contains(blockPos)) { - if (Action.avoidBreaking(blockPos) && mainBranch) {//who gives a crap if a side branch will hit lava? lol - Out.gui("Uh oh, lava nearby", Out.Mode.Debug); - miningFacing = miningFacing.rotateY(); - return false; - } - needsToBeMined.add(blockPos); - return true; - } - return false; - } - - public static boolean addPriorityBlock(BlockPos blockPos) { - if (!priorityNeedsToBeMined.contains(blockPos) && isGoalBlock(blockPos)) { - if (Action.avoidBreaking(blockPos)) { - Out.gui("Can't break " + Baritone.get(blockPos).getBlock() + " at " + blockPos + " because it's near lava", Out.Mode.Debug); - return false; - } - priorityNeedsToBeMined.add(blockPos); - if (Block.getBlockFromName("minecraft:diamond_ore").equals(Baritone.get(blockPos).getBlock())) { - chunkHasDiamonds.add(tupleFromBlockPos(blockPos)); - for (int x = -1; x <= 1; x++) { - for (int y = -1; y <= 1; y++) { - for (int z = -1; z <= 1; z++) { - BlockPos oth = new BlockPos(blockPos.getX() + x, blockPos.getY() + y, blockPos.getZ() + z); - if (!Action.avoidBreaking(oth) && !priorityNeedsToBeMined.contains(oth)) { - priorityNeedsToBeMined.add(oth); - } - } - } - } - } - return true; - } - return false; - } - - public static boolean isGoalBlock(BlockPos blockPos) { - return isGoalBlock(Baritone.get(blockPos).getBlock()); - } - - public static boolean isGoalBlock(Block block) { - return goalBlocks.contains(block); - } - - public static boolean isNull(Object object) { - try { - object.toString(); - return false; - } catch (NullPointerException ex) { - return true; - } - } - - public static IntegerTuple tupleFromChunk(Chunk chunk) { - return new IntegerTuple(chunk.x, chunk.z); - } - - public static IntegerTuple tupleFromBlockPos(BlockPos blockPos) { - return tupleFromChunk(Minecraft.getMinecraft().world.getChunk(blockPos)); - } - - @Override - protected boolean onTick0() { - if (tempDisable) { - return false; - } - Out.log("mickey" + isGoingToMine + " " + isMining); - if (!isGoingToMine && !isMining) { - Baritone.goal = new GoalYLevel(yLevel); - if (Baritone.currentPath == null && !Baritone.isPathFinding()) { - Baritone.findPathInNewThread(Baritone.playerFeet, true); - isGoingToMine = true; - } - } - if (isGoingToMine && Baritone.playerFeet.getY() == yLevel) { - isGoingToMine = false; - isMining = true; - } - updatePriorityBlocksMined(); - if (isMining) { - doMine(); - } - if (!priorityNeedsToBeMined.isEmpty()) { - doPriorityMine(); - } - Out.log("mickey done"); - return false; - } - - @Override - protected void onCancel() { - onCancel1(); - } - - private static void onCancel1() { - isGoingToMine = false; - isMining = false; - needsToBeMined.clear(); - priorityNeedsToBeMined.clear(); - branchPosition = null; - mightNeedToGoBackToPath = false; - ticksSinceBlockMined = 0; - } - - @Override - protected void onStart() { - } - - @Override - protected void onTickPre() { - tempDisable = false; - } - - public static class IntegerTuple {//why not use the normal net.minecraft.pathing.Tuple? Because it doesn't implement equals or hashCode - - private final int a; - private final int b; - - public IntegerTuple(int a, int b) { - this.a = a; - this.b = b; - } - - @Override - public String toString() { - return a + "," + b; - } - - @Override - public int hashCode() { - int hash = 3; - hash = 73 * hash + this.a; - hash = 73 * hash + this.b; - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final IntegerTuple other = (IntegerTuple) obj; - if (this.a != other.a) { - return false; - } - return this.b == other.b; - } - } -} diff --git a/src/main/resources/baritone/movement/MovementManager.java b/src/main/resources/baritone/movement/MovementManager.java deleted file mode 100644 index 357f7514..00000000 --- a/src/main/resources/baritone/movement/MovementManager.java +++ /dev/null @@ -1,230 +0,0 @@ -package baritone.movement; - -import baritone.Baritone; -import baritone.bot.utils.InputOverrideHandler; -import baritone.ui.LookManager; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class MovementManager { - - public static boolean forward = false; - public static int leftPressTime = 0; - public static boolean isRightClick = false; - public static int rightPressTime = 0; - public static boolean right = false; - public static boolean left = false; - public static boolean jumping = false; - public static boolean sneak = false; - public static boolean isLeftClick = false; - public static boolean backward = false; - - /** - * calls moveTowardsCoords on the center of this block - * - * @param p - * @return am I moving, or am I still rotating - */ - public static boolean moveTowardsBlock(BlockPos p) { - return moveTowardsBlock(p, true); - } - - public static boolean moveTowardsBlock(BlockPos p, boolean rotate) { - IBlockState b = Baritone.get(p); - AxisAlignedBB bbox = b.getBoundingBox(Baritone.world, p); - double xDiff = (bbox.minX + bbox.maxX) / 2; - double yDiff = (bbox.minY + bbox.maxY) / 2; - double zDiff = (bbox.minZ + bbox.maxZ) / 2; - if (b instanceof BlockLadder || b instanceof BlockVine) { - xDiff = 0.5; - yDiff = 0.5; - zDiff = 0.5; - } - double x = p.getX() + xDiff; - double y = p.getY() + yDiff; - double z = p.getZ() + zDiff; - return moveTowardsCoords(x, y, z, rotate); - } - - /** - * Clears movement, but nothing else. Includes jumping and sneaking, but not - * left clicking. - */ - public static void clearMovement() { - jumping = false; - forward = false; - left = false; - right = false; - backward = false; - sneak = false; - isRightClick = false; - //rightPressTime = 0; - isLeftClick = false; - //leftPressTime = 0; - } - - /** - * Do not question the logic. Called by Minecraft.java - * - * @return - */ - public static boolean rightIsPressed() { - if (rightPressTime <= 0) { - return false; - } else { - --rightPressTime; - return true; - } - } - - /** - * Called by our code - */ - public static void letGoOfLeftClick() { - leftPressTime = 0; - isLeftClick = false; - } - - /** - * Do not question the logic. Called by Minecraft.java - * - * @return - */ - public static boolean getLeftIsPressed() { - return isLeftClick && leftPressTime >= -2; - } - - /** - * Do not question the logic. Called by Minecraft.java - * - * @return - */ - public static boolean leftIsPressed() { - if (leftPressTime <= 0) { - return false; - } else { - --leftPressTime; - return true; - } - } - - /** - * Do not question the logic. Called by Minecraft.java - * - * @return - */ - public static boolean getRightIsPressed() { - return isRightClick && rightPressTime >= -2; - } - - public static void tick(){ - InputOverrideHandler handler = baritone.bot.Baritone.INSTANCE.getInputOverrideHandler(); - handler.setInputForceState(InputOverrideHandler.Input.CLICK_LEFT, isLeftClick); - handler.setInputForceState(InputOverrideHandler.Input.CLICK_RIGHT, isRightClick); - handler.setInputForceState(InputOverrideHandler.Input.MOVE_FORWARD, forward); - handler.setInputForceState(InputOverrideHandler.Input.MOVE_BACK, backward); - handler.setInputForceState(InputOverrideHandler.Input.MOVE_LEFT, left); - handler.setInputForceState(InputOverrideHandler.Input.MOVE_RIGHT, right); - handler.setInputForceState(InputOverrideHandler.Input.JUMP, jumping); - } - - public static boolean moveTowardsCoords(double x, double y, double z) { - return moveTowardsCoords(x, y, z, true); - } - - /** - * Move towards coordinates, not necesarily forwards. e.g. if coordinates - * are closest to being directly behind us, go backwards. This minimizes - * time spent waiting for rotating - * - * @param x - * @param y - * @param z - * @param doRotate - * @return true if we are moving, false if we are still rotating. we will - * rotate until within ANGLE_THRESHOLD (currently 7°) of moving in correct - * direction - */ - public static boolean moveTowardsCoords(double x, double y, double z, boolean doRotate) { - boolean rotate = doRotate; - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - float currentYaw = thePlayer.rotationYaw; - float yaw = (float) (Math.atan2(thePlayer.posX - x, -thePlayer.posZ + z) * 180 / Math.PI); - float diff = yaw - currentYaw; - if (diff < 0) { - diff += 360; - } - float distanceToForward = Math.min(Math.abs(diff - 0), Math.abs(diff - 360)) % 360; - float distanceToForwardRight = Math.abs(diff - 45) % 360; - float distanceToRight = Math.abs(diff - 90) % 360; - float distanceToBackwardRight = Math.abs(diff - 135) % 360; - float distanceToBackward = Math.abs(diff - 180) % 360; - float distanceToBackwardLeft = Math.abs(diff - 225) % 360; - float distanceToLeft = Math.abs(diff - 270) % 360; - float distanceToForwardLeft = Math.abs(diff - 315) % 360; - float tmp = Math.round(diff / 45) * 45; - if (tmp > 359) { - tmp -= 360; - } - if (rotate) { - if (LookManager.lookingYaw()) {//if something else has set the yaw, just move anyway - rotate = false; - } - LookManager.setDesiredYaw(yaw - tmp); - } - double t = rotate ? LookManager.ANGLE_THRESHOLD : 23; - if (distanceToForward < t || distanceToForward > 360 - t) { - forward = true; - return true; - } - if (distanceToForwardLeft < t || distanceToForwardLeft > 360 - t) { - forward = true; - left = true; - return true; - } - if (distanceToForwardRight < t || distanceToForwardRight > 360 - t) { - forward = true; - right = true; - return true; - } - if (distanceToBackward < t || distanceToBackward > 360 - t) { - backward = true; - return true; - } - if (distanceToBackwardLeft < t || distanceToBackwardLeft > 360 - t) { - backward = true; - left = true; - return true; - } - if (distanceToBackwardRight < t || distanceToBackwardRight > 360 - t) { - backward = true; - right = true; - return true; - } - if (distanceToLeft < t || distanceToLeft > 360 - t) { - left = true; - return true; - } - if (distanceToRight < t || distanceToRight > 360 - t) { - right = true; - return true; - } - return false; - } - - public static void rightClickMouse() { - isRightClick=true; - //TODO fix - //Minecraft.getMinecraft().rightClickMouse(); - //throw new UnsupportedOperationException("Not public"); - } -} diff --git a/src/main/resources/baritone/pathfinding/Path.java b/src/main/resources/baritone/pathfinding/Path.java deleted file mode 100644 index 12f703a1..00000000 --- a/src/main/resources/baritone/pathfinding/Path.java +++ /dev/null @@ -1,274 +0,0 @@ -package baritone.pathfinding; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.pathfinding.actions.Action; -import baritone.pathfinding.actions.ActionBridge; -import baritone.pathfinding.actions.ActionPlaceOrBreak; -import baritone.pathfinding.goals.Goal; -import baritone.ui.LookManager; -import baritone.util.Out; -import baritone.util.ToolSet; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * @author leijurv - */ -public class Path { - - public final BlockPos start; - public final BlockPos end; - public final Goal goal; - /** - * The blocks on the path. Guaranteed that path.get(0) equals start and - * path.get(path.size()-1) equals end - */ - public final ArrayList path; - final ArrayList actions; - /** - * note that this ISN'T the number of nodes in this path, it's actually the - * number of nodes used to calculate this path. this is here for idk why - */ - private final int numNodes; - - Path(Node start, Node end, Goal goal, int numNodes) { - this.numNodes = numNodes; - this.start = start.pos; - this.end = end.pos; - this.goal = goal; - this.path = new ArrayList(); - this.actions = new ArrayList(); - Node current = end; - while (!current.equals(start)) {//assemble the path - path.add(0, current.pos); - actions.add(0, current.previousAction); - current = current.previous; - } - path.add(0, start.pos); - /*Out.log("Final path: " + path); - Out.log("Final movement: " + movement); - for (int i = 0; i < path.size() - 1; i++) {//print it all out - int oldX = path.get(i).getX(); - int oldY = path.get(i).getY(); - int oldZ = path.get(i).getZ(); - int newX = path.get(i + 1).getX(); - int newY = path.get(i + 1).getY(); - int newZ = path.get(i + 1).getZ(); - int xDiff = newX - oldX; - int yDiff = newY - oldY; - int zDiff = newZ - oldZ; - Out.log(movement.get(i) + ": " + xDiff + "," + yDiff + "," + zDiff);//print it all out - }*/ - } - - /** - * We don't really use this any more - */ - public void showPathInStone() { - IBlockState[] originalStates = new IBlockState[path.size()]; - for (int i = 0; i < path.size(); i++) { - originalStates[i] = Baritone.get(path.get(i)); - Minecraft.getMinecraft().world.setBlockState(path.get(i), Block.getBlockById(1).getDefaultState()); - try { - Thread.sleep(250); - } catch (InterruptedException ex) { - Logger.getLogger(Path.class.getName()).log(Level.SEVERE, null, ex); - } - } - try { - Thread.sleep(2500); - } catch (InterruptedException ex) { - Logger.getLogger(Path.class.getName()).log(Level.SEVERE, null, ex); - } - for (int i = 0; i < path.size(); i++) { - Minecraft.getMinecraft().world.setBlockState(path.get(i), originalStates[i]); - } - } - - /** - * Where are we in the path? This is an index in the movement list - */ - int pathPosition = 0; - - public double howFarAmIFromThePath(double x, double y, double z) { - double best = -1; - for (BlockPos pos : path) { - double dist = distance(x, y, z, pos); - if (dist < best || best == -1) { - best = dist; - } - } - return best; - } - - public void calculatePathPosition() { - BlockPos playerFeet = Baritone.playerFeet; - for (int i = 0; i < path.size(); i++) { - if (playerFeet.equals(path.get(i))) { - pathPosition = i; - } - } - } - - public static double distance(double x, double y, double z, BlockPos pos) { - double xdiff = x - (pos.getX() + 0.5D); - double ydiff = y - (pos.getY() + 0.5D); - double zdiff = z - (pos.getZ() + 0.5D); - return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff); - } - - /** - * How many ticks have I been more than MAX_DISTANCE_FROM_PATH away from the - * path - */ - int ticksAway = 0; - /** - * How far away from the path can I get and still be okay - */ - static final double MAX_DISTANCE_FROM_PATH = 2; - /** - * How many ticks can I be more than MAX_DISTANCE_FROM_PATH before we - * consider it a failure - */ - static final int MAX_TICKS_AWAY = 20 * 10; - /** - * How many ticks have elapsed on this movement - */ - int ticksOnCurrent = 0; - /** - * Did I fail, either by being too far away for too long, or by having an - * movement take too long - */ - public boolean failed = false; - - public boolean tick() { - if (pathPosition >= path.size()) { - Baritone.clearPath();//stop bugging me, I'm done - return true; - } - BlockPos whereShouldIBe = path.get(pathPosition); - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - BlockPos whereAmI = Baritone.playerFeet; - if (pathPosition == path.size() - 1) { - Out.log("On last path position"); - Baritone.clearPath(); - return true; - } - if (!whereShouldIBe.equals(whereAmI)) { - Out.log("Should be at " + whereShouldIBe + " actually am at " + whereAmI); - if (!Blocks.AIR.equals(Baritone.get(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip - for (int i = 0; i < pathPosition - 2 && i < path.size(); i++) {//this happens for example when you lag out and get teleported back a couple blocks - if (whereAmI.equals(path.get(i))) { - Out.gui("Skipping back " + (pathPosition - i) + " steps, to " + i, Out.Mode.Debug); - pathPosition = Math.max(i - 1, 0); - return false; - } - } - for (int i = pathPosition + 2; i < path.size(); i++) {//dont check pathPosition+1 - if (whereAmI.equals(path.get(i))) { - Out.gui("Skipping forward " + (i - pathPosition) + " steps, to " + i, Out.Mode.Debug); - pathPosition = i - 1; - return false; - } - } - } - } - double distanceFromPath = howFarAmIFromThePath(thePlayer.posX, thePlayer.posY, thePlayer.posZ); - if (distanceFromPath > MAX_DISTANCE_FROM_PATH) { - ticksAway++; - Out.log("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + distanceFromPath + ". Threshold: " + MAX_DISTANCE_FROM_PATH); - if (ticksAway > MAX_TICKS_AWAY) { - Out.gui("Too far away from path for too long, cancelling path", Out.Mode.Standard); - Out.log("Too many ticks"); - pathPosition = path.size() + 3; - failed = true; - return true; - } - } else { - ticksAway = 0; - } - Out.log(actions.get(pathPosition)); - if (pathPosition < actions.size() - 1) {//if there are two ActionBridges in a row and they are at right angles, walk diagonally. This makes it so you walk at 45 degrees along a zigzag path instead of doing inefficient zigging and zagging - if ((actions.get(pathPosition) instanceof ActionBridge) && (actions.get(pathPosition + 1) instanceof ActionBridge)) { - ActionBridge curr = (ActionBridge) actions.get(pathPosition); - ActionBridge next = (ActionBridge) actions.get(pathPosition + 1); - if (curr.dx() != next.dx() || curr.dz() != next.dz()) {//two movement are not parallel, so this is a right angle - if (curr.amIGood() && next.amIGood()) {//nothing in the way - BlockPos cornerToCut1 = new BlockPos(next.to.getX() - next.from.getX() + curr.from.getX(), next.to.getY(), next.to.getZ() - next.from.getZ() + curr.from.getZ()); - BlockPos cornerToCut2 = cornerToCut1.up(); - //Block corner1 = Baritone.get(cornerToCut1).getBlock(); - //Block corner2 = Baritone.get(cornerToCut2).getBlock(); - //Out.gui("Cutting conner " + cornerToCut1 + " " + corner1, Out.Mode.Debug); - if (!Action.avoidWalkingInto(cornerToCut1) && !Action.avoidWalkingInto(cornerToCut2)) { - double x = (next.from.getX() + next.to.getX() + 1.0D) * 0.5D; - double z = (next.from.getZ() + next.to.getZ() + 1.0D) * 0.5D; - MovementManager.clearMovement(); - if (!MovementManager.forward && curr.oneInTen != null && curr.oneInTen) { - MovementManager.clearMovement(); - MovementManager.forward = LookManager.lookAtCoords(x, 0, z, false); - } else { - MovementManager.moveTowardsCoords(x, 0, z); - } - if (MovementManager.forward && !MovementManager.backward) { - thePlayer.setSprinting(true); - } - return false; - } - } - } - } - } - MovementManager.clearMovement(); - Action action = actions.get(pathPosition); - if (action.calculateCost0(new ToolSet()) >= Action.COST_INF) { - Out.gui("Something has changed in the world and this movement has become impossible. Cancelling.", Out.Mode.Standard); - pathPosition = path.size() + 3; - failed = true; - return true; - } - if (action.tick()) { - Out.log("Movement done, next path"); - pathPosition++; - ticksOnCurrent = 0; - } else { - ticksOnCurrent++; - if (ticksOnCurrent > action.cost(null) + 100) { - Out.gui("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + action.cost(null) + "). Cancelling.", Out.Mode.Standard); - pathPosition = path.size() + 3; - failed = true; - return true; - } - } - return false; - } - - public HashSet toMine() { - HashSet tm = new HashSet<>(); - for (int i = pathPosition; i < actions.size(); i++) { - if (actions.get(i) instanceof ActionPlaceOrBreak) { - tm.addAll(((ActionPlaceOrBreak) actions.get(i)).toMine()); - } - } - return tm; - } - - public HashSet toPlace() { - HashSet tp = new HashSet<>(); - for (int i = pathPosition; i < actions.size(); i++) { - if (actions.get(i) instanceof ActionPlaceOrBreak) { - tp.addAll(((ActionPlaceOrBreak) actions.get(i)).toPlace()); - } - } - return tp; - } -} diff --git a/src/main/resources/baritone/pathfinding/PathFinder.java b/src/main/resources/baritone/pathfinding/PathFinder.java deleted file mode 100644 index 34b78a5f..00000000 --- a/src/main/resources/baritone/pathfinding/PathFinder.java +++ /dev/null @@ -1,268 +0,0 @@ -package baritone.pathfinding; - -import baritone.Baritone; -import baritone.pathfinding.actions.*; -import baritone.pathfinding.goals.Goal; -import baritone.util.Out; -import baritone.util.ToolSet; -import net.minecraft.client.Minecraft; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.EmptyChunk; - -import java.util.HashMap; -import java.util.Random; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * @author leijurv - */ -public class PathFinder { - final BlockPos start; - final Goal goal; - final HashMap map; - - public PathFinder(BlockPos start, Goal goal) { - this.start = start; - this.goal = goal; - this.map = new HashMap(); - } - - static final double[] COEFFICIENTS = {1.5, 2, 2.5, 3, 4, 5, 10}; - public static PathFinder currentlyRunning = null; - Node[] bestSoFar; - Node startNode; - Node mostRecentConsidered; - - public Path getTempSolution() { - if (startNode == null || bestSoFar[0] == null) { - return null; - } - return new Path(startNode, bestSoFar[0], goal, 0); - } - - public Path getMostRecentNodeConsidered() { - return mostRecentConsidered == null ? null : new Path(startNode, mostRecentConsidered, goal, 0); - } - - /** - * Do the actual path calculation. The returned path might not actually go - * to goal, but it will get as close as I could get - * - * @return - */ - public Path calculatePath() { - //a lot of these vars are local. that's because if someone tries to call this from multiple threads, they won't interfere (much) - startNode = getNodeAtPosition(start); - startNode.cost = 0; - bestSoFar = new Node[COEFFICIENTS.length];//keep track of the best node by the metric of (estimatedCostToGoal + cost / COEFFICIENTS[i]) - double[] bestHeuristicSoFar = new double[COEFFICIENTS.length]; - for (int i = 0; i < bestHeuristicSoFar.length; i++) { - bestHeuristicSoFar[i] = Double.MAX_VALUE; - } - OpenSet openSet = new OpenSet(); - startNode.isOpen = true; - openSet.insert(startNode); - currentlyRunning = this; - long startTime = System.currentTimeMillis(); - long timeoutTime = startTime + (Baritone.slowPath ? 40000 : 4000); - long lastPrintout = 0; - int numNodes = 0; - ToolSet ts = new ToolSet(); - int numEmptyChunk = 0; - while (openSet.first != null && numEmptyChunk < 50 && System.currentTimeMillis() < timeoutTime) { - if (Baritone.slowPath) { - try { - Thread.sleep(100); - } catch (InterruptedException ex) { - Logger.getLogger(PathFinder.class.getName()).log(Level.SEVERE, null, ex); - } - } - Node currentNode = openSet.removeLowest(); - mostRecentConsidered = currentNode; - currentNode.isOpen = false; - currentNode.nextOpen = null; - BlockPos currentNodePos = currentNode.pos; - numNodes++; - if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second - Out.log("searching... at " + currentNodePos + ", considered " + numNodes + " nodes so far"); - lastPrintout = System.currentTimeMillis(); - } - if (goal.isInGoal(currentNodePos)) { - currentlyRunning = null; - return new Path(startNode, currentNode, goal, numNodes); - } - //long constructStart = System.nanoTime(); - Action[] possibleActions = getConnectedPositions(currentNodePos);//movement that we could take that start at myPos, in random order - shuffle(possibleActions); - //long constructEnd = System.nanoTime(); - //System.out.println(constructEnd - constructStart); - for (Action actionToGetToNeighbor : possibleActions) { - //long costStart = System.nanoTime(); - double actionCost = actionToGetToNeighbor.cost(ts); - //long costEnd = System.nanoTime(); - //System.out.println(actionToGetToNeighbor.getClass() + "" + (costEnd - costStart)); - if (actionCost >= Action.COST_INF) { - continue; - } - if (Minecraft.getMinecraft().world.getChunk(actionToGetToNeighbor.to) instanceof EmptyChunk) { - numEmptyChunk++; - continue; - } - Node neighbor = getNodeAtPosition(actionToGetToNeighbor.to); - double tentativeCost = currentNode.cost + actionCost; - if (tentativeCost < neighbor.cost) { - neighbor.previous = currentNode; - neighbor.previousAction = actionToGetToNeighbor; - neighbor.cost = tentativeCost; - if (!neighbor.isOpen) { - openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there - neighbor.isOpen = true; - } - for (int i = 0; i < bestSoFar.length; i++) { - double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i]; - if (heuristic < bestHeuristicSoFar[i]) { - bestHeuristicSoFar[i] = heuristic; - bestSoFar[i] = neighbor; - } - } - } - } - } - double bestDist = 0; - for (int i = 0; i < bestSoFar.length; i++) { - if (bestSoFar[i] == null) { - continue; - } - double dist = distFromStart(bestSoFar[i]); - if (dist > bestDist) { - bestDist = dist; - } - if (dist > MIN_DIST_PATH) { - Out.gui("A* cost coefficient " + COEFFICIENTS[i], Out.Mode.Debug); - if (COEFFICIENTS[i] >= 3) { - Out.gui("Warning: cost coefficient is greater than three! Probably means that", Out.Mode.Debug); - Out.gui("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)", Out.Mode.Debug); - Out.gui("But I'm going to do it anyway, because yolo", Out.Mode.Debug); - } - Out.gui("Path goes for " + dist + " blocks", Out.Mode.Debug); - currentlyRunning = null; - return new Path(startNode, bestSoFar[i], goal, numNodes); - } - } - Out.gui("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + bestDist + " blocks =(", Out.Mode.Debug); - Out.gui("No path found =(", Out.Mode.Standard); - currentlyRunning = null; - return null; - } - - private double distFromStart(Node n) { - int xDiff = n.pos.getX() - start.getX(); - int yDiff = n.pos.getY() - start.getY(); - int zDiff = n.pos.getZ() - start.getZ(); - return Math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff); - } - - private final double MIN_DIST_PATH = 5; - - private Node getNodeAtPosition(BlockPos pos) { - Node alr = map.get(pos); - if (alr == null) { - Node node = new Node(pos, goal); - map.put(pos, node); - return node; - } - return alr; - } - - private static Action[] getConnectedPositions(BlockPos pos) { - int x = pos.getX(); - int y = pos.getY(); - int z = pos.getZ(); - Action[] actions = new Action[26]; - actions[0] = new ActionPillar(pos); - actions[1] = new ActionBridge(pos, new BlockPos(x + 1, y, z)); - actions[2] = new ActionBridge(pos, new BlockPos(x - 1, y, z)); - actions[3] = new ActionBridge(pos, new BlockPos(x, y, z + 1)); - actions[4] = new ActionBridge(pos, new BlockPos(x, y, z - 1)); - actions[5] = new ActionClimb(pos, new BlockPos(x + 1, y + 1, z)); - actions[6] = new ActionClimb(pos, new BlockPos(x - 1, y + 1, z)); - actions[7] = new ActionClimb(pos, new BlockPos(x, y + 1, z + 1)); - actions[8] = new ActionClimb(pos, new BlockPos(x, y + 1, z - 1)); - actions[9] = new ActionDescend(pos, new BlockPos(x, y - 1, z - 1)); - actions[10] = new ActionDescend(pos, new BlockPos(x, y - 1, z + 1)); - actions[11] = new ActionDescend(pos, new BlockPos(x - 1, y - 1, z)); - actions[12] = new ActionDescend(pos, new BlockPos(x + 1, y - 1, z)); - actions[13] = new ActionFall(pos); - actions[14] = new ActionDescendTwo(pos, new BlockPos(x, y - 2, z - 1)); - actions[15] = new ActionDescendTwo(pos, new BlockPos(x, y - 2, z + 1)); - actions[16] = new ActionDescendTwo(pos, new BlockPos(x - 1, y - 2, z)); - actions[17] = new ActionDescendTwo(pos, new BlockPos(x + 1, y - 2, z)); - actions[18] = new ActionDescendThree(pos, new BlockPos(x, y - 3, z - 1)); - actions[19] = new ActionDescendThree(pos, new BlockPos(x, y - 3, z + 1)); - actions[20] = new ActionDescendThree(pos, new BlockPos(x - 1, y - 3, z)); - actions[21] = new ActionDescendThree(pos, new BlockPos(x + 1, y - 3, z)); - actions[22] = new ActionWalkDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST); - actions[23] = new ActionWalkDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST); - actions[24] = new ActionWalkDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST); - actions[25] = new ActionWalkDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST); - return actions; - } - - private final Random random = new Random(); - - private void shuffle(Action[] list) { - int len = list.length; - for (int i = 0; i < len; i++) { - int j = random.nextInt(len); - Action e = list[j]; - list[j] = list[i]; - list[i] = e; - } - } - - /** - * My own implementation of a singly linked list - */ - private static class OpenSet { - Node first = null; - - public Node removeLowest() { - if (first == null) { - return null; - } - Node current = first.nextOpen; - if (current == null) { - Node n = first; - first = null; - return n; - } - Node previous = first; - double bestValue = first.estimatedCostToGoal + first.cost; - Node bestNode = first; - Node beforeBest = null; - while (current != null) { - double comp = current.estimatedCostToGoal + current.cost; - if (comp < bestValue) { - bestValue = comp; - bestNode = current; - beforeBest = previous; - } - previous = current; - current = current.nextOpen; - } - if (beforeBest == null) { - first = first.nextOpen; - return bestNode; - } - beforeBest.nextOpen = bestNode.nextOpen; - return bestNode; - } - - public void insert(Node node) { - node.nextOpen = first; - first = node; - } - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/Action.java b/src/main/resources/baritone/pathfinding/actions/Action.java deleted file mode 100644 index eddcb2b5..00000000 --- a/src/main/resources/baritone/pathfinding/actions/Action.java +++ /dev/null @@ -1,207 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.util.Out; -import baritone.util.ToolSet; -import net.minecraft.block.Block; -import net.minecraft.block.BlockCactus; -import net.minecraft.block.BlockFire; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockLilyPad; -import net.minecraft.block.BlockLiquid; -import net.minecraft.block.BlockVine; -import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public abstract class Action { - - //These costs are measured roughly in ticks btw - public static final double WALK_ONE_BLOCK_COST = 20 / 4.317; - public static final double WALK_ONE_IN_WATER_COST = 20 / 2.2; - public static final double JUMP_ONE_BLOCK_COST = 5.72854;//see below calculation for fall. 1.25 blocks - public static final double LADDER_UP_ONE_COST = 20 / 2.35; - public static final double LADDER_DOWN_ONE_COST = 20 / 3; - public static final double SNEAK_ONE_BLOCK_COST = 20 / 1.3; - public static final double SPRINT_ONE_BLOCK_COST = 20 / 5.612; - /** - * Doesn't include walking forwards, just the falling - * - * Based on a sketchy formula from minecraftwiki - * - * d(t) = 3.92 × (99 - 49.50×(0.98^t+1) - t) - * - * Solved in mathematica - */ - public static final double FALL_ONE_BLOCK_COST = 5.11354; - public static final double FALL_TWO_BLOCK_COST = 7.28283; - public static final double FALL_THREE_BLOCK_COST = 8.96862; - /** - * It doesn't actually take ten ticks to place a block, this cost is so high - * because we want to generally conserve blocks which might be limited - */ - public static final double PLACE_ONE_BLOCK_COST = 20; - /** - * Add this to the cost of breaking any block. The cost of breaking any - * block is calculated as the number of ticks that block takes to break with - * the tools you have. You add this because there's always a little overhead - * (e.g. looking at the block) - */ - public static final double BREAK_ONE_BLOCK_ADD = 4; - public static final double COST_INF = 1000000; - public final BlockPos from; - public final BlockPos to; - private Double cost; - public boolean finished = false; - - protected Action(BlockPos from, BlockPos to) { - this.from = from; - this.to = to; - this.cost = null; - } - - /** - * Get the cost. It's cached - * - * @param ts - * @return - */ - public double cost(ToolSet ts) { - if (cost == null) { - cost = calculateCost0(ts == null ? new ToolSet() : ts); - } - if (cost < 1) { - Out.log("Bad cost " + this + " " + cost); - } - return cost; - } - - public double calculateCost0(ToolSet ts) { - if (!(this instanceof ActionPillar) && !(this instanceof ActionBridge) && !(this instanceof ActionFall)) { - Block fromDown = Baritone.get(from.down()).getBlock(); - if (fromDown instanceof BlockLadder || fromDown instanceof BlockVine) { - return COST_INF; - } - } - return calculateCost(ts); - } - - protected abstract double calculateCost(ToolSet ts); - static Block waterFlowing = Block.getBlockById(8); - static Block waterStill = Block.getBlockById(9); - static Block lavaFlowing = Block.getBlockById(10); - static Block lavaStill = Block.getBlockById(11); - - /** - * Is this block water? Includes both still and flowing - * - * @param b - * @return - */ - public static boolean isWater(Block b) { - return waterFlowing.equals(b) || waterStill.equals(b); - } - - public static boolean isWater(BlockPos bp) { - return isWater(Baritone.get(bp).getBlock()); - } - - public static boolean isLiquid(Block b) { - return b instanceof BlockLiquid; - //return b != null && (waterFlowing.equals(b) || waterStill.equals(b) || lavaFlowing.equals(b) || lavaStill.equals(b)); - } - - public static boolean isFlowing(BlockPos pos, IBlockState state) { - Block b = state.getBlock(); - Material m = b.getMaterial(state); - if (b instanceof BlockLiquid) { - System.out.println("Need to fix get flow check!!!"); - //return BlockLiquid.getFlow(Minecraft.getMinecraft().world, pos, state) != -1000.0D; - } - return false; - } - - public static boolean isLava(Block b) { - return lavaFlowing.equals(b) || lavaStill.equals(b); - } - - public static boolean isLiquid(BlockPos p) { - return isLiquid(Baritone.get(p).getBlock()); - } - - public static boolean avoidBreaking(BlockPos pos) { - Block b = Baritone.get(pos).getBlock(); - Block below = Baritone.get(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock(); - return Block.getBlockFromName("minecraft:ice").equals(b)//ice becomes water, and water can mess up the path - || isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side - || isLiquid(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())) - || isLiquid(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())) - || isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)) - || isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)) - || (!(b instanceof BlockLilyPad && isWater(below)) && isLiquid(below));//if it's a lilypad above water, it's ok to break, otherwise don't break if its liquid - } - - /** - * Can I walk through this block? e.g. air, saplings, torches, etc - * - * @param pos - * @return - */ - public static boolean canWalkThrough(BlockPos pos) { - IBlockState state = Baritone.get(pos); - Block block = state.getBlock(); - if (block instanceof BlockLilyPad || block instanceof BlockFire) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire - return false; - } - if (isFlowing(pos, state)) { - return false;//don't walk through flowing liquids - } - if (isLiquid(pos.up())) { - return false;//you could drown - } - return block.isPassable(Minecraft.getMinecraft().world, pos); - } - - public static boolean avoidWalkingInto(BlockPos pos) { - Block block = Baritone.get(pos).getBlock(); - if (isLava(block)) { - return true; - } - if (block instanceof BlockCactus) { - return true; - } - return block instanceof BlockFire; - } - - /** - * Can I walk on this block without anything weird happening like me falling - * through? Includes water because we know that we automatically jump on - * lava - * - * @param pos - * @return - */ - public static boolean canWalkOn(BlockPos pos) { - IBlockState state = Baritone.get(pos); - Block block = state.getBlock(); - if (block instanceof BlockLadder || block instanceof BlockVine) { - return true; - } - if (isWater(block)) { - return isWater(pos.up());//you can only walk on water if there is water above it - } - return block.isBlockNormalCube(state) && !isLava(block); - } - - /** - * Tick this movement - * - * @return is it done - */ - public abstract boolean tick(); -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionBridge.java b/src/main/resources/baritone/pathfinding/actions/ActionBridge.java deleted file mode 100644 index 876c5737..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionBridge.java +++ /dev/null @@ -1,182 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.ui.LookManager; -import baritone.util.Out; -import baritone.util.ToolSet; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.init.Blocks; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; - -import java.util.Objects; -import java.util.Random; - -/** - * @author leijurv - */ -public class ActionBridge extends ActionPlaceOrBreak { - - BlockPos[] against = new BlockPos[3]; - - public ActionBridge(BlockPos from, BlockPos to) { - super(from, to, new BlockPos[]{to.up(), to}, new BlockPos[]{to.down()}); - int i = 0; - if (!to.north().equals(from)) { - against[i] = to.north().down(); - i++; - } - if (!to.south().equals(from)) { - against[i] = to.south().down(); - i++; - } - if (!to.east().equals(from)) { - against[i] = to.east().down(); - i++; - } - if (!to.west().equals(from)) { - against[i] = to.west().down(); - i++; - } - //note: do NOT add ability to place against .down().down() - } - - @Override - protected double calculateCost(ToolSet ts) { - double WC = isWater(blocksToBreak[0]) || isWater(blocksToBreak[1]) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST; - if (canWalkOn(positionsToPlace[0])) {//this is a walk, not a bridge - if (canWalkThrough(positionsToBreak[0]) && canWalkThrough(positionsToBreak[1])) { - return WC; - } - //double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]); - //double hardness2 = blocksToBreak[1].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[1]); - //Out.log("Can't walk through " + blocksToBreak[0] + " (hardness" + hardness1 + ") or " + blocksToBreak[1] + " (hardness " + hardness2 + ")"); - return WC + getTotalHardnessOfBlocksToBreak(ts); - } else {//this is a bridge, so we need to place a block - //return 1000000; - Block f = Baritone.get(from.down()).getBlock(); - if (f instanceof BlockLadder || f instanceof BlockVine) { - return COST_INF; - } - if (blocksToPlace[0].equals(Blocks.AIR) || (!isWater(blocksToPlace[0]) && blocksToPlace[0].isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) { - for (BlockPos against1 : against) { - if (Baritone.isBlockNormalCube(against1)) { - return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts); - } - } - WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking - return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts); - } - return COST_INF; - //Out.log("Can't walk on " + Baritone.get(positionsToPlace[0]).getBlock()); - } - } - - boolean wasTheBridgeBlockAlwaysThere = true;//did we have to place a bridge block or was it always there - public Boolean oneInTen = null;//a one in ten chance - - public boolean amIGood() { - return canWalkThrough(positionsToBreak[0]) && canWalkThrough(positionsToBreak[1]) && canWalkOn(positionsToPlace[0]); - } - - public int dx() { - return to.getX() - from.getX(); - } - - public int dz() { - return to.getZ() - from.getZ(); - } - - @Override - protected boolean tick0() { - if (oneInTen == null) { - oneInTen = new Random().nextInt(10) == 0; - } - Block fd = Baritone.get(from.down()).getBlock(); - boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine; - boolean isTheBridgeBlockThere = canWalkOn(positionsToPlace[0]) || ladder; - //Out.log("is block there: " + isTheBridgeBlockThere + " block " + Baritone.get(positionsToPlace[0]).getBlock()); - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - BlockPos whereAmI = new BlockPos(thePlayer.posX, thePlayer.posY, thePlayer.posZ); - if (whereAmI.getY() != to.getY() && !ladder) { - Out.log("Wrong Y coordinate"); - if (whereAmI.getY() < to.getY()) { - MovementManager.jumping = true; - } - return false; - } - if (isTheBridgeBlockThere) {//either the bridge block was there the whole time or we just placed it - if (oneInTen && wasTheBridgeBlockAlwaysThere) { - //basically one in every ten blocks we walk forwards normally without sneaking and placing, rotate to look forwards. - //this way we tend towards looking forwards - MovementManager.forward = LookManager.lookAtBlock(to, false); - } else { - MovementManager.moveTowardsBlock(to); - } - if (wasTheBridgeBlockAlwaysThere) { - if (MovementManager.forward && !MovementManager.backward) { - thePlayer.setSprinting(true); - } - } - if (whereAmI.equals(to)) {//if we are there - Out.log("Done walking to " + to); - return true;//and we are done - } - Out.log("Trying to get to " + to + " currently at " + whereAmI); - return false;//not there yet - } else { - wasTheBridgeBlockAlwaysThere = false; - for (BlockPos against1 : against) { - if (Baritone.isBlockNormalCube(against1)) { - if (!switchtothrowaway(true)) {//get ready to place a throwaway block - return false; - } - MovementManager.sneak = true; - double faceX = (to.getX() + against1.getX() + 1.0D) * 0.5D; - double faceY = (to.getY() + against1.getY()) * 0.5D; - double faceZ = (to.getZ() + against1.getZ() + 1.0D) * 0.5D; - LookManager.lookAtCoords(faceX, faceY, faceZ, true); - EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit; - if (Objects.equals(Baritone.whatAreYouLookingAt(), against1) && Minecraft.getMinecraft().player.isSneaking()) { - if (Baritone.whatAreYouLookingAt().offset(side).equals(positionsToPlace[0])) { - MovementManager.rightClickMouse(); - } else { - Out.gui("Wrong. " + side + " " + Baritone.whatAreYouLookingAt().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug); - } - } - Out.log("Trying to look at " + against1 + ", actually looking at" + Baritone.whatAreYouLookingAt()); - return false; - } - } - MovementManager.sneak = true; - if (whereAmI.equals(to)) { - //if we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of - //Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI); - if (!switchtothrowaway(true)) {//get ready to place a throwaway block - return false; - } - double faceX = (to.getX() + from.getX() + 1.0D) * 0.5D; - double faceY = (to.getY() + from.getY() - 1.0D) * 0.5D; - double faceZ = (to.getZ() + from.getZ() + 1.0D) * 0.5D; - //faceX,faceY,faceZ is the middle of the face between from and to - BlockPos goalLook = from.down();//this is the block we were just standing on, and the one we want to place against - MovementManager.backward = LookManager.lookAtCoords(faceX, faceY, faceZ, true);//if we are in the block, then we are off the edge of the previous looking backward, so we should be moving backward - if (Objects.equals(Baritone.whatAreYouLookingAt(), goalLook)) { - MovementManager.rightClickMouse();//wait to right click until we are able to place - return false; - } - Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt()); - return false; - } else { - Out.log("Not there yet m9"); - MovementManager.moveTowardsBlock(to);//move towards not look at because if we are bridging for a couple blocks in a row, it is faster if we dont spin around and walk forwards then spin around and place backwards for every block - return false; - } - } - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionClimb.java b/src/main/resources/baritone/pathfinding/actions/ActionClimb.java deleted file mode 100644 index 6fbcbe91..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionClimb.java +++ /dev/null @@ -1,106 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.ui.LookManager; -import baritone.util.Out; -import baritone.util.ToolSet; -import java.util.Objects; -import net.minecraft.block.BlockFalling; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class ActionClimb extends ActionPlaceOrBreak { - - BlockPos[] against = new BlockPos[3]; - - public ActionClimb(BlockPos start, BlockPos end) { - super(start, end, new BlockPos[]{end, start.up(2), end.up()}, new BlockPos[]{end.down()}); - BlockPos placementLocation = positionsToPlace[0];//end.down() - int i = 0; - if (!placementLocation.north().equals(from)) { - against[i] = placementLocation.north(); - i++; - } - if (!placementLocation.south().equals(from)) { - against[i] = placementLocation.south(); - i++; - } - if (!placementLocation.east().equals(from)) { - against[i] = placementLocation.east(); - i++; - } - if (!placementLocation.west().equals(from)) { - against[i] = placementLocation.west(); - i++; - } - //TODO: add ability to place against .down() as well as the cardinal directions - //useful for when you are starting a staircase without anything to place against - } - - @Override - protected double calculateCost(ToolSet ts) { - if (!canWalkOn(positionsToPlace[0])) { - if (!Baritone.isAir(positionsToPlace[0]) && !isWater(positionsToPlace[0])) { - return COST_INF; - } - for (BlockPos against1 : against) { - if (Baritone.isBlockNormalCube(against1)) { - return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts); - } - } - return COST_INF; - } - if (Baritone.get(from.up(3)).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us - return COST_INF; - } - return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block to get to the edge, then we walk the other half while simultaneously jumping (math.max because of how it's in parallel) - } - int ticksWithoutPlacement = 0; - - @Override - protected boolean tick0() {//basically just hold down W and space until we are where we want to be - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - if (!canWalkOn(positionsToPlace[0])) { - for (int i = 0; i < against.length; i++) { - if (Baritone.isBlockNormalCube(against[i])) { - if (!switchtothrowaway(true)) {//get ready to place a throwaway block - return false; - } - double faceX = (to.getX() + against[i].getX() + 1.0D) * 0.5D; - double faceY = (to.getY() + against[i].getY()) * 0.5D; - double faceZ = (to.getZ() + against[i].getZ() + 1.0D) * 0.5D; - LookManager.lookAtCoords(faceX, faceY, faceZ, true); - EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit; - if (Objects.equals(Baritone.whatAreYouLookingAt(), against[i]) && Baritone.whatAreYouLookingAt().offset(side).equals(positionsToPlace[0])) { - ticksWithoutPlacement++; - MovementManager.sneak = true; - if (Minecraft.getMinecraft().player.isSneaking()) { - MovementManager.rightClickMouse(); - } - if (ticksWithoutPlacement > 20) { - MovementManager.backward = true;//we might be standing in the way, move back - } - } - Out.log("Trying to look at " + against[i] + ", actually looking at" + Baritone.whatAreYouLookingAt()); - return false; - } - } - Out.gui("This is impossible", Out.Mode.Standard); - return false; - } - double flatDistToNext = Math.abs(to.getX() - from.getX()) * Math.abs((to.getX() + 0.5D) - thePlayer.posX) + Math.abs(to.getZ() - from.getZ()) * Math.abs((to.getZ() + 0.5D) - thePlayer.posZ); - boolean pointingInCorrectDirection = MovementManager.moveTowardsBlock(to); - MovementManager.jumping = flatDistToNext < 1.2 && pointingInCorrectDirection; - //once we are pointing the right way and moving, start jumping - //this is slightly more efficient because otherwise we might start jumping before moving, and fall down without moving onto the block we want to jump onto - //also wait until we are close enough, because we might jump and hit our head on an adjacent block - return Baritone.playerFeet.equals(to); - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionDescend.java b/src/main/resources/baritone/pathfinding/actions/ActionDescend.java deleted file mode 100644 index 875ded52..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionDescend.java +++ /dev/null @@ -1,37 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.util.ToolSet; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; -import net.minecraft.util.math.BlockPos; - -/** - * @author leijurv - */ -public class ActionDescend extends ActionPlaceOrBreak { - - public ActionDescend(BlockPos start, BlockPos end) { - super(start, end, new BlockPos[]{end.up(2), end.up(), end}, new BlockPos[]{end.down()}); - } - - @Override - protected double calculateCost(ToolSet ts) { - if (!canWalkOn(positionsToPlace[0])) { - return COST_INF; - } - Block tmp1 = Baritone.get(to).getBlock(); - if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) { - return COST_INF; - } - return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST * 0.2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel) - } - - @Override - protected boolean tick0() {//basically just hold down W until we are where we want to be - MovementManager.moveTowardsBlock(to); - return Baritone.playerFeet.equals(to); // TODO wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionDescendThree.java b/src/main/resources/baritone/pathfinding/actions/ActionDescendThree.java deleted file mode 100644 index 25bd876f..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionDescendThree.java +++ /dev/null @@ -1,33 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.util.ToolSet; -import net.minecraft.util.math.BlockPos; - -/** - * @author leijurv - */ -public class ActionDescendThree extends ActionPlaceOrBreak { - - public ActionDescendThree(BlockPos start, BlockPos end) { - super(start, end, new BlockPos[]{end.up(4), end.up(3), end.up(2), end.up(), end}, new BlockPos[]{end.down()}); - } - - @Override - protected double calculateCost(ToolSet ts) { - if (!canWalkOn(positionsToPlace[0])) { - return COST_INF; - } - if (getTotalHardnessOfBlocksToBreak(ts) != 0) { - return COST_INF; - } - return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_THREE_BLOCK_COST, WALK_ONE_BLOCK_COST * 0.2);//we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel) - } - - @Override - protected boolean tick0() {//basically just hold down W until we are where we want to be - MovementManager.moveTowardsBlock(to); - return Baritone.playerFeet.equals(to); // TODO wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionDescendTwo.java b/src/main/resources/baritone/pathfinding/actions/ActionDescendTwo.java deleted file mode 100644 index 645e2c60..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionDescendTwo.java +++ /dev/null @@ -1,33 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.util.ToolSet; -import net.minecraft.util.math.BlockPos; - -/** - * @author leijurv - */ -public class ActionDescendTwo extends ActionPlaceOrBreak { - - public ActionDescendTwo(BlockPos start, BlockPos end) { - super(start, end, new BlockPos[]{end.up(3), end.up(2), end.up(), end}, new BlockPos[]{end.down()}); - } - - @Override - protected double calculateCost(ToolSet ts) { - if (!canWalkOn(positionsToPlace[0])) { - return COST_INF; - } - if (getTotalHardnessOfBlocksToBreak(ts) != 0) { - return COST_INF; - } - return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_TWO_BLOCK_COST, WALK_ONE_BLOCK_COST * 0.2);//we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel) - } - - @Override - protected boolean tick0() {//basically just hold down W until we are where we want to be - MovementManager.moveTowardsBlock(to); - return Baritone.playerFeet.equals(to); // TODO wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionFall.java b/src/main/resources/baritone/pathfinding/actions/ActionFall.java deleted file mode 100644 index f5650dff..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionFall.java +++ /dev/null @@ -1,42 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.util.ToolSet; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; -import net.minecraft.client.Minecraft; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class ActionFall extends ActionPlaceOrBreak { - public ActionFall(BlockPos start) { - super(start, start.down(), new BlockPos[]{start.down()}, new BlockPos[0]); - } - int numTicks = 0; - @Override - protected boolean tick0() { - numTicks++; - if (numTicks > 10) { - MovementManager.moveTowardsBlock(to); - } - return Baritone.playerFeet.equals(to); - } - @Override - protected double calculateCost(ToolSet ts) { - if (!Baritone.allowVerticalMotion || !canWalkOn(to.down())) { - return COST_INF; - } - Block td = Baritone.get(to).getBlock(); - boolean ladder = td instanceof BlockLadder || td instanceof BlockVine; - if (ladder) { - return LADDER_DOWN_ONE_COST; - } else { - return FALL_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts); - } - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionPillar.java b/src/main/resources/baritone/pathfinding/actions/ActionPillar.java deleted file mode 100644 index c72956ce..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionPillar.java +++ /dev/null @@ -1,140 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.ui.LookManager; -import baritone.util.Out; -import baritone.util.ToolSet; -import net.minecraft.block.Block; -import net.minecraft.block.BlockFalling; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class ActionPillar extends ActionPlaceOrBreak { - - public ActionPillar(BlockPos start) { - super(start, start.up(), new BlockPos[]{start.up(2)}, new BlockPos[]{start}); - } - - @Override - protected double calculateCost(ToolSet ts) { - Block fromDown = Baritone.get(from).getBlock(); - boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine; - if (!ladder) { - Block d = Baritone.get(from.down()).getBlock(); - if (d instanceof BlockLadder || d instanceof BlockVine) { - return COST_INF; - } - } - if ((!Baritone.hasThrowaway && !ladder) || !Baritone.allowVerticalMotion) { - return COST_INF; - } - if (fromDown instanceof BlockVine) { - if (getAgainst(from) == null) { - return COST_INF; - } - } - double hardness = getTotalHardnessOfBlocksToBreak(ts); - if (hardness != 0) { - Block tmp = Baritone.get(from.up(2)).getBlock(); - if (tmp instanceof BlockLadder || tmp instanceof BlockVine) { - hardness = 0; - } else if (!canWalkOn(from.up(3)) || canWalkThrough(from.up(3)) || Baritone.get(from.up(3)).getBlock() instanceof BlockFalling) {//if the block above where we want to break is not a full block, don't do it - return COST_INF; - } - } - if (isLiquid(from) || isLiquid(from.down())) {//can't pillar on water or in water - return COST_INF; - } - if (ladder) { - return LADDER_UP_ONE_COST + hardness; - } else { - return JUMP_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + hardness; - } - } - int numTicks = 0; - - public BlockPos getAgainst(BlockPos vine) { - if (Baritone.isBlockNormalCube(vine.north())) { - return vine.north(); - } - if (Baritone.isBlockNormalCube(vine.south())) { - return vine.south(); - } - if (Baritone.isBlockNormalCube(vine.east())) { - return vine.east(); - } - if (Baritone.isBlockNormalCube(vine.west())) { - return vine.west(); - } - return null; - } - - @Override - protected boolean tick0() { - IBlockState fromDown = Baritone.get(from); - boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine; - boolean vine = fromDown.getBlock() instanceof BlockVine; - if (!ladder && !LookManager.lookAtBlock(positionsToPlace[0], true)) { - return false; - } - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - boolean blockIsThere = canWalkOn(from) || ladder; - if (ladder) { - BlockPos against = vine ? getAgainst(from) : from.offset(fromDown.getValue(BlockLadder.FACING).getOpposite()); - if (against == null) { - Out.gui("Unable to climb vines", Out.Mode.Standard); - return false; - } - if (Baritone.playerFeet.equals(against.up()) || Baritone.playerFeet.equals(to)) { - return true; - } - /*if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) { - Baritone.moveTowardsBlock(from); - }*/ - MovementManager.moveTowardsBlock(against); - return false; - } else { - if (!switchtothrowaway(true)) {//get ready to place a throwaway block - return false; - } - numTicks++; - MovementManager.jumping = thePlayer.posY < to.getY(); //if our Y coordinate is above our goal, stop jumping - MovementManager.sneak = true; - //otherwise jump - if (numTicks > 40) { - double diffX = thePlayer.posX - (to.getX() + 0.5); - double diffZ = thePlayer.posZ - (to.getZ() + 0.5); - double dist = Math.sqrt(diffX * diffX + diffZ * diffZ); - if (dist > 0.17) {//why 0.17? because it seemed like a good number, that's why - MovementManager.forward = true;//if it's been more than forty ticks of trying to jump and we aren't done yet, go forward, maybe we are stuck - } - } - if (!blockIsThere) { - Out.log("Block not there yet"); - Block fr = Baritone.get(from).getBlock(); - if (!(Baritone.isAir(from) || fr.isReplaceable(Minecraft.getMinecraft().world, from))) { - MovementManager.isLeftClick = true; - blockIsThere = false; - } else if (Minecraft.getMinecraft().player.isSneaking()) { - MovementManager.rightClickMouse();//constantly right click - } - } - } - BlockPos whereAmI = new BlockPos(thePlayer.posX, thePlayer.posY, thePlayer.posZ); - if (whereAmI.equals(to) && blockIsThere) {//if we are at our goal and the block below us is placed - Out.log("Done pillaring to " + to); - MovementManager.jumping = false;//stop jumping - return true;//we are done - } - return false; - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java b/src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java deleted file mode 100644 index dad30aee..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java +++ /dev/null @@ -1,229 +0,0 @@ -package baritone.pathfinding.actions; - -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.ui.LookManager; -import baritone.util.Out; -import baritone.util.ToolSet; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import net.minecraft.block.Block; -import net.minecraft.block.BlockFalling; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public abstract class ActionPlaceOrBreak extends Action { - - public final BlockPos[] positionsToBreak;//the positions that need to be broken before this movement can ensue - public final BlockPos[] positionsToPlace;//the positions where we need to place a block before this aciton can ensue - public final Block[] blocksToBreak;//the blocks at those positions - public final Block[] blocksToPlace; - - public ActionPlaceOrBreak(BlockPos start, BlockPos end, BlockPos[] toBreak, BlockPos[] toPlace) { - super(start, end); - this.positionsToBreak = toBreak; - this.positionsToPlace = toPlace; - blocksToBreak = new Block[positionsToBreak.length]; - blocksToPlace = new Block[positionsToPlace.length]; - for (int i = 0; i < blocksToBreak.length; i++) { - blocksToBreak[i] = Baritone.get(positionsToBreak[i]).getBlock(); - } - for (int i = 0; i < blocksToPlace.length; i++) { - blocksToPlace[i] = Baritone.get(positionsToPlace[i]).getBlock(); - } - } - - public double getTotalHardnessOfBlocksToBreak() {//of all the blocks we need to break before starting this movement, what's the sum of how hard they are (phrasing) - ToolSet ts = new ToolSet(); - return this.getTotalHardnessOfBlocksToBreak(ts); - } - - public double getTotalHardnessOfBlocksToBreak(ToolSet ts) { - double sum = 0; - HashSet toBreak = new HashSet(); - for (BlockPos positionsToBreak1 : positionsToBreak) { - toBreak.add(positionsToBreak1); - if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us - continue; - } - BlockPos tmp = positionsToBreak1.up(); - while (canFall(tmp)) { - toBreak.add(tmp); - tmp = tmp.up(); - } - } - for (BlockPos pos : toBreak) { - sum += getHardness(ts, Baritone.get(pos), pos); - if (sum >= COST_INF) { - return COST_INF; - } - } - if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) { - for (int i = 0; i < blocksToPlace.length; i++) { - if (!canWalkOn(positionsToPlace[i])) { - return COST_INF; - } - } - } - return sum; - } - - public static boolean canFall(BlockPos pos) { - return Baritone.get(pos).getBlock() instanceof BlockFalling; - } - - public static double getHardness(ToolSet ts, IBlockState block, BlockPos position) { - if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) { - if (avoidBreaking(position)) { - return COST_INF; - } - if (!Baritone.allowBreakOrPlace) { - return COST_INF; - } - double m = Block.getBlockFromName("minecraft:crafting_table").equals(block) ? 10 : 1; - return m / ts.getStrVsBlock(block, position) + BREAK_ONE_BLOCK_ADD; - } - return 0; - } - - @Override - public String toString() { - return this.getClass() + " place " + Arrays.asList(blocksToPlace) + " break " + Arrays.asList(blocksToBreak) + " cost " + cost(null) + " break cost " + getTotalHardnessOfBlocksToBreak(); - } - - @Override - public boolean tick() { - //breaking first - for (int i = 0; i < positionsToBreak.length; i++) { - if (!canWalkThrough(positionsToBreak[i])) { - if (!Baritone.allowBreakOrPlace) { - Out.gui("BB I can't break this =(((", Out.Mode.Standard); - return false; - } - //Out.log("Breaking " + blocksToBreak[i] + " at " + positionsToBreak[i]); - boolean lookingInCorrectDirection = LookManager.lookAtBlock(positionsToBreak[i], true); - //TODO decide if when actuallyLookingAtTheBlock==true then should it still keep moving the look direction to the exact center of the block - boolean actuallyLookingAtTheBlock = positionsToBreak[i].equals(Baritone.whatAreYouLookingAt()); - if (!(lookingInCorrectDirection || actuallyLookingAtTheBlock)) { - return false; - } - /*if (!positionsToBreak[i].equals(Baritone.whatAreYouLookingAt())) {//hmmm, our crosshairs are looking at the wrong block - //TODO add a timer here, and if we are stuck looking at the wrong block for more than 1 second, do something - //(it cant take longer than twenty ticks, because the Baritone.MAX_YAW_CHANGE_PER_TICK=18, and 18*20 = 360° - Out.log("Wrong"); - return false; - }*/ - if (Baritone.whatAreYouLookingAt() != null) { - Baritone.switchtotool(Baritone.get(Baritone.whatAreYouLookingAt())); - } - MovementManager.isLeftClick = true;//hold down left click - if (canWalkThrough(positionsToBreak[i])) { - MovementManager.letGoOfLeftClick(); - Out.log("Done breaking " + blocksToBreak[i] + " at " + positionsToBreak[i]); - } - return false; - } - } - MovementManager.letGoOfLeftClick();//sometimes it keeps on left clicking so we need this here (yes it scares me too) - for (BlockPos positionsToPlace1 : positionsToPlace) { - if (!canWalkOn(positionsToPlace1)) { - if (!Baritone.allowBreakOrPlace) { - Out.gui("BB I can't place this =(((", Out.Mode.Standard); - return false; - } - //Baritone.lookAtBlock(positionsToPlace[i], true); - //Out.log("CANT DO IT. CANT WALK ON " + blocksToPlace[i] + " AT " + positionsToPlace[i]); - //one of the blocks that needs to be there isn't there - //so basically someone mined out our path from under us - // - //this doesn't really do anything, because all the cases for positionToPlace are handled in their respective movement tick0s (e.g. pillar and bridge) - } - } - return tick0(); - } - //I dont want to make this static, because then it might be executed before Item gets initialized - private static List ACCEPTABLE_THROWAWAY_ITEMS = null; - - private static void set() { - if (ACCEPTABLE_THROWAWAY_ITEMS != null) { - return; - } - ACCEPTABLE_THROWAWAY_ITEMS = Arrays.asList(new Item[]{Item.getByNameOrId("minecraft:dirt"), Item.getByNameOrId("minecraft:cobblestone")}); - } - - public static boolean switchtothrowaway(boolean message) { - set(); - EntityPlayerSP p = Minecraft.getMinecraft().player; - NonNullList inv = p.inventory.mainInventory; - for (byte i = 0; i < 9; i++) { - ItemStack item = inv.get(i); - if (item == null) { - item = new ItemStack(Item.getByNameOrId("minecraft:apple")); - } - if (ACCEPTABLE_THROWAWAY_ITEMS.contains(item.getItem())) { - p.inventory.currentItem = i; - return true; - } - } - if (message) { - Out.gui("bb pls get me some blocks. dirt or cobble", Out.Mode.Minimal); - } - return false; - } - - public static boolean hasthrowaway() { - set(); - EntityPlayerSP p = Minecraft.getMinecraft().player; - NonNullList inv = p.inventory.mainInventory; - for (byte i = 0; i < 9; i++) { - ItemStack item = inv.get(i); - if (item == null) { - item = new ItemStack(Item.getByNameOrId("minecraft:apple")); - } - if (ACCEPTABLE_THROWAWAY_ITEMS.contains(item.getItem())) { - return true; - } - } - return false; - } - - /** - * Do the actual tick. This function can assume that all blocks in - * positionsToBreak are now walk-through-able. - * - * @return - */ - protected abstract boolean tick0(); - - public ArrayList toMine() { - ArrayList result = new ArrayList<>(); - for (BlockPos positionsToBreak1 : positionsToBreak) { - if (!canWalkThrough(positionsToBreak1)) { - result.add(positionsToBreak1); - } - } - return result; - } - - public ArrayList toPlace() { - ArrayList result = new ArrayList<>(); - for (BlockPos positionsToPlace1 : positionsToPlace) { - if (!canWalkOn(positionsToPlace1)) { - result.add(positionsToPlace1); - } - } - return result; - } -} diff --git a/src/main/resources/baritone/pathfinding/actions/ActionWalkDiagonal.java b/src/main/resources/baritone/pathfinding/actions/ActionWalkDiagonal.java deleted file mode 100644 index e1897c49..00000000 --- a/src/main/resources/baritone/pathfinding/actions/ActionWalkDiagonal.java +++ /dev/null @@ -1,56 +0,0 @@ -package baritone.pathfinding.actions; - -import java.util.Random; -import baritone.Baritone; -import baritone.movement.MovementManager; -import baritone.ui.LookManager; -import baritone.util.ToolSet; -import net.minecraft.client.Minecraft; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.EnumFacing; - -/** - * - * @author leijurv - */ -public class ActionWalkDiagonal extends ActionPlaceOrBreak { - public ActionWalkDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) { - this(start, start.offset(dir1), start.offset(dir2), dir2); - //super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()}); - } - public ActionWalkDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) { - this(start, dir1.offset(drr2), dir1, dir2); - } - public ActionWalkDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) { - super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}, new BlockPos[]{end.down()}); - } - private Boolean oneInTen = null; - @Override - protected boolean tick0() { - if (oneInTen == null) { - oneInTen = new Random().nextInt(10) == 0; - } - if (oneInTen) { - MovementManager.forward = LookManager.lookAtBlock(to, false); - } else { - MovementManager.moveTowardsBlock(to); - } - if (MovementManager.forward && !MovementManager.backward) { - Minecraft.getMinecraft().player.setSprinting(true); - } - return to.equals(Baritone.playerFeet); - } - @Override - protected double calculateCost(ToolSet ts) { - if (!Baritone.allowDiagonal) { - return COST_INF; - } - if (getTotalHardnessOfBlocksToBreak(ts) != 0) { - return COST_INF; - } - if (!canWalkOn(positionsToPlace[0])) { - return COST_INF; - } - return Math.sqrt(2) * (isWater(from) || isWater(to) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST); - } -} diff --git a/src/main/resources/baritone/schematic/Schematic.java b/src/main/resources/baritone/schematic/Schematic.java deleted file mode 100644 index afb72589..00000000 --- a/src/main/resources/baritone/schematic/Schematic.java +++ /dev/null @@ -1,96 +0,0 @@ -package baritone.schematic; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map.Entry; -import net.minecraft.block.Block; -import net.minecraft.util.Tuple; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author galdara - */ -public class Schematic { - - private final HashMap schematicBlocks; - private final int width; - private final int height; - private final int length; - - public Schematic(HashMap blocks, int width, int height, int length) { - schematicBlocks = blocks; - this.width = width; - this.height = height; - this.length = length; - } - - public Schematic(Block type, int desiredWidth) { - if (type == null) { - throw new IllegalArgumentException(); - } - width = desiredWidth; - height = desiredWidth; - length = 1; - schematicBlocks = new HashMap(); - for (int i = 0; i < desiredWidth; i++) { - schematicBlocks.put(new BlockPos(i, 0, 0), type); - schematicBlocks.put(new BlockPos(i, desiredWidth - 1, 0), type); - schematicBlocks.put(new BlockPos(desiredWidth / 2, i, 0), type); - } - } - - /** - * Tuple links the BlockPos and Block to one another. - * - * @param blockPos - * @return Tuple of BlockPos and Block - */ - public Tuple getTupleFromBlockPos(BlockPos blockPos) { - if (schematicBlocks.containsKey(blockPos)) { - return new Tuple<>(blockPos, schematicBlocks.get(blockPos)); - } - return null; - } - - /** - * Gets given block type in schematic from a BlockPos - * - * @param blockPos - * @return - */ - public Block getBlockFromBlockPos(BlockPos blockPos) { - return schematicBlocks.get(blockPos); - } - - /** - * Gives the length along the X axis - * - * @return Schematic width - */ - public int getWidth() { - return width; - } - - /** - * Gives the height along the y axis - * - * @return Schematic height - */ - public int getHeight() { - return height; - } - - /** - * Gives the length along the z axis - * - * @return Schematic length - */ - public int getLength() { - return length; - } - - public ArrayList> getEntries() { - return new ArrayList(schematicBlocks.entrySet()); - } -} diff --git a/src/main/resources/baritone/schematic/SchematicBuilder.java b/src/main/resources/baritone/schematic/SchematicBuilder.java deleted file mode 100644 index beb2d65e..00000000 --- a/src/main/resources/baritone/schematic/SchematicBuilder.java +++ /dev/null @@ -1,69 +0,0 @@ -package baritone.schematic; - -import baritone.Baritone; -import baritone.pathfinding.goals.GoalComposite; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Map.Entry; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.util.Tuple; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class SchematicBuilder { - - ArrayList> plan = new ArrayList(); - BlockPos offset; - Schematic schematic; - - public SchematicBuilder(Schematic schematic, BlockPos offset) { - this.schematic = schematic; - this.offset = offset; - for (Entry entry : schematic.getEntries()) { - plan.add(new Tuple(offset(entry.getKey()), entry.getValue())); - } - } - - public void tick() { - HashSet goal = getAllBlocksToPlaceShiftedUp(); - //Out.log("Ticking " + goal); - if (goal != null) { - Baritone.goal = new GoalComposite(goal); - if (Baritone.currentPath == null && !Baritone.isThereAnythingInProgress) { - Baritone.findPathInNewThread(false); - } - } else { - //Out.gui("done building", Out.Mode.Standard); - } - } - - public HashSet getAllBlocksToPlaceShiftedUp() { - HashSet toPlace = new HashSet<>(); - Block air = Blocks.AIR; - for (int y = 0; y < schematic.getHeight(); y++) { - for (int x = 0; x < schematic.getWidth(); x++) { - for (int z = 0; z < schematic.getLength(); z++) { - BlockPos inSchematic = new BlockPos(x, y, z); - BlockPos inWorld = offset(inSchematic); - Block current = Baritone.get(inWorld).getBlock(); - Block desired = schematic.getBlockFromBlockPos(inSchematic); - //Out.log(inSchematic + " " + current + " " + desired); - boolean currentlyAir = air.equals(current); - boolean shouldBeAir = desired == null || air.equals(desired); - if (currentlyAir && !shouldBeAir) { - toPlace.add(inWorld.up()); - } - } - } - } - return toPlace.isEmpty() ? null : toPlace; - } - - private BlockPos offset(BlockPos original) { - return new BlockPos(original.getX() + offset.getX(), original.getY() + offset.getY(), original.getZ() + offset.getZ()); - } -} diff --git a/src/main/resources/baritone/schematic/SchematicLoader.java b/src/main/resources/baritone/schematic/SchematicLoader.java deleted file mode 100644 index 9823d6a7..00000000 --- a/src/main/resources/baritone/schematic/SchematicLoader.java +++ /dev/null @@ -1,76 +0,0 @@ -package baritone.schematic; - -import baritone.util.Out; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author galdara - */ -public class SchematicLoader { - - public static File schematicDir; - private static final HashMap cachedSchematics = new HashMap<>(); - - private SchematicLoader() { - schematicDir = new File(Minecraft.getMinecraft().gameDir, "schematics"); - schematicDir.mkdir(); - for (File file : schematicDir.listFiles(new FileFilter() { - @Override - public boolean accept(File pathname) { - return pathname.getName().endsWith(".schematic"); - } - })) { - try { - cachedSchematics.put(file, loadFromFile(file)); - } catch (IOException ex) { - Logger.getLogger(SchematicLoader.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - - public static SchematicLoader getLoader() { - return new SchematicLoader(); - } - - public final Schematic loadFromFile(File nbtFile) throws FileNotFoundException, IOException { - if (cachedSchematics.containsKey(nbtFile)) { - return cachedSchematics.get(nbtFile); - } - FileInputStream fileInputStream = new FileInputStream(nbtFile); - NBTTagCompound compound = CompressedStreamTools.readCompressed(fileInputStream); - System.out.print(compound); - int height, width, length; - height = compound.getInteger("Height"); - width = compound.getInteger("Width"); - length = compound.getInteger("Length"); - byte[][][] blocks = new byte[width][height][length], data = new byte[width][height][length]; - byte[] rawBlocks = compound.getByteArray("Blocks"); - HashMap blocksMap = new HashMap<>(); - for (int y = 0; y < height; y++) { - for (int z = 0; z < length; z++) { - for (int x = 0; x < width; x++) { - int index = y * width * length + z * width + x; - blocks[x][y][z] = rawBlocks[index]; - blocksMap.put(new BlockPos(x, y, z), Block.getBlockById(rawBlocks[index])); - } - } - } - Out.log(blocksMap); - Schematic schematic = new Schematic(blocksMap, width, height, length); - cachedSchematics.put(nbtFile, schematic); - return schematic; - } -} diff --git a/src/main/resources/baritone/ui/LookManager.java b/src/main/resources/baritone/ui/LookManager.java deleted file mode 100644 index 2abc017e..00000000 --- a/src/main/resources/baritone/ui/LookManager.java +++ /dev/null @@ -1,371 +0,0 @@ -package baritone.ui; - -import baritone.Baritone; -import baritone.pathfinding.goals.GoalXZ; -import baritone.util.Manager; -import java.util.ArrayList; -import java.util.Random; -import net.minecraft.block.BlockFire; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; - -/** - * - * @author leijurv - */ -public class LookManager extends Manager { - - public static boolean randomLooking = true; - static final float MAX_YAW_CHANGE_PER_TICK = 360 / 20; - static final float MAX_PITCH_CHANGE_PER_TICK = 360 / 20; - static float previousYaw = 0; - static float previousPitch = 0; - /** - * Something with smoothing between ticks - */ - static float desiredNextYaw = 0; - static float desiredNextPitch = 0; - /** - * The desired yaw, as set by whatever movement is happening. Remember to also - * set lookingYaw to true if you really want the yaw to change - * - */ - static float desiredYaw; - /** - * The desired pitch, as set by whatever movement is happening. Remember to - * also set lookingPitch to true if you really want the yaw to change - * - */ - static float desiredPitch; - /** - * Set to true if the movement wants the player's yaw to be moved towards - * desiredYaw - */ - static boolean lookingYaw = false; - /** - * Set to true if the movement wants the player's pitch to be moved towards - * desiredPitch - */ - static boolean lookingPitch = false; - - public static void frame(float partialTicks) { - //Out.log("Part: " + partialTicks); - if (Minecraft.getMinecraft() == null || Minecraft.getMinecraft().player == null) { - return; - } - if (lookingPitch) { - Minecraft.getMinecraft().player.rotationPitch = (desiredNextPitch - previousPitch) * partialTicks + previousPitch; - } - if (lookingYaw) { - Minecraft.getMinecraft().player.rotationYaw = (desiredNextYaw - previousYaw) * partialTicks + previousYaw; - } - } - /** - * Because I had to do it the janky way - */ - private static final double[][] BLOCK_SIDE_MULTIPLIERS = {{0, 0.5, 0.5}, {1, 0.5, 0.5}, {0.5, 0, 0.5}, {0.5, 1, 0.5}, {0.5, 0.5, 0}, {0.5, 0.5, 1}}; - - /** - * Called by our code in order to look in the direction of the center of a - * block - * - * @param p the position to look at - * @param alsoDoPitch whether to set desired pitch or just yaw - * @return is the actual player yaw (and actual player pitch, if alsoDoPitch - * is true) within ANGLE_THRESHOLD (currently 7°) of looking straight at - * this block? - */ - public static boolean lookAtBlock(BlockPos p, boolean alsoDoPitch) { - if (couldIReachCenter(p)) { - return lookAtCenterOfBlock(p, alsoDoPitch); - } - IBlockState b = Baritone.get(p); - AxisAlignedBB bbox = b.getBoundingBox(Baritone.world, p); - for (double[] mult : BLOCK_SIDE_MULTIPLIERS) { - double xDiff = bbox.minX * mult[0] + bbox.maxX * (1 - mult[0]);//lol - double yDiff = bbox.minY * mult[1] + bbox.maxY * (1 - mult[1]); - double zDiff = bbox.minZ * mult[2] + bbox.maxZ * (1 - mult[2]); - double x = p.getX() + xDiff; - double y = p.getY() + yDiff; - double z = p.getZ() + zDiff; - if (couldIReachByLookingAt(p, x, y, z)) { - return lookAtCoords(x, y, z, alsoDoPitch); - } - } - return lookAtCenterOfBlock(p, alsoDoPitch); - } - - public static boolean lookAtCenterOfBlock(BlockPos p, boolean alsoDoPitch) { - IBlockState b = Baritone.get(p); - AxisAlignedBB bbox = b.getBoundingBox(Baritone.world, p); - double xDiff = (bbox.minX + bbox.maxX) / 2; - double yDiff = (bbox.minY + bbox.maxY) / 2; - double zDiff = (bbox.minZ + bbox.maxZ) / 2; - if (b instanceof BlockFire) {//look at bottom of fire when putting it out - yDiff = 0; - } - double x = p.getX() + xDiff; - double y = p.getY() + yDiff; - double z = p.getZ() + zDiff; - return lookAtCoords(x, y, z, alsoDoPitch); - } - /** - * The threshold for how close it tries to get to looking straight at things - */ - public static final float ANGLE_THRESHOLD = 7; - - public static boolean couldIReach(BlockPos pos) { - if (couldIReachCenter(pos)) { - return true; - } - IBlockState b = Baritone.get(pos); - AxisAlignedBB bbox = b.getBoundingBox(Baritone.world, pos); - for (double[] mult : BLOCK_SIDE_MULTIPLIERS) { - double xDiff = bbox.minX * mult[0] + bbox.maxX * (1 - mult[0]);//lol - double yDiff = bbox.minY * mult[1] + bbox.maxY * (1 - mult[1]); - double zDiff = bbox.minZ * mult[2] + bbox.maxZ * (1 - mult[2]); - double x = pos.getX() + xDiff; - double y = pos.getY() + yDiff; - double z = pos.getZ() + zDiff; - if (couldIReachByLookingAt(pos, x, y, z)) { - return true; - } - } - return false; - } - - public static boolean couldIReachCenter(BlockPos pos) { - float[] pitchAndYaw = pitchAndYawToCenter(pos); - RayTraceResult blah = raytraceTowards(pitchAndYaw); - return blah != null && blah.typeOfHit == RayTraceResult.Type.BLOCK && blah.getBlockPos().equals(pos); - } - - public static boolean couldIReach(BlockPos pos, EnumFacing dir) { - BlockPos side = pos.offset(dir); - double faceX = (pos.getX() + side.getX() + 1.0D) * 0.5D; - double faceY = (pos.getY() + side.getY()) * 0.5D; - double faceZ = (pos.getZ() + side.getZ() + 1.0D) * 0.5D; - RayTraceResult blah = rayTraceTowards(faceX, faceY, faceZ); - return blah != null && blah.typeOfHit == RayTraceResult.Type.BLOCK && blah.getBlockPos().equals(pos) && blah.sideHit == dir; - } - - public static RayTraceResult rayTraceTowards(double x, double y, double z) { - return raytraceTowards(pitchAndYaw(x, y, z)); - } - - public static RayTraceResult raytraceTowards(float[] pitchAndYaw) { - float yaw = pitchAndYaw[0]; - float pitch = pitchAndYaw[1]; - double blockReachDistance = (double) Minecraft.getMinecraft().playerController.getBlockReachDistance(); - Vec3d vec3 = Minecraft.getMinecraft().player.getPositionEyes(1.0F); - Vec3d vec31 = getVectorForRotation(pitch, yaw); - Vec3d vec32 = vec3.add(vec31.x * blockReachDistance, vec31.y * blockReachDistance, vec31.z * blockReachDistance); - RayTraceResult blah = Minecraft.getMinecraft().world.rayTraceBlocks(vec3, vec32, false, false, true); - return blah; - } - - public static boolean couldIReachByLookingAt(BlockPos pos, double x, double y, double z) { - RayTraceResult blah = raytraceTowards(x, y, z); - return blah != null && blah.typeOfHit == RayTraceResult.Type.BLOCK && blah.getBlockPos().equals(pos); - } - - public static Vec3d getVectorForRotation(float pitch, float yaw) {//shamelessly copied from Entity.java - float f = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI); - float f1 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI); - float f2 = -MathHelper.cos(-pitch * 0.017453292F); - float f3 = MathHelper.sin(-pitch * 0.017453292F); - return new Vec3d((double) (f1 * f2), (double) f3, (double) (f * f2)); - } - - public static GoalXZ fromAngleAndDirection(double distance) { - double theta = ((double) Minecraft.getMinecraft().player.rotationYaw) * Math.PI / 180D; - double x = Minecraft.getMinecraft().player.posX - Math.sin(theta) * distance; - double z = Minecraft.getMinecraft().player.posZ + Math.cos(theta) * distance; - return new GoalXZ((int) x, (int) z); - } - - public static boolean lookingYaw() { - return lookingYaw; - } - static double SPEED = 1000; - - /** - * Smoothly moves between random pitches and yaws every second - * - * @return - */ - public static float[] getRandom() { - long now = (long) Math.ceil(((double) System.currentTimeMillis()) / SPEED); - now *= SPEED; - long prev = now - (long) SPEED; - float frac = (System.currentTimeMillis() - prev) / ((float) SPEED);//fraction between previous second and next - Random prevR = new Random(prev);//fite me - Random nowR = new Random(now); - float prevFirst = prevR.nextFloat() * 10 - 5; - float prevSecond = prevR.nextFloat() * 10 - 5; - float nowFirst = nowR.nextFloat() * 10 - 5; - float nowSecond = nowR.nextFloat() * 10 - 5; - float first = prevFirst + frac * (nowFirst - prevFirst);//smooth between previous and next second - float second = prevSecond + frac * (nowSecond - prevSecond); - return new float[]{first, second}; - } - - public static float[] pitchAndYawToCenter(BlockPos p) { - IBlockState b = Baritone.get(p); - AxisAlignedBB bbox = b.getBoundingBox(Baritone.world, p); - double xDiff = (bbox.minX + bbox.maxX) / 2; - double yDiff = (bbox.minY + bbox.maxY) / 2; - double zDiff = (bbox.minZ + bbox.maxZ) / 2; - if (b instanceof BlockFire) {//look at bottom of fire when putting it out - yDiff = 0; - } - double x = p.getX() + xDiff; - double y = p.getY() + yDiff; - double z = p.getZ() + zDiff; - return pitchAndYaw(x, y, z); - } - - public static float[] pitchAndYaw(double x, double y, double z) { - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - double yDiff = (thePlayer.posY + 1.62) - y;//lol - double yaw = Math.atan2(thePlayer.posX - x, -thePlayer.posZ + z); - double dist = Math.sqrt((thePlayer.posX - x) * (thePlayer.posX - x) + (-thePlayer.posZ + z) * (-thePlayer.posZ + z)); - double pitch = Math.atan2(yDiff, dist); - return new float[]{(float) (yaw * 180 / Math.PI), (float) (pitch * 180 / Math.PI)}; - } - static ArrayList sketchiness = new ArrayList<>(); - - public static void setDesiredYaw(float y) { - sketchiness.add(new Exception("Desired yaw already set!")); - if (lookingYaw) { - /*for (Exception ex : sketchiness) { - Logger.getLogger(LookManager.class.getName()).log(Level.SEVERE, null, ex);//print out everyone who has tried to set the desired yaw this tick to show the conflict - }*/ - sketchiness.clear(); - return; - } - desiredYaw = y; - lookingYaw = true; - } - - /** - * Look at coordinates - * - * @param x - * @param y - * @param z - * @param alsoDoPitch also adjust the pitch? if false, y is ignored - * @return is the actual player yaw (and actual player pitch, if alsoDoPitch - * is true) within ANGLE_THRESHOLD (currently 7°) of looking straight at - * these coordinates? - */ - public static boolean lookAtCoords(double x, double y, double z, boolean alsoDoPitch) { - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - double yDiff = (thePlayer.posY + 1.62) - y; - double yaw = Math.atan2(thePlayer.posX - x, -thePlayer.posZ + z); - double dist = Math.sqrt((thePlayer.posX - x) * (thePlayer.posX - x) + (-thePlayer.posZ + z) * (-thePlayer.posZ + z)); - double pitch = Math.atan2(yDiff, dist); - setDesiredYaw((float) (yaw * 180 / Math.PI)); - float yawDist = Math.abs(desiredYaw - thePlayer.rotationYaw); - boolean withinRange = yawDist < ANGLE_THRESHOLD || yawDist > 360 - ANGLE_THRESHOLD; - if (alsoDoPitch) { - lookingPitch = true; - desiredPitch = (float) (pitch * 180 / Math.PI); - float pitchDist = Math.abs(desiredPitch - thePlayer.rotationPitch); - withinRange = withinRange && (pitchDist < ANGLE_THRESHOLD || pitchDist > 360 - ANGLE_THRESHOLD); - } - return withinRange; - } - - @Override - public void onTickPre() { - if (lookingYaw) { - Minecraft.getMinecraft().player.rotationYaw = desiredNextYaw; - } - if (lookingPitch) { - Minecraft.getMinecraft().player.rotationPitch = desiredNextPitch; - } - lookingYaw = false; - sketchiness.clear(); - lookingPitch = false; - } - - public static void nudgeToLevel() { - EntityPlayerSP thePlayer = Minecraft.getMinecraft().player; - if (!lookingPitch) { - if (thePlayer.rotationPitch < -20) { - thePlayer.rotationPitch++; - } else if (thePlayer.rotationPitch > 20) { - thePlayer.rotationPitch--; - } - } - } - - @Override - public void onTickPost() { - if (randomLooking) { - desiredYaw += getRandom()[0]; - desiredPitch += getRandom()[1]; - } - if (desiredPitch > 90) { - desiredPitch = 90; - } - if (desiredPitch < -90) { - desiredPitch = -90; - } - if (lookingYaw) { - previousYaw = Minecraft.getMinecraft().player.rotationYaw; - desiredYaw += 360; - desiredYaw %= 360; - float yawDistance = Minecraft.getMinecraft().player.rotationYaw - desiredYaw; - if (yawDistance > 180) { - yawDistance -= 360; - } else if (yawDistance < -180) { - yawDistance += 360; - } - if (Math.abs(yawDistance) > MAX_YAW_CHANGE_PER_TICK) { - yawDistance = Math.signum(yawDistance) * MAX_YAW_CHANGE_PER_TICK; - } - desiredNextYaw = Minecraft.getMinecraft().player.rotationYaw - yawDistance; - } - if (lookingPitch) { - previousPitch = Minecraft.getMinecraft().player.rotationPitch; - desiredPitch += 360; - desiredPitch %= 360; - float pitchDistance = Minecraft.getMinecraft().player.rotationPitch - desiredPitch; - if (pitchDistance > 180) { - pitchDistance -= 360; - } else if (pitchDistance < -180) { - pitchDistance += 360; - } - if (Math.abs(pitchDistance) > MAX_PITCH_CHANGE_PER_TICK) { - pitchDistance = Math.signum(pitchDistance) * MAX_PITCH_CHANGE_PER_TICK; - } - desiredNextPitch = Minecraft.getMinecraft().player.rotationPitch - pitchDistance; - } - } - - @Override - protected void onTick() { - } - - @Override - protected void onCancel() { - } - - @Override - protected void onStart() { - } - - @Override - protected boolean onEnabled(boolean enabled) { - return true; - } -} diff --git a/src/main/resources/baritone/ui/PathRenderer.java b/src/main/resources/baritone/ui/PathRenderer.java deleted file mode 100644 index 2b264273..00000000 --- a/src/main/resources/baritone/ui/PathRenderer.java +++ /dev/null @@ -1,178 +0,0 @@ -package baritone.ui; - -import baritone.Baritone; -import baritone.pathfinding.Path; -import baritone.pathfinding.PathFinder; -import baritone.pathfinding.actions.Action; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import org.lwjgl.opengl.GL11; - -import java.awt.*; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * @author leijurv - */ -public class PathRenderer { - - public static void render(EntityPlayer player, float partialTicks) { - if (Baritone.currentPath != null) { - drawPath(Baritone.currentPath, player, partialTicks, Color.RED); - for (BlockPos pos : Baritone.currentPath.toMine()) { - drawSelectionBox(player, pos, partialTicks, Color.RED); - } - for (BlockPos pos : Baritone.currentPath.toPlace()) { - drawSelectionBox(player, pos, partialTicks, Color.GREEN); - } - } - if (Baritone.nextPath != null) { - drawPath(Baritone.nextPath, player, partialTicks, Color.GREEN); - for (BlockPos pos : Baritone.nextPath.toMine()) { - drawSelectionBox(player, pos, partialTicks, Color.RED); - } - for (BlockPos pos : Baritone.nextPath.toPlace()) { - drawSelectionBox(player, pos, partialTicks, Color.GREEN); - } - } - try { - if (PathFinder.currentlyRunning != null) { - Path p = PathFinder.currentlyRunning.getTempSolution(); - if (p != null) { - drawPath(p, player, partialTicks, Color.BLUE); - Path mr = PathFinder.currentlyRunning.getMostRecentNodeConsidered(); - if (mr != null) { - drawPath(mr, player, partialTicks, Color.CYAN); - drawSelectionBox(player, mr.end, partialTicks, Color.CYAN); - } - } - } - } catch (Exception ex) { - Logger.getLogger(PathRenderer.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public static void drawPath(Path path, EntityPlayer player, float partialTicks, Color color) { - /*for (BlockPos pos : path.path) { - drawSelectionBox(player, pos, partialTicks, color); - }*/ - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F); - GL11.glLineWidth(3.0F); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - boolean[] cornerFirstHalf = new boolean[path.path.size()]; - boolean[] cornerSecondHalf = new boolean[path.path.size()]; - for (int i = 0; i < path.path.size() - 2; i++) { - BlockPos a = path.path.get(i); - BlockPos b = path.path.get(i + 1); - BlockPos c = path.path.get(i + 2); - if (a.getY() != b.getY() || b.getY() != c.getY()) { - continue; - } - if (b.getX() - a.getX() == c.getX() - b.getX() && b.getZ() - a.getZ() == c.getZ() - b.getZ()) { - continue; - } - if (a.getX() != b.getX() && a.getZ() != b.getZ()) { - continue; - } - if (b.getX() != c.getX() && b.getZ() != c.getZ()) { - continue; - } - BlockPos corner = new BlockPos(c.getX() - b.getX() + a.getX(), a.getY(), c.getZ() - b.getZ() + a.getZ()); - if (Action.avoidWalkingInto(corner) || Action.avoidWalkingInto(corner.up())) { - continue; - } - cornerFirstHalf[i] = true; - cornerSecondHalf[i + 1] = true; - double bp1x = (a.getX() + b.getX()) * 0.5D; - double bp1z = (a.getZ() + b.getZ()) * 0.5D; - double bp2x = (c.getX() + b.getX()) * 0.5D; - double bp2z = (c.getZ() + b.getZ()) * 0.5D; - drawLine(player, bp1x, a.getY(), bp1z, bp2x, a.getY(), bp2z, partialTicks); - } - for (int i = 0; i < path.path.size() - 1; i++) { - BlockPos a = path.path.get(i); - BlockPos b = path.path.get(i + 1); - if (cornerFirstHalf[i] && !cornerSecondHalf[i]) { - drawLine(player, a.getX(), a.getY(), a.getZ(), (b.getX() + a.getX()) * 0.5D, b.getY(), (b.getZ() + a.getZ()) * 0.5D, partialTicks); - } - if (cornerSecondHalf[i] && !cornerFirstHalf[i]) { - drawLine(player, (a.getX() + b.getX()) * 0.5D, a.getY(), (a.getZ() + b.getZ()) * 0.5D, b.getX(), b.getY(), b.getZ(), partialTicks); - } - if (!cornerFirstHalf[i] && !cornerSecondHalf[i]) { - drawLine(player, a.getX(), a.getY(), a.getZ(), b.getX(), b.getY(), b.getZ(), partialTicks); - } else { - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.1F); - drawLine(player, a.getX(), a.getY(), a.getZ(), b.getX(), b.getY(), b.getZ(), partialTicks); - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F); - } - } - //GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f); - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } - - - public static void drawSelectionBox(EntityPlayer player, BlockPos blockpos, float partialTicks, Color color) { - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); - GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F); - GL11.glLineWidth(5.0F); - GlStateManager.disableTexture2D(); - GlStateManager.depthMask(false); - float f = 0.002F; - //BlockPos blockpos = movingObjectPositionIn.getBlockPos(); - IBlockState state = Baritone.get(blockpos); - Block block = state.getBlock(); - if (block.equals(Blocks.AIR)) { - block = Blocks.DIRT; - } - //block.setBlockBoundsBasedOnState(Minecraft.getMinecraft().world, blockpos); - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; - AxisAlignedBB toDraw = block.getSelectedBoundingBox(state, Minecraft.getMinecraft().world, blockpos).expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2); - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder worldrenderer = tessellator.getBuffer(); - worldrenderer.begin(3, DefaultVertexFormats.POSITION); - worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); - worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); - worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - tessellator.draw(); - worldrenderer.begin(3, DefaultVertexFormats.POSITION); - worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); - worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); - worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - tessellator.draw(); - worldrenderer.begin(1, DefaultVertexFormats.POSITION); - worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); - worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); - worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); - worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); - tessellator.draw(); - GlStateManager.depthMask(true); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } -} diff --git a/src/main/resources/baritone/util/Autorun.java b/src/main/resources/baritone/util/Autorun.java deleted file mode 100644 index 3d281a60..00000000 --- a/src/main/resources/baritone/util/Autorun.java +++ /dev/null @@ -1,42 +0,0 @@ -package baritone.util; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Arrays; -import baritone.util.Out; -import net.minecraft.client.main.Main; - -/** - * - * @author avecowa - */ -public class Autorun { - public static void start(String[] args) { - Out.log(Arrays.asList(args)); - Out.log(System.getProperty("java.library.path")); - //System.setProperty("java.library.path", System.getProperty("user.home") + "/Dropbox/Baritone/mcp918/jars/versions/1.8.8/1.8.8-natives/"); - //Out.log(System.getProperty("java.library.path")); - Main.main(concat(new String[]{"--version", "mcp", "--accessToken", "0", "--assetsDir", "assets", "--assetIndex", "1.8", "--userProperties", "{}"}, args)); - } - public static void runprocess(String s) throws IOException { - Process p; - Out.log(p = Runtime.getRuntime().exec(s)); - InputStream i = p.getInputStream(); - InputStream e = p.getErrorStream(); - OutputStream o = p.getOutputStream(); - while (p.isAlive() || e.available() > 0 || i.available() > 0) { - while (i.available() > 0) { - System.out.print((char) (i.read())); - } - while (e.available() > 0) { - System.out.print((char) (e.read())); - } - } - } - public static T[] concat(T[] first, T[] second) { - T[] result = Arrays.copyOf(first, first.length + second.length); - System.arraycopy(second, 0, result, first.length, second.length); - return result; - } -} diff --git a/src/main/resources/baritone/util/BlockPuncher.java b/src/main/resources/baritone/util/BlockPuncher.java deleted file mode 100644 index fcc0c7f2..00000000 --- a/src/main/resources/baritone/util/BlockPuncher.java +++ /dev/null @@ -1,43 +0,0 @@ -package baritone.util; - -import java.util.ArrayList; -import java.util.Arrays; -import baritone.Baritone; -import baritone.pathfinding.goals.Goal; -import baritone.pathfinding.goals.GoalComposite; -import baritone.pathfinding.goals.GoalTwoBlocks; -import baritone.util.Out; -import net.minecraft.util.math.BlockPos; - -/** - * yeah so just like go and punch this type of block - * - * @author avecowa - * @author leijurv - * - * =P - */ -public class BlockPuncher { - public static boolean setGoalTo(String... block) { - ArrayList closest = Memory.closest(10, block); - if (closest == null || closest.isEmpty()) { - Out.gui("NO " + Arrays.asList(block) + " NEARBY. OH MAN", Out.Mode.Standard); - return false; - } - Goal[] goals = new Goal[closest.size()]; - for (int i = 0; i < goals.length; i++) { - goals[i] = new GoalTwoBlocks(closest.get(i)); - } - Baritone.goal = new GoalComposite(goals); - return true; - } - public static boolean tick(String... block) { - if (!setGoalTo(block)) { - return false; - } - if (Baritone.currentPath == null && !Baritone.isThereAnythingInProgress) { - Baritone.findPathInNewThread(false); - } - return true; - } -} diff --git a/src/main/resources/baritone/util/ChatCommand.java b/src/main/resources/baritone/util/ChatCommand.java deleted file mode 100644 index 6277b92c..00000000 --- a/src/main/resources/baritone/util/ChatCommand.java +++ /dev/null @@ -1,385 +0,0 @@ -package baritone.util; - -import baritone.Baritone; -import baritone.mining.MickeyMine; -import baritone.pathfinding.goals.GoalBlock; -import baritone.pathfinding.goals.GoalGetToBlock; -import baritone.pathfinding.goals.GoalXZ; -import baritone.pathfinding.goals.GoalYLevel; -import baritone.schematic.Schematic; -import baritone.schematic.SchematicBuilder; -import baritone.schematic.SchematicLoader; -import baritone.ui.LookManager; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Random; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author avecowa - */ -public class ChatCommand { - - private static WorldClient theWorld() { - return Minecraft.getMinecraft().world; - } - - private static EntityPlayerSP thePlayer() { - return Minecraft.getMinecraft().player; - } - private static ArrayList fields; - private static ArrayList methods; - private static Method DONTYOUDARE; - - static { - DONTYOUDARE = null; -// try { -// DONTYOUDARE = ChatCommand.class.getMethod("message", String.class); -// } catch (NoSuchMethodException ex) { -// Logger.getLogger(ChatCommand.class.getName()).log(Level.SEVERE, null, ex); -// } catch (SecurityException ex) { -// Logger.getLogger(ChatCommand.class.getName()).log(Level.SEVERE, null, ex); -// } - methods = new ArrayList(); - fields = new ArrayList(); - addMethods(ChatCommand.class); - addMethods(MCEdit.class); - addFields(Baritone.class); - addFields(LookManager.class); - } - - public static void addFields(Class c) { - Field[] temp = c.getFields(); - for (Field f : temp) { - if (f.getType().equals(boolean.class) && Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers()) && !Modifier.isFinal(f.getModifiers())) { - fields.add(f); - } - } - } - - public static void addMethods(Class c) { - Method[] temp = c.getDeclaredMethods(); - for (Method m : temp) { - if (m.getParameterCount() == 1 && m.getParameterTypes()[0].equals(String.class) && m.getReturnType().equals(String.class) && !m.equals(DONTYOUDARE)) { - methods.add(m); - } - } - } - - public static boolean message(String message) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Out.log("MSG: " + message); - String text = (message.charAt(0) == '/' ? message.substring(1) : message).trim(); - String command = text.split(" ")[0]; - for (Method method : methods) { - if (method.getName().equalsIgnoreCase(command)) { - message = (String) method.invoke(null, text); - Out.gui(message, Out.Mode.Minimal); - return true; - } - } - int argc = text.split(" ").length; - for (Field field : fields) { - if (field.getName().equalsIgnoreCase(command)) { - boolean value = argc == 1 ? !field.getBoolean(null) : Boolean.parseBoolean(text.split(" ")[2]); - field.setBoolean(null, value); - Out.gui(command + " is now " + value, Out.Mode.Minimal); - return true; - } - } - return false; - } - - public static String set(String message) throws IllegalArgumentException, IllegalAccessException { - int argc = message.split(" ").length; - if (argc <= 1) { - return "Arguments plz"; - } - String item = message.split(" ")[1]; - for (Field field : fields) { - if (field.getName().equalsIgnoreCase(item)) { - boolean value; - if (argc == 2) { - value = !field.getBoolean(null); - } else { - value = Boolean.parseBoolean(message.split(" ")[2]); - } - field.setBoolean(null, value); - return item + " is now " + value; - } - } - return "THATS NOT A THING"; - } - - public static String importfrom(String message) throws ClassNotFoundException { - String[] args = message.split(" "); - if (args.length != 3 || (!"m".equals(args[1]) && !"f".equals(args[1]))) { - return "import (m/f) class"; - } - Class c = Class.forName(args[2]); - if (args[1].equals("m")) { - addMethods(c); - } else { - addFields(c); - } - return "Added from " + c; - } - - public static String death(String message) { - Baritone.goal = new GoalBlock(Baritone.death); - return "Set goal to " + Baritone.goal; - } - - public static String ore(String message) { - MickeyMine.toggleOre(message.substring(3).trim()); - return ""; - } - - public static String mine(String message) { - return "Mreow mine: " + Manager.toggle(MickeyMine.class); - } - - public static String wizard(String message) { - return "YOURE A LIZARD HARRY " + (Baritone.isThereAnythingInProgress ^= true); - } - - public static String actuallyTalk(String message) { - Baritone.actuallyPutMessagesInChat ^= true; - return "toggled to " + Baritone.actuallyPutMessagesInChat; - } - - public static String allowPlaceOrBreak(String message) { - return adventure(message); - } - - public static String adventure(String message) { - return "allowBreakOrPlace: " + (Baritone.allowBreakOrPlace ^= true); - } - - public static String save(String message) { - String t = message.substring(4).trim(); - if (Baritone.goal == null) { - return "no goal to save"; - } - if (!(Baritone.goal instanceof GoalBlock)) { - return "sorry, goal has to be instanceof GoalBlock"; - } - Memory.goalMemory.put(t, ((GoalBlock) Baritone.goal).pos()); - return "Saved " + Baritone.goal + " under " + t; - } - - public static String load(String message) { - return "Set goal to " + (Baritone.goal = new GoalBlock(Memory.goalMemory.get(message.substring(4).trim()))); - } - - public static String random(String message) { - double dist = Double.parseDouble(message.substring("random direction".length()).trim()); - double ang = new Random().nextDouble() * Math.PI * 2; - Out.gui("Angle: " + ang, Out.Mode.Debug); - BlockPos playerFeet = new BlockPos(thePlayer().posX, thePlayer().posY, thePlayer().posZ); - int x = playerFeet.getX() + (int) (Math.sin(ang) * dist); - int z = playerFeet.getZ() + (int) (Math.cos(ang) * dist); - Baritone.goal = new GoalXZ(x, z); - return "Set goal to " + Baritone.goal; - } - - public static String findgo(String message) { - return Memory.findGoCommand(message.substring(6).trim()); - } - - public static String find(String message) { - return Memory.findCommand(message.substring(4).trim()); - } - - public static String look(String message) { - LookManager.lookAtBlock(new BlockPos(0, 0, 0), true); - return ""; - } - - public static String cancel(String message) { - Baritone.cancelPath(); - Baritone.plsCancel = true; - Manager.cancel(LookManager.class); - return Baritone.isThereAnythingInProgress ? "Cancelled it, but btw I'm pathing right now" : "Cancelled it"; - } - - public static String st(String message) { - WorldClient theWorld = theWorld(); - EntityPlayerSP thePlayer = thePlayer(); - BlockPos playerFeet = new BlockPos(thePlayer.posX, thePlayer.posY, thePlayer.posZ); - Out.gui(Baritone.info(playerFeet), Out.Mode.Minimal); - Out.gui(Baritone.info(playerFeet.down()), Out.Mode.Minimal); - Out.gui(Baritone.info(playerFeet.up()), Out.Mode.Minimal); - return ""; - } - - public static String setgoal(String message) { - return goal(message); - } - - public static String goal(String message) { - Baritone.plsCancel = false; - int ind = message.indexOf(' ') + 1; - if (ind == 0) { - Baritone.goal = new GoalBlock(Baritone.playerFeet); - return "Set goal to " + Baritone.goal; - } - String[] strs = message.substring(ind).split(" "); - int[] coords = new int[strs.length]; - for (int i = 0; i < strs.length; i++) { - try { - coords[i] = Integer.parseInt(strs[i]); - } catch (NumberFormatException nfe) { - Baritone.goal = new GoalBlock(); - return strs[i] + ". yup. A+ coordinate";//A+? you might even say A* - } - } - switch (strs.length) { - case 3: - Baritone.goal = new GoalBlock(coords[0], coords[1], coords[2]); - break; - case 2: - Baritone.goal = new GoalXZ(coords[0], coords[1]); - break; - case 1: - Baritone.goal = new GoalYLevel(coords[0]); - break; - default: - Baritone.goal = new GoalBlock(); - if (strs.length != 0) { - return strs.length + " coordinates. Nice."; - } - break; - } - return "Set goal to " + Baritone.goal; - } - - public static String gotoblock(String message) { - return Memory.gotoCommand(message.substring(4).trim().toLowerCase()); - } - - public static String player(String message) { - return Memory.playerCommand(message.substring(6).trim()); - } - - public static String thisway(String message) { - return "Set goal to " + (Baritone.goal = LookManager.fromAngleAndDirection(Double.parseDouble(message.substring(7).trim()))); - } - - public static String path(String message) { - Baritone.plsCancel = false; - String[] split = message.split(" "); - Baritone.findPathInNewThread(Baritone.playerFeet, split.length > 1 ? Boolean.parseBoolean(split[1]) : true); - return ""; - } - - public static String hardness(String message) { - BlockPos bp = Baritone.whatAreYouLookingAt(); - return bp == null ? "0" : (1 / theWorld().getBlockState(bp).getBlock().getPlayerRelativeBlockHardness(theWorld().getBlockState(bp), thePlayer(), theWorld(), Baritone.whatAreYouLookingAt())) + ""; - } - - public static String info(String message) { - return Baritone.info(Baritone.whatAreYouLookingAt()); - } - - public static String toggle(String message) throws IllegalArgumentException, IllegalAccessException { - return set(message); - } - - public static String printtag(String message) throws IOException { - Schematic sch = SchematicLoader.getLoader().loadFromFile(new File("/Users/galdara/Downloads/schematics/Bakery.schematic")); - Baritone.currentBuilder = new SchematicBuilder(sch, Baritone.playerFeet); - return "printed schematic to console."; - } - - public static String samplebuild(String message) { - int size = 5; - BlockPos pl = Baritone.playerFeet; - BlockPos center = new BlockPos(pl.getX() - size / 2, pl.getY(), pl.getZ()); - Baritone.currentBuilder = new SchematicBuilder(new Schematic(Block.getBlockFromName("dirt"), size), center); - return "ok"; - } - - public static String getToGoal(String message) { - Baritone.plsCancel = false; - int ind = message.indexOf(' ') + 1; - if (ind == 0) { - Baritone.goal = new GoalGetToBlock(Baritone.playerFeet); - return "Set goal to " + Baritone.goal; - } - String[] strs = message.substring(ind).split(" "); - int[] coords = new int[strs.length]; - for (int i = 0; i < strs.length; i++) { - try { - coords[i] = Integer.parseInt(strs[i]); - } catch (NumberFormatException nfe) { - Baritone.goal = new GoalGetToBlock(); - return strs[i] + ". yup. A+ coordinate";//A+? you might even say A* - } - } - switch (strs.length) { - case 3: - Baritone.goal = new GoalGetToBlock(new BlockPos(coords[0], coords[1], coords[2])); - break; - default: - Baritone.goal = new GoalGetToBlock(); - if (strs.length != 0) { - return strs.length + " coordinates. Nice."; - } - break; - } - return "Set goal to " + Baritone.goal; - } - - public static String debug(String message) { - Out.mode = Out.Mode.Debug; - return "Set mode to debug"; - } - - public static String chatMode(String message) { - String[] args = message.split(" "); - if (args.length == 1) { - return "To what..."; - } - String arg = args[1].toLowerCase(); - switch (arg) { - case "none": - case "1": - Out.mode = Out.Mode.None; - break; - case "minimal": - case "2": - Out.mode = Out.Mode.Minimal; - break; - case "standard": - case "3": - Out.mode = Out.Mode.Standard; - break; - case "debug": - case "4": - Out.mode = Out.Mode.Debug; - break; - case "ludicrous": - case "5": - Out.mode = Out.Mode.Ludicrous; - break; - default: - return "That is note a valid mode"; - } - return "ok"; - } -// public static String testcode(String message) { -// Out.mode = Out.Mode.Debug; -// Out.gui("Testing", Out.Mode.Debug); -// return "OK"; -// } -} diff --git a/src/main/resources/baritone/util/MCEdit.java b/src/main/resources/baritone/util/MCEdit.java deleted file mode 100644 index 007a0db8..00000000 --- a/src/main/resources/baritone/util/MCEdit.java +++ /dev/null @@ -1,71 +0,0 @@ -package baritone.util; - -import baritone.Baritone; -import baritone.pathfinding.goals.GoalComposite; -import java.util.HashSet; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class MCEdit extends Manager { - - static BlockPos pos1 = null; - static BlockPos pos2 = null; - - public static String pos1(String s) { - return "Pos 1: " + (pos1 = Baritone.playerFeet); - } - - public static String pos2(String s) { - return "Pos 2: " + (pos2 = Baritone.playerFeet); - } - - public static String delete(String s) { - Manager.getManager(MCEdit.class).toggle(); - return "k"; - } - - private static HashSet toBreak() { - HashSet toBreak = new HashSet<>(); - for (int x = Math.min(pos1.getX(), pos2.getX()); x <= Math.max(pos1.getX(), pos2.getX()); x++) { - for (int y = Math.max(pos1.getY(), pos2.getY()); y >= Math.min(pos1.getY(), pos2.getY()); y--) { - for (int z = Math.min(pos1.getZ(), pos2.getZ()); z <= Math.max(pos1.getZ(), pos2.getZ()); z++) { - BlockPos po = new BlockPos(x, y, z); - Block b = Baritone.get(po).getBlock(); - if (!Blocks.AIR.equals(b)) { - toBreak.add(po); - if (toBreak.size() > 20) { - return toBreak; - } - } - } - } - } - return toBreak; - } - - @Override - protected void onTick() { - HashSet toBreak = toBreak(); - if (!toBreak.isEmpty()) { - Baritone.goal = new GoalComposite(toBreak); - if (Baritone.currentPath == null && !Baritone.isThereAnythingInProgress) { - Baritone.findPathInNewThread(false); - } - } - } - - @Override - protected void onCancel() { - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - protected void onStart() { - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } -} diff --git a/src/main/resources/baritone/util/Manager.java b/src/main/resources/baritone/util/Manager.java deleted file mode 100644 index 4e70f274..00000000 --- a/src/main/resources/baritone/util/Manager.java +++ /dev/null @@ -1,109 +0,0 @@ -package baritone.util; - -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author avecowa - */ -public abstract class Manager { - private boolean enabled = false; - private static HashMap, Manager> managers = new HashMap, Manager>(); - public final static Manager getManager(Class c) { - if (managers.get(c) == null) { - try { - managers.put(c, (Manager) c.getMethod("createInstance", Class.class).invoke(null, c)); - } catch (NoSuchMethodException ex) { - Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); - managers.put(c, createInstance(c)); - } catch (SecurityException ex) { - Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); - } catch (IllegalArgumentException ex) { - Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); - } catch (InvocationTargetException ex) { - Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); - } - } - if (managers.get(c) == null) { - throw new RuntimeException("Wtf idek"); - } - return managers.get(c); - } - public final static void tick(Class c) { - getManager(c).tick(); - } - public final static void tick(Class c, boolean prepost) { - getManager(c).tick(prepost); - } - public final static boolean enabled(Class c) { - return getManager(c).enabled(); - } - public final static void cancel(Class c) { - getManager(c).cancel(); - } - public final static void start(Class c) { - getManager(c).start(); - } - public final static boolean toggle(Class c) { - return getManager(c).toggle(); - } - public static Manager createInstance(Class c) { - try { - return (Manager) c.newInstance(); - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } - } - public final void tick() { - this.tick((Boolean) null); - } - public final void tick(Boolean prepost) { - //Out.log(this + " " + enabled()); - if (!enabled()) { - return; - } - if (prepost == null) { - onTick(); - } else if (prepost) { - onTickPre(); - } else { - onTickPost(); - } - } - public final boolean enabled() { - return onEnabled(enabled); - } - public final void cancel() { - enabled = false; - onCancel(); - } - public final void start() { - enabled = true; - onStart(); - } - public final boolean toggle() { - if (enabled()) { - cancel(); - } else { - start(); - } - return enabled(); - } - protected void onTickPre() { - } - protected void onTickPost() { - } - protected boolean onEnabled(boolean enabled) { - return enabled; - } - protected abstract void onTick(); - protected abstract void onCancel(); - protected abstract void onStart(); -} diff --git a/src/main/resources/baritone/util/ManagerTick.java b/src/main/resources/baritone/util/ManagerTick.java deleted file mode 100644 index 6d8dc673..00000000 --- a/src/main/resources/baritone/util/ManagerTick.java +++ /dev/null @@ -1,18 +0,0 @@ -package baritone.util; - -/** - * - * @author avecowa - */ -public abstract class ManagerTick extends Manager { - public static boolean tickPath = false; - @Override - protected final void onTick() { - if (tickPath) { - if (onTick0()) { - tickPath = false; - } - } - } - protected abstract boolean onTick0(); -} diff --git a/src/main/resources/baritone/util/Memory.java b/src/main/resources/baritone/util/Memory.java deleted file mode 100644 index 62ef08a4..00000000 --- a/src/main/resources/baritone/util/Memory.java +++ /dev/null @@ -1,398 +0,0 @@ -package baritone.util; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Random; -import java.util.logging.Level; -import java.util.logging.Logger; -import baritone.Baritone; -import static baritone.Baritone.findPathInNewThread; -import static baritone.Baritone.goal; -import baritone.pathfinding.goals.GoalBlock; -import baritone.pathfinding.goals.GoalTwoBlocks; -import baritone.util.Manager; -import baritone.util.Out; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.EmptyChunk; - -/** - * - * @author leijurv - */ -public class Memory extends Manager { - public static HashMap blockMemory = new HashMap(); - public static HashMap playerLocationMemory = new HashMap(); - public static HashMap goalMemory = new HashMap(); - public static ArrayList playersCurrentlyInRange = new ArrayList(); - public static Thread scanThread = null; - public static Block air = null; - public Memory() { - } - @Override - protected void onCancel() { - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - @Override - protected void onStart() { - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - @Override - protected boolean onEnabled(boolean enabled) { - return true; - } - - public static class BlockMemory { - final Block block; - final ArrayList knownPositions;//idk whether to use hashset or arraylist here... - private volatile double furthest; - public BlockMemory(Block block) { - this.block = block; - this.knownPositions = new ArrayList(); - } - public void checkForChange() { - for (BlockPos pos : new ArrayList(knownPositions)) {//make duplicate to prevent concurrent modification exceptions - boolean loaded = blockLoaded(pos); - if (!loaded) { - //Out.gui("Too far away from " + pos + " to remember that it's " + block, true); - } - Block current = Baritone.get(pos).getBlock(); - if (!current.equals(block) || !loaded) { - //Out.gui("Block at " + pos + " has changed from " + block + " to " + current + ". Removing from memory.", true); - knownPositions.remove(pos); - if (loaded) { - scanBlock(pos);//rescan to put in proper memory - } - } - } - } - public void put(BlockPos pos) { - if (knownPositions.size() < 100) { - knownPositions.add(pos); - double dist = distSq(pos); - if (dist > furthest) { - furthest = dist; - return; - } - } - double dist = distSq(pos); - if (dist < furthest) { - knownPositions.add(pos); - knownPositions.remove(furthest()); - recalcFurthest(); - } - } - public BlockPos getOne() { - for (BlockPos pos : knownPositions) { - return pos; - } - return null; - } - public BlockPos closest() { - BlockPos best = null; - double dist = Double.MAX_VALUE; - for (BlockPos pos : knownPositions) { - if (!blockLoaded(pos)) { - continue; - } - if (!block.equals(Baritone.get(pos).getBlock())) { - continue; - } - double d = distSq(pos); - if (best == null || d < dist) { - dist = d; - best = pos; - } - } - return best; - } - public void recalcFurthest() { - double dist = Double.MIN_VALUE; - for (BlockPos pos : knownPositions) { - double d = distSq(pos); - if (d > dist) { - dist = d; - } - } - furthest = dist; - } - public BlockPos furthest() { - BlockPos best = null; - double dist = Double.MIN_VALUE; - for (BlockPos pos : knownPositions) { - double d = distSq(pos); - if (best == null || d > dist) { - dist = d; - best = pos; - } - } - return best; - } - } - public static double distSq(BlockPos pos) { - EntityPlayerSP player = Minecraft.getMinecraft().player; - double diffX = player.posX - (pos.getX() + 0.5D); - double diffY = (player.posY + 1.62) - (pos.getY() + 0.5D); - double diffZ = player.posZ - (pos.getZ() + 0.5D); - return diffX * diffX + diffY * diffY + diffZ * diffZ; - } - @Override - public void onTick() { - if (air == null) { - air = Blocks.AIR; - } - playersCurrentlyInRange.clear(); - for (EntityPlayer pl : Minecraft.getMinecraft().world.playerEntities) { - String blah = pl.getName().trim().toLowerCase(); - playerLocationMemory.put(blah, new BlockPos(pl.posX, pl.posY, pl.posZ)); - playersCurrentlyInRange.add(blah); - } - if (scanThread == null) { - scanThread = new Thread() { - @Override - public void run() { - try { - run1(); - } catch (Exception ex) { - Logger.getLogger(Memory.class.getName()).log(Level.SEVERE, null, ex); - } - scanThread = null; - } - public void run1() { - Out.gui("Starting passive block scan thread", Out.Mode.Debug); - try { - Thread.sleep(2000); - } catch (InterruptedException ex) { - Logger.getLogger(Memory.class.getName()).log(Level.SEVERE, null, ex); - return; - } - while (true) { - if (Minecraft.getMinecraft() != null && Minecraft.getMinecraft().player != null && Minecraft.getMinecraft().world != null) { - //Out.gui("Beginning passive block scan", true); - long start = System.currentTimeMillis(); - scan(); - long end = System.currentTimeMillis(); - //Out.gui("Passive block scan over after " + (end - start) + "ms", true); - } - try { - Thread.sleep(10000); - } catch (InterruptedException ex) { - Logger.getLogger(Memory.class.getName()).log(Level.SEVERE, null, ex); - return; - } - } - } - }; - scanThread.start(); - } - } - public static String findCommand(String block) { - String lower = block.toLowerCase(); - Out.log(lower); - BlockPos best = null; - double d = Double.MAX_VALUE; - for (Block type : blockMemory.keySet()) { - //Out.log("Considering " + type); - if (type.toString().toLowerCase().contains(lower)) { - BlockPos pos = blockMemory.get(type).closest(); - Out.log("find" + type + " " + pos); - if (pos != null) { - double dist = distSq(pos); - if (best == null || dist < d) { - d = dist; - best = pos; - } - } - } - } - if (best != null) { - return block + " at " + best; - } - return "none"; - } - public static BlockPos closestOne(String... block) { - /*BlockPos best = null; - double d = Double.MAX_VALUE; - for (Block type : blockMemory.keySet()) { - //Out.log("Considering " + type); - for (String b : block) { - String lower = "block{minecraft:" + b.toLowerCase() + "}"; - if (type.toString().toLowerCase().equals(lower)) { - BlockPos pos = blockMemory.get(type).closest(); - Out.log("closest" + type + " " + pos); - if (pos != null) { - double dist = distSq(pos); - if (best == null || dist < d) { - d = dist; - best = pos; - } - } - } - } - } - return best;*/ - ArrayList u = closest(1, block); - if (u.isEmpty()) { - return null; - } - return u.get(0); - } - public static ArrayList closest(int num, String... block) { - ArrayList result = new ArrayList(); - for (Block type : blockMemory.keySet()) { - //Out.log("Considering " + type); - for (String b : block) { - String lower = "block{minecraft:" + b.toLowerCase() + "}"; - if (type.toString().toLowerCase().equals(lower)) { - for (BlockPos pos : blockMemory.get(type).knownPositions) { - if (type.equals(Baritone.get(pos).getBlock()) && !result.contains(pos)) { - if (b.equals("stone")) { - if (!type.getItemDropped(Baritone.get(pos), new Random(), 0).equals(Item.getByNameOrId("cobblestone"))) { - continue; - } - } - result.add(pos); - } - } - } - } - } - result.sort(new Comparator() { - @Override - public int compare(BlockPos o1, BlockPos o2) { - return Double.compare(distSq(o1), distSq(o2)); - } - }); - return new ArrayList(result.subList(0, Math.min(num, result.size()))); - } - public static String findGoCommand(String block) { - String lower = block.toLowerCase(); - Out.log(lower); - BlockPos best = null; - double d = Double.MAX_VALUE; - for (Block type : blockMemory.keySet()) { - //Out.log("Considering " + type); - if (type.toString().toLowerCase().contains(lower)) { - BlockPos pos = blockMemory.get(type).closest(); - Out.log("findgo" + type + " " + pos); - if (pos != null) { - double dist = distSq(pos); - if (best == null || dist < d) { - d = dist; - best = pos; - } - } - } - } - if (best != null) { - goal = new GoalTwoBlocks(best); - Baritone.findPathInNewThread(true); - return "Pathing to " + goal + " " + block + " at " + best; - } - return "none"; - } - public static void scan() { - for (Block block : blockMemory.keySet()) { - blockMemory.get(block).checkForChange(); - } - for (Block block : blockMemory.keySet()) { - blockMemory.get(block).recalcFurthest(); - } - BlockPos playerFeet = Baritone.playerFeet; - int X = playerFeet.getX(); - int Y = playerFeet.getY(); - int Z = playerFeet.getZ(); - int ymin = Math.max(0, Y - 10); - int ymax = Math.min(Y + 10, 256); - for (int x = X; x >= X - SCAN_DIST && blockLoaded(new BlockPos(x, Y, Z)); x--) { - for (int z = Z; z >= Z - SCAN_DIST && blockLoaded(new BlockPos(x, Y, z)); z--) { - for (int y = ymin; y <= ymax; y++) { - scanBlock(new BlockPos(x, y, z)); - } - } - for (int z = Z; z <= Z + SCAN_DIST && blockLoaded(new BlockPos(x, Y, z)); z++) { - for (int y = ymin; y <= ymax; y++) { - scanBlock(new BlockPos(x, y, z)); - } - } - } - for (int x = X; x <= X + SCAN_DIST && blockLoaded(new BlockPos(x, Y, Z)); x++) { - for (int z = Z; z >= Z - SCAN_DIST && blockLoaded(new BlockPos(x, Y, z)); z--) { - for (int y = ymin; y <= ymax; y++) { - scanBlock(new BlockPos(x, y, z)); - } - } - for (int z = Z; z <= Z + SCAN_DIST && blockLoaded(new BlockPos(x, Y, z)); z++) { - for (int y = ymin; y <= ymax; y++) { - scanBlock(new BlockPos(x, y, z)); - } - } - } - } - public static final int SCAN_DIST = 50; - public static void scanBlock(BlockPos pos) { - Block block = Baritone.get(pos).getBlock(); - if (Blocks.AIR.equals(block)) { - return; - } - BlockMemory memory = getMemory(block); - memory.put(pos); - } - public static BlockMemory getMemory(Block block) { - BlockMemory cached = blockMemory.get(block); - if (cached != null) { - return cached; - } - BlockMemory n = new BlockMemory(block); - blockMemory.put(block, n); - return n; - } - public static boolean blockLoaded(BlockPos pos) { - return !(Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk); - } - public static String gotoCommand(String targetName) { - for (String name : playerLocationMemory.keySet()) { - if (name.contains(targetName) || targetName.contains(name)) { - Baritone.goal = new GoalBlock(playerLocationMemory.get(name)); - findPathInNewThread(Baritone.playerFeet, true); - return "Pathing to " + name + " at " + goal; - } - } - /* - for (EntityPlayer pl : Minecraft.getMinecraft().world.playerEntities) { - String blah = pl.getName().trim().toLowerCase(); - if (blah.contains(name) || name.contains(blah)) { - BlockPos pos = new BlockPos(pl.posX, pl.posY, pl.posZ); - goal = new GoalBlock(pos); - findPathInNewThread(Baritone.playerFeet, true); - return "Pathing to " + pl.getName() + " at " + goal; - } - }*/ - return "Couldn't find " + targetName; - } - public static String playerCommand(String targetName) { - String resp = ""; - for (EntityPlayer pl : Minecraft.getMinecraft().world.playerEntities) { - resp += "(" + pl.getName() + "," + pl.posX + "," + pl.posY + "," + pl.posZ + ")\n"; - if (pl.getName().equals(targetName)) { - BlockPos pos = new BlockPos(pl.posX, pl.posY, pl.posZ); - goal = new GoalBlock(pos); - return "Set goal to " + goal; - } - } - for (String x : resp.split("\n")) { - Out.gui(x, Out.Mode.Minimal); - } - if (targetName.equals("")) { - return ""; - } - return "Couldn't find " + targetName; - } -} diff --git a/src/main/resources/baritone/util/Out.java b/src/main/resources/baritone/util/Out.java deleted file mode 100644 index fb587d25..00000000 --- a/src/main/resources/baritone/util/Out.java +++ /dev/null @@ -1,123 +0,0 @@ -package baritone.util; - -import net.minecraft.client.Minecraft; -import net.minecraft.util.text.TextComponentString; - -/** - * This class serves the purpose of filtering what messages get send to the chat - * and the standard out. - * - * @author avecowa - */ -public class Out { - - /** - * Out has an Mode at all times. The Mode determines behavior of of the - * filter. - */ - public static enum Mode { - /** - * This mode signifies that NO messages should be sent to the chat. - */ - None, - /** - * This mode signifies that almost no messages should be sent to the - * chat. The exceptions are mainly outputs of chat commands.Background - * activities should not use this mode. - */ - Minimal, - /** - * This mode signifies that important messages should be sent to the - * chat. Rapidly repeating messages or long messages should not use this - * mode. Generally no more than 1 of these should be called within 4 - * seconds. The expectation is for the user to read everything that is - * of this mode. - */ - Standard, - /** - * This mode signifies that all messages should be sent to the chat. - * This mode should not exclude any messages Additionally, if this is - * set all messages will begin with a file trace: - * "baritone.pathing.Out:44\tMessage" - */ - Debug, - /** - * This is a dangerous game. All log writes will also be posted to the - * chat. Expect messages to fire at you at about 10 per tick. You may - * not survive. - */ - Ludicrous - } - public static Mode mode = Mode.Standard; - - /** - * Logs a message to the standard system output. Before writing it runs a - * stacktrace and appends the class and line number of the calling method to - * the front of the message. - * - * @see Out.Mode.Ludicrous - * @param o This is the object to be printed out. If this is not a String, - * o.toString() will be used. - */ - public static void log(Object o) { - String trace = trace(); - System.out.println(trace + '\t' + o.toString()); - if (mode == Mode.Ludicrous) { - chatRaw("§5[§dLog§5|§2" + trace + "§5]§f " + o.toString()); - } - } - - /** - * Prints a message to the client's chat GUI. Messages will not be displayed - * if their Mode is a lower importance than the set mode. - * - * @param o This is the object to be printed out. If this is not a String, - * o.toString() will be used. - * @param req This determines how the filter will treat the message. If a - * message is sent with a Mode.Debug requirement, it will only be printed if - * Out.mode is Debug or Ludicrous. Do not use a Mode.None or a - * Mode.Ludicrous in this parameter. - * @exception IllegalArgumentException This will only be triggered if a - * messages given with a req of PathNode or Ludicrous - */ - public static void gui(Object o, Mode req) throws IllegalArgumentException { - if (req.equals(Mode.None) || req.equals(Mode.Ludicrous)) { - throw new IllegalArgumentException("You cannot send messages of mode " + req); - } - if (o == null) { - return; - } - String message = o.toString(); - if (message.isEmpty()) { - return; - } - String trace = trace(); - System.out.println(trace + '\t' + message); - if (req.compareTo(mode) <= 0) { - if (Mode.Debug.compareTo(mode) <= 0) { - message = "§5[§dBaritone§5|§2" + trace() + "§5]§f " + message; - } else { - message = "§5[§dBaritone§5]§7 " + message; - } - chatRaw(message); - } - } - - private static void chatRaw(String s) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(s)); - } - - private static String trace() { - StackTraceElement[] stack = Thread.currentThread().getStackTrace(); - StackTraceElement trace = stack[3]; - boolean a = false; - for (int i = 3; i < stack.length; i++) { - StackTraceElement e = stack[i]; - if (!e.getClassName().equals(Out.class.getName())) { - trace = e; - break; - } - } - return trace.getClassName() + ":" + trace.getLineNumber(); - } -}