This commit is contained in:
Leijurv 2018-08-05 20:07:24 -04:00
commit 6dddb2e895
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
10 changed files with 82 additions and 70 deletions

View File

@ -2,10 +2,7 @@ package baritone.bot;
import baritone.bot.behavior.Behavior;
import baritone.bot.event.IGameEventListener;
import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.ChunkEvent;
import baritone.bot.event.events.RenderEvent;
import baritone.bot.event.events.WorldEvent;
import baritone.bot.event.events.*;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;
@ -20,8 +17,8 @@ public final class GameEventHandler implements IGameEventListener {
GameEventHandler() {}
@Override
public final void onTick() {
dispatch(Behavior::onTick);
public final void onTick(TickEvent event) {
dispatch(behavior -> behavior.onTick(event));
}
@Override

View File

@ -47,7 +47,7 @@ public class Behavior implements AbstractGameEventListener, Helper {
/**
* 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 overriden by behaviors
* proposed state. Intended to be overridden by behaviors
* that should always be active, given that the bot itself is
* active.
*

View File

@ -1,9 +1,7 @@
package baritone.bot.behavior.impl;
import baritone.bot.behavior.Behavior;
import baritone.bot.utils.Utils;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import java.util.Optional;
@ -12,7 +10,7 @@ public class LookBehavior extends Behavior {
public static final LookBehavior INSTANCE = new LookBehavior();
public LookBehavior() {
target = Optional.empty();
}
/**
@ -21,12 +19,7 @@ public class LookBehavior extends Behavior {
* getFirst() -> yaw
* getSecond() -> pitch
*/
private Optional<Tuple<Float, Float>> target = Optional.empty();
public void updateTarget(BlockPos blockPos) {
Utils.calcRotationFromVec3d(player().getPositionEyes(1.0F),
Utils.calcCenterFromCoords(blockPos, world()));
}
private Optional<Tuple<Float, Float>> target;
public void updateTarget(Tuple<Float, Float> target) {
this.target = Optional.of(target);

View File

@ -3,6 +3,7 @@ package baritone.bot.behavior.impl;
import baritone.bot.behavior.Behavior;
import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.RenderEvent;
import baritone.bot.event.events.TickEvent;
import baritone.bot.pathing.calc.AStarPathFinder;
import baritone.bot.pathing.calc.AbstractNodeCostSearch;
import baritone.bot.pathing.calc.IPathFinder;
@ -23,7 +24,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import org.lwjgl.opengl.GL11;
import java.awt.*;
@ -40,12 +40,12 @@ public class PathingBehavior extends Behavior {
private Goal goal;
@Override
public void onTick() {
//System.out.println("Ticking");
public void onTick(TickEvent event) {
// System.out.println("Ticking");
if (current == null) {
return;
}
//current.onTick();
// current.onTick();
if (current.failed() || current.finished()) {
current = null;
}
@ -62,16 +62,12 @@ public class PathingBehavior extends Behavior {
return current.getPath();
}
private static void chatRaw(String s) {
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(s));
}
@Override
public void onSendChatMessage(ChatEvent event) {
String msg = event.getMessage();
if (msg.equals("goal")) {
goal = new GoalBlock(playerFeet());
chatRaw("Goal: " + goal);
displayChatMessageRaw("Goal: " + goal);
event.cancel();
return;
}
@ -90,33 +86,27 @@ public class PathingBehavior extends Behavior {
* @param talkAboutIt
*/
public void findPathInNewThread(final BlockPos start, final boolean talkAboutIt) {
new Thread() {
@Override
public void run() {
if (talkAboutIt) {
chatRaw("Starting to search for path from " + start + " to " + goal);
}
try {
IPath path = findPath(start);
if (path != null) {
current = new PathExecutor(path);
}
} catch (Exception e) {
}
/*isThereAnythingInProgress = false;
if (!currentPath.goal.isInGoal(currentPath.end)) {
if (talkAboutIt) {
Out.gui("I couldn't get all the way to " + goal + ", but I'm going to get as close as I can. " + currentPath.numNodes + " nodes considered", Out.Mode.Standard);
}
planAhead();
} else if (talkAboutIt) {
Out.gui("Finished finding a path from " + start + " to " + goal + ". " + currentPath.numNodes + " nodes considered", Out.Mode.Debug);
}*/
new Thread(() -> {
if (talkAboutIt) {
displayChatMessageRaw("Starting to search for path from " + start + " to " + goal);
}
}.start();
try {
IPath path = findPath(start);
if (path != null) {
current = new PathExecutor(path);
}
} catch (Exception ignored) {}
/*isThereAnythingInProgress = false;
if (!currentPath.goal.isInGoal(currentPath.end)) {
if (talkAboutIt) {
Out.gui("I couldn't get all the way to " + goal + ", but I'm going to get as close as I can. " + currentPath.numNodes + " nodes considered", Out.Mode.Standard);
}
planAhead();
} else if (talkAboutIt) {
Out.gui("Finished finding a path from " + start + " to " + goal + ". " + currentPath.numNodes + " nodes considered", Out.Mode.Debug);
}*/
}).start();
}
/**
@ -127,7 +117,7 @@ public class PathingBehavior extends Behavior {
*/
private IPath findPath(BlockPos start) {
if (goal == null) {
chatRaw("no goal");
displayChatMessageRaw("no goal");
return null;
}
try {
@ -184,8 +174,6 @@ public class PathingBehavior extends Behavior {
double z2 = b.getZ();
drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks);
}
//GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
@ -256,5 +244,4 @@ public class PathingBehavior extends Behavior {
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
}

View File

@ -1,13 +1,10 @@
package baritone.bot.event;
import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.ChunkEvent;
import baritone.bot.event.events.RenderEvent;
import baritone.bot.event.events.WorldEvent;
import baritone.bot.event.events.*;
/**
* An implementation of {@link IGameEventListener} that has all methods
* overriden with empty bodies, allowing inheritors of this class to choose
* overridden with empty bodies, allowing inheritors of this class to choose
* which events they would like to listen in on.
*
* Has no implementors at the moment, but will likely be used with the
@ -21,7 +18,7 @@ import baritone.bot.event.events.WorldEvent;
public interface AbstractGameEventListener extends IGameEventListener {
@Override
default void onTick() {}
default void onTick(TickEvent event) {}
@Override
default void onPlayerUpdate() {}

View File

@ -1,9 +1,6 @@
package baritone.bot.event;
import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.ChunkEvent;
import baritone.bot.event.events.RenderEvent;
import baritone.bot.event.events.WorldEvent;
import baritone.bot.event.events.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
@ -21,7 +18,7 @@ public interface IGameEventListener {
*
* @see Minecraft#runTick()
*/
void onTick();
void onTick(TickEvent event);
/**
* Run once per game tick from before the player rotation is sent to the server.

View File

@ -0,0 +1,29 @@
package baritone.bot.event.events;
import baritone.bot.event.events.type.EventState;
import javafx.event.EventType;
public final class TickEvent {
private final EventState state;
private final Type type;
public TickEvent(EventState state, Type type) {
this.state = state;
this.type = type;
}
public enum Type {
/**
* When guarantees can be made about
* the game state and in-game variables.
*/
IN,
/**
* No guarantees can be made about the game state.
* This probably means we are at the main menu.
*/
OUT,
}
}

View File

@ -1,6 +1,7 @@
package baritone.bot.pathing.path;
import baritone.bot.behavior.Behavior;
import baritone.bot.event.events.TickEvent;
import baritone.bot.pathing.movement.ActionCosts;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.MovementState;
@ -33,7 +34,8 @@ public class PathExecutor extends Behavior {
this.pathPosition = 0;
}
public void onTick() {
@Override
public void onTick(TickEvent event) {
if (pathPosition >= path.length()) {
//stop bugging me, I'm done
//TODO Baritone.INSTANCE.behaviors.remove(this)

View File

@ -4,7 +4,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.util.text.TextComponentString;
/**
* @author Brady
@ -18,7 +18,7 @@ public interface Helper {
return mc.player;
}
default World world() {
default WorldClient world() {
return mc.world;
}
@ -26,4 +26,7 @@ public interface Helper {
return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ);
}
default void displayChatMessageRaw(String message) {
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(message));
}
}

View File

@ -1,6 +1,7 @@
package baritone.launch.mixins;
import baritone.bot.Baritone;
import baritone.bot.event.events.TickEvent;
import baritone.bot.event.events.WorldEvent;
import baritone.bot.event.events.type.EventState;
import net.minecraft.client.Minecraft;
@ -47,7 +48,13 @@ public class MixinMinecraft {
)
)
private void runTick(CallbackInfo ci) {
Baritone.INSTANCE.getGameEventHandler().onTick();
Minecraft mc = (Minecraft) (Object) this;
Baritone.INSTANCE.getGameEventHandler().onTick(new TickEvent(
EventState.PRE,
(mc.player != null && mc.world != null)
? TickEvent.Type.IN
: TickEvent.Type.OUT
));
}
@Redirect(