Move Behavior to api
This commit is contained in:
parent
fb8ee44447
commit
0a0209d2e1
@ -15,19 +15,18 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.behavior;
|
||||
package baritone.api.behavior;
|
||||
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.interfaces.Toggleable;
|
||||
import baritone.api.utils.interfaces.Toggleable;
|
||||
|
||||
/**
|
||||
* A generic bot behavior.
|
||||
* 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, Helper {
|
||||
public class Behavior implements AbstractGameEventListener, Toggleable {
|
||||
|
||||
/**
|
||||
* Whether or not this behavior is enabled
|
||||
@ -51,35 +50,18 @@ public class Behavior implements AbstractGameEventListener, Toggleable, Helper {
|
||||
*/
|
||||
@Override
|
||||
public final boolean setEnabled(boolean enabled) {
|
||||
boolean newState = getNewState(this.enabled, enabled);
|
||||
if (newState == this.enabled) {
|
||||
if (enabled == this.enabled)
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
if (this.enabled = newState) {
|
||||
onStart();
|
||||
if (this.enabled = enabled) {
|
||||
this.onEnable();
|
||||
} else {
|
||||
onCancel();
|
||||
this.onDisable();
|
||||
}
|
||||
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to determine what the new enabled state of this
|
||||
* {@link Behavior} should be given the old state, and the
|
||||
* proposed state. Intended to be overridden by behaviors
|
||||
* that should always be active, given that the bot itself is
|
||||
* active.
|
||||
*
|
||||
* @param oldState The old state
|
||||
* @param proposedState The proposed state
|
||||
* @return The new state
|
||||
*/
|
||||
public boolean getNewState(boolean oldState, boolean proposedState) {
|
||||
return proposedState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not this {@link Behavior} is active.
|
||||
*/
|
||||
@ -87,14 +69,4 @@ public class Behavior implements AbstractGameEventListener, Toggleable, Helper {
|
||||
public final boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the state changes from disabled to enabled
|
||||
*/
|
||||
public void onStart() {}
|
||||
|
||||
/**
|
||||
* Called when the state changes from enabled to disabled
|
||||
*/
|
||||
public void onCancel() {}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils.interfaces;
|
||||
package baritone.api.utils.interfaces;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@ -41,4 +41,14 @@ public interface Toggleable {
|
||||
* @return Whether or not this {@link Toggleable} object is enabled
|
||||
*/
|
||||
boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Called when the state changes from disabled to enabled
|
||||
*/
|
||||
default void onEnable() {}
|
||||
|
||||
/**
|
||||
* Called when the state changes from enabled to disabled
|
||||
*/
|
||||
default void onDisable() {}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
package baritone;
|
||||
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.behavior.impl.*;
|
||||
import baritone.event.GameEventHandler;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
|
@ -18,7 +18,7 @@
|
||||
package baritone.behavior.impl;
|
||||
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.pathing.goals.GoalNear;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -17,11 +17,12 @@
|
||||
|
||||
package baritone.behavior.impl;
|
||||
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.cache.Waypoint;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.api.event.events.BlockInteractEvent;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.block.BlockBed;
|
||||
|
||||
/**
|
||||
@ -33,7 +34,7 @@ import net.minecraft.block.BlockBed;
|
||||
* @author Brady
|
||||
* @since 8/22/2018
|
||||
*/
|
||||
public final class LocationTrackingBehavior extends Behavior {
|
||||
public final class LocationTrackingBehavior extends Behavior implements Helper {
|
||||
|
||||
public static final LocationTrackingBehavior INSTANCE = new LocationTrackingBehavior();
|
||||
|
||||
|
@ -21,10 +21,11 @@ import baritone.Baritone;
|
||||
import baritone.Settings;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.RotationMoveEvent;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.Rotation;
|
||||
|
||||
public class LookBehavior extends Behavior {
|
||||
public class LookBehavior extends Behavior implements Helper {
|
||||
|
||||
public static final LookBehavior INSTANCE = new LookBehavior();
|
||||
|
||||
|
@ -3,7 +3,8 @@ package baritone.behavior.impl;
|
||||
import baritone.api.event.events.PacketEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.client.CPacketCloseWindow;
|
||||
@ -20,7 +21,7 @@ import java.util.*;
|
||||
* @author Brady
|
||||
* @since 8/6/2018 9:47 PM
|
||||
*/
|
||||
public class MemoryBehavior extends Behavior {
|
||||
public class MemoryBehavior extends Behavior implements Helper {
|
||||
|
||||
public static MemoryBehavior INSTANCE = new MemoryBehavior();
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
package baritone.behavior.impl;
|
||||
|
||||
import baritone.api.event.events.PathEvent;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.cache.CachedChunk;
|
||||
import baritone.cache.ChunkPacker;
|
||||
import baritone.cache.WorldProvider;
|
||||
@ -27,6 +27,7 @@ import baritone.pathing.goals.Goal;
|
||||
import baritone.pathing.goals.GoalComposite;
|
||||
import baritone.pathing.goals.GoalTwoBlocks;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
@ -42,7 +43,8 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class MineBehavior extends Behavior {
|
||||
public class MineBehavior extends Behavior implements Helper {
|
||||
|
||||
public static final MineBehavior INSTANCE = new MineBehavior();
|
||||
|
||||
private MineBehavior() {
|
||||
|
@ -22,7 +22,7 @@ import baritone.api.event.events.PathEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.RenderEvent;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.pathing.calc.AStarPathFinder;
|
||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
import baritone.pathing.calc.IPathFinder;
|
||||
@ -31,6 +31,7 @@ import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.path.IPath;
|
||||
import baritone.pathing.path.PathExecutor;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.PathRenderer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -40,7 +41,7 @@ import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class PathingBehavior extends Behavior {
|
||||
public final class PathingBehavior extends Behavior implements Helper {
|
||||
|
||||
public static final PathingBehavior INSTANCE = new PathingBehavior();
|
||||
|
||||
|
@ -25,7 +25,7 @@ import baritone.cache.WorldProvider;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.interfaces.Toggleable;
|
||||
import baritone.api.utils.interfaces.Toggleable;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
@ -20,7 +20,7 @@ package baritone.utils;
|
||||
import baritone.Baritone;
|
||||
import baritone.Settings;
|
||||
import baritone.api.event.events.ChatEvent;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.api.behavior.Behavior;
|
||||
import baritone.behavior.impl.FollowBehavior;
|
||||
import baritone.behavior.impl.MineBehavior;
|
||||
import baritone.behavior.impl.PathingBehavior;
|
||||
@ -41,7 +41,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ExampleBaritoneControl extends Behavior {
|
||||
public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
|
||||
public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl();
|
||||
|
||||
private ExampleBaritoneControl() {
|
||||
|
Loading…
Reference in New Issue
Block a user