Fix mobtarget and obstacles
-Fix trapdoors -Fix mobtarget (and make the setting global)
This commit is contained in:
@@ -929,13 +929,21 @@ public class LegacyAgent extends Agent {
|
||||
}
|
||||
|
||||
private boolean checkObstacles(Terminator bot, Block block, LivingEntity player) {
|
||||
if (LegacyMats.OBSTACLES.contains(block.getType())) {
|
||||
if (LegacyMats.OBSTACLES.contains(block.getType()) || isDoorObstacle(block)) {
|
||||
preBreak(bot, player, block, LegacyLevel.AT_D);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isDoorObstacle(Block block) {
|
||||
if (block.getType().data == Door.class)
|
||||
return true;
|
||||
if (block.getType().data == TrapDoor.class && ((TrapDoor)block.getBlockData()).isOpen())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkAt(Terminator bot, Block block, LivingEntity player) {
|
||||
if (LegacyMats.BREAK.contains(block.getType())) {
|
||||
@@ -1503,12 +1511,12 @@ public class LegacyAgent extends Agent {
|
||||
if (region == null)
|
||||
return 0;
|
||||
double diffX = Math.max(0, Math.abs(region.getCenterX() - loc.getX()) - region.getWidthX() * 0.5);
|
||||
double diffY = Math.max(0, Math.abs(region.getCenterY() - loc.getY()) - region.getHeight() * 0.5);
|
||||
double diffZ = Math.max(0, Math.abs(region.getCenterZ() - loc.getZ()) - region.getWidthZ() * 0.5);
|
||||
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0)
|
||||
if (diffX > 0 || diffY > 0 || diffZ > 0)
|
||||
return Double.MAX_VALUE;
|
||||
return diffX * diffX * regionWeightX + diffY * diffY * regionWeightY + diffZ * diffZ * regionWeightZ;
|
||||
double diffY = Math.max(0, Math.abs(region.getCenterY() - loc.getY()) - region.getHeight() * 0.5);
|
||||
double diffZ = Math.max(0, Math.abs(region.getCenterZ() - loc.getZ()) - region.getWidthZ() * 0.5);
|
||||
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0)
|
||||
if (diffX > 0 || diffY > 0 || diffZ > 0)
|
||||
return Double.MAX_VALUE;
|
||||
return diffX * diffX * regionWeightX + diffY * diffY * regionWeightY + diffZ * diffZ * regionWeightZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -921,12 +921,4 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
this.yRotO = this.getYRot();
|
||||
this.xRotO = this.getXRot();
|
||||
}
|
||||
|
||||
public boolean isIgnoredByMobs() {
|
||||
return ignoredByMobs;
|
||||
}
|
||||
|
||||
public void setIgnoredByMobs(boolean ignoredByMobs) {
|
||||
this.ignoredByMobs = ignoredByMobs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,10 @@ public class BotManagerImpl implements BotManager, Listener {
|
||||
if (target != null) {
|
||||
Terminator closest = null;
|
||||
for (Terminator bot : bots) {
|
||||
if (name.equals(bot.getBotName()) && (closest == null
|
||||
|| target.distanceSquared(bot.getLocation()) < target.distanceSquared(closest.getLocation()))) {
|
||||
closest = bot;
|
||||
}
|
||||
if (name.equals(bot.getBotName()) && (closest == null
|
||||
|| target.distanceSquared(bot.getLocation()) < target.distanceSquared(closest.getLocation()))) {
|
||||
closest = bot;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
@@ -149,7 +149,6 @@ public class BotManagerImpl implements BotManager, Listener {
|
||||
} else if (i > 1) {
|
||||
bot.setVelocity(randomVelocity().multiply(f));
|
||||
}
|
||||
bot.setIgnoredByMobs(!mobTarget);
|
||||
|
||||
bots.add(bot);
|
||||
i++;
|
||||
@@ -232,8 +231,10 @@ public class BotManagerImpl implements BotManager, Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onMobTarget(EntityTargetLivingEntityEvent event) {
|
||||
Bot bot = (Bot) getBot(event.getEntity().getUniqueId());
|
||||
if (bot != null && bot.isIgnoredByMobs()) {
|
||||
if (mobTarget || event.getTarget() == null)
|
||||
return;
|
||||
Bot bot = (Bot) getBot(event.getTarget().getUniqueId());
|
||||
if (bot != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,8 +291,8 @@ public class BotCommand extends CommandInstance {
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra);
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "setgoal" + ChatUtils.BULLET_FORMATTED + "Set the global bot target selection method.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "mobtarget" + ChatUtils.BULLET_FORMATTED + "Allow all future bots spawned to be targeted by hostile mobs.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "playertarget" + ChatUtils.BULLET_FORMATTED + "Sets a player name for the bots to focus on if the goal is PLAYER.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "mobtarget" + ChatUtils.BULLET_FORMATTED + "Allow all bots to be targeted by hostile mobs.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "playertarget" + ChatUtils.BULLET_FORMATTED + "Sets a player name for spawned bots to focus on if the goal is PLAYER.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "region" + ChatUtils.BULLET_FORMATTED + "Sets a region for the bots to prioritize entities inside.");
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
return;
|
||||
@@ -325,7 +325,7 @@ public class BotCommand extends CommandInstance {
|
||||
return;
|
||||
}
|
||||
manager.setMobTarget(Boolean.parseBoolean(arg2));
|
||||
sender.sendMessage("Mob targeting is now " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ". (for all future bots)");
|
||||
sender.sendMessage("Mob targeting is now " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
} else if (arg1.equalsIgnoreCase("playertarget")) {
|
||||
if (args.size() < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify a player name!");
|
||||
|
||||
Reference in New Issue
Block a user