Skip to content

Instantly share code, notes, and snippets.

@aikar
Created September 8, 2014 03:57
Show Gist options
  • Save aikar/3b6f30f4e7ac0e6746ee to your computer and use it in GitHub Desktop.
Save aikar/3b6f30f4e7ac0e6746ee to your computer and use it in GitHub Desktop.
this.V *= 0.4F;
double d3 = this.locX;
double d4 = this.locY;
double d5 = this.locZ;
if (this.I) {
this.I = false;
d0 *= 0.25D;
d1 *= 0.05000000074505806D;
d2 *= 0.25D;
this.motX = 0.0D;
this.motY = 0.0D;
this.motZ = 0.0D;
}
double d6 = d0;
double d7 = d1;
double d8 = d2;
AxisAlignedBB axisalignedbb = this.boundingBox.clone();
boolean flag = this.onGround && this.isSneaking() && this instanceof EntityHuman;
if (flag) {
double d9;
for (d9 = 0.05D; d0 != 0.0D && this.world.getCubes(this, this.boundingBox.c(d0, -1.0D, 0.0D)).isEmpty(); d6 = d0) {
if (d0 < d9 && d0 >= -d9) {
d0 = 0.0D;
} else if (d0 > 0.0D) {
d0 -= d9;
} else {
d0 += d9;
}
}
for (; d2 != 0.0D && this.world.getCubes(this, this.boundingBox.c(0.0D, -1.0D, d2)).isEmpty(); d8 = d2) {
if (d2 < d9 && d2 >= -d9) {
d2 = 0.0D;
} else if (d2 > 0.0D) {
d2 -= d9;
} else {
d2 += d9;
}
}
while (d0 != 0.0D && d2 != 0.0D && this.world.getCubes(this, this.boundingBox.c(d0, -1.0D, d2)).isEmpty()) {
if (d0 < d9 && d0 >= -d9) {
d0 = 0.0D;
} else if (d0 > 0.0D) {
d0 -= d9;
} else {
d0 += d9;
}
if (d2 < d9 && d2 >= -d9) {
d2 = 0.0D;
} else if (d2 > 0.0D) {
d2 -= d9;
} else {
d2 += d9;
}
d6 = d0;
d8 = d2;
}
}
List list = this.world.getCubes(this, this.boundingBox.a(d0, d1, d2));
for (int i = 0; i < list.size(); ++i) {
d1 = ((AxisAlignedBB) list.get(i)).b(this.boundingBox, d1);
}
this.boundingBox.d(0.0D, d1, 0.0D);
if (!this.J && d7 != d1) {
d2 = 0.0D;
d1 = 0.0D;
d0 = 0.0D;
}
boolean flag1 = this.onGround || d7 != d1 && d7 < 0.0D;
int j;
for (j = 0; j < list.size(); ++j) {
d0 = ((AxisAlignedBB) list.get(j)).a(this.boundingBox, d0);
}
this.boundingBox.d(d0, 0.0D, 0.0D);
if (!this.J && d6 != d0) {
d2 = 0.0D;
d1 = 0.0D;
d0 = 0.0D;
}
for (j = 0; j < list.size(); ++j) {
d2 = ((AxisAlignedBB) list.get(j)).c(this.boundingBox, d2);
}
this.boundingBox.d(0.0D, 0.0D, d2);
if (!this.J && d8 != d2) {
d2 = 0.0D;
d1 = 0.0D;
d0 = 0.0D;
}
double d10;
double d11;
double d12;
int k;
if (this.W > 0.0F && flag1 && (flag || this.V < 0.05F) && (d6 != d0 || d8 != d2)) {
d10 = d0;
d11 = d1;
d12 = d2;
d0 = d6;
d1 = (double) this.W;
d2 = d8;
AxisAlignedBB axisalignedbb1 = this.boundingBox.clone();
this.boundingBox.d(axisalignedbb);
list = this.world.getCubes(this, this.boundingBox.a(d6, d1, d8));
for (k = 0; k < list.size(); ++k) {
d1 = ((AxisAlignedBB) list.get(k)).b(this.boundingBox, d1);
}
this.boundingBox.d(0.0D, d1, 0.0D);
if (!this.J && d7 != d1) {
d2 = 0.0D;
d1 = 0.0D;
d0 = 0.0D;
}
for (k = 0; k < list.size(); ++k) {
d0 = ((AxisAlignedBB) list.get(k)).a(this.boundingBox, d0);
}
this.boundingBox.d(d0, 0.0D, 0.0D);
if (!this.J && d6 != d0) {
d2 = 0.0D;
d1 = 0.0D;
d0 = 0.0D;
}
for (k = 0; k < list.size(); ++k) {
d2 = ((AxisAlignedBB) list.get(k)).c(this.boundingBox, d2);
}
this.boundingBox.d(0.0D, 0.0D, d2);
if (!this.J && d8 != d2) {
d2 = 0.0D;
d1 = 0.0D;
d0 = 0.0D;
}
if (!this.J && d7 != d1) {
d2 = 0.0D;
d1 = 0.0D;
d0 = 0.0D;
} else {
d1 = (double) (-this.W);
for (k = 0; k < list.size(); ++k) {
d1 = ((AxisAlignedBB) list.get(k)).b(this.boundingBox, d1);
}
this.boundingBox.d(0.0D, d1, 0.0D);
}
if (d10 * d10 + d12 * d12 >= d0 * d0 + d2 * d2) {
d0 = d10;
d1 = d11;
d2 = d12;
this.boundingBox.d(axisalignedbb1);
}
}
this.world.methodProfiler.b();
this.world.methodProfiler.a("rest");
this.locX = (this.boundingBox.a + this.boundingBox.d) / 2.0D;
this.locY = this.boundingBox.b + (double) this.height - (double) this.V;
this.locZ = (this.boundingBox.c + this.boundingBox.f) / 2.0D;
this.positionChanged = d6 != d0 || d8 != d2;
this.F = d7 != d1;
this.onGround = d7 != d1 && d7 < 0.0D;
this.G = this.positionChanged || this.F;
this.a(d1, this.onGround);
if (d6 != d0) {
this.motX = 0.0D;
}
if (d7 != d1) {
this.motY = 0.0D;
}
if (d8 != d2) {
this.motZ = 0.0D;
}
d10 = this.locX - d3;
d11 = this.locY - d4;
d12 = this.locZ - d5;
// CraftBukkit start
if ((this.positionChanged) && (this.getBukkitEntity() instanceof Vehicle)) {
Vehicle vehicle = (Vehicle) this.getBukkitEntity();
org.bukkit.block.Block block = this.world.getWorld().getBlockAt(MathHelper.floor(this.locX), MathHelper.floor(this.locY - (double) this.height), MathHelper.floor(this.locZ));
if (d6 > d0) {
block = block.getRelative(BlockFace.EAST);
} else if (d6 < d0) {
block = block.getRelative(BlockFace.WEST);
} else if (d8 > d2) {
block = block.getRelative(BlockFace.SOUTH);
} else if (d8 < d2) {
block = block.getRelative(BlockFace.NORTH);
}
VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, block);
this.world.getServer().getPluginManager().callEvent(event);
}
// CraftBukkit end
if (this.g_() && !flag && this.vehicle == null) {
int l = MathHelper.floor(this.locX);
k = MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height);
int i1 = MathHelper.floor(this.locZ);
Block block = this.world.getType(l, k, i1);
int j1 = this.world.getType(l, k - 1, i1).b();
if (j1 == 11 || j1 == 32 || j1 == 21) {
block = this.world.getType(l, k - 1, i1);
}
if (block != Blocks.LADDER) {
d11 = 0.0D;
}
this.P = (float) ((double) this.P + (double) MathHelper.sqrt(d10 * d10 + d12 * d12) * 0.6D);
this.Q = (float) ((double) this.Q + (double) MathHelper.sqrt(d10 * d10 + d11 * d11 + d12 * d12) * 0.6D);
if (this.Q > (float) this.d && block.getMaterial() != Material.AIR) {
this.d = (int) this.Q + 1;
if (this.M()) {
float f = MathHelper.sqrt(this.motX * this.motX * 0.20000000298023224D + this.motY * this.motY + this.motZ * this.motZ * 0.20000000298023224D) * 0.35F;
if (f > 1.0F) {
f = 1.0F;
}
this.makeSound(this.H(), f, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
}
this.a(l, k, i1, block);
block.b(this.world, l, k, i1, this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment