vector exceptions handled

This commit is contained in:
batchprogrammer314
2021-07-09 15:49:10 -05:00
parent 0f86796f96
commit 7bd2e50afd
6 changed files with 123 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.Objects;
import java.util.UUID;
public class Bot extends EntityPlayer {
@@ -26,11 +27,7 @@ public class Bot extends EntityPlayer {
private byte jumpTicks;
private byte groundTicks;
private final double regenAmount = 0.05;
private final double frictionMin = 0.01;
private final double kbUp = 0.3;
private Vector offset;
private final Vector offset;
public Bot(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile profile, PlayerInteractManager manager) {
super(minecraftServer, worldServer, profile, manager);
@@ -43,7 +40,7 @@ public class Bot extends EntityPlayer {
public static Bot createBot(Location loc, String name, String skin) {
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
WorldServer nmsWorld = ((CraftWorld) Objects.requireNonNull(loc.getWorld())).getHandle();
UUID uuid = SteveUUID.generate();
@@ -135,6 +132,7 @@ public class Bot extends EntityPlayer {
double health = player.getHealth();
double maxHealth = player.getHealthScale();
double regenAmount = 0.05;
double amount;
if (health < maxHealth - regenAmount) {
@@ -218,6 +216,8 @@ public class Bot extends EntityPlayer {
}
public void addFriction() {
double frictionMin = 0.01;
double x = velocity.getX();
double z = velocity.getZ();
@@ -291,6 +291,7 @@ public class Bot extends EntityPlayer {
private void kb(Location loc1, Location loc2) {
double f = 4;
double kbUp = 0.3;
Vector diff = loc1.toVector().subtract(loc2.toVector()).setY(0).normalize().multiply(f).setY(kbUp);
Vector vel = velocity.clone().add(diff).multiply(0.3 / f);

View File

@@ -71,14 +71,17 @@ public class BotAgent {
// if checkVertical(bot) { break block action add; return; }
// BotSituation situation = BotSituation.create(bot);
// based on the situation, the bot can perform different actions
// there can be priorities assigned
if (bot.tickDelay(3)) attack(bot, player, loc);
move(bot, player, loc, target);
}
private void attack(Bot bot, Player player, Location loc) {
if (!PlayerUtils.isVulnerableGamemode(player.getGameMode())
|| player.getNoDamageTicks() >= 5
|| loc.distance(player.getLocation()) >= 4) return;
if (player.getNoDamageTicks() >= 5 || loc.distance(player.getLocation()) >= 4) return;
bot.attack(player);
}
@@ -92,7 +95,9 @@ public class BotAgent {
vel.checkFinite();
vel.add(bot.velocity);
} catch (IllegalArgumentException e) {
return;
if (!MathUtils.isFinite(vel)) {
MathUtils.clean(vel);
}
}
if (vel.length() > 1) vel.normalize();
@@ -105,7 +110,7 @@ public class BotAgent {
Player result = null;
for (Player player : Bukkit.getOnlinePlayers()) {
if (loc.getWorld() != player.getWorld()) continue;
if (!PlayerUtils.isTargetable(player.getGameMode()) || loc.getWorld() != player.getWorld()) continue;
if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
result = player;