Create IPathingBehavior and expose all behaviors
This is still a biiiiiig WIP
This commit is contained in:
parent
62b8bc0f47
commit
4ac2ade7c6
76
src/api/java/baritone/api/BaritoneAPI.java
Normal file
76
src/api/java/baritone/api/BaritoneAPI.java
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import baritone.api.behavior.*;
|
||||
|
||||
/**
|
||||
* API exposure for various things implemented in Baritone.
|
||||
* <p>
|
||||
* W.I.P
|
||||
*
|
||||
* @author Brady
|
||||
* @since 9/23/2018
|
||||
*/
|
||||
public class BaritoneAPI {
|
||||
|
||||
private static IFollowBehavior followBehavior;
|
||||
private static ILookBehavior lookBehavior;
|
||||
private static IMemoryBehavior memoryBehavior;
|
||||
private static IMineBehavior mineBehavior;
|
||||
private static IPathingBehavior pathingBehavior;
|
||||
|
||||
public static IFollowBehavior getFollowBehavior() {
|
||||
return followBehavior;
|
||||
}
|
||||
|
||||
public static ILookBehavior getLookBehavior() {
|
||||
return lookBehavior;
|
||||
}
|
||||
|
||||
public static IMemoryBehavior getMemoryBehavior() {
|
||||
return memoryBehavior;
|
||||
}
|
||||
|
||||
public static IMineBehavior getMineBehavior() {
|
||||
return mineBehavior;
|
||||
}
|
||||
|
||||
public static IPathingBehavior getPathingBehavior() {
|
||||
return pathingBehavior;
|
||||
}
|
||||
|
||||
/**
|
||||
* FOR INTERNAL USE ONLY
|
||||
*/
|
||||
// @formatter:off
|
||||
public static void registerDefaultBehaviors(
|
||||
IFollowBehavior followBehavior,
|
||||
ILookBehavior lookBehavior,
|
||||
IMemoryBehavior memoryBehavior,
|
||||
IMineBehavior mineBehavior,
|
||||
IPathingBehavior pathingBehavior
|
||||
) {
|
||||
BaritoneAPI.followBehavior = followBehavior;
|
||||
BaritoneAPI.lookBehavior = lookBehavior;
|
||||
BaritoneAPI.memoryBehavior = memoryBehavior;
|
||||
BaritoneAPI.mineBehavior = mineBehavior;
|
||||
BaritoneAPI.pathingBehavior = pathingBehavior;
|
||||
}
|
||||
// @formatter:on
|
||||
}
|
68
src/api/java/baritone/api/behavior/IPathingBehavior.java
Normal file
68
src/api/java/baritone/api/behavior/IPathingBehavior.java
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.api.behavior;
|
||||
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 9/23/2018
|
||||
*/
|
||||
public interface IPathingBehavior extends IBehavior {
|
||||
|
||||
/**
|
||||
* Returns the estimated remaining ticks in the current pathing
|
||||
* segment. Given that the return type is an optional, {@link Optional#empty()}
|
||||
* will be returned in the case that there is no current segment being pathed.
|
||||
*
|
||||
* @return The estimated remaining ticks in the current segment.
|
||||
*/
|
||||
Optional<Double> ticksRemainingInSegment();
|
||||
|
||||
/**
|
||||
* Sets the pathing goal.
|
||||
*
|
||||
* @param goal The pathing goal
|
||||
*/
|
||||
void setGoal(Goal goal);
|
||||
|
||||
/**
|
||||
* @return The current pathing goal
|
||||
*/
|
||||
Goal getGoal();
|
||||
|
||||
/**
|
||||
* Begins pathing. Calculation will start in a new thread, and once completed,
|
||||
* movement will commence. Returns whether or not the operation was successful.
|
||||
*
|
||||
* @return Whether or not the operation was successful
|
||||
*/
|
||||
boolean path();
|
||||
|
||||
/**
|
||||
* @return Whether or not a path is currently being executed.
|
||||
*/
|
||||
boolean isPathing();
|
||||
|
||||
/**
|
||||
* Cancels the pathing behavior or the current path calculation.
|
||||
*/
|
||||
void cancel();
|
||||
}
|
@ -15,9 +15,8 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.pathing.goals;
|
||||
package baritone.api.pathing.goals;
|
||||
|
||||
import baritone.pathing.movement.ActionCosts;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
@ -25,7 +24,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public interface Goal extends ActionCosts {
|
||||
public interface Goal {
|
||||
|
||||
/**
|
||||
* Returns whether or not the specified position
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -18,7 +18,7 @@
|
||||
package baritone.pathing.calc.openset;
|
||||
|
||||
import baritone.pathing.calc.PathNode;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
Loading…
Reference in New Issue
Block a user