Create IPathingBehavior and expose all behaviors
This is still a biiiiiig WIP
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.behavior.*;
|
||||
@@ -89,6 +90,16 @@ public enum Baritone {
|
||||
registerBehavior(LocationTrackingBehavior.INSTANCE);
|
||||
registerBehavior(FollowBehavior.INSTANCE);
|
||||
registerBehavior(MineBehavior.INSTANCE);
|
||||
|
||||
// TODO: Clean this up
|
||||
// Maybe combine this call in someway with the registerBehavior calls?
|
||||
BaritoneAPI.registerDefaultBehaviors(
|
||||
FollowBehavior.INSTANCE,
|
||||
LookBehavior.INSTANCE,
|
||||
MemoryBehavior.INSTANCE,
|
||||
MineBehavior.INSTANCE,
|
||||
PathingBehavior.INSTANCE
|
||||
);
|
||||
}
|
||||
this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone");
|
||||
if (!Files.exists(dir.toPath())) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import baritone.cache.CachedChunk;
|
||||
import baritone.cache.ChunkPacker;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.goals.GoalBlock;
|
||||
import baritone.pathing.goals.GoalComposite;
|
||||
import baritone.pathing.goals.GoalTwoBlocks;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.behavior;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.behavior.IPathingBehavior;
|
||||
import baritone.api.event.events.PathEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.RenderEvent;
|
||||
@@ -25,7 +26,7 @@ import baritone.api.event.events.TickEvent;
|
||||
import baritone.pathing.calc.AStarPathFinder;
|
||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
import baritone.pathing.calc.IPathFinder;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.goals.GoalXZ;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.path.IPath;
|
||||
@@ -46,7 +47,7 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class PathingBehavior extends Behavior implements Helper {
|
||||
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
|
||||
|
||||
public static final PathingBehavior INSTANCE = new PathingBehavior();
|
||||
|
||||
@@ -172,6 +173,7 @@ public final class PathingBehavior extends Behavior implements Helper {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> ticksRemainingInSegment() {
|
||||
if (current == null) {
|
||||
return Optional.empty();
|
||||
@@ -179,10 +181,12 @@ public final class PathingBehavior extends Behavior implements Helper {
|
||||
return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGoal(Goal goal) {
|
||||
this.goal = goal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Goal getGoal() {
|
||||
return goal;
|
||||
}
|
||||
@@ -195,10 +199,19 @@ public final class PathingBehavior extends Behavior implements Helper {
|
||||
return next;
|
||||
}
|
||||
|
||||
// TODO: Expose this method in the API?
|
||||
// In order to do so, we'd need to move over IPath which has a whole lot of references to other
|
||||
// things that may not need to be exposed necessarily, so we'll need to figure that out.
|
||||
public Optional<IPath> getPath() {
|
||||
return Optional.ofNullable(current).map(PathExecutor::getPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPathing() {
|
||||
return this.current != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
dispatchPathEvent(PathEvent.CANCELED);
|
||||
current = null;
|
||||
@@ -212,6 +225,7 @@ public final class PathingBehavior extends Behavior implements Helper {
|
||||
*
|
||||
* @return true if this call started path calculation, false if it was already calculating or executing a path
|
||||
*/
|
||||
@Override
|
||||
public boolean path() {
|
||||
if (goal == null) {
|
||||
return false;
|
||||
@@ -234,7 +248,10 @@ public final class PathingBehavior extends Behavior implements Helper {
|
||||
}
|
||||
}
|
||||
|
||||
public BlockPos pathStart() {
|
||||
/**
|
||||
* @return The starting {@link BlockPos} for a new path
|
||||
*/
|
||||
private BlockPos pathStart() {
|
||||
BetterBlockPos feet = playerFeet();
|
||||
if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR) && MovementHelper.canWalkOn(feet.down().down())) {
|
||||
return feet.down();
|
||||
|
||||
@@ -19,7 +19,7 @@ package baritone.pathing.calc;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.ActionCosts;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Moves;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
package baritone.pathing.calc;
|
||||
|
||||
import baritone.behavior.PathingBehavior;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.path.IPath;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package baritone.pathing.calc;
|
||||
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.path.IPath;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package baritone.pathing.calc;
|
||||
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.Moves;
|
||||
import baritone.pathing.path.IPath;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package baritone.pathing.calc;
|
||||
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.ActionCosts;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.pathing.movement.ActionCosts;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* An abstract Goal for pathing, can be anything from a specific block to just a Y coordinate.
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public interface Goal extends ActionCosts {
|
||||
|
||||
/**
|
||||
* Returns whether or not the specified position
|
||||
* meets the requirement for this goal based.
|
||||
*
|
||||
* @return Whether or not it satisfies this goal
|
||||
*/
|
||||
boolean isInGoal(int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Estimate the number of ticks it will take to get to the goal
|
||||
*
|
||||
* @return The estimate number of ticks to satisfy the goal
|
||||
*/
|
||||
double heuristic(int x, int y, int z);
|
||||
|
||||
default boolean isInGoal(BlockPos pos) {
|
||||
return isInGoal(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
default double heuristic(BlockPos pos) {
|
||||
return heuristic(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
|
||||
public class GoalAxis implements Goal {
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.utils.Utils;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
@@ -17,12 +17,15 @@
|
||||
|
||||
package baritone.pathing.goals;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside;
|
||||
|
||||
/**
|
||||
* Useful for mining (getting to diamond / iron level)
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class GoalYLevel implements Goal {
|
||||
public class GoalYLevel implements Goal, ActionCostsButOnlyTheOnesThatMakeMickeyDieInside {
|
||||
|
||||
/**
|
||||
* The target Y level
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package baritone.pathing.path;
|
||||
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
package baritone.pathing.path;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.Utils;
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.Settings;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.event.events.ChatEvent;
|
||||
import baritone.behavior.FollowBehavior;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.pathing.goals.GoalComposite;
|
||||
import baritone.pathing.goals.GoalTwoBlocks;
|
||||
import baritone.pathing.goals.GoalXZ;
|
||||
|
||||
Reference in New Issue
Block a user