use of net.minecraft.server.v1_15_R1.Vec3D in project Citizens2 by CitizensDev.
the class PlayerNavigation method m.
@Override
protected void m() {
Vec3D var0 = this.b();
this.l = this.a.getWidth() > 0.75F ? this.a.getWidth() / 2.0F : 0.75F - this.a.getWidth() / 2.0F;
Vec3D var1 = this.c.g();
if (Math.abs(this.a.locX - (var1.x + 0.5D)) < this.l && Math.abs(this.a.locZ - (var1.z + 0.5D)) < this.l && Math.abs(this.a.locY - var1.y) < 1.0D) {
this.c.c(this.c.f() + 1);
}
this.a(var0);
}
use of net.minecraft.server.v1_15_R1.Vec3D in project Citizens2 by CitizensDev.
the class PlayerNavigation method l.
@Override
protected void l() {
Vec3D localVec3D1 = c();
int k = this.d.d();
for (int m = this.d.e(); m < this.d.d(); m++) {
if (this.d.a(m).b != (int) localVec3D1.b) {
k = m;
break;
}
}
float f1 = this.b.width * this.b.width * this.i;
for (int n = this.d.e(); n < k; n++) {
Vec3D localVec3D2 = this.d.a(this.b, n);
if (localVec3D1.distanceSquared(localVec3D2) < f1) {
this.d.c(n + 1);
}
}
int n = MathHelper.f(this.b.width);
int i1 = (int) this.b.length + 1;
int i2 = n;
for (int i3 = k - 1; i3 >= this.d.e(); i3--) {
if (a(localVec3D1, this.d.a(this.b, i3), n, i1, i2)) {
this.d.c(i3);
break;
}
}
a(localVec3D1);
}
use of net.minecraft.server.v1_15_R1.Vec3D in project Citizens2 by CitizensDev.
the class PlayerNavigation method a.
@Override
public boolean a(PathEntity paramPathEntity, double paramDouble) {
if (paramPathEntity == null) {
this.d = null;
return false;
}
if (!paramPathEntity.a(this.d)) {
this.d = paramPathEntity;
}
d();
if (this.d.d() == 0) {
return false;
}
this.e = paramDouble;
Vec3D localVec3D = c();
this.g = this.f;
this.h = localVec3D;
return true;
}
use of net.minecraft.server.v1_15_R1.Vec3D in project custom-items-gradle by knokko.
the class Raytracer method raytrace.
/**
* <p>Performs a raytrace from {@code startLocation} towards {@code startLocation + vector}.
* The {@code vector} determines both the direction and the maximum distance of the raytrace!</p>
*
* <p>If an intersection with any block or entity was found, a RaytraceResult representing the intersection
* that is closest to {@code startLocation} will be returned. If no such intersection was found, this
* method will return null.</p>
*
* <p>Entities included in {@code entitiesToExclude} and dropped item entities will be ignored by
* the raytrace.</p>
*
* @param startLocation The location from which the raytrace will start
* @param vector The direction and maximum distance of the raytrace
* @param entitiesToExclude An array of entities that will be ignored by this raytrace, may contain null
* @return A RaytraceResult for the nearest intersection, or null if no intersection was found
*/
public static RaytraceResult raytrace(Location startLocation, Vector vector, Entity... entitiesToExclude) {
// Important variables
World world = startLocation.getWorld();
Vec3D rayStart = new Vec3D(startLocation.getX(), startLocation.getY(), startLocation.getZ());
Vec3D velocityVec = new Vec3D(vector.getX(), vector.getY(), vector.getZ());
Vec3D rayEnd = new Vec3D(rayStart.x + velocityVec.x, rayStart.y + velocityVec.y, rayStart.z + velocityVec.z);
CraftWorld craftWorld = (CraftWorld) world;
WorldServer nmsWorld = craftWorld.getHandle();
// Start with infinity to make sure that any other distance will be shorter
double nearestDistanceSq = Double.POSITIVE_INFINITY;
Vec3D intersectionPos = null;
// The block raytrace
MovingObjectPosition rayResult = nmsWorld.rayTrace(rayStart, rayEnd, true, true, false);
if (rayResult != null && rayResult.type == EnumMovingObjectType.BLOCK) {
double blockDistanceSq = rayResult.pos.distanceSquared(rayStart);
if (blockDistanceSq < vector.lengthSquared()) {
intersectionPos = rayResult.pos;
nearestDistanceSq = blockDistanceSq;
}
}
// The entity raytrace
AxisAlignedBB movementBB = new AxisAlignedBB(rayStart.x, rayStart.y, rayStart.z, rayEnd.x, rayEnd.y, rayEnd.z);
List<net.minecraft.server.v1_12_R1.Entity> nmsEntityList = nmsWorld.getEntities(null, movementBB);
net.minecraft.server.v1_12_R1.Entity intersectedEntity = null;
entityListLoop: for (net.minecraft.server.v1_12_R1.Entity nmsEntity : nmsEntityList) {
// It's currently convenient to ignore dropped items
if (nmsEntity instanceof EntityItem)
continue entityListLoop;
// Since the entities in entitiesToExclude could be null, it's important to call equals() on craftEntity
CraftEntity craftEntity = nmsEntity.getBukkitEntity();
for (Entity exclude : entitiesToExclude) if (craftEntity.equals(exclude))
continue entityListLoop;
// Check if we intersect this entity and check if the distance to it is smaller than the nearest distance so far
MovingObjectPosition entityIntersection = nmsEntity.getBoundingBox().b(rayStart, rayEnd);
if (entityIntersection != null) {
double distanceSq = rayStart.distanceSquared(entityIntersection.pos);
if (distanceSq < nearestDistanceSq) {
nearestDistanceSq = distanceSq;
intersectedEntity = nmsEntity;
intersectionPos = entityIntersection.pos;
}
}
}
// Determining the final result
if (nearestDistanceSq < Double.POSITIVE_INFINITY) {
Location hitLocation = new Location(world, intersectionPos.x, intersectionPos.y, intersectionPos.z);
if (intersectedEntity != null) {
return RaytraceResult.hitEntity(intersectedEntity.getBukkitEntity(), hitLocation);
} else {
return RaytraceResult.hitBlock(hitLocation);
}
} else {
return null;
}
}
use of net.minecraft.server.v1_15_R1.Vec3D in project Citizens2 by CitizensDev.
the class PlayerNavigation method k.
@Override
public void k() {
this.f += 1;
if (m()) {
return;
}
if (b()) {
l();
} else if ((this.d != null) && (this.d.e() < this.d.d())) {
Vec3D localVec3D = c();
Vec3D localObject = this.d.a(this.b, this.d.e());
if ((localVec3D.b > localObject.b) && (!this.b.onGround) && (MathHelper.floor(localVec3D.a) == MathHelper.floor(localObject.a)) && (MathHelper.floor(localVec3D.c) == MathHelper.floor(localObject.c))) {
this.d.c(this.d.e() + 1);
}
}
if (m()) {
return;
}
Vec3D localVec3D = this.d.a(this.b);
if (localVec3D == null) {
return;
}
Object localObject = new AxisAlignedBB(localVec3D.a, localVec3D.b, localVec3D.c, localVec3D.a, localVec3D.b, localVec3D.c).grow(0.5D, 0.5D, 0.5D);
List<AxisAlignedBB> localList = this.c.getCubes(this.b, ((AxisAlignedBB) localObject).a(0.0D, -1.0D, 0.0D));
double d1 = -1.0D;
localObject = ((AxisAlignedBB) localObject).c(0.0D, 1.0D, 0.0D);
for (AxisAlignedBB localAxisAlignedBB : localList) {
d1 = localAxisAlignedBB.b((AxisAlignedBB) localObject, d1);
}
this.b.getControllerMove().a(localVec3D.a, localVec3D.b + d1, localVec3D.c, this.e);
}
Aggregations