2018-08-14 03:57:29 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
2018-09-17 22:11:40 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2018-08-14 03:57:29 +00:00
|
|
|
* 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
|
2018-09-17 22:11:40 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-08-14 03:57:29 +00:00
|
|
|
*
|
2018-09-17 22:11:40 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2018-08-14 03:57:29 +00:00
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-22 20:15:56 +00:00
|
|
|
package baritone.utils;
|
|
|
|
|
|
|
|
import baritone.Baritone;
|
2018-09-23 23:35:55 +00:00
|
|
|
import baritone.api.Settings;
|
2018-09-24 17:48:00 +00:00
|
|
|
import baritone.api.cache.IWaypoint;
|
2018-09-24 01:00:54 +00:00
|
|
|
import baritone.api.event.events.ChatEvent;
|
2018-09-25 01:32:39 +00:00
|
|
|
import baritone.api.pathing.goals.*;
|
|
|
|
import baritone.api.pathing.movement.ActionCosts;
|
2018-10-14 05:55:30 +00:00
|
|
|
import baritone.api.utils.RayTraceUtils;
|
2018-10-09 01:05:08 +00:00
|
|
|
import baritone.api.utils.SettingsUtil;
|
2018-09-23 21:50:18 +00:00
|
|
|
import baritone.behavior.Behavior;
|
2018-09-12 22:58:33 +00:00
|
|
|
import baritone.behavior.FollowBehavior;
|
|
|
|
import baritone.behavior.MineBehavior;
|
|
|
|
import baritone.behavior.PathingBehavior;
|
2018-09-11 17:28:03 +00:00
|
|
|
import baritone.cache.ChunkPacker;
|
|
|
|
import baritone.cache.Waypoint;
|
|
|
|
import baritone.cache.WorldProvider;
|
2018-09-01 21:45:57 +00:00
|
|
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
2018-09-27 23:11:55 +00:00
|
|
|
import baritone.pathing.movement.Movement;
|
|
|
|
import baritone.pathing.movement.Moves;
|
2018-08-23 19:54:12 +00:00
|
|
|
import net.minecraft.block.Block;
|
2018-09-16 20:43:54 +00:00
|
|
|
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
2018-08-28 02:05:21 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2018-09-17 17:56:37 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2018-08-14 03:57:29 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-09-16 20:43:54 +00:00
|
|
|
import net.minecraft.world.chunk.Chunk;
|
2018-08-14 03:57:29 +00:00
|
|
|
|
2018-08-23 16:54:29 +00:00
|
|
|
import java.util.*;
|
2018-09-24 01:00:54 +00:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
2018-08-14 22:04:41 +00:00
|
|
|
|
2018-09-13 16:15:50 +00:00
|
|
|
public class ExampleBaritoneControl extends Behavior implements Helper {
|
2018-09-12 22:53:29 +00:00
|
|
|
|
2018-08-14 03:57:29 +00:00
|
|
|
public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl();
|
|
|
|
|
|
|
|
private ExampleBaritoneControl() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initAndRegister() {
|
|
|
|
Baritone.INSTANCE.registerBehavior(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSendChatMessage(ChatEvent event) {
|
2018-10-27 21:41:25 +00:00
|
|
|
if (!Baritone.settings().chatControl.get() && !Baritone.settings().removePrefix.get()) {
|
|
|
|
return;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
String msg = event.getMessage();
|
2018-08-24 03:12:36 +00:00
|
|
|
if (Baritone.settings().prefix.get()) {
|
|
|
|
if (!msg.startsWith("#")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg = msg.substring(1);
|
|
|
|
}
|
2018-10-16 18:13:08 +00:00
|
|
|
if (runCommand(msg)) {
|
|
|
|
event.cancel();
|
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
}
|
2018-09-17 17:38:37 +00:00
|
|
|
|
2018-10-27 21:41:25 +00:00
|
|
|
public boolean runCommand(String msg0) {
|
|
|
|
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
2018-09-17 17:38:37 +00:00
|
|
|
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
|
|
|
for (Settings.Setting<Boolean> setting : toggleable) {
|
|
|
|
if (msg.equalsIgnoreCase(setting.getName())) {
|
|
|
|
setting.value ^= true;
|
|
|
|
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
2018-10-09 01:05:08 +00:00
|
|
|
SettingsUtil.save(Baritone.settings());
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-17 17:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg.equals("baritone") || msg.equals("settings")) {
|
|
|
|
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
|
|
|
logDirect(setting.toString());
|
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-17 17:38:37 +00:00
|
|
|
}
|
|
|
|
if (msg.contains(" ")) {
|
|
|
|
String[] data = msg.split(" ");
|
|
|
|
if (data.length == 2) {
|
|
|
|
Settings.Setting setting = Baritone.settings().byLowerName.get(data[0]);
|
|
|
|
if (setting != null) {
|
|
|
|
try {
|
|
|
|
if (setting.value.getClass() == Long.class) {
|
|
|
|
setting.value = Long.parseLong(data[1]);
|
|
|
|
}
|
|
|
|
if (setting.value.getClass() == Integer.class) {
|
|
|
|
setting.value = Integer.parseInt(data[1]);
|
|
|
|
}
|
|
|
|
if (setting.value.getClass() == Double.class) {
|
|
|
|
setting.value = Double.parseDouble(data[1]);
|
|
|
|
}
|
|
|
|
if (setting.value.getClass() == Float.class) {
|
|
|
|
setting.value = Float.parseFloat(data[1]);
|
|
|
|
}
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
logDirect("Unable to parse " + data[1]);
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-17 17:38:37 +00:00
|
|
|
}
|
2018-10-09 01:05:08 +00:00
|
|
|
SettingsUtil.save(Baritone.settings());
|
2018-09-17 17:38:37 +00:00
|
|
|
logDirect(setting.toString());
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-17 17:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Baritone.settings().byLowerName.containsKey(msg)) {
|
|
|
|
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg);
|
|
|
|
logDirect(setting.toString());
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-17 17:38:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.startsWith("goal")) {
|
|
|
|
String[] params = msg.substring(4).trim().split(" ");
|
2018-08-14 03:57:29 +00:00
|
|
|
if (params[0].equals("")) {
|
|
|
|
params = new String[]{};
|
|
|
|
}
|
|
|
|
Goal goal;
|
|
|
|
try {
|
|
|
|
switch (params.length) {
|
|
|
|
case 0:
|
|
|
|
goal = new GoalBlock(playerFeet());
|
|
|
|
break;
|
|
|
|
case 1:
|
2018-08-16 23:51:43 +00:00
|
|
|
if (params[0].equals("clear") || params[0].equals("none")) {
|
|
|
|
goal = null;
|
|
|
|
} else {
|
|
|
|
goal = new GoalYLevel(Integer.parseInt(params[0]));
|
|
|
|
}
|
2018-08-14 03:57:29 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
goal = new GoalXZ(Integer.parseInt(params[0]), Integer.parseInt(params[1]));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2])));
|
|
|
|
break;
|
|
|
|
default:
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("unable to understand lol");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
|
|
|
} catch (NumberFormatException ex) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("unable to parse integer " + ex);
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
|
|
|
PathingBehavior.INSTANCE.setGoal(goal);
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Goal: " + goal);
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
|
|
|
if (msg.equals("path")) {
|
2018-08-28 18:43:28 +00:00
|
|
|
if (!PathingBehavior.INSTANCE.path()) {
|
2018-09-04 22:53:11 +00:00
|
|
|
if (PathingBehavior.INSTANCE.getGoal() == null) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("No goal.");
|
2018-09-04 22:53:11 +00:00
|
|
|
} else {
|
2018-09-09 20:09:56 +00:00
|
|
|
if (PathingBehavior.INSTANCE.getGoal().isInGoal(playerFeet())) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Already in goal");
|
2018-09-09 20:09:56 +00:00
|
|
|
} else {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Currently executing a path. Please cancel it first.");
|
2018-09-09 20:09:56 +00:00
|
|
|
}
|
2018-09-04 22:53:11 +00:00
|
|
|
}
|
2018-08-28 18:43:28 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
2018-09-16 20:43:54 +00:00
|
|
|
if (msg.equals("repack") || msg.equals("rescan")) {
|
|
|
|
ChunkProviderClient cli = world().getChunkProvider();
|
|
|
|
int playerChunkX = playerFeet().getX() >> 4;
|
|
|
|
int playerChunkZ = playerFeet().getZ() >> 4;
|
|
|
|
int count = 0;
|
|
|
|
for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) {
|
|
|
|
for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) {
|
|
|
|
Chunk chunk = cli.getLoadedChunk(x, z);
|
|
|
|
if (chunk != null) {
|
|
|
|
count++;
|
2018-09-24 23:45:41 +00:00
|
|
|
WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().queueForPacking(chunk);
|
2018-09-16 20:43:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logDirect("Queued " + count + " chunks for repacking");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-16 20:43:54 +00:00
|
|
|
}
|
2018-09-15 19:51:37 +00:00
|
|
|
if (msg.equals("axis")) {
|
|
|
|
PathingBehavior.INSTANCE.setGoal(new GoalAxis());
|
|
|
|
PathingBehavior.INSTANCE.path();
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-15 19:51:37 +00:00
|
|
|
}
|
2018-09-27 23:11:55 +00:00
|
|
|
if (msg.equals("cancel") || msg.equals("stop")) {
|
2018-08-28 18:43:28 +00:00
|
|
|
MineBehavior.INSTANCE.cancel();
|
2018-09-14 16:21:52 +00:00
|
|
|
FollowBehavior.INSTANCE.cancel();
|
|
|
|
PathingBehavior.INSTANCE.cancel();
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("ok canceled");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-25 22:09:47 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.equals("forcecancel")) {
|
2018-09-24 16:57:06 +00:00
|
|
|
MineBehavior.INSTANCE.cancel();
|
|
|
|
FollowBehavior.INSTANCE.cancel();
|
|
|
|
PathingBehavior.INSTANCE.cancel();
|
2018-09-01 21:45:57 +00:00
|
|
|
AbstractNodeCostSearch.forceCancel();
|
2018-09-24 16:57:06 +00:00
|
|
|
PathingBehavior.INSTANCE.forceCancel();
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("ok force canceled");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-01 21:45:57 +00:00
|
|
|
}
|
2018-09-22 15:47:02 +00:00
|
|
|
if (msg.equals("gc")) {
|
|
|
|
System.gc();
|
|
|
|
logDirect("Called System.gc();");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-22 15:47:02 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.equals("invert")) {
|
2018-08-25 22:09:47 +00:00
|
|
|
Goal goal = PathingBehavior.INSTANCE.getGoal();
|
|
|
|
BlockPos runAwayFrom;
|
|
|
|
if (goal instanceof GoalXZ) {
|
|
|
|
runAwayFrom = new BlockPos(((GoalXZ) goal).getX(), 0, ((GoalXZ) goal).getZ());
|
|
|
|
} else if (goal instanceof GoalBlock) {
|
|
|
|
runAwayFrom = ((GoalBlock) goal).getGoalPos();
|
|
|
|
} else {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Goal must be GoalXZ or GoalBlock to invert");
|
|
|
|
logDirect("Inverting goal of player feet");
|
2018-08-25 22:09:47 +00:00
|
|
|
runAwayFrom = playerFeet();
|
|
|
|
}
|
|
|
|
PathingBehavior.INSTANCE.setGoal(new GoalRunAway(1, runAwayFrom) {
|
|
|
|
@Override
|
|
|
|
public boolean isInGoal(BlockPos pos) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2018-08-28 18:43:28 +00:00
|
|
|
if (!PathingBehavior.INSTANCE.path()) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Currently executing a path. Please cancel it first.");
|
2018-08-28 18:43:28 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-28 02:05:21 +00:00
|
|
|
}
|
2018-09-17 17:56:37 +00:00
|
|
|
if (msg.startsWith("follow")) {
|
|
|
|
String name = msg.substring(6).trim();
|
|
|
|
Optional<Entity> toFollow = Optional.empty();
|
|
|
|
if (name.length() == 0) {
|
2018-10-14 05:55:30 +00:00
|
|
|
toFollow = RayTraceUtils.getSelectedEntity();
|
2018-09-17 17:56:37 +00:00
|
|
|
} else {
|
|
|
|
for (EntityPlayer pl : world().playerEntities) {
|
|
|
|
String theirName = pl.getName().trim().toLowerCase();
|
2018-10-27 21:41:25 +00:00
|
|
|
if (!theirName.equals(player().getName().trim().toLowerCase()) && (theirName.contains(name) || name.contains(theirName))) { // don't follow ourselves lol
|
|
|
|
toFollow = Optional.of(pl);
|
2018-09-17 17:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!toFollow.isPresent()) {
|
|
|
|
logDirect("Not found");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-28 02:05:21 +00:00
|
|
|
}
|
2018-09-17 17:56:37 +00:00
|
|
|
FollowBehavior.INSTANCE.follow(toFollow.get());
|
|
|
|
logDirect("Following " + toFollow.get());
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.equals("reloadall")) {
|
2018-09-24 23:45:41 +00:00
|
|
|
WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().reloadAllFromDisk();
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("ok");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 19:54:12 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.equals("saveall")) {
|
2018-09-24 23:45:41 +00:00
|
|
|
WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().save();
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("ok");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 19:54:12 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.startsWith("find")) {
|
|
|
|
String blockType = msg.substring(4).trim();
|
2018-09-24 23:45:41 +00:00
|
|
|
LinkedList<BlockPos> locs = WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, 4);
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Have " + locs.size() + " locations");
|
2018-08-23 19:54:12 +00:00
|
|
|
for (BlockPos pos : locs) {
|
|
|
|
Block actually = BlockStateInterface.get(pos).getBlock();
|
|
|
|
if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) {
|
|
|
|
System.out.println("Was looking for " + blockType + " but actually found " + actually + " " + ChunkPacker.blockToString(actually));
|
|
|
|
}
|
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 19:54:12 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.startsWith("mine")) {
|
|
|
|
String[] blockTypes = msg.substring(4).trim().split(" ");
|
2018-09-17 21:22:45 +00:00
|
|
|
try {
|
|
|
|
int quantity = Integer.parseInt(blockTypes[1]);
|
2018-09-25 00:18:46 +00:00
|
|
|
Block block = ChunkPacker.stringToBlock(blockTypes[0]);
|
|
|
|
Objects.requireNonNull(block);
|
|
|
|
MineBehavior.INSTANCE.mine(quantity, block);
|
2018-09-17 21:22:45 +00:00
|
|
|
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-17 21:22:45 +00:00
|
|
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
2018-09-04 22:03:59 +00:00
|
|
|
for (String s : blockTypes) {
|
|
|
|
if (ChunkPacker.stringToBlock(s) == null) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect(s + " isn't a valid block name");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-04 22:03:59 +00:00
|
|
|
}
|
2018-09-17 21:22:45 +00:00
|
|
|
|
2018-09-04 22:03:59 +00:00
|
|
|
}
|
2018-09-17 21:22:45 +00:00
|
|
|
MineBehavior.INSTANCE.mine(0, blockTypes);
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 19:54:12 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.startsWith("thisway")) {
|
2018-09-13 23:40:55 +00:00
|
|
|
try {
|
|
|
|
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
|
|
|
PathingBehavior.INSTANCE.setGoal(goal);
|
|
|
|
logDirect("Goal: " + goal);
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
logDirect("Error unable to parse '" + msg.substring(7).trim() + "' to a double.");
|
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.startsWith("list") || msg.startsWith("get ") || msg.startsWith("show")) {
|
|
|
|
String waypointType = msg.substring(4).trim();
|
2018-08-23 16:54:29 +00:00
|
|
|
if (waypointType.endsWith("s")) {
|
|
|
|
// for example, "show deaths"
|
|
|
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
|
|
|
}
|
2018-08-28 01:06:38 +00:00
|
|
|
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
2018-08-23 16:54:29 +00:00
|
|
|
if (tag == null) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 16:54:29 +00:00
|
|
|
}
|
2018-09-24 19:42:22 +00:00
|
|
|
Set<IWaypoint> waypoints = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getByTag(tag);
|
2018-08-23 16:54:29 +00:00
|
|
|
// might as well show them from oldest to newest
|
2018-09-24 17:48:00 +00:00
|
|
|
List<IWaypoint> sorted = new ArrayList<>(waypoints);
|
|
|
|
sorted.sort(Comparator.comparingLong(IWaypoint::getCreationTimestamp));
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Waypoints under tag " + tag + ":");
|
2018-09-24 17:48:00 +00:00
|
|
|
for (IWaypoint waypoint : sorted) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect(waypoint.toString());
|
2018-08-23 16:54:29 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 16:54:29 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.startsWith("save")) {
|
2018-09-24 23:15:59 +00:00
|
|
|
String name = msg.substring(4).trim();
|
|
|
|
BlockPos pos = playerFeet();
|
|
|
|
if (name.contains(" ")) {
|
|
|
|
logDirect("Name contains a space, assuming it's in the format 'save waypointName X Y Z'");
|
|
|
|
String[] parts = name.split(" ");
|
|
|
|
if (parts.length != 4) {
|
|
|
|
logDirect("Unable to parse, expected four things");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-24 23:15:59 +00:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
pos = new BlockPos(Integer.parseInt(parts[1]), Integer.parseInt(parts[2]), Integer.parseInt(parts[3]));
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
logDirect("Unable to parse coordinate integers");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-24 23:15:59 +00:00
|
|
|
}
|
|
|
|
name = parts[0];
|
|
|
|
}
|
|
|
|
WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, Waypoint.Tag.USER, pos));
|
|
|
|
logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto user' to set goal, say 'list user' to list.");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-13 16:15:50 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.startsWith("goto")) {
|
|
|
|
String waypointType = msg.substring(4).trim();
|
2018-09-01 18:31:42 +00:00
|
|
|
if (waypointType.endsWith("s") && Waypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) {
|
2018-08-23 16:54:29 +00:00
|
|
|
// for example, "show deaths"
|
|
|
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
|
|
|
}
|
2018-08-28 01:06:38 +00:00
|
|
|
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
2018-09-24 23:21:14 +00:00
|
|
|
IWaypoint waypoint;
|
2018-08-23 16:54:29 +00:00
|
|
|
if (tag == null) {
|
2018-09-01 18:30:02 +00:00
|
|
|
String mining = waypointType;
|
2018-09-12 22:12:06 +00:00
|
|
|
Block block = ChunkPacker.stringToBlock(mining);
|
2018-09-11 20:45:43 +00:00
|
|
|
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
2018-09-12 22:12:06 +00:00
|
|
|
if (block == null) {
|
2018-09-24 23:21:14 +00:00
|
|
|
waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
|
|
|
if (waypoint == null) {
|
|
|
|
logDirect("No locations for " + mining + " known, cancelling");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-24 23:21:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-10-26 18:30:16 +00:00
|
|
|
List<BlockPos> locs = MineBehavior.INSTANCE.searchWorld(Collections.singletonList(block), 64);
|
2018-09-24 23:21:14 +00:00
|
|
|
if (locs.isEmpty()) {
|
|
|
|
logDirect("No locations for " + mining + " known, cancelling");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-24 23:21:14 +00:00
|
|
|
}
|
|
|
|
PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)));
|
|
|
|
PathingBehavior.INSTANCE.path();
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-01 18:30:02 +00:00
|
|
|
}
|
2018-09-24 23:21:14 +00:00
|
|
|
} else {
|
|
|
|
waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(tag);
|
|
|
|
if (waypoint == null) {
|
|
|
|
logDirect("None saved for tag " + tag);
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-01 18:30:02 +00:00
|
|
|
}
|
2018-08-23 16:54:29 +00:00
|
|
|
}
|
2018-09-24 17:36:03 +00:00
|
|
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
2018-08-23 16:54:29 +00:00
|
|
|
PathingBehavior.INSTANCE.setGoal(goal);
|
2018-10-27 21:41:25 +00:00
|
|
|
if (!PathingBehavior.INSTANCE.path() && !goal.isInGoal(playerFeet())) {
|
|
|
|
logDirect("Currently executing a path. Please cancel it first.");
|
2018-08-28 18:43:28 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 16:54:29 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.equals("spawn") || msg.equals("bed")) {
|
2018-09-24 19:42:22 +00:00
|
|
|
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.BED);
|
2018-08-23 00:56:08 +00:00
|
|
|
if (waypoint == null) {
|
|
|
|
BlockPos spawnPoint = player().getBedLocation();
|
|
|
|
// for some reason the default spawnpoint is underground sometimes
|
|
|
|
Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ());
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal);
|
2018-08-23 00:56:08 +00:00
|
|
|
PathingBehavior.INSTANCE.setGoal(goal);
|
|
|
|
} else {
|
2018-09-24 17:36:03 +00:00
|
|
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
2018-08-23 00:56:08 +00:00
|
|
|
PathingBehavior.INSTANCE.setGoal(goal);
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Set goal to most recent bed " + goal);
|
2018-08-23 00:56:08 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-20 05:28:47 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.equals("sethome")) {
|
2018-09-24 19:42:22 +00:00
|
|
|
WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet()));
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("Saved. Say home to set goal.");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 00:49:55 +00:00
|
|
|
}
|
2018-09-16 23:45:56 +00:00
|
|
|
if (msg.equals("home")) {
|
2018-09-24 19:42:22 +00:00
|
|
|
IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.HOME);
|
2018-08-23 00:49:55 +00:00
|
|
|
if (waypoint == null) {
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect("home not saved");
|
2018-08-23 00:49:55 +00:00
|
|
|
} else {
|
2018-09-24 17:36:03 +00:00
|
|
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
2018-08-23 00:49:55 +00:00
|
|
|
PathingBehavior.INSTANCE.setGoal(goal);
|
2018-09-20 03:30:17 +00:00
|
|
|
PathingBehavior.INSTANCE.path();
|
|
|
|
logDirect("Going to saved home " + goal);
|
2018-08-23 00:49:55 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-08-23 00:49:55 +00:00
|
|
|
}
|
2018-09-24 01:00:54 +00:00
|
|
|
if (msg.equals("costs")) {
|
|
|
|
List<Movement> moves = Stream.of(Moves.values()).map(x -> x.apply0(playerFeet())).collect(Collectors.toCollection(ArrayList::new));
|
2018-09-09 20:19:48 +00:00
|
|
|
while (moves.contains(null)) {
|
|
|
|
moves.remove(null);
|
|
|
|
}
|
2018-10-09 00:57:22 +00:00
|
|
|
moves.sort(Comparator.comparingDouble(Movement::getCost));
|
2018-08-17 23:46:02 +00:00
|
|
|
for (Movement move : moves) {
|
|
|
|
String[] parts = move.getClass().toString().split("\\.");
|
2018-10-09 00:57:22 +00:00
|
|
|
double cost = move.getCost();
|
2018-08-17 23:46:02 +00:00
|
|
|
String strCost = cost + "";
|
|
|
|
if (cost >= ActionCosts.COST_INF) {
|
|
|
|
strCost = "IMPOSSIBLE";
|
|
|
|
}
|
2018-09-11 20:45:43 +00:00
|
|
|
logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost);
|
2018-08-17 23:46:02 +00:00
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-09-24 01:00:54 +00:00
|
|
|
}
|
2018-10-03 17:44:28 +00:00
|
|
|
if (msg.equals("pause")) {
|
2018-10-03 17:45:57 +00:00
|
|
|
boolean enabled = PathingBehavior.INSTANCE.toggle();
|
|
|
|
logDirect("Pathing Behavior has " + (enabled ? "resumed" : "paused") + ".");
|
2018-10-16 17:47:44 +00:00
|
|
|
return true;
|
2018-10-03 17:44:28 +00:00
|
|
|
}
|
2018-10-03 20:45:33 +00:00
|
|
|
if (msg.equals("damn")) {
|
|
|
|
logDirect("daniel");
|
|
|
|
}
|
2018-10-16 17:47:44 +00:00
|
|
|
return false;
|
2018-08-14 03:57:29 +00:00
|
|
|
}
|
|
|
|
}
|