From 86c50f24c71ffddc230ef8d421b312e8c8b5c0fb Mon Sep 17 00:00:00 2001 From: batchprogrammer314 Date: Sun, 27 Jun 2021 21:45:11 -0500 Subject: [PATCH] more efficient ground detection --- src/main/java/net/nuggetmc/ai/bot/Bot.java | 23 ++++++++----------- .../java/net/nuggetmc/ai/utils/MojangAPI.java | 1 - 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/nuggetmc/ai/bot/Bot.java b/src/main/java/net/nuggetmc/ai/bot/Bot.java index 60f0d3c..bea675a 100644 --- a/src/main/java/net/nuggetmc/ai/bot/Bot.java +++ b/src/main/java/net/nuggetmc/ai/bot/Bot.java @@ -44,9 +44,7 @@ public class Bot extends EntityPlayer { GameProfile profile = new GameProfile(uuid, name); PlayerInteractManager interactManager = new PlayerInteractManager(nmsWorld); - if (skin != null) { - setSkin(profile, skin); - } + setSkin(profile, skin); Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager); @@ -130,12 +128,17 @@ public class Bot extends EntityPlayer { private void updateLocation() { velocity.setY(velocity.getY() - 0.1); + double y; + if (predictGround()) { velocity.setY(0); addFriction(); + y = 0; + } else { + y = velocity.getY(); } - this.move(EnumMoveType.SELF, new Vec3D(velocity.getX(), velocity.getY(), velocity.getZ())); + this.move(EnumMoveType.SELF, new Vec3D(velocity.getX(), y, velocity.getZ())); } public boolean predictGround() { @@ -145,8 +148,6 @@ public class Bot extends EntityPlayer { return false; } - double m = vy / 20.0; - World world = getBukkitEntity().getWorld(); AxisAlignedBB box = getBoundingBox(); @@ -164,14 +165,10 @@ public class Bot extends EntityPlayer { for (double z : zVals) { double i = locY(); - for (int n = 0; n < 20; n++) { - Location test = new Location(world, x, i, z); + Location test = new Location(world, x, i - 0.05, z); - if (test.getBlock().getType().isSolid()) { - return true; - } - - i += m; + if (test.getBlock().getType().isSolid()) { + return true; } } } diff --git a/src/main/java/net/nuggetmc/ai/utils/MojangAPI.java b/src/main/java/net/nuggetmc/ai/utils/MojangAPI.java index 7cab667..ac531a1 100644 --- a/src/main/java/net/nuggetmc/ai/utils/MojangAPI.java +++ b/src/main/java/net/nuggetmc/ai/utils/MojangAPI.java @@ -17,7 +17,6 @@ public class MojangAPI { .openStream())).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); return new String[] {property.get("value").getAsString(), property.get("signature").getAsString()}; } catch (Exception e) { - e.printStackTrace(); return null; } }