merge
This commit is contained in:
commit
6dddb2e895
@ -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
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
|
@ -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,7 +40,7 @@ public class PathingBehavior extends Behavior {
|
||||
private Goal goal;
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
public void onTick(TickEvent event) {
|
||||
// System.out.println("Ticking");
|
||||
if (current == null) {
|
||||
return;
|
||||
@ -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,13 +86,9 @@ public class PathingBehavior extends Behavior {
|
||||
* @param talkAboutIt
|
||||
*/
|
||||
public void findPathInNewThread(final BlockPos start, final boolean talkAboutIt) {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Thread(() -> {
|
||||
if (talkAboutIt) {
|
||||
|
||||
chatRaw("Starting to search for path from " + start + " to " + goal);
|
||||
displayChatMessageRaw("Starting to search for path from " + start + " to " + goal);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -104,8 +96,7 @@ public class PathingBehavior extends Behavior {
|
||||
if (path != null) {
|
||||
current = new PathExecutor(path);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
/*isThereAnythingInProgress = false;
|
||||
if (!currentPath.goal.isInGoal(currentPath.end)) {
|
||||
if (talkAboutIt) {
|
||||
@ -115,8 +106,7 @@ public class PathingBehavior extends Behavior {
|
||||
} else if (talkAboutIt) {
|
||||
Out.gui("Finished finding a path from " + start + " to " + goal + ". " + currentPath.numNodes + " nodes considered", Out.Mode.Debug);
|
||||
}*/
|
||||
}
|
||||
}.start();
|
||||
}).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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {}
|
||||
|
@ -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.
|
||||
|
29
src/main/java/baritone/bot/event/events/TickEvent.java
Normal file
29
src/main/java/baritone/bot/event/events/TickEvent.java
Normal 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,
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user