Search in sources :

Example 26 with Vec3D

use of net.minecraft.server.v1_16_R2.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);
}
Also used : Vec3D(net.minecraft.server.v1_8_R3.Vec3D) PathPoint(net.minecraft.server.v1_8_R3.PathPoint)

Example 27 with Vec3D

use of net.minecraft.server.v1_16_R2.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;
}
Also used : Vec3D(net.minecraft.server.v1_8_R3.Vec3D)

Example 28 with Vec3D

use of net.minecraft.server.v1_16_R2.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;
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) Entity(org.bukkit.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) WorldServer(net.minecraft.server.v1_12_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) World(org.bukkit.World) Vec3D(net.minecraft.server.v1_12_R1.Vec3D) MovingObjectPosition(net.minecraft.server.v1_12_R1.MovingObjectPosition) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) EntityItem(net.minecraft.server.v1_12_R1.EntityItem) Location(org.bukkit.Location)

Example 29 with Vec3D

use of net.minecraft.server.v1_16_R2.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);
}
Also used : AxisAlignedBB(net.minecraft.server.v1_8_R3.AxisAlignedBB) Vec3D(net.minecraft.server.v1_8_R3.Vec3D)

Example 30 with Vec3D

use of net.minecraft.server.v1_16_R2.Vec3D in project Citizens2 by CitizensDev.

the class PlayerNavigation method m.

@Override
protected void m() {
    Vec3D localVec3D1 = c();
    int i1 = this.c.d();
    for (int i2 = this.c.e(); i2 < this.c.d(); i2++) {
        if (this.c.a(i2).b != Math.floor(localVec3D1.y)) {
            i1 = i2;
            break;
        }
    }
    this.n = (this.a.width > 0.75F ? this.a.width / 2.0F : 0.75F - this.a.width / 2.0F);
    Vec3D localVec3D2 = this.c.f();
    if ((MathHelper.e((float) (this.a.locX - (localVec3D2.x + 0.5D))) < this.n) && (MathHelper.e((float) (this.a.locZ - (localVec3D2.z + 0.5D))) < this.n) && (Math.abs(this.a.locY - localVec3D2.y) < 1.0D)) {
        this.c.c(this.c.e() + 1);
    }
    int i3 = MathHelper.f(this.a.width);
    int i4 = MathHelper.f(this.a.length);
    int i5 = i3;
    for (int i6 = i1 - 1; i6 >= this.c.e(); i6--) {
        if (a(localVec3D1, this.c.a(this.a, i6), i3, i4, i5)) {
            this.c.c(i6);
            break;
        }
    }
    a(localVec3D1);
}
Also used : Vec3D(net.minecraft.server.v1_11_R1.Vec3D) PathPoint(net.minecraft.server.v1_11_R1.PathPoint)

Aggregations

Vec3D (net.minecraft.server.v1_16_R3.Vec3D)11 Vec3D (net.minecraft.server.v1_15_R1.Vec3D)10 Vec3D (net.minecraft.server.v1_14_R1.Vec3D)9 Vec3D (net.minecraft.server.v1_12_R1.Vec3D)7 Vec3D (net.minecraft.server.v1_10_R1.Vec3D)5 Vec3D (net.minecraft.server.v1_11_R1.Vec3D)5 Vec3D (net.minecraft.server.v1_8_R3.Vec3D)4 Gravity (net.citizensnpcs.trait.Gravity)3 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)2 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)2 AxisAlignedBB (net.minecraft.server.v1_12_R1.AxisAlignedBB)2 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)2 MovingObjectPosition (net.minecraft.server.v1_12_R1.MovingObjectPosition)2 BlockPosition (net.minecraft.server.v1_14_R1.BlockPosition)2 AxisAlignedBB (net.minecraft.server.v1_16_R3.AxisAlignedBB)2 BaseBlockPosition (net.minecraft.server.v1_16_R3.BaseBlockPosition)2 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)2 PathPoint (net.minecraft.server.v1_16_R3.PathPoint)2 AxisAlignedBB (net.minecraft.server.v1_8_R3.AxisAlignedBB)2 LivingEntity (org.bukkit.entity.LivingEntity)2