command handler optimizations

This commit is contained in:
batchprogrammer314
2021-07-04 03:15:30 -05:00
parent e9aa334aee
commit 0f86796f96
6 changed files with 62 additions and 36 deletions

View File

@@ -128,11 +128,13 @@ public class Bot extends EntityPlayer {
groundTicks = 0;
}
Player botPlayer = getBukkitEntity();
if (botPlayer.isDead()) return;
Player player = getBukkitEntity();
if (player.isDead()) return;
double health = botPlayer.getHealth();
double maxHealth = botPlayer.getHealthScale();
updateLocation();
double health = player.getHealth();
double maxHealth = player.getHealthScale();
double amount;
if (health < maxHealth - regenAmount) {
@@ -141,9 +143,7 @@ public class Bot extends EntityPlayer {
amount = maxHealth;
}
botPlayer.setHealth(amount);
updateLocation();
player.setHealth(amount);
}
private void updateLocation() {
@@ -182,10 +182,7 @@ public class Bot extends EntityPlayer {
}
public void punch() {
PacketPlayOutAnimation packet = new PacketPlayOutAnimation(this, 0);
for (Player player : Bukkit.getOnlinePlayers()) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
swingHand(EnumHand.MAIN_HAND);
}
@Override
@@ -293,8 +290,10 @@ public class Bot extends EntityPlayer {
}
private void kb(Location loc1, Location loc2) {
Vector diff = loc1.toVector().subtract(loc2.toVector()).normalize().setY(kbUp);
Vector vel = velocity.clone().add(diff).multiply(0.5);
double f = 4;
Vector diff = loc1.toVector().subtract(loc2.toVector()).setY(0).normalize().multiply(f).setY(kbUp);
Vector vel = velocity.clone().add(diff).multiply(0.3 / f);
if (vel.length() > 1) vel.normalize();
if (groundTicks != 0) vel.multiply(0.8).setY(0.4);

View File

@@ -3,6 +3,7 @@ package net.nuggetmc.ai.bot.agent;
import net.nuggetmc.ai.PlayerAI;
import net.nuggetmc.ai.bot.Bot;
import net.nuggetmc.ai.bot.BotManager;
import net.nuggetmc.ai.utils.MathUtils;
import net.nuggetmc.ai.utils.PlayerUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -91,7 +92,7 @@ public class BotAgent {
vel.checkFinite();
vel.add(bot.velocity);
} catch (IllegalArgumentException e) {
vel = new Vector(0, 0.5, 0);
return;
}
if (vel.length() > 1) vel.normalize();