Java Code Examples for net.minecraft.entity.Entity#canBeCollidedWith()

The following examples show how to use net.minecraft.entity.Entity#canBeCollidedWith() . 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: EndPort.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private Entity getMouseOver(float partialTicks, double distance, boolean canBeCollidedWith) {
    Minecraft mc = Wrapper.INSTANCE.mc();
    Entity pointedEntity = null;
    MovingObjectPosition rayTrace = null;

    if (mc.renderViewEntity != null) {
        if (mc.theWorld != null) {
            Vec3 positionVec = mc.renderViewEntity.getPosition(partialTicks);
            Vec3 lookVec = mc.renderViewEntity.getLook(partialTicks);
            Vec3 posDistVec = positionVec.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance);
            double boxExpand = 1.0F;
            List<Entity> entities = mc.theWorld.getEntitiesWithinAABBExcludingEntity(mc.renderViewEntity, mc.renderViewEntity.boundingBox.addCoord(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance).expand(boxExpand, boxExpand, boxExpand));
            double mincalc = Double.MAX_VALUE;
            for (int i = 0; i < entities.size(); i++) {
                Entity entity = entities.get(i);
                if (!canBeCollidedWith || entity.canBeCollidedWith()) {
                    double borderSize = entity.getCollisionBorderSize();
                    AxisAlignedBB expEntityBox = entity.boundingBox.expand(borderSize, borderSize, borderSize);
                    MovingObjectPosition calculateInterceptPos = expEntityBox.calculateIntercept(positionVec, posDistVec);
                    if (calculateInterceptPos != null) {
                        double calcInterceptPosDist = positionVec.distanceTo(calculateInterceptPos.hitVec);
                        if (mincalc > calcInterceptPosDist) {
                            mincalc = calcInterceptPosDist;
                            pointedEntity = entity;
                        }
                    }
                }
            }
            if (pointedEntity != null) {
                return pointedEntity;
            }
        }
    }

    return null;
}
 
Example 2
Source File: ShowArmor.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public Entity getMouseOver(float partialTicks, double distance, boolean canBeCollidedWith) {
    Minecraft mc = Wrapper.INSTANCE.mc();
    Entity pointedEntity = null;
    MovingObjectPosition rayTrace = null;

    if (mc.renderViewEntity != null) {
        if (mc.theWorld != null) {
            Vec3 positionVec = mc.renderViewEntity.getPosition(partialTicks);
            Vec3 lookVec = mc.renderViewEntity.getLook(partialTicks);
            Vec3 posDistVec = positionVec.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance);
            double boxExpand = 1.0F;
            @SuppressWarnings("unchecked")
            List<Entity> entities = mc.theWorld.getEntitiesWithinAABBExcludingEntity(mc.renderViewEntity, mc.renderViewEntity.boundingBox.addCoord(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance).expand(boxExpand, boxExpand, boxExpand));
            double mincalc = Double.MAX_VALUE;
            for (Entity entity : entities) {
                if (!canBeCollidedWith || entity.canBeCollidedWith()) {
                    double borderSize = entity.getCollisionBorderSize();
                    AxisAlignedBB expEntityBox = entity.boundingBox.expand(borderSize, borderSize, borderSize);
                    MovingObjectPosition calculateInterceptPos = expEntityBox.calculateIntercept(positionVec, posDistVec);
                    if (calculateInterceptPos != null) {
                        double calcInterceptPosDist = positionVec.distanceTo(calculateInterceptPos.hitVec);
                        if (mincalc > calcInterceptPosDist) {
                            mincalc = calcInterceptPosDist;
                            pointedEntity = entity;
                        }
                    }
                }
            }
            if (pointedEntity != null) {
                return pointedEntity;
            }
        }
    }

    return null;
}
 
Example 3
Source File: ProjectilesModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check if our path collides with an entity.
 *
 * @param prediction     the predicted position
 * @param blockCollision block collision if we had one
 */
