Begin to create default behavior exposing interfaces in api
This commit is contained in:
parent
182c1e6ff5
commit
a6aa659629
@ -17,16 +17,13 @@
|
||||
|
||||
package baritone.api.behavior;
|
||||
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.api.utils.interfaces.Toggleable;
|
||||
|
||||
/**
|
||||
* A type of game event listener that can be toggled.
|
||||
*
|
||||
* @author Brady
|
||||
* @since 8/1/2018 6:29 PM
|
||||
*/
|
||||
public class Behavior implements AbstractGameEventListener, Toggleable {
|
||||
public class Behavior implements IBehavior {
|
||||
|
||||
/**
|
||||
* Whether or not this behavior is enabled
|
||||
|
27
src/api/java/baritone/api/behavior/IBehavior.java
Normal file
27
src/api/java/baritone/api/behavior/IBehavior.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.event.listener.AbstractGameEventListener;
|
||||
import baritone.api.utils.interfaces.Toggleable;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 9/23/2018
|
||||
*/
|
||||
public interface IBehavior extends AbstractGameEventListener, Toggleable {}
|
44
src/api/java/baritone/api/behavior/IFollowBehavior.java
Normal file
44
src/api/java/baritone/api/behavior/IFollowBehavior.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 net.minecraft.entity.Entity;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 9/23/2018
|
||||
*/
|
||||
public interface IFollowBehavior extends IBehavior {
|
||||
|
||||
/**
|
||||
* Set the follow target to the specified entity;
|
||||
*
|
||||
* @param entity The entity to follow
|
||||
*/
|
||||
void follow(Entity entity);
|
||||
|
||||
/**
|
||||
* @return The entity that is currently being followed
|
||||
*/
|
||||
Entity following();
|
||||
|
||||
/**
|
||||
* Cancels the follow behavior, this will clear the current follow target.
|
||||
*/
|
||||
void cancel();
|
||||
}
|
39
src/api/java/baritone/api/behavior/ILookBehavior.java
Normal file
39
src/api/java/baritone/api/behavior/ILookBehavior.java
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.utils.Rotation;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 9/23/2018
|
||||
*/
|
||||
public interface ILookBehavior extends IBehavior {
|
||||
|
||||
/**
|
||||
* Updates the current {@link ILookBehavior} target to target
|
||||
* the specified rotations on the next tick. If force is {@code true},
|
||||
* then freeLook will be overriden and angles will be set regardless.
|
||||
* If any sort of block interaction is required, force should be {@code true},
|
||||
* otherwise, it should be {@code false};
|
||||
*
|
||||
* @param rotation The target rotations
|
||||
* @param force Whether or not to "force" the rotations
|
||||
*/
|
||||
void updateTarget(Rotation rotation, boolean force);
|
||||
}
|
70
src/api/java/baritone/api/behavior/IMineBehavior.java
Normal file
70
src/api/java/baritone/api/behavior/IMineBehavior.java
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 net.minecraft.block.Block;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 9/23/2018
|
||||
*/
|
||||
public interface IMineBehavior {
|
||||
|
||||
/**
|
||||
* Begin to search for and mine the specified blocks until
|
||||
* the number of specified items to get from the blocks that
|
||||
* are mined. This is based on the first target block to mine.
|
||||
*
|
||||
* @param quantity The number of items to get from blocks mined
|
||||
* @param blocks The blocks to mine
|
||||
*/
|
||||
void mine(int quantity, String... blocks);
|
||||
|
||||
/**
|
||||
* Begin to search for and mine the specified blocks until
|
||||
* the number of specified items to get from the blocks that
|
||||
* are mined. This is based on the first target block to mine.
|
||||
*
|
||||
* @param quantity The number of items to get from blocks mined
|
||||
* @param blocks The blocks to mine
|
||||
*/
|
||||
void mine(int quantity, Block... blocks);
|
||||
|
||||
/**
|
||||
* Begin to search for and mine the specified blocks.
|
||||
*
|
||||
* @param blocks The blocks to mine
|
||||
*/
|
||||
default void mine(String... blocks) {
|
||||
this.mine(0, blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin to search for and mine the specified blocks.
|
||||
*
|
||||
* @param blocks The blocks to mine
|
||||
*/
|
||||
default void mine(Block... blocks) {
|
||||
this.mine(0, blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the current mining task
|
||||
*/
|
||||
void cancel();
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils;
|
||||
package baritone.api.utils;
|
||||
|
||||
import net.minecraft.util.Tuple;
|
||||
|
@ -19,6 +19,7 @@ package baritone.behavior;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.api.behavior.IFollowBehavior;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.pathing.goals.GoalNear;
|
||||
import baritone.pathing.goals.GoalXZ;
|
||||
@ -31,7 +32,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public final class FollowBehavior extends Behavior implements Helper {
|
||||
public final class FollowBehavior extends Behavior implements IFollowBehavior, Helper {
|
||||
|
||||
public static final FollowBehavior INSTANCE = new FollowBehavior();
|
||||
|
||||
@ -61,14 +62,17 @@ public final class FollowBehavior extends Behavior implements Helper {
|
||||
PathingBehavior.INSTANCE.path();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void follow(Entity entity) {
|
||||
this.following = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity following() {
|
||||
return this.following;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
PathingBehavior.INSTANCE.cancel();
|
||||
follow(null);
|
||||
|
@ -20,12 +20,13 @@ package baritone.behavior;
|
||||
import baritone.Baritone;
|
||||
import baritone.Settings;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.api.behavior.ILookBehavior;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.RotationMoveEvent;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.Rotation;
|
||||
import baritone.api.utils.Rotation;
|
||||
|
||||
public final class LookBehavior extends Behavior implements Helper {
|
||||
public final class LookBehavior extends Behavior implements ILookBehavior, Helper {
|
||||
|
||||
public static final LookBehavior INSTANCE = new LookBehavior();
|
||||
|
||||
@ -51,6 +52,7 @@ public final class LookBehavior extends Behavior implements Helper {
|
||||
|
||||
private LookBehavior() {}
|
||||
|
||||
@Override
|
||||
public void updateTarget(Rotation target, boolean force) {
|
||||
this.target = target;
|
||||
this.force = force || !Baritone.settings().freeLook.get();
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.behavior;
|
||||
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.utils.*;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -19,6 +19,7 @@ package baritone.behavior;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.api.behavior.IMineBehavior;
|
||||
import baritone.api.event.events.PathEvent;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.cache.CachedChunk;
|
||||
@ -46,7 +47,7 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public final class MineBehavior extends Behavior implements Helper {
|
||||
public final class MineBehavior extends Behavior implements IMineBehavior, Helper {
|
||||
|
||||
public static final MineBehavior INSTANCE = new MineBehavior();
|
||||
|
||||
@ -109,7 +110,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
||||
PathingBehavior.INSTANCE.path();
|
||||
}
|
||||
|
||||
public static GoalComposite coalesce(List<BlockPos> locs) {
|
||||
public GoalComposite coalesce(List<BlockPos> locs) {
|
||||
return new GoalComposite(locs.stream().map(loc -> {
|
||||
if (!Baritone.settings().forceInternalMining.get()) {
|
||||
return new GoalTwoBlocks(loc);
|
||||
@ -133,7 +134,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
||||
}).toArray(Goal[]::new));
|
||||
}
|
||||
|
||||
public static List<BlockPos> scanFor(List<Block> mining, int max) {
|
||||
public List<BlockPos> scanFor(List<Block> mining, int max) {
|
||||
List<BlockPos> locs = new ArrayList<>();
|
||||
List<Block> uninteresting = new ArrayList<>();
|
||||
//long b = System.currentTimeMillis();
|
||||
@ -156,7 +157,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
||||
return prune(locs, mining, max);
|
||||
}
|
||||
|
||||
public static List<BlockPos> prune(List<BlockPos> locs, List<Block> mining, int max) {
|
||||
public List<BlockPos> prune(List<BlockPos> locs, List<Block> mining, int max) {
|
||||
BlockPos playerFeet = MineBehavior.INSTANCE.playerFeet();
|
||||
locs.sort(Comparator.comparingDouble(playerFeet::distanceSq));
|
||||
|
||||
@ -171,6 +172,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
||||
return locs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mine(int quantity, String... blocks) {
|
||||
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList());
|
||||
this.quantity = quantity;
|
||||
@ -178,12 +180,15 @@ public final class MineBehavior extends Behavior implements Helper {
|
||||
updateGoal();
|
||||
}
|
||||
|
||||
public void mine(Block... blocks) {
|
||||
@Override
|
||||
public void mine(int quantity, Block... blocks) {
|
||||
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks);
|
||||
this.quantity = quantity;
|
||||
this.locationsCache = new ArrayList<>();
|
||||
updateGoal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
mine(0, (String[]) null);
|
||||
PathingBehavior.INSTANCE.cancel();
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.pathing.movement;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.behavior.LookBehavior;
|
||||
import baritone.behavior.LookBehaviorUtils;
|
||||
import baritone.pathing.movement.MovementState.MovementStatus;
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.pathing.movement;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.behavior.LookBehaviorUtils;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.utils.*;
|
||||
|
@ -18,7 +18,7 @@
|
||||
package baritone.pathing.movement;
|
||||
|
||||
import baritone.utils.InputOverrideHandler.Input;
|
||||
import baritone.utils.Rotation;
|
||||
import baritone.api.utils.Rotation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.pathing.movement.movements;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
|
@ -23,7 +23,7 @@ import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Rotation;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.*;
|
||||
|
@ -25,7 +25,7 @@ import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.Rotation;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.utils.Utils;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.*;
|
||||
|
@ -368,7 +368,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
logDirect("No locations for " + mining + " known, cancelling");
|
||||
return;
|
||||
}
|
||||
List<BlockPos> locs = MineBehavior.scanFor(Collections.singletonList(block), 64);
|
||||
List<BlockPos> locs = MineBehavior.INSTANCE.scanFor(Collections.singletonList(block), 64);
|
||||
if (locs.isEmpty()) {
|
||||
logDirect("No locations for " + mining + " known, cancelling");
|
||||
return;
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.api.utils.Rotation;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.api.utils.Rotation;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
|
Loading…
Reference in New Issue
Block a user