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

The following examples show how to use net.minecraft.entity.Entity#getLook() . 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: DiscreteMovementCommandsImplementation.java    From malmo with MIT License 6 votes vote down vote up
private RayTraceResult getObjectMouseOver(DiscreteMovementCommand command)
{
    RayTraceResult mop = null;
    if (command.equals(DiscreteMovementCommand.USE))
        mop = Minecraft.getMinecraft().objectMouseOver;
    else if (command.equals(DiscreteMovementCommand.JUMPUSE))
    {
        long partialTicks = 0;  //Minecraft.timer.renderPartialTicks
        Entity viewer = Minecraft.getMinecraft().player;
        double blockReach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
        Vec3d eyePos = viewer.getPositionEyes(partialTicks);
        Vec3d lookVec = viewer.getLook(partialTicks);
        int yOffset = 1;    // For the jump
        Vec3d searchVec = eyePos.addVector(lookVec.xCoord * blockReach, yOffset + lookVec.yCoord * blockReach, lookVec.zCoord * blockReach);
        mop = Minecraft.getMinecraft().world.rayTraceBlocks(eyePos, searchVec, false, false, false);
    }
    return mop;
}
 
Example 2
Source File: ItemBasicLaserGun.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public RayTraceResult rayTraceEntity(World world, Entity entity) {

		Vec3d vec3d = new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
		Vec3d vec3d1 = entity.getLook(0);
		Vec3d vec3d2 = vec3d.addVector(vec3d1.x * reachDistance, vec3d1.y * reachDistance, vec3d1.z * reachDistance);


		List<Entity> list = world.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().grow(vec3d1.x * reachDistance, vec3d1.y * reachDistance, vec3d1.z * reachDistance).expand(1.0D, 1.0D, 1.0D), Predicates.and(EntitySelectors.NOT_SPECTATING, new Predicate<Entity>()
				{
			public boolean apply(@Nullable Entity p_apply_1_)
			{
				return p_apply_1_ != null && p_apply_1_.canBeCollidedWith();
			}
				}));

		for (int j = 0; j < list.size(); ++j)
		{
			Entity entity1 = (Entity)list.get(j);
			AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow((double)entity1.getCollisionBorderSize());
			RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(vec3d, vec3d2);

			if (axisalignedbb.contains(vec3d))
			{
			}
			else if (raytraceresult != null)
			{
				raytraceresult.entityHit = entity1;
				return raytraceresult;
			}
		}

		return null;
	}
 
Example 3
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the index of the BB in the given list that the given entity is currently looking at.
 * @return the list index of the pointed box, or -1 of no hit was detected
 */
public static int getPointedBox(Entity entity, double reach, List<AxisAlignedBB> boxes, float partialTicks)
{
    Vec3d eyesVec = entity.getPositionEyes(partialTicks);
    Vec3d lookVec = entity.getLook(partialTicks);

    return getPointedBox(eyesVec, lookVec, reach, boxes);
}
 
Example 4
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the index of the BB in the given list that the given entity is currently looking at.
 * @return the list index of the pointed box, or null of no hit was detected
 */
public static <T> T getPointedBox(Entity entity, double reach, Map<T, AxisAlignedBB> boxes, float partialTicks)
{
    Vec3d eyesVec = entity.getPositionEyes(partialTicks);
    Vec3d lookVec = entity.getLook(partialTicks);

    return getPointedBox(eyesVec, lookVec, reach, boxes);
}
 
Example 5
Source File: MixinEntityRenderer.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @author
 */
