Search in sources :

Example 26 with Vec3D

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

the class PlayerNavigation method b.

@Override
public void b(BlockPosition var0) {
    if (this.c != null && !this.c.b() && this.c.e() != 0) {
        PathPoint var1 = this.c.c();
        Vec3D var2 = new Vec3D((var1.a + this.a.locX) / 2.0D, (var1.b + this.a.locY) / 2.0D, (var1.c + this.a.locZ) / 2.0D);
        if (var0.a(var2, this.c.e() - this.c.f())) {
            this.k();
        }
    }
}
Also used : PathPoint(net.minecraft.server.v1_14_R1.PathPoint) Vec3D(net.minecraft.server.v1_14_R1.Vec3D)

Example 27 with Vec3D

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

Example 28 with Vec3D

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

Example 29 with Vec3D

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

Example 30 with Vec3D

use of net.minecraft.server.v1_14_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;
    }
}
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)

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_14_R1.BlockPosition)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 PathPoint (net.minecraft.server.v1_14_R1.PathPoint)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