path event
This commit is contained in:
parent
90316b3359
commit
28be7121e3
@ -19,6 +19,7 @@ package baritone.behavior.impl;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
|
import baritone.event.events.PathEvent;
|
||||||
import baritone.event.events.PlayerUpdateEvent;
|
import baritone.event.events.PlayerUpdateEvent;
|
||||||
import baritone.event.events.RenderEvent;
|
import baritone.event.events.RenderEvent;
|
||||||
import baritone.event.events.TickEvent;
|
import baritone.event.events.TickEvent;
|
||||||
@ -59,6 +60,14 @@ public class PathingBehavior extends Behavior {
|
|||||||
|
|
||||||
private boolean lastAutoJump;
|
private boolean lastAutoJump;
|
||||||
|
|
||||||
|
private void dispatchPathEvent(PathEvent event) {
|
||||||
|
new Thread() {
|
||||||
|
public void run() {
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onPathEvent(event);
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick(TickEvent event) {
|
public void onTick(TickEvent event) {
|
||||||
if (event.getType() == TickEvent.Type.OUT) {
|
if (event.getType() == TickEvent.Type.OUT) {
|
||||||
@ -74,6 +83,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
current = null;
|
current = null;
|
||||||
if (goal == null || goal.isInGoal(playerFeet())) {
|
if (goal == null || goal.isInGoal(playerFeet())) {
|
||||||
displayChatMessageRaw("All done. At " + goal);
|
displayChatMessageRaw("All done. At " + goal);
|
||||||
|
dispatchPathEvent(PathEvent.AT_GOAL);
|
||||||
next = null;
|
next = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -85,10 +95,12 @@ public class PathingBehavior extends Behavior {
|
|||||||
// but if we fail in the middle of current
|
// but if we fail in the middle of current
|
||||||
// we're nowhere close to our planned ahead path
|
// we're nowhere close to our planned ahead path
|
||||||
// so need to discard it sadly.
|
// so need to discard it sadly.
|
||||||
|
dispatchPathEvent(PathEvent.DISCARD_NEXT);
|
||||||
next = null;
|
next = null;
|
||||||
}
|
}
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
displayChatMessageRaw("Continuing on to planned next path");
|
displayChatMessageRaw("Continuing on to planned next path");
|
||||||
|
dispatchPathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT);
|
||||||
current = next;
|
current = next;
|
||||||
next = null;
|
next = null;
|
||||||
return;
|
return;
|
||||||
@ -96,9 +108,11 @@ public class PathingBehavior extends Behavior {
|
|||||||
// at this point, current just ended, but we aren't in the goal and have no plan for the future
|
// at this point, current just ended, but we aren't in the goal and have no plan for the future
|
||||||
synchronized (pathCalcLock) {
|
synchronized (pathCalcLock) {
|
||||||
if (isPathCalcInProgress) {
|
if (isPathCalcInProgress) {
|
||||||
|
dispatchPathEvent(PathEvent.PATH_FINISHED_NEXT_STILL_CALCULATING);
|
||||||
// if we aren't calculating right now
|
// if we aren't calculating right now
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
dispatchPathEvent(PathEvent.CALC_STARTED);
|
||||||
findPathInNewThread(pathStart(), true, Optional.empty());
|
findPathInNewThread(pathStart(), true, Optional.empty());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -110,6 +124,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
if (next.getPath().positions().contains(playerFeet())) {
|
if (next.getPath().positions().contains(playerFeet())) {
|
||||||
// jump directly onto the next path
|
// jump directly onto the next path
|
||||||
displayChatMessageRaw("Splicing into planned next path early...");
|
displayChatMessageRaw("Splicing into planned next path early...");
|
||||||
|
dispatchPathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
|
||||||
current = next;
|
current = next;
|
||||||
next = null;
|
next = null;
|
||||||
return;
|
return;
|
||||||
@ -132,6 +147,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) {
|
if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) {
|
||||||
// and this path has 5 seconds or less left
|
// and this path has 5 seconds or less left
|
||||||
displayChatMessageRaw("Path almost over. Planning ahead...");
|
displayChatMessageRaw("Path almost over. Planning ahead...");
|
||||||
|
dispatchPathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED);
|
||||||
findPathInNewThread(current.getPath().getDest(), false, Optional.of(current.getPath()));
|
findPathInNewThread(current.getPath().getDest(), false, Optional.of(current.getPath()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,6 +208,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
if (isPathCalcInProgress) {
|
if (isPathCalcInProgress) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
dispatchPathEvent(PathEvent.CALC_STARTED);
|
||||||
findPathInNewThread(pathStart(), true, Optional.empty());
|
findPathInNewThread(pathStart(), true, Optional.empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,19 +244,29 @@ public class PathingBehavior extends Behavior {
|
|||||||
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
|
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
|
||||||
path = path.map(IPath::cutoffAtLoadedChunks);
|
path = path.map(IPath::cutoffAtLoadedChunks);
|
||||||
}
|
}
|
||||||
path.map(p -> p.staticCutoff(goal)).map(PathExecutor::new).ifPresent(p -> {
|
Optional<PathExecutor> executor = path.map(p -> p.staticCutoff(goal)).map(PathExecutor::new);
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
current = p;
|
if (executor.isPresent()) {
|
||||||
|
dispatchPathEvent(PathEvent.CALC_FINISHED_NOW_EXECUTING);
|
||||||
|
current = executor.get();
|
||||||
} else {
|
} else {
|
||||||
if (next == null) {
|
dispatchPathEvent(PathEvent.CALC_FAILED);
|
||||||
next = p;
|
}
|
||||||
|
} else {
|
||||||
|
if (next == null) {
|
||||||
|
if (executor.isPresent()) {
|
||||||
|
dispatchPathEvent(PathEvent.NEXT_SEGMENT_CALC_FINISHED);
|
||||||
|
next = executor.get();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("I have no idea what to do with this path");
|
dispatchPathEvent(PathEvent.NEXT_CALC_FAILED);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("I have no idea what to do with this path");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (talkAboutIt && current != null && current.getPath() != null) {
|
if (talkAboutIt && current != null && current.getPath() != null) {
|
||||||
if (goal == null || goal.isInGoal(current.getPath().getDest())) {
|
if (goal == null || goal.isInGoal(current.getPath().getDest())) {
|
||||||
displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
|
displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
|
||||||
|
@ -42,10 +42,6 @@ import baritone.event.listener.IGameEventListener;
|
|||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import baritone.utils.interfaces.Toggleable;
|
import baritone.utils.interfaces.Toggleable;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
@ -181,6 +177,11 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
dispatch(IGameEventListener::onPlayerDeath);
|
dispatch(IGameEventListener::onPlayerDeath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPathEvent(PathEvent event) {
|
||||||
|
dispatch(listener -> listener.onPathEvent(event));
|
||||||
|
}
|
||||||
|
|
||||||
public final void registerEventListener(IGameEventListener listener) {
|
public final void registerEventListener(IGameEventListener listener) {
|
||||||
this.listeners.add(listener);
|
this.listeners.add(listener);
|
||||||
}
|
}
|
||||||
@ -192,27 +193,4 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
private boolean canDispatch(IGameEventListener listener) {
|
private boolean canDispatch(IGameEventListener listener) {
|
||||||
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
|
return !(listener instanceof Toggleable) || ((Toggleable) listener).isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawChunkLine(int posX, int posZ, float partialTicks) {
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
||||||
GlStateManager.color(1.0F, 1.0F, 0.0F, 0.4F);
|
|
||||||
GlStateManager.glLineWidth(2.0F);
|
|
||||||
GlStateManager.disableTexture2D();
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
double d0 = mc.getRenderManager().viewerPosX;
|
|
||||||
double d1 = mc.getRenderManager().viewerPosY;
|
|
||||||
double d2 = mc.getRenderManager().viewerPosZ;
|
|
||||||
buffer.begin(3, DefaultVertexFormats.POSITION);
|
|
||||||
buffer.pos(posX - d0, 0 - d1, posZ - d2).endVertex();
|
|
||||||
buffer.pos(posX - d0, 256 - d1, posZ - d2).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
|
|
||||||
GlStateManager.enableDepth();
|
|
||||||
GlStateManager.depthMask(true);
|
|
||||||
GlStateManager.enableTexture2D();
|
|
||||||
GlStateManager.disableBlend();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
22
src/main/java/baritone/event/events/PathEvent.java
Normal file
22
src/main/java/baritone/event/events/PathEvent.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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.event.events;
|
||||||
|
|
||||||
|
public enum PathEvent {
|
||||||
|
CALC_STARTED, CALC_FINISHED_NOW_EXECUTING, CALC_FAILED, NEXT_SEGMENT_CALC_STARTED, NEXT_SEGMENT_CALC_FINISHED, CONTINUING_ONTO_PLANNED_NEXT, SPLICING_ONTO_NEXT_EARLY, AT_GOAL, PATH_FINISHED_NEXT_STILL_CALCULATING, NEXT_CALC_FAILED, DISCARD_NEXT;
|
||||||
|
}
|
@ -41,9 +41,8 @@ import baritone.event.events.*;
|
|||||||
* overridden 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.
|
* which events they would like to listen in on.
|
||||||
*
|
*
|
||||||
* @see IGameEventListener
|
|
||||||
*
|
|
||||||
* @author Brady
|
* @author Brady
|
||||||
|
* @see IGameEventListener
|
||||||
* @since 8/1/2018 6:29 PM
|
* @since 8/1/2018 6:29 PM
|
||||||
*/
|
*/
|
||||||
public interface AbstractGameEventListener extends IGameEventListener {
|
public interface AbstractGameEventListener extends IGameEventListener {
|
||||||
@ -86,4 +85,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onPlayerDeath() {}
|
default void onPlayerDeath() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onPathEvent(PathEvent event) {}
|
||||||
}
|
}
|
||||||
|
@ -149,4 +149,11 @@ public interface IGameEventListener {
|
|||||||
* @see GuiGameOver(ITextComponent)
|
* @see GuiGameOver(ITextComponent)
|
||||||
*/
|
*/
|
||||||
void onPlayerDeath();
|
void onPlayerDeath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the pathfinder's state changes
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
void onPathEvent(PathEvent event);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user