Merge remote-tracking branch 'origin/master' into 1.13.2

This commit is contained in:
Brady 2019-03-12 01:09:11 -05:00
commit 841a927033
No known key found for this signature in database
GPG Key ID: 73A788379A197567
16 changed files with 111 additions and 48 deletions

View File

@ -26,7 +26,7 @@ Examples of unacceptable behavior by participants include:
* Anime
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* ~~Trolling, insulting/derogatory comments, and personal or political attacks~~
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission

View File

@ -29,7 +29,7 @@ A Minecraft pathfinder bot.
Baritone is the pathfinding system used in [Impact](https://impactdevelopment.github.io/) since 4.4. There's a [showcase video](https://www.youtube.com/watch?v=yI8hgW_m6dQ) made by @Adovin#3153 on Baritone's integration into Impact. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a video I made showing off what it can do.
This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/),
the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths).
the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths).
Have committed at least once a day for the last 7 months =D 🦀
@ -72,7 +72,7 @@ That's what it's for, sure! (As long as usage is in compliance with the LGPL 3 L
## How is it so fast?
Magic. (Hours of [Leijurv](https://github.com/leijurv) enduring excruciating pain)
Magic. (Hours of [leijurv](https://github.com/leijurv) enduring excruciating pain)
## Why is it called Baritone?

View File

@ -485,10 +485,12 @@ public final class Settings {
public final Setting<Boolean> sprintInWater = new Setting<>(true);
/**
* When GetToBlockProcess fails to calculate a path, instead of just giving up, mark the closest instances
* of that block as "unreachable" and go towards the next closest
* When GetToBlockProcess or MineProcess fails to calculate a path, instead of just giving up, mark the closest instance
* of that block as "unreachable" and go towards the next closest. GetToBlock expands this seaarch to the whole "vein"; MineProcess does not.
* This is because MineProcess finds individual impossible blocks (like one block in a vein that has gravel on top then lava, so it can't break)
* Whereas GetToBlock should blacklist the whole "vein" if it can't get to any of them.
*/
public final Setting<Boolean> blacklistOnGetToBlockFailure = new Setting<>(true);
public final Setting<Boolean> blacklistClosestOnFailure = new Setting<>(true);
/**
* 😎 Render cached chunks as semitransparent. Doesn't work with OptiFine 😭 Rarely randomly crashes, see <a href="https://github.com/cabaletta/baritone/issues/327">this issue</a>.

View File

@ -35,6 +35,16 @@ import baritone.api.event.events.PathEvent;
*/
public interface IBaritoneProcess {
/**
* Default priority. Most normal processes should have this value.
* <p>
* Some examples of processes that should have different values might include some kind of automated mob avoidance
* that would be temporary and would forcefully take control. Same for something that pauses pathing for auto eat, etc.
* <p>
* The value is -1 beacuse that's what Impact 4.5's beta auto walk returns and I want to tie with it.
*/
double DEFAULT_PRIORITY = -1;
/**
* Would this process like to be in control?
*
@ -82,7 +92,9 @@ public interface IBaritoneProcess {
*
* @return A double representing the priority
*/
double priority();
default double priority() {
return DEFAULT_PRIORITY;
}
/**
* Returns a user-friendly name for this process. Suitable for a HUD.

View File

@ -53,4 +53,9 @@ public class PathingCommand {
this.goal = goal;
this.commandType = commandType;
}
@Override
public String toString() {
return commandType + " " + goal;
}
}

View File

@ -155,6 +155,10 @@ public class MovementAscend extends Movement {
return state.setStatus(MovementStatus.SUCCESS);
}
if (ctx.playerFeet().y < src.y) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
ticksWithoutPlacement++;

View File

@ -149,6 +149,10 @@ public class MovementPillar extends Movement {
return state;
}
if (ctx.playerFeet().y < src.y) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
IBlockState fromDown = BlockStateInterface.get(ctx, src);
if (MovementHelper.isWater(fromDown) && MovementHelper.isWater(ctx, dest)) {
// stay centered while swimming up a water column

View File

@ -24,8 +24,6 @@ import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.utils.BaritoneProcessHelper;
import java.util.Objects;
/**
* As set by ExampleBaritoneControl or something idk
*
@ -46,7 +44,7 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
private State state;
public CustomGoalProcess(Baritone baritone) {
super(baritone, 3);
super(baritone);
}
@Override
@ -79,20 +77,20 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
switch (this.state) {
case GOAL_SET:
if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal() + "", this.goal + "")) {
this.state = State.NONE;
}
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
case PATH_REQUESTED:
// return FORCE_REVALIDATE_GOAL_AND_PATH just once
PathingCommand ret = new PathingCommand(this.goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
this.state = State.EXECUTING;
return ret;
case EXECUTING:
if (calcFailed) {
onLostControl();
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
}
if (this.goal == null || this.goal.isInGoal(ctx.playerFeet())) {
onLostControl(); // we're there xd
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
}
return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH);
default:

View File

@ -31,7 +31,7 @@ public class ExploreProcess extends BaritoneProcessHelper {
private BlockPos explorationOrigin;
public ExploreProcess(Baritone baritone) {
super(baritone, 0);
super(baritone);
}
@Override

View File

@ -46,7 +46,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
private List<Entity> cache;
public FollowProcess(Baritone baritone) {
super(baritone, 1);
super(baritone);
}
@Override

View File

@ -44,7 +44,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
private int tickCount = 0;
public GetToBlockProcess(Baritone baritone) {
super(baritone, 2);
super(baritone);
}
@Override
@ -83,8 +83,8 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
}
Goal goal = new GoalComposite(knownLocations.stream().map(this::createGoal).toArray(Goal[]::new));
if (calcFailed) {
if (Baritone.settings().blacklistOnGetToBlockFailure.value) {
logDirect("Unable to find any path to " + gettingTo + ", blacklisting presumably unreachable closest instances");
if (Baritone.settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + gettingTo + ", blacklisting presumably unreachable closest instances...");
blacklistClosest();
return onTick(false, isSafeToCancel); // gamer moment
} else {
@ -161,11 +161,14 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
@Override
public String displayName() {
return "Get To Block " + gettingTo;
if (knownLocations.isEmpty()) {
return "Exploring randomly to find " + gettingTo + ", no known locations";
}
return "Get To Block " + gettingTo + ", " + knownLocations.size() + " known locations";
}
private synchronized void rescan(List<BlockPos> known, CalculationContext context) {
List<BlockPos> positions = MineProcess.searchWorld(context, Collections.singletonList(gettingTo), 64, known);
List<BlockPos> positions = MineProcess.searchWorld(context, Collections.singletonList(gettingTo), 64, known, blacklist);
positions.removeIf(blacklist::contains);
knownLocations = positions;
}

View File

@ -55,13 +55,14 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
private List<Block> mining;
private List<BlockPos> knownOreLocations;
private List<BlockPos> blacklist; // inaccessible
private BlockPos branchPoint;
private GoalRunAway branchPointRunaway;
private int desiredQuantity;
private int tickCount;
public MineProcess(Baritone baritone) {
super(baritone, 0);
super(baritone);
}
@Override
@ -81,6 +82,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null;
}
}
if (calcFailed && !knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + mining + ", blacklisting presumably unreachable closest instance...");
knownOreLocations.stream().sorted(Comparator.comparingDouble(ctx.player()::getDistanceSq)).findFirst().ifPresent(blacklist::add);
knownOreLocations.removeIf(blacklist::contains);
calcFailed = false; // 😎
}
if (calcFailed) {
logDirect("Unable to find any path to " + mining + ", canceling Mine");
cancel();
@ -119,7 +126,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
boolean legit = Baritone.settings().legitMine.value;
List<BlockPos> locs = knownOreLocations;
if (!locs.isEmpty()) {
List<BlockPos> locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT);
List<BlockPos> locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT, blacklist);
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(ctx, loc, locs2)).toArray(Goal[]::new));
knownOreLocations = locs2;
@ -161,10 +168,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (Baritone.settings().legitMine.value) {
return;
}
List<BlockPos> locs = searchWorld(context, mining, ORE_LOCATIONS_COUNT, already);
List<BlockPos> locs = searchWorld(context, mining, ORE_LOCATIONS_COUNT, already, blacklist);
locs.addAll(droppedItemsScan(mining, ctx.world()));
if (locs.isEmpty()) {
logDebug("No locations for " + mining + " known, cancelling");
logDirect("No locations for " + mining + " known, cancelling");
cancel();
return;
}
@ -205,7 +212,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return ret;
}
public static List<BlockPos> searchWorld(CalculationContext ctx, List<Block> mining, int max, List<BlockPos> alreadyKnown) {
public static List<BlockPos> searchWorld(CalculationContext ctx, List<Block> mining, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist) {
List<BlockPos> locs = new ArrayList<>();
List<Block> uninteresting = new ArrayList<>();
//long b = System.currentTimeMillis();
@ -217,6 +224,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
uninteresting.add(m);
}
}
locs = prune(ctx, locs, mining, max, blacklist);
//System.out.println("Scan of cached chunks took " + (System.currentTimeMillis() - b) + "ms");
if (locs.isEmpty()) {
uninteresting = mining;
@ -227,7 +235,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
//System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms");
}
locs.addAll(alreadyKnown);
return prune(ctx, locs, mining, max);
return prune(ctx, locs, mining, max, blacklist);
}
private void addNearby() {
@ -250,10 +258,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
}
}
knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, mining, ORE_LOCATIONS_COUNT);
knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, mining, ORE_LOCATIONS_COUNT, blacklist);
}
public static List<BlockPos> prune(CalculationContext ctx, List<BlockPos> locs2, List<Block> mining, int max) {
private static List<BlockPos> prune(CalculationContext ctx, List<BlockPos> locs2, List<Block> mining, int max, List<BlockPos> blacklist) {
List<BlockPos> dropped = droppedItemsScan(mining, ctx.world);
dropped.removeIf(drop -> {
for (BlockPos pos : locs2) {
@ -273,6 +281,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
// remove any that are implausible to mine (encased in bedrock, or touching lava)
.filter(pos -> MineProcess.plausibleToBreak(ctx.bsi, pos))
.filter(pos -> !blacklist.contains(pos))
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().playerFeet()::distanceSq))
.collect(Collectors.toList());
@ -301,6 +311,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks);
this.desiredQuantity = quantity;
this.knownOreLocations = new ArrayList<>();
this.blacklist = new ArrayList<>();
this.branchPoint = null;
this.branchPointRunaway = null;
if (mining != null) {

View File

@ -25,12 +25,10 @@ public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper
protected final Baritone baritone;
protected final IPlayerContext ctx;
private final double priority;
public BaritoneProcessHelper(Baritone baritone, double priority) {
public BaritoneProcessHelper(Baritone baritone) {
this.baritone = baritone;
this.ctx = baritone.getPlayerContext();
this.priority = priority;
baritone.getPathingControlManager().registerProcess(this);
}
@ -38,9 +36,4 @@ public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper
public boolean isTemporary() {
return false;
}
@Override
public double priority() {
return priority;
}
}

View File

@ -24,6 +24,7 @@ import baritone.api.cache.IWaypoint;
import baritone.api.event.events.ChatEvent;
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;
@ -225,6 +226,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
}
return true;
}
if (msg.equals("proc")) {
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
if (!proc.isPresent()) {
logDirect("No process is in control");
return true;
}
IBaritoneProcess p = proc.get();
logDirect("Class: " + p.getClass());
logDirect("Priority: " + p.priority());
logDirect("Temporary: " + p.isTemporary());
logDirect("Display name: " + p.displayName());
logDirect("Command: " + baritone.getPathingControlManager().mostRecentCommand());
return true;
}
if (msg.equals("version")) {
String version = ExampleBaritoneControl.class.getPackage().getImplementationVersion();
if (version == null) {
@ -518,7 +533,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true;
}
}
Goal goal = new GoalBlock(waypoint.getLocation());
Goal goal = waypoint.getTag() == Waypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation());
customGoalProcess.setGoalAndPath(goal);
return true;
}

View File

@ -39,7 +39,7 @@ import static org.lwjgl.opengl.GL11.*;
public class GuiClickMeme extends GuiScreen {
// My name is Brady and I grant Leijurv permission to use this pasted code
// My name is Brady and I grant leijurv permission to use this pasted code
private final FloatBuffer MODELVIEW = BufferUtils.createFloatBuffer(16);
private final FloatBuffer PROJECTION = BufferUtils.createFloatBuffer(16);
private final IntBuffer VIEWPORT = BufferUtils.createIntBuffer(16);
@ -57,7 +57,7 @@ public class GuiClickMeme extends GuiScreen {
double mx = mc.mouseHelper.getMouseX();
double my = mc.mouseHelper.getMouseY();
Vec3d near = toWorld(mx, my, 0);
Vec3d far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - Leijurv
Vec3d far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - leijurv
if (near != null && far != null) {
Vec3d viewerPos = new Vec3d(mc.getRenderManager().viewerPosX, mc.getRenderManager().viewerPosY, mc.getRenderManager().viewerPosZ);
RayTraceResult result = mc.world.rayTraceBlocks(near.add(viewerPos), far.add(viewerPos), RayTraceFluidMode.NEVER, false, true);

View File

@ -24,16 +24,17 @@ import baritone.api.pathing.calc.IPathingControlManager;
import baritone.api.pathing.goals.Goal;
import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
import net.minecraft.util.math.BlockPos;
import java.util.*;
import java.util.stream.Stream;
public class PathingControlManager implements IPathingControlManager {
private final Baritone baritone;
private final HashSet<IBaritoneProcess> processes; // unGh
private final List<IBaritoneProcess> active;
private IBaritoneProcess inControlLastTick;
private IBaritoneProcess inControlThisTick;
private PathingCommand command;
@ -41,13 +42,13 @@ public class PathingControlManager implements IPathingControlManager {
public PathingControlManager(Baritone baritone) {
this.baritone = baritone;
this.processes = new HashSet<>();
this.active = new ArrayList<>();
baritone.getGameEventHandler().registerEventListener(new AbstractGameEventListener() { // needs to be after all behavior ticks
@Override
public void onTick(TickEvent event) {
if (event.getType() == TickEvent.Type.OUT) {
return;
if (event.getType() == TickEvent.Type.IN) {
postTick();
}
postTick();
}
});
}
@ -62,6 +63,7 @@ public class PathingControlManager implements IPathingControlManager {
inControlLastTick = null;
inControlThisTick = null;
command = null;
active.clear();
for (IBaritoneProcess proc : processes) {
proc.onLostControl();
if (proc.isActive() && !proc.isTemporary()) { // it's okay only for a temporary thing (like combat pause) to maintain control even if you say to cancel
@ -87,8 +89,14 @@ public class PathingControlManager implements IPathingControlManager {
command = executeProcesses();
if (command == null) {
p.cancelSegmentIfSafe();
p.secretInternalSetGoal(null);
return;
}
if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE) {
// if control has changed, and the new process wants to do something
p.cancelSegmentIfSafe();
// get rid of the in progress stuff from the last process
}
switch (command.commandType) {
case REQUEST_PAUSE:
p.requestPause();
@ -172,12 +180,20 @@ public class PathingControlManager implements IPathingControlManager {
public PathingCommand executeProcesses() {
Stream<IBaritoneProcess> inContention = processes.stream()
.filter(IBaritoneProcess::isActive)
.sorted(Comparator.comparingDouble(IBaritoneProcess::priority).reversed());
for (IBaritoneProcess process : processes) {
if (process.isActive()) {
if (!active.contains(process)) {
// put a newly active process at the very front of the queue
active.add(0, process);
}
} else {
active.remove(process);
}
}
// ties are broken by which was added to the beginning of the list first
active.sort(Comparator.comparingDouble(IBaritoneProcess::priority).reversed());
Iterator<IBaritoneProcess> iterator = inContention.iterator();
Iterator<IBaritoneProcess> iterator = active.iterator();
while (iterator.hasNext()) {
IBaritoneProcess proc = iterator.next();