Java Code Examples for net.minecraft.util.Vec3#squareDistanceTo()

The following examples show how to use net.minecraft.util.Vec3#squareDistanceTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockGardenProxy.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
public MovingObjectPosition collisionRayTrace (World world, int x, int y, int z, Vec3 startVec, Vec3 endVec) {
    TileEntityGarden te = getGardenEntity(world, x, y, z);
    BlockGarden garden = getGardenBlock(world, x, y, z);
    if (te == null || garden == null)
        return super.collisionRayTrace(world, x, y, z, startVec, endVec);

    int baseY = getBaseBlockYCoord(world, x, y, z);

    MovingObjectPosition mop = null;
    for (int slot : garden.getSlotProfile().getPlantSlots()) {
        Block block = getPlantBlock(te, slot);
        if (block == null)
            continue;

        bindSlot(world, x, y, z, te, slot);
        try {
            float offsetX = garden.getSlotProfile().getPlantOffsetX(world, x, baseY, z, slot);
            float offsetY = garden.getSlotProfile().getPlantOffsetY(world, x, baseY, z, slot);
            float offsetZ = garden.getSlotProfile().getPlantOffsetZ(world, x, baseY, z, slot);

            Vec3 slotStartVec = Vec3.createVectorHelper(startVec.xCoord - offsetX, startVec.yCoord - offsetY, startVec.zCoord - offsetZ);
            Vec3 slotEndVec = Vec3.createVectorHelper(endVec.xCoord - offsetX, endVec.yCoord - offsetY, endVec.zCoord - offsetZ);

            MovingObjectPosition sub = block.collisionRayTrace(world, x, y, z, slotStartVec, slotEndVec);
            if (mop == null || slotStartVec.squareDistanceTo(mop.hitVec) > slotStartVec.squareDistanceTo(sub.hitVec))
                mop = sub;
        }
        catch (Exception e) {
            continue;
        }
        finally {
            unbindSlot(world, x, y, z, te);
        }
    }

    return mop;
}
 
Example 2
Source File: AltAxisAlignedBB.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
public MovingObjectPosition calculateIntercept(Vec3 par1Vec3, Vec3 par2Vec3) {
    Vec3 var3 = par1Vec3.getIntermediateWithXValue(par2Vec3, this.minX);
    Vec3 var4 = par1Vec3.getIntermediateWithXValue(par2Vec3, this.maxX);
    Vec3 var5 = par1Vec3.getIntermediateWithYValue(par2Vec3, this.minY);
    Vec3 var6 = par1Vec3.getIntermediateWithYValue(par2Vec3, this.maxY);
    Vec3 var7 = par1Vec3.getIntermediateWithZValue(par2Vec3, this.minZ);
    Vec3 var8 = par1Vec3.getIntermediateWithZValue(par2Vec3, this.maxZ);
    if (!this.isVecInYZ(var3)) {
        var3 = null;
    }
    if (!this.isVecInYZ(var4)) {
        var4 = null;
    }
    if (!this.isVecInXZ(var5)) {
        var5 = null;
    }
    if (!this.isVecInXZ(var6)) {
        var6 = null;
    }
    if (!this.isVecInXY(var7)) {
        var7 = null;
    }
    if (!this.isVecInXY(var8)) {
        var8 = null;
    }
    Vec3 var9 = null;
    if (var3 != null) {
        var9 = var3;
    }
    if (var4 != null && (var9 == null || par1Vec3.squareDistanceTo(var4) < par1Vec3.squareDistanceTo(var9))) {
        var9 = var4;
    }
    if (var5 != null && (var9 == null || par1Vec3.squareDistanceTo(var5) < par1Vec3.squareDistanceTo(var9))) {
        var9 = var5;
    }
    if (var6 != null && (var9 == null || par1Vec3.squareDistanceTo(var6) < par1Vec3.squareDistanceTo(var9))) {
        var9 = var6;
    }
    if (var7 != null && (var9 == null || par1Vec3.squareDistanceTo(var7) < par1Vec3.squareDistanceTo(var9))) {
        var9 = var7;
    }
    if (var8 != null && (var9 == null || par1Vec3.squareDistanceTo(var8) < par1Vec3.squareDistanceTo(var9))) {
        var9 = var8;
    }
    if (var9 == null) {
        return null;
    }
    int var10 = -1;
    if (var9 == var3) {
        var10 = 4;
    }
    if (var9 == var4) {
        var10 = 5;
    }
    if (var9 == var5) {
        var10 = 0;
    }
    if (var9 == var6) {
        var10 = 1;
    }
    if (var9 == var7) {
        var10 = 2;
    }
    if (var9 == var8) {
        var10 = 3;
    }
    return new MovingObjectPosition(0, 0, 0, var10, var9);
}
 
Example 3
Source File: DistanceEntitySorter.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public int compare(Entity entity1, Entity entity2){
    Vec3 vec = drone.getPosition();
    double d0 = vec.squareDistanceTo(entity1.posX, entity1.posY, entity1.posZ);
    double d1 = vec.squareDistanceTo(entity2.posX, entity2.posY, entity2.posZ);
    return d0 < d1 ? -1 : d0 > d1 ? 1 : 0;
}