@Overwrite
public void getMouseOver(float p_getMouseOver_1_) {
    Entity entity = this.mc.getRenderViewEntity();
    if(entity != null && this.mc.theWorld != null) {
        this.mc.mcProfiler.startSection("pick");
        this.mc.pointedEntity = null;

        final Reach reach = (Reach) LiquidBounce.moduleManager.getModule(Reach.class);

        double d0 = reach.getState() ? reach.getMaxRange() : (double) this.mc.playerController.getBlockReachDistance();
        this.mc.objectMouseOver = entity.rayTrace(reach.getState() ? reach.getBuildReachValue().get() : d0, p_getMouseOver_1_);
        double d1 = d0;
        Vec3 vec3 = entity.getPositionEyes(p_getMouseOver_1_);
        boolean flag = false;
        if(this.mc.playerController.extendedReach()) {
            d0 = 6.0D;
            d1 = 6.0D;
        }else if(d0 > 3.0D) {
            flag = true;
        }

        if(this.mc.objectMouseOver != null) {
            d1 = this.mc.objectMouseOver.hitVec.distanceTo(vec3);
        }

        if(reach.getState()) {
            d1 = reach.getCombatReachValue().get();

            final MovingObjectPosition movingObjectPosition = entity.rayTrace(d1, p_getMouseOver_1_);

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

        Vec3 vec31 = entity.getLook(p_getMouseOver_1_);
        Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
        this.pointedEntity = null;
        Vec3 vec33 = null;
        float f = 1.0F;
        List<Entity> list = this.mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand((double) f, (double) f, (double) f), Predicates.and(EntitySelectors.NOT_SPECTATING, p_apply_1_ -> p_apply_1_.canBeCollidedWith()));
        double d2 = d1;

        for(int j = 0; j < list.size(); ++j) {
            Entity entity1 = (Entity) list.get(j);
            float f1 = entity1.getCollisionBorderSize();
            AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double) f1, (double) f1, (double) f1);
            MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
            if(axisalignedbb.isVecInside(vec3)) {
                if(d2 >= 0.0D) {
                    this.pointedEntity = entity1;
                    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(entity1 == entity.ridingEntity && !entity.canRiderInteract()) {
                        if(d2 == 0.0D) {
                            this.pointedEntity = entity1;
                            vec33 = movingobjectposition.hitVec;
                        }
                    }else{
                        this.pointedEntity = entity1;
                        vec33 = movingobjectposition.hitVec;
                        d2 = d3;
                    }
                }
            }
        }

        if (this.pointedEntity != null && flag && vec3.distanceTo(vec33) > (reach.getState() ? reach.getCombatReachValue().get() : 3.0D)) {
            this.pointedEntity = null;
            this.mc.objectMouseOver = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec33, (EnumFacing) null, new BlockPos(vec33));
        }

        if(this.pointedEntity != null && (d2 < d1 || this.mc.objectMouseOver == null)) {
            this.mc.objectMouseOver = new MovingObjectPosition(this.pointedEntity, vec33);
            if(this.pointedEntity instanceof EntityLivingBase || this.pointedEntity instanceof EntityItemFrame) {
                this.mc.pointedEntity = this.pointedEntity;
            }
        }

        this.mc.mcProfiler.endSection();
    }
}
 
Example 6
Source File: MixinEntityRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @author - Sk1er (added forward for distance)
 * @reason - ReachDisplay
 */
