waypoint convenience methods
This commit is contained in:
parent
bde507cac6
commit
3ce764a472
@ -19,6 +19,8 @@ package baritone.chunk;
|
|||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -61,14 +63,28 @@ public class Waypoint {
|
|||||||
return name.hashCode() + tag.hashCode() + (int) creationTimestamp + location.hashCode(); //lol
|
return name.hashCode() + tag.hashCode() + (int) creationTimestamp + location.hashCode(); //lol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long creationTimestamp() {
|
||||||
|
return creationTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return name + " " + location.toString() + " " + new Date(creationTimestamp).toString();
|
||||||
|
}
|
||||||
|
|
||||||
public enum Tag {
|
public enum Tag {
|
||||||
HOME, DEATH, BED, USER;
|
HOME, DEATH, BED, USER;
|
||||||
|
|
||||||
{
|
|
||||||
map.put(name().toLowerCase(), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, Tag> map = new HashMap<>();
|
public static final Map<String, Tag> TAG_MAP;
|
||||||
|
|
||||||
|
static {
|
||||||
|
HashMap<String, Tag> map = new HashMap<>();
|
||||||
|
map.put("home", Tag.HOME);
|
||||||
|
map.put("base", Tag.HOME);
|
||||||
|
map.put("bed", Tag.BED);
|
||||||
|
map.put("spawn", Tag.BED);
|
||||||
|
map.put("death", Tag.DEATH);
|
||||||
|
TAG_MAP = Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,7 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ExampleBaritoneControl extends Behavior {
|
public class ExampleBaritoneControl extends Behavior {
|
||||||
public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl();
|
public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl();
|
||||||
@ -115,6 +112,53 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (msg.toLowerCase().startsWith("list") || msg.toLowerCase().startsWith("get ") || msg.toLowerCase().startsWith("show")) {
|
||||||
|
String waypointType = msg.toLowerCase().substring(4).trim();
|
||||||
|
if (waypointType.endsWith("s")) {
|
||||||
|
// for example, "show deaths"
|
||||||
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||||
|
}
|
||||||
|
Waypoint.Tag tag = Waypoint.TAG_MAP.get(waypointType);
|
||||||
|
if (tag == null) {
|
||||||
|
displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
|
event.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<Waypoint> waypoints = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getByTag(tag);
|
||||||
|
// might as well show them from oldest to newest
|
||||||
|
List<Waypoint> sorted = new ArrayList<>(waypoints);
|
||||||
|
sorted.sort(Comparator.comparingLong(Waypoint::creationTimestamp).reversed());
|
||||||
|
displayChatMessageRaw("Waypoints under tag " + tag + ":");
|
||||||
|
for (Waypoint waypoint : sorted) {
|
||||||
|
displayChatMessageRaw(waypoint.toString());
|
||||||
|
}
|
||||||
|
event.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (msg.toLowerCase().startsWith("goto")) {
|
||||||
|
String waypointType = msg.toLowerCase().substring(4).trim();
|
||||||
|
if (waypointType.endsWith("s")) {
|
||||||
|
// for example, "show deaths"
|
||||||
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||||
|
}
|
||||||
|
Waypoint.Tag tag = Waypoint.TAG_MAP.get(waypointType);
|
||||||
|
if (tag == null) {
|
||||||
|
displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
|
event.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag);
|
||||||
|
if (waypoint == null) {
|
||||||
|
displayChatMessageRaw("None saved for tag " + tag);
|
||||||
|
event.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Goal goal = new GoalBlock(waypoint.location);
|
||||||
|
PathingBehavior.INSTANCE.setGoal(goal);
|
||||||
|
PathingBehavior.INSTANCE.path();
|
||||||
|
event.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (msg.toLowerCase().equals("spawn") || msg.toLowerCase().equals("bed")) {
|
if (msg.toLowerCase().equals("spawn") || msg.toLowerCase().equals("bed")) {
|
||||||
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.BED);
|
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.BED);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user