Begin to create default behavior exposing interfaces in api

This commit is contained in:
Brady 2018-09-23 16:44:35 -05:00
parent 182c1e6ff5
commit a6aa659629
No known key found for this signature in database
GPG Key ID: 73A788379A197567
20 changed files with 212 additions and 17 deletions

View File

@ -17,16 +17,13 @@
package baritone.api.behavior; 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. * A type of game event listener that can be toggled.
* *
* @author Brady * @author Brady
* @since 8/1/2018 6:29 PM * @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 * Whether or not this behavior is enabled

View 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 {}

View 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();
}

View 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);
}

View 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();
}

View File

@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.utils; package baritone.api.utils;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;

View File

@ -19,6 +19,7 @@ package baritone.behavior;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.behavior.Behavior; import baritone.api.behavior.Behavior;
import baritone.api.behavior.IFollowBehavior;
import baritone.api.event.events.TickEvent; import baritone.api.event.events.TickEvent;
import baritone.pathing.goals.GoalNear; import baritone.pathing.goals.GoalNear;
import baritone.pathing.goals.GoalXZ; import baritone.pathing.goals.GoalXZ;
@ -31,7 +32,7 @@ import net.minecraft.util.math.BlockPos;
* *
* @author leijurv * @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(); public static final FollowBehavior INSTANCE = new FollowBehavior();
@ -61,14 +62,17 @@ public final class FollowBehavior extends Behavior implements Helper {
PathingBehavior.INSTANCE.path(); PathingBehavior.INSTANCE.path();
} }
@Override
public void follow(Entity entity) { public void follow(Entity entity) {
this.following = entity; this.following = entity;
} }
@Override
public Entity following() { public Entity following() {
return this.following; return this.following;
} }
@Override
public void cancel() { public void cancel() {
PathingBehavior.INSTANCE.cancel(); PathingBehavior.INSTANCE.cancel();
follow(null); follow(null);

View File

@ -20,12 +20,13 @@ package baritone.behavior;
import baritone.Baritone; import baritone.Baritone;
import baritone.Settings; import baritone.Settings;
import baritone.api.behavior.Behavior; import baritone.api.behavior.Behavior;
import baritone.api.behavior.ILookBehavior;
import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.RotationMoveEvent; import baritone.api.event.events.RotationMoveEvent;
import baritone.utils.Helper; 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(); public static final LookBehavior INSTANCE = new LookBehavior();
@ -51,6 +52,7 @@ public final class LookBehavior extends Behavior implements Helper {
private LookBehavior() {} private LookBehavior() {}
@Override
public void updateTarget(Rotation target, boolean force) { public void updateTarget(Rotation target, boolean force) {
this.target = target; this.target = target;
this.force = force || !Baritone.settings().freeLook.get(); this.force = force || !Baritone.settings().freeLook.get();

View File

@ -17,6 +17,7 @@
package baritone.behavior; package baritone.behavior;
import baritone.api.utils.Rotation;
import baritone.utils.*; import baritone.utils.*;
import net.minecraft.block.BlockFire; import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;

View File

@ -19,6 +19,7 @@ package baritone.behavior;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.behavior.Behavior; import baritone.api.behavior.Behavior;
import baritone.api.behavior.IMineBehavior;
import baritone.api.event.events.PathEvent; import baritone.api.event.events.PathEvent;
import baritone.api.event.events.TickEvent; import baritone.api.event.events.TickEvent;
import baritone.cache.CachedChunk; import baritone.cache.CachedChunk;
@ -46,7 +47,7 @@ import java.util.stream.Collectors;
* *
* @author leijurv * @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(); public static final MineBehavior INSTANCE = new MineBehavior();
@ -109,7 +110,7 @@ public final class MineBehavior extends Behavior implements Helper {
PathingBehavior.INSTANCE.path(); PathingBehavior.INSTANCE.path();
} }
public static GoalComposite coalesce(List<BlockPos> locs) { public GoalComposite coalesce(List<BlockPos> locs) {
return new GoalComposite(locs.stream().map(loc -> { return new GoalComposite(locs.stream().map(loc -> {
if (!Baritone.settings().forceInternalMining.get()) { if (!Baritone.settings().forceInternalMining.get()) {
return new GoalTwoBlocks(loc); return new GoalTwoBlocks(loc);
@ -133,7 +134,7 @@ public final class MineBehavior extends Behavior implements Helper {
}).toArray(Goal[]::new)); }).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<BlockPos> locs = new ArrayList<>();
List<Block> uninteresting = new ArrayList<>(); List<Block> uninteresting = new ArrayList<>();
//long b = System.currentTimeMillis(); //long b = System.currentTimeMillis();
@ -156,7 +157,7 @@ public final class MineBehavior extends Behavior implements Helper {
return prune(locs, mining, max); 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(); BlockPos playerFeet = MineBehavior.INSTANCE.playerFeet();
locs.sort(Comparator.comparingDouble(playerFeet::distanceSq)); locs.sort(Comparator.comparingDouble(playerFeet::distanceSq));
@ -171,6 +172,7 @@ public final class MineBehavior extends Behavior implements Helper {
return locs; return locs;
} }
@Override
public void mine(int quantity, String... blocks) { 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.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList());
this.quantity = quantity; this.quantity = quantity;
@ -178,12 +180,15 @@ public final class MineBehavior extends Behavior implements Helper {
updateGoal(); 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.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks);
this.quantity = quantity;
this.locationsCache = new ArrayList<>(); this.locationsCache = new ArrayList<>();
updateGoal(); updateGoal();
} }
@Override
public void cancel() { public void cancel() {
mine(0, (String[]) null); mine(0, (String[]) null);
PathingBehavior.INSTANCE.cancel(); PathingBehavior.INSTANCE.cancel();

View File

@ -18,6 +18,7 @@
package baritone.pathing.movement; package baritone.pathing.movement;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.utils.Rotation;
import baritone.behavior.LookBehavior; import baritone.behavior.LookBehavior;
import baritone.behavior.LookBehaviorUtils; import baritone.behavior.LookBehaviorUtils;
import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementStatus;

View File

@ -18,6 +18,7 @@
package baritone.pathing.movement; package baritone.pathing.movement;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.utils.Rotation;
import baritone.behavior.LookBehaviorUtils; import baritone.behavior.LookBehaviorUtils;
import baritone.pathing.movement.MovementState.MovementTarget; import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.*; import baritone.utils.*;

View File

@ -18,7 +18,7 @@
package baritone.pathing.movement; package baritone.pathing.movement;
import baritone.utils.InputOverrideHandler.Input; import baritone.utils.InputOverrideHandler.Input;
import baritone.utils.Rotation; import baritone.api.utils.Rotation;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import java.util.HashMap; import java.util.HashMap;

View File

@ -18,6 +18,7 @@
package baritone.pathing.movement.movements; package baritone.pathing.movement.movements;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.utils.Rotation;
import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement; import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;

View File

@ -23,7 +23,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.Rotation; import baritone.api.utils.Rotation;
import baritone.utils.Utils; import baritone.utils.Utils;
import baritone.utils.pathing.BetterBlockPos; import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.*; import net.minecraft.block.*;

View File

@ -25,7 +25,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.Rotation; import baritone.api.utils.Rotation;
import baritone.utils.Utils; import baritone.utils.Utils;
import baritone.utils.pathing.BetterBlockPos; import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.*; import net.minecraft.block.*;

View File

@ -368,7 +368,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
logDirect("No locations for " + mining + " known, cancelling"); logDirect("No locations for " + mining + " known, cancelling");
return; return;
} }
List<BlockPos> locs = MineBehavior.scanFor(Collections.singletonList(block), 64); List<BlockPos> locs = MineBehavior.INSTANCE.scanFor(Collections.singletonList(block), 64);
if (locs.isEmpty()) { if (locs.isEmpty()) {
logDirect("No locations for " + mining + " known, cancelling"); logDirect("No locations for " + mining + " known, cancelling");
return; return;

View File

@ -18,6 +18,7 @@
package baritone.utils; package baritone.utils;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.utils.Rotation;
import baritone.utils.pathing.BetterBlockPos; import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.BlockSlab; import net.minecraft.block.BlockSlab;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;

View File

@ -17,6 +17,7 @@
package baritone.utils; package baritone.utils;
import baritone.api.utils.Rotation;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;

View File

@ -17,6 +17,7 @@
package baritone.utils; package baritone.utils;
import baritone.api.utils.Rotation;
import net.minecraft.block.BlockFire; import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;