@Overwrite
public void getMouseOver(float partialTicks) {
    Entity entity = mc.getRenderViewEntity();
    if (entity != null && mc.theWorld != null) {
        mc.mcProfiler.startSection("pick");
        mc.pointedEntity = null;
        double d0 = mc.playerController.getBlockReachDistance();
        mc.objectMouseOver = entity.rayTrace(d0, partialTicks);
        double d1 = d0;
        Vec3 vec3 = entity.getPositionEyes(partialTicks);
        boolean flag = false;

        if (mc.playerController.extendedReach()) {
            d0 = 6.0D;
            d1 = 6.0D;
        } else if (d0 > 3.0D) {
            flag = true;
        }

        if (mc.objectMouseOver != null) d1 = mc.objectMouseOver.hitVec.distanceTo(vec3);

        Vec3 vec31 = entity.getLook(partialTicks);
        Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
        pointedEntity = null;
        Vec3 vec33 = null;
        float f = 1.0F;
        List<Entity> list = mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0,
            vec31.yCoord * d0, vec31.zCoord * d0).expand(f, f, f), Predicates.and(EntitySelectors.NOT_SPECTATING, Entity::canBeCollidedWith));
        double d2 = d1;

        for (Entity entity1 : list) {
            float f1 = entity1.getCollisionBorderSize();
            AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand(f1, f1, f1);
            MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);

            if (axisalignedbb.isVecInside(vec3)) {
                if (d2 >= 0.0D) {
                    pointedEntity = entity1;
                    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 (entity1 == entity.ridingEntity) {
                        if (d2 == 0.0D) {
                            pointedEntity = entity1;
                            vec33 = movingobjectposition.hitVec;
                        }
                    } else {
                        pointedEntity = entity1;
                        vec33 = movingobjectposition.hitVec;
                        d2 = d3;
                    }
                }
            }
        }
        double v = 0;

        if (pointedEntity != null && flag && (v = vec3.distanceTo(vec33)) > 3.0D) {
            pointedEntity = null;
            mc.objectMouseOver = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec33, null, new BlockPos(vec33));
        }

        if (v != 0 || pointedEntity != null) ReachDisplay.dis = v;

        if (pointedEntity != null && (d2 < d1 || mc.objectMouseOver == null)) {
            mc.objectMouseOver = new MovingObjectPosition(pointedEntity, vec33);

            if (pointedEntity instanceof EntityLivingBase || pointedEntity instanceof EntityItemFrame) {
                mc.pointedEntity = pointedEntity;
            }
        }

        mc.mcProfiler.endSection();
    }
}
 
Example 7
Source File: RenderUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void renderEntityDebugBoundingBox(Entity entityIn, float partialTicks, boolean renderLook, boolean renderEyeHeight)
{
    Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity();
    double x = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks;
    double y = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks;
    double z = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks;
    x -= renderViewEntity.lastTickPosX + (renderViewEntity.posX - renderViewEntity.lastTickPosX) * (double)partialTicks;
    y -= renderViewEntity.lastTickPosY + (renderViewEntity.posY - renderViewEntity.lastTickPosY) * (double)partialTicks;
    z -= renderViewEntity.lastTickPosZ + (renderViewEntity.posZ - renderViewEntity.lastTickPosZ) * (double)partialTicks;

    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.depthMask(false);
    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    GlStateManager.disableCull();
    GlStateManager.disableBlend();
    GlStateManager.glLineWidth(1.0F);

    double entityRadius = entityIn.width / 2.0D;
    AxisAlignedBB bb = entityIn.getEntityBoundingBox();

    RenderGlobal.drawBoundingBox(bb.minX - entityIn.posX + x,
                                 bb.minY - entityIn.posY + y,
                                 bb.minZ - entityIn.posZ + z,
                                 bb.maxX - entityIn.posX + x,
                                 bb.maxY - entityIn.posY + y,
                                 bb.maxZ - entityIn.posZ + z,
                                 1.0F, 1.0F, 1.0F, 1.0F);

    if (renderEyeHeight && entityIn instanceof EntityLivingBase)
    {
        RenderGlobal.drawBoundingBox(x - entityRadius,
                                     y + entityIn.getEyeHeight() - 0.01D,
                                     z - entityRadius,
                                     x + entityRadius,
                                     y + entityIn.getEyeHeight() + 0.01D,
                                     z + entityRadius, 1.0F, 0.0F, 0.0F, 1.0F);
    }

    if (renderLook)
    {
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder vertexbuffer = tessellator.getBuffer();
        Vec3d look = entityIn.getLook(partialTicks);
        vertexbuffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
        vertexbuffer.pos(x, y + entityIn.getEyeHeight(), z).color(0, 0, 255, 255).endVertex();
        vertexbuffer.pos(x + look.x * 2.0D, y + entityIn.getEyeHeight() + look.y * 2.0D, z + look.z * 2.0D).color(0, 0, 255, 255).endVertex();
        tessellator.draw();
    }

    GlStateManager.enableTexture2D();
    GlStateManager.enableLighting();
    GlStateManager.enableCull();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
}