private void onCollideWithEntity(Vec3d prediction, RayTraceResult blockCollision) {
    Entity collidingEntity = null;
    RayTraceResult collidingPosition = null;

    double currentDistance = 0.0d;
    // Get all possible collision entities disregarding the local player
    List<Entity> collisionEntities = Minecraft.getMinecraft().world.getEntitiesWithinAABBExcludingEntity(this.shooter, this.boundingBox.expand(this.motion.x, this.motion.y, this.motion.z).grow(1.0D, 1.0D, 1.0D));

    // Loop through every loaded entity in the world
    for (Entity entity : collisionEntities) {
        // Check if we can collide with the entity or it's ourself
        if (!entity.canBeCollidedWith()) {
            continue;
        }

        // Check if we collide with our bounding box
        float collisionSize = entity.getCollisionBorderSize();
        AxisAlignedBB expandedBox = entity.getEntityBoundingBox().expand(collisionSize, collisionSize, collisionSize);
        RayTraceResult objectPosition = expandedBox.calculateIntercept(this.position, prediction);

        // Check if we have a collision
        if (objectPosition != null) {
            double distanceTo = this.position.distanceTo(objectPosition.hitVec);

            // Check if we've gotten a closer entity
            if (distanceTo < currentDistance || currentDistance == 0.0D) {
                collidingEntity = entity;
                collidingPosition = objectPosition;
                currentDistance = distanceTo;
            }
        }
    }

    // Check if we had an entity
    if (collidingEntity != null) {
        // Set our target to the result
        this.target = new RayTraceResult(collidingEntity, collidingPosition.hitVec);
    } else {
        // Fallback to the block collision
        this.target = blockCollision;
    }
}
 
Example 4
Source File: PneumaticCraftUtils.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static MovingObjectPosition getMouseOverServer(EntityLivingBase lookingEntity, double range){

        MovingObjectPosition mop = raytraceEntityBlocks(lookingEntity, range);
        double d1 = range;
        Pair<Vec3, Vec3> startAndEnd = getStartAndEndLookVec(lookingEntity, (float)range);
        Vec3 vec3 = startAndEnd.getLeft();

        if(mop != null) {
            d1 = mop.hitVec.distanceTo(vec3);
        }

        Vec3 vec31 = lookingEntity.getLookVec();
        Vec3 vec32 = startAndEnd.getRight();
        Entity pointedEntity = null;
        Vec3 vec33 = null;
        float f1 = 1.0F;
        List list = lookingEntity.worldObj.getEntitiesWithinAABBExcludingEntity(lookingEntity, lookingEntity.boundingBox.addCoord(vec31.xCoord * range, vec31.yCoord * range, vec31.zCoord * range).expand(f1, f1, f1));
        double d2 = d1;

        for(int i = 0; i < list.size(); ++i) {
            Entity entity = (Entity)list.get(i);

            if(entity.canBeCollidedWith()) {
                float f2 = entity.getCollisionBorderSize();
                AxisAlignedBB axisalignedbb = entity.boundingBox.expand(f2, f2, f2);
                MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);

                if(axisalignedbb.isVecInside(vec3)) {
                    if(0.0D < d2 || d2 == 0.0D) {
                        pointedEntity = entity;
                        vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
                        d2 = 0.0D;
                    }
                } else if(movingobjectposition != null) {
                    double d3 = vec3.distanceTo(movingobjectposition.hitVec);

                    if(d3 < d2 || d2 == 0.0D) {
                        if(entity == entity.ridingEntity && !entity.canRiderInteract()) {
                            if(d2 == 0.0D) {
                                pointedEntity = entity;
                                vec33 = movingobjectposition.hitVec;
                            }
                        } else {
                            pointedEntity = entity;
                            vec33 = movingobjectposition.hitVec;
                            d2 = d3;
                        }
                    }
                }
            }
        }

        if(pointedEntity != null && (d2 < d1 || mop == null)) {
            mop = new MovingObjectPosition(pointedEntity, vec33);
        }
        return mop;
    }