Move Behavior to api
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,100 +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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.behavior;
|
||||
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.interfaces.Toggleable;
|
||||
|
||||
/**
|
||||
* A generic bot behavior.
|
||||
*
|
||||
* @author Brady
|
||||
* @since 8/1/2018 6:29 PM
|
||||
*/
|
||||
public class Behavior implements AbstractGameEventListener, Toggleable, Helper {
|
||||
|
||||
/**
|
||||
* Whether or not this behavior is enabled
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Toggles the enabled state of this {@link Behavior}.
|
||||
*
|
||||
* @return The new state.
|
||||
*/
|
||||
@Override
|
||||
public final boolean toggle() {
|
||||
return this.setEnabled(!this.enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this {@link Behavior}.
|
||||
*
|
||||
* @return The new state.
|
||||
*/
|
||||
@Override
|
||||
public final boolean setEnabled(boolean enabled) {
|
||||
boolean newState = getNewState(this.enabled, enabled);
|
||||
if (newState == this.enabled) {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
if (this.enabled = newState) {
|
||||
onStart();
|
||||
} else {
|
||||
onCancel();
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
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() {}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -1,44 +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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils.interfaces;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 8/20/2018
|
||||
*/
|
||||
public interface Toggleable {
|
||||
|
||||
/**
|
||||
* Toggles the enabled state of this {@link Toggleable}.
|
||||
*
|
||||
* @return The new state.
|
||||
*/
|
||||
boolean toggle();
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this {@link Toggleable}.
|
||||
*
|
||||
* @return The new state.
|
||||
*/
|
||||
boolean setEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* @return Whether or not this {@link Toggleable} object is enabled
|
||||
*/
|
||||
boolean isEnabled();
|
||||
}
|
||||
Reference in New Issue
Block a user