more efficient ground detection

This commit is contained in:
batchprogrammer314
2021-06-27 21:45:11 -05:00
parent eaab1c0bc7
commit 86c50f24c7
2 changed files with 10 additions and 14 deletions

View File

@@ -44,9 +44,7 @@ public class Bot extends EntityPlayer {
GameProfile profile = new GameProfile(uuid, name); GameProfile profile = new GameProfile(uuid, name);
PlayerInteractManager interactManager = new PlayerInteractManager(nmsWorld); PlayerInteractManager interactManager = new PlayerInteractManager(nmsWorld);
if (skin != null) {
setSkin(profile, skin); setSkin(profile, skin);
}
Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager); Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager);
@@ -130,12 +128,17 @@ public class Bot extends EntityPlayer {
private void updateLocation() { private void updateLocation() {
velocity.setY(velocity.getY() - 0.1); velocity.setY(velocity.getY() - 0.1);
double y;
if (predictGround()) { if (predictGround()) {
velocity.setY(0); velocity.setY(0);
addFriction(); 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() { public boolean predictGround() {
@@ -145,8 +148,6 @@ public class Bot extends EntityPlayer {
return false; return false;
} }
double m = vy / 20.0;
World world = getBukkitEntity().getWorld(); World world = getBukkitEntity().getWorld();
AxisAlignedBB box = getBoundingBox(); AxisAlignedBB box = getBoundingBox();
@@ -164,15 +165,11 @@ public class Bot extends EntityPlayer {
for (double z : zVals) { for (double z : zVals) {
double i = locY(); double i = locY();
for (int n = 0; n < 20; n++) { Location test = new Location(world, x, i - 0.05, z);
Location test = new Location(world, x, i, z);
if (test.getBlock().getType().isSolid()) { if (test.getBlock().getType().isSolid()) {
return true; return true;
} }
i += m;
}
} }
} }

View File

@@ -17,7 +17,6 @@ public class MojangAPI {
.openStream())).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); .openStream())).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
return new String[] {property.get("value").getAsString(), property.get("signature").getAsString()}; return new String[] {property.get("value").getAsString(), property.get("signature").getAsString()};
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return null; return null;
} }
} }