Fix bot stuck issues

-Fix bot being sometimes clipped into the ground at checkup (5 tick delay -> 3)
-Fix stuck on snow layer issue
This commit is contained in:
ThisTestUser
2022-12-11 19:13:39 -05:00
parent 6e8deef5a5
commit a41d9245b2
4 changed files with 78 additions and 84 deletions

View File

@@ -510,6 +510,24 @@ public class LegacyAgent extends Agent {
Collections.sort(locStanding, (a, b) -> Collections.sort(locStanding, (a, b) ->
Double.compare(BotUtils.getHorizSqDist(a, player.getLocation()), BotUtils.getHorizSqDist(b, player.getLocation()))); Double.compare(BotUtils.getHorizSqDist(a, player.getLocation()), BotUtils.getHorizSqDist(b, player.getLocation())));
//Break snow in the way
for (Location loc : locStanding) {
if (loc.getBlock().getType() == Material.SNOW) {
get = loc.getBlock();
npc.faceLocation(get.getLocation());
level = LegacyLevel.getOffset(player.getLocation(), loc);
if (level != null) {
preBreak(npc, player, get, level);
return level;
} else {
//This should not happen
level = null;
get = null;
}
}
}
//Break potential obstructing walls //Break potential obstructing walls
for (Location loc : locStanding) { for (Location loc : locStanding) {
boolean up = false; boolean up = false;
@@ -847,7 +865,7 @@ public class LegacyAgent extends Agent {
towerList.put(playerNPC, playerNPC.getLocation()); towerList.put(playerNPC, playerNPC.getLocation());
} }
} }
}, 5); }, 3);
if (npc.isBotOnGround()) { if (npc.isBotOnGround()) {
if (target.getLocation().distance(playerNPC.getLocation()) < 16) { if (target.getLocation().distance(playerNPC.getLocation()) < 16) {
@@ -1077,67 +1095,12 @@ public class LegacyAgent extends Agent {
byte i = mining.get(this); byte i = mining.get(this);
Block cur; Block cur;
switch (wrapper.getLevel()) { if (wrapper.getLevel() == null)
case ABOVE:
cur = player.getLocation().add(0, 2, 0).getBlock();
break;
case BELOW:
cur = bot.getStandingOn().isEmpty() ? null : bot.getStandingOn().get(0);
break;
case NORTH_U:
cur = player.getLocation().add(0, 2, -1).getBlock();
break;
case SOUTH_U:
cur = player.getLocation().add(0, 2, 1).getBlock();
break;
case EAST_U:
cur = player.getLocation().add(1, 2, 0).getBlock();
break;
case WEST_U:
cur = player.getLocation().add(-1, 2, 0).getBlock();
break;
case NORTH:
cur = player.getLocation().add(0, 1, -1).getBlock();
break;
case SOUTH:
cur = player.getLocation().add(0, 1, 1).getBlock();
break;
case EAST:
cur = player.getLocation().add(1, 1, 0).getBlock();
break;
case WEST:
cur = player.getLocation().add(-1, 1, 0).getBlock();
break;
case NORTH_D:
cur = player.getLocation().add(0, 0, -1).getBlock();
break;
case SOUTH_D:
cur = player.getLocation().add(0, 0, 1).getBlock();
break;
case EAST_D:
cur = player.getLocation().add(1, 0, 0).getBlock();
break;
case WEST_D:
cur = player.getLocation().add(-1, 0, 0).getBlock();
break;
case NORTH_D_2:
cur = player.getLocation().add(0, -1, -1).getBlock();
break;
case SOUTH_D_2:
cur = player.getLocation().add(0, -1, 1).getBlock();
break;
case EAST_D_2:
cur = player.getLocation().add(1, -1, 0).getBlock();
break;
case WEST_D_2:
cur = player.getLocation().add(-1, -1, 0).getBlock();
break;
case AT_D:
cur = player.getLocation().getBlock();
break;
default:
cur = player.getLocation().add(0, 1, 0).getBlock(); cur = player.getLocation().add(0, 1, 0).getBlock();
} else if (wrapper.getLevel() == LegacyLevel.BELOW)
cur = bot.getStandingOn().isEmpty() ? null : bot.getStandingOn().get(0);
else
cur = wrapper.getLevel().offset(player.getLocation()).getBlock();
// Fix boat clutching while breaking block // Fix boat clutching while breaking block
// As a side effect, the bot is able to break multiple blocks at once while over lava // As a side effect, the bot is able to break multiple blocks at once while over lava

View File

@@ -6,7 +6,6 @@ import net.nuggetmc.tplus.api.utils.BotUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@@ -4,27 +4,43 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.bukkit.Location;
public enum LegacyLevel { public enum LegacyLevel {
ABOVE, ABOVE(0, 2, 0),
BELOW, BELOW(0, -1, 0),
AT, AT(0, 1, 0),
AT_D, AT_D(0, 0, 0),
NORTH_U, NORTH_U(0, 2, -1),
SOUTH_U, SOUTH_U(0, 2, 1),
EAST_U, EAST_U(1, 2, 0),
WEST_U, WEST_U(-1, 2, 0),
NORTH, NORTH(0, 1, -1),
SOUTH, SOUTH(0, 1, 1),
EAST, EAST(1, 1, 0),
WEST, WEST(-1, 1, 0),
NORTH_D, NORTH_D(0, 0, -1),
SOUTH_D, SOUTH_D(0, 0, 1),
EAST_D, EAST_D(1, 0, 0),
WEST_D, WEST_D(-1, 0, 0),
NORTH_D_2, NORTHWEST_D(-1, 0, -1),
SOUTH_D_2, SOUTHWEST_D(-1, 0, 1),
EAST_D_2, NORTHEAST_D(1, 0, -1),
WEST_D_2; SOUTHEAST_D(1, 0, 1),
NORTH_D_2(0, -1, -1),
SOUTH_D_2(0, -1, 1),
EAST_D_2(1, -1, 0),
WEST_D_2(-1, -1, 0);
private final int offsetX;
private final int offsetY;
private final int offsetZ;
private LegacyLevel(int offsetX, int offsetY, int offsetZ) {
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
}
private static final Set<LegacyLevel> NON_SIDE = new HashSet<>(Arrays.asList( private static final Set<LegacyLevel> NON_SIDE = new HashSet<>(Arrays.asList(
ABOVE, ABOVE,
@@ -115,6 +131,22 @@ public enum LegacyLevel {
} }
} }
public static LegacyLevel getOffset(Location start, Location end) {
int diffX = end.getBlockX() - start.getBlockX();
int diffY = end.getBlockY() - start.getBlockY();
int diffZ = end.getBlockZ() - start.getBlockZ();
for (LegacyLevel level : LegacyLevel.values()) {
if (level.offsetX == diffX && level.offsetY == diffY && level.offsetZ == diffZ) {
return level;
}
}
return null;
}
public Location offset(Location loc) {
return loc.add(offsetX, offsetY, offsetZ);
}
public static class LevelWrapper { public static class LevelWrapper {
private LegacyLevel level; private LegacyLevel level;

View File

@@ -213,7 +213,7 @@ public class BotCommand extends CommandInstance {
String botName = bot.getBotName(); String botName = bot.getBotName();
String world = ChatColor.YELLOW + bot.getBukkitEntity().getWorld().getName(); String world = ChatColor.YELLOW + bot.getBukkitEntity().getWorld().getName();
Location loc = bot.getLocation(); Location loc = bot.getLocation();
String strLoc = ChatColor.YELLOW + formatter.format(loc.getBlockX()) + ", " + formatter.format(loc.getBlockY()) + ", " + formatter.format(loc.getBlockZ()); String strLoc = ChatColor.YELLOW + formatter.format(loc.getX()) + ", " + formatter.format(loc.getY()) + ", " + formatter.format(loc.getZ());
Vector vel = bot.getVelocity(); Vector vel = bot.getVelocity();
String strVel = ChatColor.AQUA + formatter.format(vel.getX()) + ", " + formatter.format(vel.getY()) + ", " + formatter.format(vel.getZ()); String strVel = ChatColor.AQUA + formatter.format(vel.getX()) + ", " + formatter.format(vel.getY()) + ", " + formatter.format(vel.getZ());