From 236d02cb47e25235e07380de4e35c8bed4b9a16f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 13 Apr 2019 08:36:14 -0700 Subject: [PATCH 01/18] add a way to pause builder --- src/main/java/baritone/process/BuilderProcess.java | 4 ++++ src/main/java/baritone/utils/ExampleBaritoneControl.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 4e4fc3df..4af6c800 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -89,6 +89,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro paused = false; } + public void pause() { + paused = true; + } + @Override public boolean build(String name, File schematic, Vec3i origin) { NBTTagCompound tag; diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 7b422ef2..f4261f07 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -358,6 +358,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("resumed"); return true; } + if (msg.equals("pause")) { + baritone.getBuilderProcess().pause(); + logDirect("paused"); + return true; + } if (msg.equals("reset")) { for (Settings.Setting setting : Baritone.settings().allSettings) { setting.reset(); From f7f003c0f982cf90cc1fee877a6a18f0b8c7399c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 13 Apr 2019 19:05:54 -0700 Subject: [PATCH 02/18] farm --- src/main/java/baritone/Baritone.java | 6 + .../movement/movements/MovementParkour.java | 4 +- .../java/baritone/process/FarmProcess.java | 121 ++++++++++++++++++ .../utils/ExampleBaritoneControl.java | 5 + 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/main/java/baritone/process/FarmProcess.java diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index f7a20b0f..33916d59 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -80,6 +80,7 @@ public class Baritone implements IBaritone { private CustomGoalProcess customGoalProcess; private BuilderProcess builderProcess; private ExploreProcess exploreProcess; + private FarmProcess farmProcess; private PathingControlManager pathingControlManager; @@ -120,6 +121,7 @@ public class Baritone implements IBaritone { getToBlockProcess = new GetToBlockProcess(this); builderProcess = new BuilderProcess(this); exploreProcess = new ExploreProcess(this); + farmProcess = new FarmProcess(this); } this.worldProvider = new WorldProvider(); @@ -197,6 +199,10 @@ public class Baritone implements IBaritone { return this.mineProcess; } + public FarmProcess getFarmProcess() { + return this.farmProcess; + } + @Override public PathingBehavior getPathingBehavior() { return this.pathingBehavior; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index ce5f77e9..fbf57e6c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -106,7 +106,9 @@ public class MovementParkour extends Movement { return; } } - if (MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i)) { + IBlockState landingOn = context.bsi.get0(x + xDiff * i, y - 1, z + zDiff * i); + // farmland needs to be canwalkon otherwise farm can never work at all, but we want to specifically disallow ending a jumy on farmland haha + if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i, landingOn)) { res.x = x + xDiff * i; res.y = y; res.z = z + zDiff * i; diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java new file mode 100644 index 00000000..9d27f953 --- /dev/null +++ b/src/main/java/baritone/process/FarmProcess.java @@ -0,0 +1,121 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.process; + +import baritone.Baritone; +import baritone.api.pathing.goals.Goal; +import baritone.api.pathing.goals.GoalBlock; +import baritone.api.pathing.goals.GoalComposite; +import baritone.api.process.PathingCommand; +import baritone.api.process.PathingCommandType; +import baritone.api.utils.Rotation; +import baritone.api.utils.RotationUtils; +import baritone.api.utils.input.Input; +import baritone.cache.WorldScanner; +import baritone.utils.BaritoneProcessHelper; +import net.minecraft.block.BlockAir; +import net.minecraft.block.BlockCrops; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +public class FarmProcess extends BaritoneProcessHelper { + + private boolean active; + + public FarmProcess(Baritone baritone) { + super(baritone); + } + + @Override + public boolean isActive() { + return active; + } + + public void doit() { + active = true; + } + + @Override + public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { + List memes = WorldScanner.INSTANCE.scanChunkRadius(ctx, Arrays.asList(Blocks.FARMLAND, Blocks.WHEAT), 256, 10, 4); + + List toBreak = new ArrayList<>(); + List toRightClickOnTop = new ArrayList<>(); + for (BlockPos pos : memes) { + IBlockState state = ctx.world().getBlockState(pos); + if (state.getBlock() == Blocks.FARMLAND) { + if (ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir) { + toRightClickOnTop.add(pos); + } + } else { + if (state.getValue(BlockCrops.AGE) == 7) { + toBreak.add(pos); + } + } + } + + baritone.getInputOverrideHandler().clearAllKeys(); + for (BlockPos pos : toBreak) { + Optional rot = RotationUtils.reachable(ctx, pos); + if (rot.isPresent()) { + baritone.getLookBehavior().updateTarget(rot.get(), true); + if (ctx.objectMouseOver() != null && ctx.objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK && ctx.objectMouseOver().getBlockPos().equals(pos)) { + baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true); + } + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } + } + for (BlockPos pos : toRightClickOnTop) { + Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance()); + if (rot.isPresent()) { + baritone.getLookBehavior().updateTarget(rot.get(), true); + if (ctx.objectMouseOver() != null && ctx.objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK && ctx.objectMouseOver().getBlockPos().equals(pos)) { + baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); + } + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } + } + + List goalz = new ArrayList<>(); + for (BlockPos pos : toBreak) { + goalz.add(new GoalBlock(pos)); + } + for (BlockPos pos : toRightClickOnTop) { + goalz.add(new GoalBlock(pos.up())); + } + return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH); + } + + @Override + public void onLostControl() { + active = false; + } + + @Override + public String displayName0() { + return "Farming"; + } +} diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index f4261f07..4a819d74 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -382,6 +382,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("okay"); return true; } + if (msg.equals("farm")) { + baritone.getFarmProcess().doit(); + logDirect("farming"); + return true; + } if (msg.equals("echest")) { Optional> contents = baritone.getMemoryBehavior().echest(); if (contents.isPresent()) { From 3333797144f4e3150b6e93387c3236bb2c5aee3e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 14 Apr 2019 10:06:37 -0700 Subject: [PATCH 03/18] fix region pruning --- src/api/java/baritone/api/Settings.java | 6 ++++-- src/main/java/baritone/cache/CachedWorld.java | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index b61656a9..1de894dc 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -401,10 +401,12 @@ public final class Settings { * On save, delete from RAM any cached regions that are more than 1024 blocks away from the player *

* Temporarily disabled + *

+ * Temporarily reenabled * * @see Issue #248 */ - public final Setting pruneRegionsFromRAM = new Setting<>(false); + public final Setting pruneRegionsFromRAM = new Setting<>(true); /** * Remember the contents of containers (chests, echests, furnaces) @@ -575,7 +577,7 @@ public final class Settings { /** * How far to move before repeating the build. -1 for the size of the build in that axis. 0 to disable */ - public final Setting buildRepeatDistance=new Setting<>(0); + public final Setting buildRepeatDistance = new Setting<>(0); /** * What direction te repeat the build in diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index c025d489..949f818c 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -180,8 +180,8 @@ public final class CachedWorld implements ICachedWorld, Helper { if (region == null) { continue; } - int distX = (region.getX() << 9 + 256) - pruneCenter.getX(); - int distZ = (region.getZ() << 9 + 256) - pruneCenter.getZ(); + int distX = ((region.getX() << 9) + 256) - pruneCenter.getX(); + int distZ = ((region.getZ() << 9) + 256) - pruneCenter.getZ(); double dist = Math.sqrt(distX * distX + distZ * distZ); if (dist > 1024) { logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram"); @@ -216,7 +216,7 @@ public final class CachedWorld implements ICachedWorld, Helper { if (mostRecentlyModified == null) { return new BlockPos(0, 0, 0); } - return new BlockPos(mostRecentlyModified.x << 4 + 8, 0, mostRecentlyModified.z << 4 + 8); + return new BlockPos((mostRecentlyModified.x << 4) + 8, 0, (mostRecentlyModified.z << 4) + 8); } private synchronized List allRegions() { From e0a618a791a63b4fe945446bec2edf4c2808ad7f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 15 Apr 2019 17:12:20 -0700 Subject: [PATCH 04/18] epic farm --- src/api/java/baritone/api/Settings.java | 5 +- .../baritone/api/utils/IPlayerContext.java | 14 +- .../movement/movements/MovementFall.java | 4 +- .../baritone/pathing/path/PathExecutor.java | 5 +- .../java/baritone/process/BuilderProcess.java | 4 +- .../java/baritone/process/FarmProcess.java | 200 ++++++++++++++++-- 6 files changed, 201 insertions(+), 31 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index b61656a9..fbf0baef 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -142,7 +142,8 @@ public final class Settings { public final Setting> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList( Item.getItemFromBlock(Blocks.DIRT), Item.getItemFromBlock(Blocks.COBBLESTONE), - Item.getItemFromBlock(Blocks.NETHERRACK) + Item.getItemFromBlock(Blocks.NETHERRACK), + Item.getItemFromBlock(Blocks.STONE) ))); /** @@ -575,7 +576,7 @@ public final class Settings { /** * How far to move before repeating the build. -1 for the size of the build in that axis. 0 to disable */ - public final Setting buildRepeatDistance=new Setting<>(0); + public final Setting buildRepeatDistance = new Setting<>(0); /** * What direction te repeat the build in diff --git a/src/api/java/baritone/api/utils/IPlayerContext.java b/src/api/java/baritone/api/utils/IPlayerContext.java index 83040ab5..9acb2ad9 100644 --- a/src/api/java/baritone/api/utils/IPlayerContext.java +++ b/src/api/java/baritone/api/utils/IPlayerContext.java @@ -71,20 +71,26 @@ public interface IPlayerContext { * @return The position of the highlighted block */ default Optional getSelectedBlock() { - if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK) { - return Optional.of(objectMouseOver().getBlockPos()); + RayTraceResult result = objectMouseOver(); + if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { + return Optional.of(result.getBlockPos()); } return Optional.empty(); } + default boolean isLookingAt(BlockPos pos) { + return getSelectedBlock().equals(Optional.of(pos)); + } + /** * Returns the entity that the crosshair is currently placed over. Updated once per tick. * * @return The entity */ default Optional getSelectedEntity() { - if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.ENTITY) { - return Optional.of(objectMouseOver().entityHit); + RayTraceResult result = objectMouseOver(); + if (result != null && result.typeOfHit == RayTraceResult.Type.ENTITY) { + return Optional.of(result.entityHit); } return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 93f60f5d..0a4c38c7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -39,7 +39,6 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; @@ -92,8 +91,7 @@ public class MovementFall extends Movement { targetRotation = new Rotation(toDest.getYaw(), 90.0F); - RayTraceResult trace = ctx.objectMouseOver(); - if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK && (trace.getBlockPos().equals(dest) || trace.getBlockPos().equals(dest.down()))) { + if (ctx.isLookingAt(dest) || ctx.isLookingAt(dest.down())) { state.setInput(Input.CLICK_RIGHT, true); } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 6ddcda0f..3e767499 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -441,7 +441,10 @@ public class PathExecutor implements IPathExecutor, Helper { IMovement prev = path.movements().get(pathPosition - 1); if (prev instanceof MovementDescend && prev.getDirection().up().equals(current.getDirection().down())) { BlockPos center = current.getSrc().up(); - if (ctx.player().posY >= center.getY()) { // playerFeet adds 0.1251 to account for soul sand + // playerFeet adds 0.1251 to account for soul sand + // farmland is 0.9375 + // 0.07 is to account for farmland + if (ctx.player().posY >= center.getY() - 0.07) { behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false); return true; } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 4af6c800..982e22ce 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -362,7 +362,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro // and is unable since it's unsneaked in the intermediary tick baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true); } - if (Objects.equals(ctx.objectMouseOver().getBlockPos(), pos) || ctx.playerRotations().isReallyCloseTo(rot)) { + if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) { baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true); } return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); @@ -374,7 +374,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro baritone.getLookBehavior().updateTarget(rot, true); ctx.player().inventory.currentItem = toPlace.get().hotbarSelection; baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true); - if ((Objects.equals(ctx.objectMouseOver().getBlockPos(), toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) { + if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) { baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); } return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index 9d27f953..0e2fdaae 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -27,24 +27,60 @@ import baritone.api.utils.Rotation; import baritone.api.utils.RotationUtils; import baritone.api.utils.input.Input; import baritone.cache.WorldScanner; +import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; -import net.minecraft.block.BlockAir; -import net.minecraft.block.BlockCrops; +import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.Item; +import net.minecraft.item.ItemDye; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.function.Predicate; public class FarmProcess extends BaritoneProcessHelper { private boolean active; + private static final List FARMLAND_PLANTABLE = Arrays.asList( + Items.BEETROOT_SEEDS, + Items.MELON_SEEDS, + Items.WHEAT_SEEDS, + Items.PUMPKIN_SEEDS, + Items.POTATO, + Items.CARROT + ); + + private static final List PICKUP_DROPPED = Arrays.asList( + Items.BEETROOT_SEEDS, + Items.WHEAT, + Items.MELON_SEEDS, + Items.MELON, + Items.WHEAT_SEEDS, + Items.WHEAT, + Items.PUMPKIN_SEEDS, + Items.POTATO, + Items.CARROT, + Items.BEETROOT, + Item.getItemFromBlock(Blocks.PUMPKIN), + Item.getItemFromBlock(Blocks.MELON_BLOCK), + Items.NETHER_WART, + Items.REEDS, + Item.getItemFromBlock(Blocks.CACTUS) + ); + public FarmProcess(Baritone baritone) { super(baritone); } @@ -58,21 +94,115 @@ public class FarmProcess extends BaritoneProcessHelper { active = true; } + private enum Harvest { + WHEAT((BlockCrops) Blocks.WHEAT), + CARROTS((BlockCrops) Blocks.CARROTS), + POTATOES((BlockCrops) Blocks.POTATOES), + BEETROOT((BlockCrops) Blocks.BEETROOTS), + PUMPKIN(Blocks.PUMPKIN, state -> true), + MELON(Blocks.MELON_BLOCK, state -> true), + NETHERWART(Blocks.NETHER_WART, state -> state.getValue(BlockNetherWart.AGE) >= 3), + SUGARCANE(Blocks.REEDS, null) { + @Override + public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) { + return world.getBlockState(pos.down()).getBlock() instanceof BlockReed; + } + }, + CACTUS(Blocks.CACTUS, null) { + @Override + public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) { + return world.getBlockState(pos.down()).getBlock() instanceof BlockCactus; + } + }; + public final Block block; + public final Predicate readyToHarvest; + + Harvest(BlockCrops blockCrops) { + this(blockCrops, blockCrops::isMaxAge); + // max age is 7 for wheat, carrots, and potatoes, but 3 for beetroot + } + + Harvest(Block block, Predicate readyToHarvest) { + this.block = block; + this.readyToHarvest = readyToHarvest; + } + + public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) { + return readyToHarvest.test(state); + } + } + + private boolean readyForHarvest(World world, BlockPos pos, IBlockState state) { + for (Harvest harvest : Harvest.values()) { + if (harvest.block == state.getBlock()) { + return harvest.readyToHarvest(world, pos, state); + } + } + return false; + } + + private boolean selectFarmlandPlantable(boolean doSelect) {//EnumDyeColor.WHITE == EnumDyeColor.byDyeDamage(stack.getMetadata()) + NonNullList invy = ctx.player().inventory.mainInventory; + for (int i = 0; i < 9; i++) { + if (FARMLAND_PLANTABLE.contains(invy.get(i).getItem())) { + if (doSelect) { + ctx.player().inventory.currentItem = i; + } + return true; + } + } + return false; + } + + private boolean selectBoneMeal(boolean doSelect) { + if (isBoneMeal(ctx.player().inventory.offHandInventory.get(0))) { + return true; + } + NonNullList invy = ctx.player().inventory.mainInventory; + for (int i = 0; i < 9; i++) { + if (isBoneMeal(invy.get(i))) { + if (doSelect) { + ctx.player().inventory.currentItem = i; + } + return true; + } + } + return false; + } + + private boolean isBoneMeal(ItemStack stack) { + return !stack.isEmpty() && stack.getItem() instanceof ItemDye && EnumDyeColor.byDyeDamage(stack.getMetadata()) == EnumDyeColor.WHITE; + } + @Override public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { - List memes = WorldScanner.INSTANCE.scanChunkRadius(ctx, Arrays.asList(Blocks.FARMLAND, Blocks.WHEAT), 256, 10, 4); + ArrayList scan = new ArrayList<>(); + for (Harvest harvest : Harvest.values()) { + scan.add(harvest.block); + } + scan.add(Blocks.FARMLAND); + + List locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 4); List toBreak = new ArrayList<>(); - List toRightClickOnTop = new ArrayList<>(); - for (BlockPos pos : memes) { + List openFarmland = new ArrayList<>(); + List bonemealable = new ArrayList<>(); + for (BlockPos pos : locations) { IBlockState state = ctx.world().getBlockState(pos); if (state.getBlock() == Blocks.FARMLAND) { if (ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir) { - toRightClickOnTop.add(pos); + openFarmland.add(pos); } - } else { - if (state.getValue(BlockCrops.AGE) == 7) { - toBreak.add(pos); + continue; + } + if (readyForHarvest(ctx.world(), pos, state)) { + toBreak.add(pos); + continue; + } + if (state.getBlock() instanceof IGrowable) { + IGrowable ig = (IGrowable) state.getBlock(); + if (ig.canGrow(ctx.world(), pos, state, true) && ig.canUseBonemeal(ctx.world(), ctx.world().rand, pos, state)) { + bonemealable.add(pos); } } } @@ -80,31 +210,63 @@ public class FarmProcess extends BaritoneProcessHelper { baritone.getInputOverrideHandler().clearAllKeys(); for (BlockPos pos : toBreak) { Optional rot = RotationUtils.reachable(ctx, pos); - if (rot.isPresent()) { + if (rot.isPresent() && isSafeToCancel) { baritone.getLookBehavior().updateTarget(rot.get(), true); - if (ctx.objectMouseOver() != null && ctx.objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK && ctx.objectMouseOver().getBlockPos().equals(pos)) { + MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos)); + if (ctx.isLookingAt(pos)) { baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true); } return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } } - for (BlockPos pos : toRightClickOnTop) { - Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance()); - if (rot.isPresent()) { + for (BlockPos pos : openFarmland) { + Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance()); + if (rot.isPresent() && isSafeToCancel && selectFarmlandPlantable(true)) { baritone.getLookBehavior().updateTarget(rot.get(), true); - if (ctx.objectMouseOver() != null && ctx.objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK && ctx.objectMouseOver().getBlockPos().equals(pos)) { + if (ctx.isLookingAt(pos)) { + baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); + } + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } + } + for (BlockPos pos : bonemealable) { + Optional rot = RotationUtils.reachable(ctx, pos); + if (rot.isPresent() && isSafeToCancel && selectBoneMeal(true)) { + baritone.getLookBehavior().updateTarget(rot.get(), true); + if (ctx.isLookingAt(pos)) { baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); } return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } } + if (calcFailed) { + logDirect("Farm failed"); + onLostControl(); + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } + List goalz = new ArrayList<>(); for (BlockPos pos : toBreak) { - goalz.add(new GoalBlock(pos)); + goalz.add(new BuilderProcess.GoalBreak(pos)); } - for (BlockPos pos : toRightClickOnTop) { - goalz.add(new GoalBlock(pos.up())); + if (selectFarmlandPlantable(false)) { + for (BlockPos pos : openFarmland) { + goalz.add(new GoalBlock(pos.up())); + } + } + if (selectBoneMeal(false)) { + for (BlockPos pos : bonemealable) { + goalz.add(new GoalBlock(pos)); + } + } + for (Entity entity : ctx.world().loadedEntityList) { + if (entity instanceof EntityItem && entity.onGround) { + EntityItem ei = (EntityItem) entity; + if (PICKUP_DROPPED.contains(ei.getItem().getItem())) { + goalz.add(new GoalBlock(new BlockPos(entity.posX, entity.posY + 0.1, entity.posZ))); + } + } } return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH); } From 96414b37f3994c245f9548a8e7b217cb2db8c7d3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 15 Apr 2019 18:14:20 -0700 Subject: [PATCH 05/18] whoops this was fixed monthhs ago --- USAGE.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/USAGE.md b/USAGE.md index 22460378..085f49c2 100644 --- a/USAGE.md +++ b/USAGE.md @@ -63,9 +63,6 @@ There are about a hundred settings, but here are some fun / interesting / import # Troubleshooting / common issues -## Baritone highlights a block in green but gets completely stuck? Also I'm using Baritone with Future? -Baritone is trying to right click to place a block there, but it can't since there's a conflicting mixin. Baritone can't force click right click when Future is also installed. Left click **does work** on recent Baritone even with Future, however. For now, turn off `allowPlace` and Baritone will only search for paths that don't require placing blocks to complete. `allowBreak` can remain on. - ## Why doesn't Baritone respond to any of my chat commands? This could be one of many things. From f49df63183423ae5ba8e707fc3623e851f6df79d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 16 Apr 2019 10:20:23 -0700 Subject: [PATCH 06/18] that can never be null --- src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index a7d104cf..588b773e 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -186,7 +186,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper { } protected Optional bestSoFar(boolean logInfo, int numNodes) { - if (startNode == null || bestSoFar == null) { + if (startNode == null) { return Optional.empty(); } double bestDist = 0; From a1a9b4e6b915d0143b7a11984f846c5becf293d4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 16 Apr 2019 10:25:32 -0700 Subject: [PATCH 07/18] allow spaces --- src/api/java/baritone/api/utils/SettingsUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index ae97ad7b..60014bbd 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -147,12 +147,11 @@ public class SettingsUtil { FLOAT(Float.class, Float::parseFloat), LONG(Long.class, Long::parseLong), - ITEM_LIST(ArrayList.class, str -> Stream.of(str.split(",")).map(Item::getByNameOrId).collect(Collectors.toCollection(ArrayList::new)), list -> ((ArrayList) list).stream().map(Item.REGISTRY::getNameForObject).map(ResourceLocation::toString).collect(Collectors.joining(","))), + ITEM_LIST(ArrayList.class, str -> Stream.of(str.split(",")).map(String::trim).map(Item::getByNameOrId).collect(Collectors.toCollection(ArrayList::new)), list -> ((ArrayList) list).stream().map(Item.REGISTRY::getNameForObject).map(ResourceLocation::toString).collect(Collectors.joining(","))), COLOR(Color.class, str -> new Color(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])), color -> color.getRed() + "," + color.getGreen() + "," + color.getBlue()), ENUMFACING(EnumFacing.class, EnumFacing::byName); - Class klass; Function parser; Function toString; From c136182e176056feb8fbb0d82badfbfcd01cb6da Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 16 Apr 2019 18:04:43 -0700 Subject: [PATCH 08/18] add option to manually blacklist closest --- .../java/baritone/process/GetToBlockProcess.java | 3 ++- .../baritone/utils/ExampleBaritoneControl.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 2dbefd50..0116df83 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -117,7 +117,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } // blacklist the closest block and its adjacent blocks - public synchronized void blacklistClosest() { + public synchronized boolean blacklistClosest() { List newBlacklist = new ArrayList<>(); knownLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(newBlacklist::add); outer: @@ -140,6 +140,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } logDebug("Blacklisting unreachable locations " + newBlacklist); blacklist.addAll(newBlacklist); + return !newBlacklist.isEmpty(); } // safer than direct double comparison from distanceSq diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 4a819d74..0f80ea54 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -35,6 +35,7 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.Moves; import baritone.process.CustomGoalProcess; +import baritone.process.GetToBlockProcess; import baritone.utils.pathing.SegmentedCalculator; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -466,6 +467,19 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Exploring from " + centerX + "," + centerZ); return true; } + if (msg.equals("blacklist")) { + GetToBlockProcess proc = baritone.getGetToBlockProcess(); + if (!proc.isActive()) { + logDirect("GetToBlockProcess is not currently active"); + return true; + } + if (proc.blacklistClosest()) { + logDirect("Blacklisted closest instances"); + } else { + logDirect("No known locations, unable to blacklist"); + } + return true; + } if (msg.startsWith("find")) { String blockType = msg.substring(4).trim(); ArrayList locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4); From 44d757347bb8e4d3aa5905173c04df082bd16863 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 16 Apr 2019 22:43:33 -0700 Subject: [PATCH 09/18] fix unable to move while paused --- src/main/java/baritone/process/BuilderProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 982e22ce..286f8cf8 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -296,7 +296,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro } baritone.getInputOverrideHandler().clearAllKeys(); if (paused) { - return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); } if (Baritone.settings().buildInLayers.value) { if (realSchematic == null) { From fe51220e3c9fd9431e0f2f121bb5b434b89d5024 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 16 Apr 2019 23:19:55 -0700 Subject: [PATCH 10/18] this might help --- src/main/java/baritone/process/BuilderProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 286f8cf8..2550f84d 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -365,7 +365,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) { baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true); } - return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); } List desirableOnHotbar = new ArrayList<>(); Optional toPlace = searchForPlacables(bcc, desirableOnHotbar); @@ -377,7 +377,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) { baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); } - return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL); } List approxPlacable = placable(36); From c013d1e0d91206c4560956b50fcd0c7f77f37a83 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 18:10:47 -0700 Subject: [PATCH 11/18] fix various toxic clouds --- src/api/java/baritone/api/IBaritone.java | 14 ++ .../api/behavior/IPathingBehavior.java | 7 + .../java/baritone/api/cache/ICachedWorld.java | 2 + .../java/baritone/api}/cache/Waypoint.java | 5 +- .../baritone/api/process/IBuilderProcess.java | 13 ++ .../baritone/api/process/IExploreProcess.java | 22 +++ .../baritone/api/process/IFarmProcess.java | 22 +++ .../api/process/IGetToBlockProcess.java | 2 + .../java/baritone/api/utils/BlockUtils.java | 63 ++++++++ .../api}/utils/ExampleBaritoneControl.java | 137 ++++++++---------- .../java/baritone/api}/utils/Helper.java | 8 +- src/main/java/baritone/Baritone.java | 21 +-- .../baritone/behavior/MemoryBehavior.java | 2 +- .../baritone/behavior/PathingBehavior.java | 9 +- src/main/java/baritone/cache/CachedChunk.java | 3 +- .../java/baritone/cache/CachedRegion.java | 7 +- src/main/java/baritone/cache/CachedWorld.java | 2 +- src/main/java/baritone/cache/ChunkPacker.java | 25 +--- .../baritone/cache/WaypointCollection.java | 1 + .../java/baritone/cache/WorldProvider.java | 2 +- .../java/baritone/event/GameEventHandler.java | 2 +- .../pathing/calc/AbstractNodeCostSearch.java | 2 +- src/main/java/baritone/pathing/calc/Path.java | 2 +- .../pathing/movement/MovementHelper.java | 2 +- .../baritone/pathing/path/PathExecutor.java | 2 +- .../java/baritone/process/BuilderProcess.java | 6 - .../java/baritone/process/ExploreProcess.java | 4 +- .../java/baritone/process/FarmProcess.java | 6 +- .../java/baritone/process/MineProcess.java | 5 +- .../java/baritone/utils/BaritoneAutoTest.java | 1 + .../baritone/utils/BaritoneProcessHelper.java | 1 + .../java/baritone/utils/BlockBreakHelper.java | 1 + .../java/baritone/utils/BlockPlaceHelper.java | 1 + .../java/baritone/utils/PathRenderer.java | 1 + .../utils/player/PrimaryPlayerContext.java | 2 +- .../utils/player/PrimaryPlayerController.java | 2 +- 36 files changed, 262 insertions(+), 145 deletions(-) rename src/{main/java/baritone => api/java/baritone/api}/cache/Waypoint.java (94%) create mode 100644 src/api/java/baritone/api/process/IExploreProcess.java create mode 100644 src/api/java/baritone/api/process/IFarmProcess.java create mode 100644 src/api/java/baritone/api/utils/BlockUtils.java rename src/{main/java/baritone => api/java/baritone/api}/utils/ExampleBaritoneControl.java (85%) rename src/{main/java/baritone => api/java/baritone/api}/utils/Helper.java (93%) diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index a12b206d..a356922c 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -71,6 +71,18 @@ public interface IBaritone { */ IBuilderProcess getBuilderProcess(); + /** + * @return The {@link IExploreProcess} instance + * @see IExploreProcess + */ + IExploreProcess getExploreProcess(); + + /** + * @return The {@link IFarmProcess} instance + * @see IFarmProcess + */ + IFarmProcess getFarmProcess(); + /** * @return The {@link ICustomGoalProcess} instance * @see ICustomGoalProcess @@ -115,4 +127,6 @@ public interface IBaritone { * @see IEventBus */ IEventBus getGameEventHandler(); + + void openClick(); } diff --git a/src/api/java/baritone/api/behavior/IPathingBehavior.java b/src/api/java/baritone/api/behavior/IPathingBehavior.java index 64be71d5..15777448 100644 --- a/src/api/java/baritone/api/behavior/IPathingBehavior.java +++ b/src/api/java/baritone/api/behavior/IPathingBehavior.java @@ -80,6 +80,13 @@ public interface IPathingBehavior extends IBehavior { */ boolean cancelEverything(); + /** + * PLEASE never call this + *

+ * If cancelEverything was like "kill" this is "sudo kill -9". Or shutting off your computer. + */ + void forceCancel(); + /** * Returns the current path, from the current path executor, if there is one. * diff --git a/src/api/java/baritone/api/cache/ICachedWorld.java b/src/api/java/baritone/api/cache/ICachedWorld.java index e681ce51..837ae076 100644 --- a/src/api/java/baritone/api/cache/ICachedWorld.java +++ b/src/api/java/baritone/api/cache/ICachedWorld.java @@ -81,4 +81,6 @@ public interface ICachedWorld { * in a new thread by default. */ void save(); + + } diff --git a/src/main/java/baritone/cache/Waypoint.java b/src/api/java/baritone/api/cache/Waypoint.java similarity index 94% rename from src/main/java/baritone/cache/Waypoint.java rename to src/api/java/baritone/api/cache/Waypoint.java index 19e574f9..2b9a7232 100644 --- a/src/main/java/baritone/cache/Waypoint.java +++ b/src/api/java/baritone/api/cache/Waypoint.java @@ -15,9 +15,8 @@ * along with Baritone. If not, see . */ -package baritone.cache; +package baritone.api.cache; -import baritone.api.cache.IWaypoint; import net.minecraft.util.math.BlockPos; import java.util.Date; @@ -47,7 +46,7 @@ public class Waypoint implements IWaypoint { * @param location The waypoint location * @param creationTimestamp When the waypoint was created */ - Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) { + public Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) { this.name = name; this.tag = tag; this.location = location; diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java index 694c8752..d9397786 100644 --- a/src/api/java/baritone/api/process/IBuilderProcess.java +++ b/src/api/java/baritone/api/process/IBuilderProcess.java @@ -18,6 +18,8 @@ package baritone.api.process; import baritone.api.utils.ISchematic; +import net.minecraft.client.Minecraft; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3i; import java.io.File; @@ -46,4 +48,15 @@ public interface IBuilderProcess extends IBaritoneProcess { * @return Whether or not the schematic was able to load from file */ boolean build(String name, File schematic, Vec3i origin); + + default boolean build(String schematicFile, BlockPos origin) { + File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile); + return build(schematicFile, file, origin); + } + + void pause(); + + void resume(); + + void clearArea(BlockPos corner1, BlockPos corner2); } diff --git a/src/api/java/baritone/api/process/IExploreProcess.java b/src/api/java/baritone/api/process/IExploreProcess.java new file mode 100644 index 00000000..bf30fa22 --- /dev/null +++ b/src/api/java/baritone/api/process/IExploreProcess.java @@ -0,0 +1,22 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.process; + +public interface IExploreProcess extends IBaritoneProcess { + void explore(int centerX, int centerZ); +} diff --git a/src/api/java/baritone/api/process/IFarmProcess.java b/src/api/java/baritone/api/process/IFarmProcess.java new file mode 100644 index 00000000..c9234a24 --- /dev/null +++ b/src/api/java/baritone/api/process/IFarmProcess.java @@ -0,0 +1,22 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.process; + +public interface IFarmProcess extends IBaritoneProcess { + void farm(); +} diff --git a/src/api/java/baritone/api/process/IGetToBlockProcess.java b/src/api/java/baritone/api/process/IGetToBlockProcess.java index ff3dc9b5..a5a35577 100644 --- a/src/api/java/baritone/api/process/IGetToBlockProcess.java +++ b/src/api/java/baritone/api/process/IGetToBlockProcess.java @@ -25,4 +25,6 @@ import net.minecraft.block.Block; public interface IGetToBlockProcess extends IBaritoneProcess { void getToBlock(Block block); + + boolean blacklistClosest(); } diff --git a/src/api/java/baritone/api/utils/BlockUtils.java b/src/api/java/baritone/api/utils/BlockUtils.java new file mode 100644 index 00000000..a7e00608 --- /dev/null +++ b/src/api/java/baritone/api/utils/BlockUtils.java @@ -0,0 +1,63 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.api.utils; + +import net.minecraft.block.Block; +import net.minecraft.util.ResourceLocation; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class BlockUtils { + private static transient Map resourceCache = new HashMap<>(); + + public static String blockToString(Block block) { + ResourceLocation loc = Block.REGISTRY.getNameForObject(block); + String name = loc.getPath(); // normally, only write the part after the minecraft: + if (!loc.getNamespace().equals("minecraft")) { + // Baritone is running on top of forge with mods installed, perhaps? + name = loc.toString(); // include the namespace with the colon + } + return name; + } + + public static Block stringToBlockRequired(String name) { + Block block = stringToBlockNullable(name); + Objects.requireNonNull(block); + return block; + } + + public static Block stringToBlockNullable(String name) { + // do NOT just replace this with a computeWithAbsent, it isn't thread safe + Block block = resourceCache.get(name); // map is never mutated in place so this is safe + if (block != null) { + return block; + } + if (resourceCache.containsKey(name)) { + return null; // cached as null + } + block = Block.getBlockFromName(name.contains(":") ? name : "minecraft:" + name); + Map copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification + copy.put(name, block); + resourceCache = copy; + return block; + } + + private BlockUtils() {} +} diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java similarity index 85% rename from src/main/java/baritone/utils/ExampleBaritoneControl.java rename to src/api/java/baritone/api/utils/ExampleBaritoneControl.java index 0f80ea54..f758d15e 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java @@ -15,28 +15,21 @@ * along with Baritone. If not, see . */ -package baritone.utils; +package baritone.api.utils; -import baritone.Baritone; +import baritone.api.BaritoneAPI; +import baritone.api.IBaritone; import baritone.api.Settings; +import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IRememberedInventory; import baritone.api.cache.IWaypoint; +import baritone.api.cache.Waypoint; import baritone.api.event.events.ChatEvent; +import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.pathing.goals.*; -import baritone.api.pathing.movement.ActionCosts; import baritone.api.process.IBaritoneProcess; -import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.SettingsUtil; -import baritone.behavior.Behavior; -import baritone.behavior.PathingBehavior; -import baritone.cache.ChunkPacker; -import baritone.cache.Waypoint; -import baritone.pathing.movement.CalculationContext; -import baritone.pathing.movement.Movement; -import baritone.pathing.movement.Moves; -import baritone.process.CustomGoalProcess; -import baritone.process.GetToBlockProcess; -import baritone.utils.pathing.SegmentedCalculator; +import baritone.api.process.ICustomGoalProcess; +import baritone.api.process.IGetToBlockProcess; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ChunkProviderClient; @@ -47,10 +40,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.Chunk; import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; -public class ExampleBaritoneControl extends Behavior implements Helper { +public class ExampleBaritoneControl implements Helper, AbstractGameEventListener { private static final String HELP_MSG = "baritone - Output settings into chat\n" + @@ -84,21 +75,26 @@ public class ExampleBaritoneControl extends Behavior implements Helper { private static final String COMMAND_PREFIX = "#"; - public ExampleBaritoneControl(Baritone baritone) { - super(baritone); + public final IBaritone baritone; + public final IPlayerContext ctx; + + public ExampleBaritoneControl(IBaritone baritone) { + this.baritone = baritone; + this.ctx = baritone.getPlayerContext(); + baritone.getGameEventHandler().registerEventListener(this); } @Override public void onSendChatMessage(ChatEvent event) { String msg = event.getMessage(); - if (Baritone.settings().prefixControl.value && msg.startsWith(COMMAND_PREFIX)) { + if (BaritoneAPI.getSettings().prefixControl.value && msg.startsWith(COMMAND_PREFIX)) { if (!runCommand(msg.substring(COMMAND_PREFIX.length()))) { logDirect("Invalid command"); } event.cancel(); // always cancel if using prefixControl return; } - if (!Baritone.settings().chatControl.value && !Baritone.settings().removePrefix.value) { + if (!BaritoneAPI.getSettings().chatControl.value && !BaritoneAPI.getSettings().removePrefix.value) { return; } if (runCommand(msg)) { @@ -108,20 +104,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper { public boolean runCommand(String msg0) { // you may think this can be private, but impcat calls it from .b =) String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL - PathingBehavior pathingBehavior = baritone.getPathingBehavior(); - CustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); - List> toggleable = Baritone.settings().getAllValuesByType(Boolean.class); + IPathingBehavior pathingBehavior = baritone.getPathingBehavior(); + ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); + List> toggleable = BaritoneAPI.getSettings().getAllValuesByType(Boolean.class); for (Settings.Setting setting : toggleable) { if (msg.equalsIgnoreCase(setting.getName())) { setting.value ^= true; logDirect("Toggled " + setting.getName() + " to " + setting.value); - SettingsUtil.save(Baritone.settings()); + SettingsUtil.save(BaritoneAPI.getSettings()); return true; } } if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) { logDirect("All settings that have been modified from their default values:"); - for (Settings.Setting setting : SettingsUtil.modifiedSettings(Baritone.settings())) { + for (Settings.Setting setting : SettingsUtil.modifiedSettings(BaritoneAPI.getSettings())) { logDirect(setting.toString()); } return true; @@ -131,15 +127,15 @@ public class ExampleBaritoneControl extends Behavior implements Helper { try { int page = Integer.parseInt(rest.trim()); int min = page * 10; - int max = Math.min(Baritone.settings().allSettings.size(), (page + 1) * 10); + int max = Math.min(BaritoneAPI.getSettings().allSettings.size(), (page + 1) * 10); logDirect("Settings " + min + " to " + (max - 1) + ":"); for (int i = min; i < max; i++) { - logDirect(Baritone.settings().allSettings.get(i).toString()); + logDirect(BaritoneAPI.getSettings().allSettings.get(i).toString()); } } catch (Exception ex) { // NumberFormatException | ArrayIndexOutOfBoundsException and probably some others I'm forgetting lol ex.printStackTrace(); logDirect("All settings:"); - for (Settings.Setting setting : Baritone.settings().allSettings) { + for (Settings.Setting setting : BaritoneAPI.getSettings().allSettings) { logDirect(setting.toString()); } logDirect("To get one page of ten settings at a time, do settings "); @@ -155,26 +151,26 @@ public class ExampleBaritoneControl extends Behavior implements Helper { if (msg.contains(" ")) { String settingName = msg.substring(0, msg.indexOf(' ')); String settingValue = msg.substring(msg.indexOf(' ') + 1); - Settings.Setting setting = Baritone.settings().byLowerName.get(settingName); + Settings.Setting setting = BaritoneAPI.getSettings().byLowerName.get(settingName); if (setting != null) { if (settingValue.equals("reset")) { logDirect("Resetting setting " + settingName + " to default value."); setting.reset(); } else { try { - SettingsUtil.parseAndApply(Baritone.settings(), settingName, settingValue); + SettingsUtil.parseAndApply(BaritoneAPI.getSettings(), settingName, settingValue); } catch (Exception ex) { logDirect("Unable to parse setting"); return true; } } - SettingsUtil.save(Baritone.settings()); + SettingsUtil.save(BaritoneAPI.getSettings()); logDirect(setting.toString()); return true; } } - if (Baritone.settings().byLowerName.containsKey(msg)) { - Settings.Setting setting = Baritone.settings().byLowerName.get(msg); + if (BaritoneAPI.getSettings().byLowerName.containsKey(msg)) { + Settings.Setting setting = BaritoneAPI.getSettings().byLowerName.get(msg); logDirect(setting.toString()); return true; } @@ -210,7 +206,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } return true; } - if (msg.equals("fullpath")) { + /*if (msg.equals("fullpath")) { if (pathingBehavior.getGoal() == null) { logDirect("No goal."); } else { @@ -226,7 +222,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { }); } return true; - } + }*/ if (msg.equals("proc")) { Optional proc = baritone.getPathingControlManager().mostRecentInControl(); if (!proc.isPresent()) { @@ -284,7 +280,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("come")) { - customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(mc.getRenderViewEntity()))); + customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(Helper.mc.getRenderViewEntity()))); logDirect("Coming"); return true; } @@ -365,10 +361,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("reset")) { - for (Settings.Setting setting : Baritone.settings().allSettings) { + for (Settings.Setting setting : BaritoneAPI.getSettings().allSettings) { setting.reset(); } - SettingsUtil.save(Baritone.settings()); + SettingsUtil.save(BaritoneAPI.getSettings()); logDirect("Baritone settings reset"); return true; } @@ -384,11 +380,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("farm")) { - baritone.getFarmProcess().doit(); + baritone.getFarmProcess().farm(); logDirect("farming"); return true; } - if (msg.equals("echest")) { + // this literally doesn't work, memory is disabled lol + /*if (msg.equals("echest")) { Optional> contents = baritone.getMemoryBehavior().echest(); if (contents.isPresent()) { logDirect("echest contents:"); @@ -397,18 +394,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("echest contents unknown"); } return true; - } + }*/ if (msg.equals("chests")) { - System.out.println(baritone.getWorldProvider()); - System.out.println(baritone.getWorldProvider().getCurrentWorld()); - - System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory()); - - System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories()); - - System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()); - - System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()); for (Map.Entry entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) { logDirect(entry.getKey() + ""); log(entry.getValue().getContents()); @@ -468,7 +455,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("blacklist")) { - GetToBlockProcess proc = baritone.getGetToBlockProcess(); + IGetToBlockProcess proc = baritone.getGetToBlockProcess(); if (!proc.isActive()) { logDirect("GetToBlockProcess is not currently active"); return true; @@ -485,9 +472,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper { ArrayList locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4); logDirect("Have " + locs.size() + " locations"); for (BlockPos pos : locs) { - Block actually = BlockStateInterface.get(ctx, pos).getBlock(); - if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) { - System.out.println("Was looking for " + blockType + " but actually found " + actually + " " + ChunkPacker.blockToString(actually)); + Block actually = ctx.world().getBlockState(pos).getBlock(); + if (!BlockUtils.blockToString(actually).equalsIgnoreCase(blockType)) { + logDebug("Was looking for " + blockType + " but actually found " + actually + " " + BlockUtils.blockToString(actually)); } } return true; @@ -496,13 +483,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper { String[] blockTypes = msg.substring(4).trim().split(" "); try { int quantity = Integer.parseInt(blockTypes[1]); - Block block = ChunkPacker.stringToBlockRequired(blockTypes[0]); + Block block = BlockUtils.stringToBlockRequired(blockTypes[0]); baritone.getMineProcess().mine(quantity, block); logDirect("Will mine " + quantity + " " + blockTypes[0]); return true; } catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {} for (String s : blockTypes) { - if (ChunkPacker.stringToBlockNullable(s) == null) { + if (BlockUtils.stringToBlockNullable(s) == null) { logDirect(s + " isn't a valid block name"); return true; } @@ -513,12 +500,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("click")) { - new Thread(() -> { - try { - Thread.sleep(100); - mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiClick())); - } catch (Exception ignored) {} - }).start(); + baritone.openClick(); logDirect("aight dude"); return true; } @@ -538,9 +520,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper { // for example, "show deaths" waypointType = waypointType.substring(0, waypointType.length() - 1); } - Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); + IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType); if (tag == null) { - logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); + logDirect("Not a valid tag. Tags are: " + Arrays.asList(IWaypoint.Tag.values()).toString().toLowerCase()); return true; } Set waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(tag); @@ -571,21 +553,21 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } name = parts[0]; } - baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, Waypoint.Tag.USER, pos)); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, IWaypoint.Tag.USER, pos)); logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto " + name + "' to set goal, say 'list user' to list custom waypoints."); return true; } if (msg.startsWith("goto")) { String waypointType = msg.substring(4).trim(); - if (waypointType.endsWith("s") && Waypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) { + if (waypointType.endsWith("s") && IWaypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) { // for example, "show deaths" waypointType = waypointType.substring(0, waypointType.length() - 1); } - Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); + IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType); IWaypoint waypoint; if (tag == null) { String mining = waypointType; - Block block = ChunkPacker.stringToBlockNullable(mining); + Block block = BlockUtils.stringToBlockNullable(mining); //logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); if (block == null) { waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null); @@ -608,12 +590,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } } - Goal goal = waypoint.getTag() == Waypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation()); + Goal goal = waypoint.getTag() == IWaypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation()); customGoalProcess.setGoalAndPath(goal); return true; } if (msg.equals("spawn") || msg.equals("bed")) { - IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.BED); + IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(IWaypoint.Tag.BED); if (waypoint == null) { BlockPos spawnPoint = ctx.player().getBedLocation(); // for some reason the default spawnpoint is underground sometimes @@ -628,12 +610,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("sethome")) { - baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", Waypoint.Tag.HOME, ctx.playerFeet())); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", IWaypoint.Tag.HOME, ctx.playerFeet())); logDirect("Saved. Say home to set goal."); return true; } if (msg.equals("home")) { - IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.HOME); + IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(IWaypoint.Tag.HOME); if (waypoint == null) { logDirect("home not saved"); } else { @@ -643,7 +625,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } return true; } - if (msg.equals("costs")) { + // this is completely impossible from api + /*if (msg.equals("costs")) { List moves = Stream.of(Moves.values()).map(x -> x.apply0(new CalculationContext(baritone), ctx.playerFeet())).collect(Collectors.toCollection(ArrayList::new)); while (moves.contains(null)) { moves.remove(null); @@ -659,7 +642,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost); } return true; - } + }*/ if (msg.equals("damn")) { logDirect("daniel"); } diff --git a/src/main/java/baritone/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java similarity index 93% rename from src/main/java/baritone/utils/Helper.java rename to src/api/java/baritone/api/utils/Helper.java index 7bcc605c..99683d8a 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/api/java/baritone/api/utils/Helper.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see . */ -package baritone.utils; +package baritone.api.utils; -import baritone.Baritone; +import baritone.api.BaritoneAPI; import net.minecraft.client.Minecraft; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; @@ -50,7 +50,7 @@ public interface Helper { * @param message The message to display in chat */ default void logDebug(String message) { - if (!Baritone.settings().chatDebug.value) { + if (!BaritoneAPI.getSettings().chatDebug.value) { //System.out.println("Suppressed debug message:"); //System.out.println(message); return; @@ -67,6 +67,6 @@ public interface Helper { ITextComponent component = MESSAGE_PREFIX.createCopy(); component.getStyle().setColor(TextFormatting.GRAY); component.appendSibling(new TextComponentString(" " + message)); - Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.value.accept(component)); + Minecraft.getMinecraft().addScheduledTask(() -> BaritoneAPI.getSettings().logger.value.accept(component)); } } diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 33916d59..65937c46 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -21,6 +21,8 @@ import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.Settings; import baritone.api.event.listener.IEventBus; +import baritone.api.utils.ExampleBaritoneControl; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import baritone.behavior.*; import baritone.cache.WorldProvider; @@ -33,8 +35,6 @@ import net.minecraft.client.Minecraft; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -67,7 +67,6 @@ public class Baritone implements IBaritone { private GameEventHandler gameEventHandler; - private List behaviors; private PathingBehavior pathingBehavior; private LookBehavior lookBehavior; private MemoryBehavior memoryBehavior; @@ -102,7 +101,6 @@ public class Baritone implements IBaritone { // Define this before behaviors try and get it, or else it will be null and the builds will fail! this.playerContext = PrimaryPlayerContext.INSTANCE; - this.behaviors = new ArrayList<>(); { // the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist pathingBehavior = new PathingBehavior(this); @@ -138,12 +136,7 @@ public class Baritone implements IBaritone { return this.pathingControlManager; } - public List getBehaviors() { - return this.behaviors; - } - public void registerBehavior(Behavior behavior) { - this.behaviors.add(behavior); this.gameEventHandler.registerEventListener(behavior); } @@ -218,6 +211,16 @@ public class Baritone implements IBaritone { return this.gameEventHandler; } + @Override + public void openClick() { + new Thread(() -> { + try { + Thread.sleep(100); + Helper.mc.addScheduledTask(() -> Helper.mc.displayGuiScreen(new GuiClick())); + } catch (Exception ignored) {} + }).start(); + } + public static Settings settings() { return BaritoneAPI.getSettings(); } diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 50beda0f..72d648d9 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -24,7 +24,7 @@ import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.TickEvent; import baritone.api.event.events.type.EventState; import baritone.cache.ContainerMemory; -import baritone.cache.Waypoint; +import baritone.api.cache.Waypoint; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; import net.minecraft.block.BlockBed; diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 00ac5a4c..ac826fbf 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -32,7 +32,7 @@ import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.pathing.path.PathExecutor; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import baritone.utils.PathRenderer; import baritone.utils.PathingCommandContext; import baritone.utils.pathing.Favoring; @@ -350,7 +350,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } } - public void forceCancel() { // NOT exposed on public api + @Override + public void forceCancel() { // exposed on public api because :sob: cancelEverything(); secretInternalSegmentCancel(); synchronized (pathCalcLock) { @@ -358,11 +359,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } } - public void secretCursedFunctionDoNotCall(IPath path) { + /*public void secretCursedFunctionDoNotCall(IPath path) { synchronized (pathPlanLock) { current = new PathExecutor(this, path); } - } + }*/ public CalculationContext secretInternalGetCalculationContext() { return context; diff --git a/src/main/java/baritone/cache/CachedChunk.java b/src/main/java/baritone/cache/CachedChunk.java index bc5e2ac9..631b7150 100644 --- a/src/main/java/baritone/cache/CachedChunk.java +++ b/src/main/java/baritone/cache/CachedChunk.java @@ -17,6 +17,7 @@ package baritone.cache; +import baritone.api.utils.BlockUtils; import baritone.utils.pathing.PathingBlockType; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minecraft.block.Block; @@ -177,7 +178,7 @@ public final class CachedChunk { if (special != null) { String str = special.get(index); if (str != null) { - return ChunkPacker.stringToBlockRequired(str).getDefaultState(); + return BlockUtils.stringToBlockRequired(str).getDefaultState(); } } diff --git a/src/main/java/baritone/cache/CachedRegion.java b/src/main/java/baritone/cache/CachedRegion.java index d395f168..630dcc9e 100644 --- a/src/main/java/baritone/cache/CachedRegion.java +++ b/src/main/java/baritone/cache/CachedRegion.java @@ -19,6 +19,7 @@ package baritone.cache; import baritone.Baritone; import baritone.api.cache.ICachedRegion; +import baritone.api.utils.BlockUtils; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; @@ -149,7 +150,7 @@ public final class CachedRegion implements ICachedRegion { for (int z = 0; z < 32; z++) { if (chunks[x][z] != null) { for (int i = 0; i < 256; i++) { - out.writeUTF(ChunkPacker.blockToString(chunks[x][z].getOverview()[i].getBlock())); + out.writeUTF(BlockUtils.blockToString(chunks[x][z].getOverview()[i].getBlock())); } } } @@ -240,7 +241,7 @@ public final class CachedRegion implements ICachedRegion { for (int z = 0; z < 32; z++) { if (present[x][z]) { for (int i = 0; i < 256; i++) { - overview[x][z][i] = ChunkPacker.stringToBlockRequired(in.readUTF()).getDefaultState(); + overview[x][z][i] = BlockUtils.stringToBlockRequired(in.readUTF()).getDefaultState(); } } } @@ -255,7 +256,7 @@ public final class CachedRegion implements ICachedRegion { int numSpecialBlockTypes = in.readShort() & 0xffff; for (int i = 0; i < numSpecialBlockTypes; i++) { String blockName = in.readUTF(); - ChunkPacker.stringToBlockRequired(blockName); + BlockUtils.stringToBlockRequired(blockName); List locs = new ArrayList<>(); location[x][z].put(blockName, locs); int numLocations = in.readShort() & 0xffff; diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index 949f818c..7c8e4291 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -22,7 +22,7 @@ import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.cache.ICachedWorld; import baritone.api.cache.IWorldData; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index 6834549b..cc5f2188 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -17,12 +17,12 @@ package baritone.cache; +import baritone.api.utils.BlockUtils; import baritone.pathing.movement.MovementHelper; import baritone.utils.pathing.PathingBlockType; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; @@ -36,8 +36,6 @@ import java.util.*; */ public final class ChunkPacker { - private static final Map resourceCache = new HashMap<>(); - private ChunkPacker() {} public static CachedChunk pack(Chunk chunk) { @@ -75,7 +73,7 @@ public final class ChunkPacker { bitSet.set(index + 1, bits[1]); Block block = state.getBlock(); if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) { - String name = blockToString(block); + String name = BlockUtils.blockToString(block); specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z)); } } @@ -105,25 +103,6 @@ public final class ChunkPacker { return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks, System.currentTimeMillis()); } - public static String blockToString(Block block) { - ResourceLocation loc = Block.REGISTRY.getNameForObject(block); - String name = loc.getPath(); // normally, only write the part after the minecraft: - if (!loc.getNamespace().equals("minecraft")) { - // Baritone is running on top of forge with mods installed, perhaps? - name = loc.toString(); // include the namespace with the colon - } - return name; - } - - public static Block stringToBlockRequired(String name) { - Block block = stringToBlockNullable(name); - Objects.requireNonNull(block); - return block; - } - - public static Block stringToBlockNullable(String name) { - return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n)); - } private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) { Block block = state.getBlock(); diff --git a/src/main/java/baritone/cache/WaypointCollection.java b/src/main/java/baritone/cache/WaypointCollection.java index ef319602..18b13b89 100644 --- a/src/main/java/baritone/cache/WaypointCollection.java +++ b/src/main/java/baritone/cache/WaypointCollection.java @@ -19,6 +19,7 @@ package baritone.cache; import baritone.api.cache.IWaypoint; import baritone.api.cache.IWaypointCollection; +import baritone.api.cache.Waypoint; import net.minecraft.util.math.BlockPos; import java.io.*; diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index fe2efa4e..63d0b219 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -19,7 +19,7 @@ package baritone.cache; import baritone.Baritone; import baritone.api.cache.IWorldProvider; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import baritone.utils.accessor.IAnvilChunkLoader; import baritone.utils.accessor.IChunkProviderServer; import net.minecraft.server.integrated.IntegratedServer; diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index b1bb1182..465b5c3f 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -24,7 +24,7 @@ import baritone.api.event.listener.IEventBus; import baritone.api.event.listener.IGameEventListener; import baritone.cache.WorldProvider; import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 588b773e..4ab7dc1a 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -24,7 +24,7 @@ import baritone.api.pathing.goals.Goal; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.PathCalculationResult; import baritone.pathing.movement.CalculationContext; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import java.util.Optional; diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java index 37441743..92b7c440 100644 --- a/src/main/java/baritone/pathing/calc/Path.java +++ b/src/main/java/baritone/pathing/calc/Path.java @@ -25,7 +25,7 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.Moves; import baritone.pathing.path.CutoffPath; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import baritone.utils.pathing.PathBase; import java.util.ArrayList; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 447e4f08..7215faeb 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -25,7 +25,7 @@ import baritone.api.utils.*; import baritone.api.utils.input.Input; import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import baritone.utils.ToolSet; import net.minecraft.block.*; import net.minecraft.block.properties.PropertyBool; diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 3e767499..e63bf8f1 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -35,7 +35,7 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.movements.*; import baritone.utils.BlockStateInterface; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import net.minecraft.block.BlockLiquid; import net.minecraft.init.Blocks; import net.minecraft.util.Tuple; diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 2550f84d..74912464 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -69,12 +69,6 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro super(baritone); } - public boolean build(String schematicFile, BlockPos origin) { - File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile); - System.out.println(file + " " + file.exists()); - return build(schematicFile, file, origin); - } - @Override public void build(String name, ISchematic schematic, Vec3i origin) { this.name = name; diff --git a/src/main/java/baritone/process/ExploreProcess.java b/src/main/java/baritone/process/ExploreProcess.java index eff4d2de..fa252f76 100644 --- a/src/main/java/baritone/process/ExploreProcess.java +++ b/src/main/java/baritone/process/ExploreProcess.java @@ -22,6 +22,7 @@ import baritone.api.cache.ICachedWorld; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalComposite; import baritone.api.pathing.goals.GoalXZ; +import baritone.api.process.IExploreProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.cache.CachedWorld; @@ -31,7 +32,7 @@ import net.minecraft.util.math.BlockPos; import java.util.ArrayList; import java.util.List; -public class ExploreProcess extends BaritoneProcessHelper { +public class ExploreProcess extends BaritoneProcessHelper implements IExploreProcess { private BlockPos explorationOrigin; @@ -44,6 +45,7 @@ public class ExploreProcess extends BaritoneProcessHelper { return explorationOrigin != null; } + @Override public void explore(int centerX, int centerZ) { explorationOrigin = new BlockPos(centerX, 0, centerZ); } diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index 0e2fdaae..43b8b424 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalComposite; +import baritone.api.process.IFarmProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.utils.Rotation; @@ -50,7 +51,7 @@ import java.util.List; import java.util.Optional; import java.util.function.Predicate; -public class FarmProcess extends BaritoneProcessHelper { +public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess { private boolean active; @@ -90,7 +91,8 @@ public class FarmProcess extends BaritoneProcessHelper { return active; } - public void doit() { + @Override + public void farm() { active = true; } diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 07e47b91..708666a7 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -22,6 +22,7 @@ import baritone.api.pathing.goals.*; import baritone.api.process.IMineProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; +import baritone.api.utils.BlockUtils; import baritone.api.utils.IPlayerContext; import baritone.api.utils.RotationUtils; import baritone.cache.CachedChunk; @@ -219,7 +220,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro for (Block m : mining) { if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) { // maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that - locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), Baritone.settings().maxCachedWorldScanCount.value, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2)); + locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(BlockUtils.blockToString(m), Baritone.settings().maxCachedWorldScanCount.value, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2)); } else { uninteresting.add(m); } @@ -303,7 +304,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro @Override public void mineByName(int quantity, String... blocks) { - mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlockRequired).toArray(Block[]::new)); + mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(BlockUtils::stringToBlockRequired).toArray(Block[]::new)); } @Override diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index c798c563..a723ebc5 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -22,6 +22,7 @@ import baritone.api.event.events.TickEvent; import baritone.api.event.listener.AbstractGameEventListener; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalBlock; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiMainMenu; diff --git a/src/main/java/baritone/utils/BaritoneProcessHelper.java b/src/main/java/baritone/utils/BaritoneProcessHelper.java index 61c2fd44..6abec949 100644 --- a/src/main/java/baritone/utils/BaritoneProcessHelper.java +++ b/src/main/java/baritone/utils/BaritoneProcessHelper.java @@ -19,6 +19,7 @@ package baritone.utils; import baritone.Baritone; import baritone.api.process.IBaritoneProcess; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper { diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index db56b91f..36e2dfea 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -17,6 +17,7 @@ package baritone.utils; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; diff --git a/src/main/java/baritone/utils/BlockPlaceHelper.java b/src/main/java/baritone/utils/BlockPlaceHelper.java index ed472d57..ee8f2b73 100644 --- a/src/main/java/baritone/utils/BlockPlaceHelper.java +++ b/src/main/java/baritone/utils/BlockPlaceHelper.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index e4fd58b1..d1afe34d 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -23,6 +23,7 @@ import baritone.api.event.events.RenderEvent; import baritone.api.pathing.calc.IPath; import baritone.api.pathing.goals.*; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; import baritone.api.utils.interfaces.IGoalRenderPos; import baritone.behavior.PathingBehavior; import baritone.pathing.path.PathExecutor; diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index 20fe9836..61c0f9b0 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -22,7 +22,7 @@ import baritone.api.cache.IWorldData; import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerController; import baritone.api.utils.RayTraceUtils; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/PrimaryPlayerController.java index b9828c80..5445c105 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerController.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerController.java @@ -18,7 +18,7 @@ package baritone.utils.player; import baritone.api.utils.IPlayerController; -import baritone.utils.Helper; +import baritone.api.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.entity.player.EntityPlayer; From 0b72a8b4b38681cb3ce6f700cc2b0b187c2f4086 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 19:46:25 -0700 Subject: [PATCH 12/18] fix overshoot --- .../baritone/pathing/movement/MovementHelper.java | 5 ++++- src/main/java/baritone/pathing/path/PathExecutor.java | 11 +++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7215faeb..3abba65f 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -25,7 +25,6 @@ import baritone.api.utils.*; import baritone.api.utils.input.Input; import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.BlockStateInterface; -import baritone.api.utils.Helper; import baritone.utils.ToolSet; import net.minecraft.block.*; import net.minecraft.block.properties.PropertyBool; @@ -312,6 +311,10 @@ public interface MovementHelper extends ActionCosts, Helper { return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state); } + static boolean canWalkOn(IPlayerContext ctx, BlockPos pos) { + return canWalkOn(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ()); + } + static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) { return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z); } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index e63bf8f1..c848f42b 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -23,10 +23,7 @@ import baritone.api.pathing.movement.ActionCosts; import baritone.api.pathing.movement.IMovement; import baritone.api.pathing.movement.MovementStatus; import baritone.api.pathing.path.IPathExecutor; -import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.IPlayerContext; -import baritone.api.utils.RotationUtils; -import baritone.api.utils.VecUtils; +import baritone.api.utils.*; import baritone.api.utils.input.Input; import baritone.behavior.PathingBehavior; import baritone.pathing.calc.AbstractNodeCostSearch; @@ -35,7 +32,6 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.movements.*; import baritone.utils.BlockStateInterface; -import baritone.api.utils.Helper; import net.minecraft.block.BlockLiquid; import net.minecraft.init.Blocks; import net.minecraft.util.Tuple; @@ -569,7 +565,10 @@ public class PathExecutor implements IPathExecutor, Helper { if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { return true; } - if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(ctx, next.getDest().down())) { + if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) { + return false; + } + if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection())) { return true; } return next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.value; From 518fa1c74daa7e8b9f764038410cc7b4fb982e94 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 19:49:04 -0700 Subject: [PATCH 13/18] reformat all files --- src/api/java/baritone/api/behavior/IBehavior.java | 3 +-- .../java/baritone/api/pathing/goals/GoalStrictDirection.java | 1 - src/main/java/baritone/behavior/MemoryBehavior.java | 2 +- src/main/java/baritone/behavior/PathingBehavior.java | 2 +- src/main/java/baritone/event/GameEventHandler.java | 2 +- .../java/baritone/pathing/calc/AbstractNodeCostSearch.java | 2 +- src/main/java/baritone/pathing/calc/Path.java | 2 +- .../baritone/pathing/movement/movements/MovementAscend.java | 2 +- src/main/java/baritone/process/BuilderProcess.java | 1 - src/main/java/baritone/process/MineProcess.java | 1 - src/main/java/baritone/utils/player/PrimaryPlayerContext.java | 2 +- .../java/baritone/utils/player/PrimaryPlayerController.java | 2 +- 12 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/api/java/baritone/api/behavior/IBehavior.java b/src/api/java/baritone/api/behavior/IBehavior.java index fbef5258..811563b9 100644 --- a/src/api/java/baritone/api/behavior/IBehavior.java +++ b/src/api/java/baritone/api/behavior/IBehavior.java @@ -23,9 +23,8 @@ import baritone.api.event.listener.IGameEventListener; /** * A behavior is simply a type that is able to listen to events. * - * @see IGameEventListener - * * @author Brady + * @see IGameEventListener * @since 9/23/2018 */ public interface IBehavior extends AbstractGameEventListener {} diff --git a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java index 749bed62..24ae385a 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java +++ b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java @@ -17,7 +17,6 @@ package baritone.api.pathing.goals; -import baritone.api.BaritoneAPI; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 72d648d9..d98e3237 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -18,13 +18,13 @@ package baritone.behavior; import baritone.Baritone; +import baritone.api.cache.Waypoint; import baritone.api.event.events.BlockInteractEvent; import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.TickEvent; import baritone.api.event.events.type.EventState; import baritone.cache.ContainerMemory; -import baritone.api.cache.Waypoint; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; import net.minecraft.block.BlockBed; diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index ac826fbf..e0031c8c 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -25,6 +25,7 @@ import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalXZ; import baritone.api.process.PathingCommand; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; import baritone.api.utils.PathCalculationResult; import baritone.api.utils.interfaces.IGoalRenderPos; import baritone.pathing.calc.AStarPathFinder; @@ -32,7 +33,6 @@ import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.pathing.path.PathExecutor; -import baritone.api.utils.Helper; import baritone.utils.PathRenderer; import baritone.utils.PathingCommandContext; import baritone.utils.pathing.Favoring; diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index 465b5c3f..2ff688ad 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -22,9 +22,9 @@ import baritone.api.event.events.*; import baritone.api.event.events.type.EventState; import baritone.api.event.listener.IEventBus; import baritone.api.event.listener.IGameEventListener; +import baritone.api.utils.Helper; import baritone.cache.WorldProvider; import baritone.utils.BlockStateInterface; -import baritone.api.utils.Helper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 4ab7dc1a..30282748 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -22,9 +22,9 @@ import baritone.api.pathing.calc.IPath; import baritone.api.pathing.calc.IPathFinder; import baritone.api.pathing.goals.Goal; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; import baritone.api.utils.PathCalculationResult; import baritone.pathing.movement.CalculationContext; -import baritone.api.utils.Helper; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import java.util.Optional; diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java index 92b7c440..a3f9dd22 100644 --- a/src/main/java/baritone/pathing/calc/Path.java +++ b/src/main/java/baritone/pathing/calc/Path.java @@ -21,11 +21,11 @@ import baritone.api.pathing.calc.IPath; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.movement.IMovement; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.Moves; import baritone.pathing.path.CutoffPath; -import baritone.api.utils.Helper; import baritone.utils.pathing.PathBase; import java.util.ArrayList; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 2ba10f70..b37fd4d0 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -197,7 +197,7 @@ public class MovementAscend extends Movement { if (headBonkClear()) { return state.setInput(Input.JUMP, true); } - + if (flatDistToNext > 1.2 || sideDist > 0.2) { return state; } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 74912464..299862cc 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -36,7 +36,6 @@ import baritone.utils.PathingCommandContext; import baritone.utils.schematic.AirSchematic; import baritone.utils.schematic.Schematic; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 708666a7..cc168c56 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -26,7 +26,6 @@ import baritone.api.utils.BlockUtils; import baritone.api.utils.IPlayerContext; import baritone.api.utils.RotationUtils; import baritone.cache.CachedChunk; -import baritone.cache.ChunkPacker; import baritone.cache.WorldScanner; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java index 61c0f9b0..3cb498ac 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerContext.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerContext.java @@ -19,10 +19,10 @@ package baritone.utils.player; import baritone.api.BaritoneAPI; import baritone.api.cache.IWorldData; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerController; import baritone.api.utils.RayTraceUtils; -import baritone.api.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; diff --git a/src/main/java/baritone/utils/player/PrimaryPlayerController.java b/src/main/java/baritone/utils/player/PrimaryPlayerController.java index 5445c105..120f996c 100644 --- a/src/main/java/baritone/utils/player/PrimaryPlayerController.java +++ b/src/main/java/baritone/utils/player/PrimaryPlayerController.java @@ -17,8 +17,8 @@ package baritone.utils.player; -import baritone.api.utils.IPlayerController; import baritone.api.utils.Helper; +import baritone.api.utils.IPlayerController; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.entity.player.EntityPlayer; From 343bb20bd861d48bc7a04e1fd7faf2783721be6f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 20:02:02 -0700 Subject: [PATCH 14/18] fix weird cache behavior at chunk edge --- src/main/java/baritone/cache/ChunkPacker.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index cc5f2188..864f23d6 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -112,15 +112,20 @@ public final class ChunkPacker { if (MovementHelper.possiblyFlowing(state)) { return PathingBlockType.AVOID; } + if ( + (x != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z))) + || (x != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z))) + || (z != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1))) + || (z != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1))) + ) { + return PathingBlockType.AVOID; + } if (x == 0 || x == 15 || z == 0 || z == 15) { if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) == -1000.0F) { return PathingBlockType.WATER; } return PathingBlockType.AVOID; } - if (MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1))) { - return PathingBlockType.AVOID; - } return PathingBlockType.WATER; } From 6599736e00bda2f6358d9880d86999e68e41af10 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 20:23:30 -0700 Subject: [PATCH 15/18] fix that reference --- .../pathing/movement/movements/MovementTraverse.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 012180e5..881571bc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -246,12 +246,13 @@ public class MovementTraverse extends Movement { if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, ctx.playerFeet()) || Baritone.settings().sprintInWater.value) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) { state.setInput(Input.SPRINT, true); } - Block destDown = BlockStateInterface.get(ctx, dest.down()).getBlock(); - if (whereAmI.getY() != dest.getY() && ladder && (destDown == Blocks.VINE || destDown == Blocks.LADDER)) { - new MovementPillar(baritone, dest.down(), dest).updateState(state); // i'm sorry - return state; + + IBlockState destDown = BlockStateInterface.get(ctx, dest.down()); + BlockPos against = positionsToBreak[0]; + if (whereAmI.getY() != dest.getY() && ladder && (destDown.getBlock() == Blocks.VINE || destDown.getBlock() == Blocks.LADDER)) { + against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.getValue(BlockLadder.FACING).getOpposite()); } - MovementHelper.moveTowards(ctx, state, positionsToBreak[0]); + MovementHelper.moveTowards(ctx, state, against); return state; } else { wasTheBridgeBlockAlwaysThere = false; From 26256e71554e379cc2b8a5f55eb83f728b1c4eee Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 22:17:09 -0700 Subject: [PATCH 16/18] mine is now MUCH more epic --- .../api/pathing/goals/GoalTwoBlocks.java | 6 +- .../java/baritone/process/MineProcess.java | 62 +++++++++++++++++-- .../java/baritone/utils/pathing/Favoring.java | 3 +- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java index b1dc07a1..f1026ab5 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java +++ b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java @@ -31,17 +31,17 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { /** * The X block position of this goal */ - private final int x; + protected final int x; /** * The Y block position of this goal */ - private final int y; + protected final int y; /** * The Z block position of this goal */ - private final int z; + protected final int z; public GoalTwoBlocks(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index cc168c56..5ace2130 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -24,7 +24,9 @@ import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.utils.BlockUtils; import baritone.api.utils.IPlayerContext; +import baritone.api.utils.Rotation; import baritone.api.utils.RotationUtils; +import baritone.api.utils.input.Input; import baritone.cache.CachedChunk; import baritone.cache.WorldScanner; import baritone.pathing.movement.CalculationContext; @@ -32,6 +34,8 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; @@ -94,14 +98,35 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return null; } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; + List curr = new ArrayList<>(knownOreLocations); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - List curr = new ArrayList<>(knownOreLocations); CalculationContext context = new CalculationContext(baritone, true); Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { addNearby(); } + Optional shaft = curr.stream() + .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ()) + .filter(pos -> pos.getY() > ctx.playerFeet().getY()) + .filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof BlockAir)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =( + .min(Comparator.comparingDouble(ctx.player()::getDistanceSq)); + baritone.getInputOverrideHandler().clearAllKeys(); + if (shaft.isPresent()) { + BlockPos pos = shaft.get(); + IBlockState state = baritone.bsi.get0(pos); + if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) { + Optional rot = RotationUtils.reachable(ctx, pos); + if (rot.isPresent() && isSafeToCancel) { + baritone.getLookBehavior().updateTarget(rot.get(), true); + MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos)); + if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot.get())) { + baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true); + } + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } + } + } PathingCommand command = updateGoal(); if (command == null) { // none in range @@ -178,15 +203,42 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro knownOreLocations = locs; } + private static boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List locs) { + return locs.contains(pos) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, pos) instanceof BlockAir); + } + private static Goal coalesce(IPlayerContext ctx, BlockPos loc, List locs) { if (!Baritone.settings().forceInternalMining.value) { - return new GoalTwoBlocks(loc); + return new GoalThreeBlocks(loc); } + //if upwardGoal is false, and downward is true + // Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of) - boolean upwardGoal = locs.contains(loc.up()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.up()) == Blocks.AIR); - boolean downwardGoal = locs.contains(loc.down()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.down()) == Blocks.AIR); - return upwardGoal == downwardGoal ? new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : new GoalBlock(loc.down()); + boolean upwardGoal = internalMiningGoal(loc.up(), ctx, locs); + boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs); + boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), ctx, locs); + return upwardGoal == downwardGoal ? doubleDownwardGoal ? new GoalThreeBlocks(loc) : new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : doubleDownwardGoal ? new GoalTwoBlocks(loc.down()) : new GoalBlock(loc.down()); + } + + private static class GoalThreeBlocks extends GoalTwoBlocks { + + public GoalThreeBlocks(BlockPos pos) { + super(pos); + } + + @Override + public boolean isInGoal(int x, int y, int z) { + return x == this.x && (y == this.y || y == this.y - 1 || y == this.y - 2) && z == this.z; + } + + @Override + public double heuristic(int x, int y, int z) { + int xDiff = x - this.x; + int yDiff = y - this.y; + int zDiff = z - this.z; + return GoalBlock.calculate(xDiff, yDiff < -1 ? yDiff + 2 : yDiff == -1 ? 0 : yDiff, zDiff); + } } public static List droppedItemsScan(List mining, World world) { diff --git a/src/main/java/baritone/utils/pathing/Favoring.java b/src/main/java/baritone/utils/pathing/Favoring.java index 8a601758..56ccb006 100644 --- a/src/main/java/baritone/utils/pathing/Favoring.java +++ b/src/main/java/baritone/utils/pathing/Favoring.java @@ -19,6 +19,7 @@ package baritone.utils.pathing; import baritone.api.pathing.calc.IPath; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import baritone.pathing.movement.CalculationContext; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; @@ -31,7 +32,7 @@ public final class Favoring { for (Avoidance avoid : Avoidance.create(ctx)) { avoid.applySpherical(favorings); } - System.out.println("Favoring size: " + favorings.size()); + Helper.HELPER.logDebug("Favoring size: " + favorings.size()); } public Favoring(IPath previous, CalculationContext context) { // create one just from previous path, no mob avoidances From b64154e3b370a8e39c38428a68bef68a37b5cf63 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 23:25:55 -0700 Subject: [PATCH 17/18] meme for cached blocks that arent packed yet --- src/api/java/baritone/api/Settings.java | 7 +++++++ src/main/java/baritone/process/MineProcess.java | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 0892f28d..89dc6565 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -570,6 +570,13 @@ public final class Settings { */ public final Setting exploreForBlocks = new Setting<>(true); + /** + * When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too. + *

+ * Only if you have a beefy CPU and automatically mine blocks that are in cache + */ + public final Setting extendCacheOnThreshold = new Setting<>(false); + /** * Don't consider the next layer in builder until the current one is done */ diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 5ace2130..bda8e446 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -267,7 +267,6 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro public static List searchWorld(CalculationContext ctx, List mining, int max, List alreadyKnown, List blacklist) { List locs = new ArrayList<>(); List uninteresting = new ArrayList<>(); - //long b = System.currentTimeMillis(); for (Block m : mining) { if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) { // maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that @@ -277,14 +276,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } locs = prune(ctx, locs, mining, max, blacklist); - //System.out.println("Scan of cached chunks took " + (System.currentTimeMillis() - b) + "ms"); - if (locs.isEmpty()) { + if (locs.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) { uninteresting = mining; } if (!uninteresting.isEmpty()) { - //long before = System.currentTimeMillis(); locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx.getBaritone().getPlayerContext(), uninteresting, max, 10, 32)); // maxSearchRadius is NOT sq - //System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms"); } locs.addAll(alreadyKnown); return prune(ctx, locs, mining, max, blacklist); From 7a2f26ef620e015f0292f6477fed257c8bbeff02 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 18 Apr 2019 10:36:20 -0700 Subject: [PATCH 18/18] replace scuffed ternary with commented if --- .../java/baritone/process/MineProcess.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index bda8e446..a1a69526 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -204,6 +204,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } private static boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List locs) { + // Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of) return locs.contains(pos) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, pos) instanceof BlockAir); } @@ -211,14 +212,34 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro if (!Baritone.settings().forceInternalMining.value) { return new GoalThreeBlocks(loc); } - - //if upwardGoal is false, and downward is true - - // Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of) boolean upwardGoal = internalMiningGoal(loc.up(), ctx, locs); boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs); boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), ctx, locs); - return upwardGoal == downwardGoal ? doubleDownwardGoal ? new GoalThreeBlocks(loc) : new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : doubleDownwardGoal ? new GoalTwoBlocks(loc.down()) : new GoalBlock(loc.down()); + if (upwardGoal == downwardGoal) { // symmetric + if (doubleDownwardGoal) { + // we have a checkerboard like pattern + // this one, and the one two below it + // therefore it's fine to path to immediately below this one, since your feet will be in the doubleDownwardGoal + return new GoalThreeBlocks(loc); + } else { + // this block has nothing interesting two below, but is symmetric vertically so we can get either feet or head into it + return new GoalTwoBlocks(loc); + } + } + if (upwardGoal) { + // downwardGoal known to be false + // ignore the gap then potential doubleDownward, because we want to path feet into this one and head into upwardGoal + return new GoalBlock(loc); + } + // upwardGoal known to be false, downwardGoal known to be true + if (doubleDownwardGoal) { + // this block and two below it are goals + // path into the center of the one below, because that includes directly below this one + return new GoalTwoBlocks(loc.down()); + } + // upwardGoal false, downwardGoal true, doubleDownwardGoal false + // just this block and the one immediately below, no others + return new GoalBlock(loc.down()); } private static class GoalThreeBlocks extends GoalTwoBlocks {