optimizations

This commit is contained in:
batchprogrammer314
2021-07-01 01:12:18 -05:00
parent 302b0f5483
commit e9aa334aee
9 changed files with 88 additions and 61 deletions

View File

@@ -171,6 +171,10 @@ public class Bot extends EntityPlayer {
}
}
public void jump() {
jump(new Vector(0, 0.5, 0));
}
public void attack(org.bukkit.entity.Entity entity) {
faceLocation(entity.getLocation());
punch();

View File

@@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.util.Vector;
import java.util.Set;
public class BotAgent {
private PlayerAI plugin;
@@ -21,6 +23,8 @@ public class BotAgent {
private int taskID;
private int count;
public BotAgent(BotManager manager) {
this.plugin = PlayerAI.getInstance();
this.manager = manager;
@@ -44,24 +48,28 @@ public class BotAgent {
}
private void tick() {
manager.fetch().forEach(this::tickBot);
Set<Bot> bots = manager.fetch();
count = bots.size();
bots.forEach(this::tickBot);
}
private void tickBot(Bot bot) {
Location loc = bot.getLocation();
// if bot.hasHoldState() return; << This will be to check if a bot is mining or something similar where it can't move
Player player = nearestPlayer(loc);
if (player == null) return;
Location target = player.getLocation();
if (manager.fetch().size() > 1) {
target.add(bot.getOffset());
}
if (count > 1) target.add(bot.getOffset());
// Make the XZ offsets stored in the bot object (so they don't form a straight line),
// and make it so when mining and stuff, the offset is not taken into account
// if checkVertical(bot) { break block action add; return; }
if (bot.tickDelay(3)) attack(bot, player, loc);
move(bot, player, loc, target);
}