Java Code Examples for net.minecraft.world.World#rayTraceBlocks()

The following examples show how to use net.minecraft.world.World#rayTraceBlocks() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: TofuCraftReload   File: DiamondTofuToolHandler.java    License: MIT License 6 votes vote down vote up
protected static RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids) {
    float f = playerIn.rotationPitch;
    float f1 = playerIn.rotationYaw;
    double d0 = playerIn.posX;
    double d1 = playerIn.posY + (double) playerIn.getEyeHeight();
    double d2 = playerIn.posZ;
    Vec3d vec3d = new Vec3d(d0, d1, d2);
    float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI);
    float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI);
    float f4 = -MathHelper.cos(-f * 0.017453292F);
    float f5 = MathHelper.sin(-f * 0.017453292F);
    float f6 = f3 * f4;
    float f7 = f2 * f4;
    double d3 = playerIn.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
    Vec3d vec3d1 = vec3d.addVector((double) f6 * d3, (double) f5 * d3, (double) f7 * d3);
    return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
}
 
Example 2
public static void addBlockLandingEffects(World worldObj, Vector3 entityPos, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager, int numParticles) {
    Vector3 start = entityPos.copy();
    Vector3 end = start.copy().add(Vector3.down.copy().multiply(4));
    RayTraceResult traceResult = worldObj.rayTraceBlocks(start.vec3(), end.vec3(), true, false, true);
    double speed = 0.15;
    Random randy = new Random();

    float red = (spriteColor >> 16 & 255) / 255.0F;
    float green = (spriteColor >> 8 & 255) / 255.0F;
    float blue = (spriteColor & 255) / 255.0F;

    if (traceResult != null && traceResult.typeOfHit == Type.BLOCK && numParticles != 0) {
        for (int i = 0; i < numParticles; i++) {
            double mX = randy.nextGaussian() * speed;
            double mY = randy.nextGaussian() * speed;
            double mZ = randy.nextGaussian() * speed;
            DigIconParticle digIconParticle = DigIconParticle.newLandingParticle(worldObj, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, atlasSprite);
            digIconParticle.setRBGColorF(red, green, blue);
            manager.addEffect(digIconParticle);
        }
    }
}
 
Example 3
Source Project: AdvancedRocketry   File: ItemBasicLaserGun.java    License: MIT License 6 votes vote down vote up
@Override
protected RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn,
		boolean useLiquids) {
	float f = playerIn.rotationPitch;
	float f1 = playerIn.rotationYaw;
	double d0 = playerIn.posX;
	double d1 = playerIn.posY + (double)playerIn.getEyeHeight();
	double d2 = playerIn.posZ;
	Vec3d vec3d = new Vec3d(d0, d1, d2);
	float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI);
	float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI);
	float f4 = -MathHelper.cos(-f * 0.017453292F);
	float f5 = MathHelper.sin(-f * 0.017453292F);
	float f6 = f3 * f4;
	float f7 = f2 * f4;
	double d3 = reachDistance;

	Vec3d vec3d1 = vec3d.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
	return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false);
}
 
Example 4
Source Project: Chisel-2   File: General.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) {
	float var4 = 1.0F;
	float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4;
	float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4;
	double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * var4;
	double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * var4 + 1.62D - par2EntityPlayer.yOffset;
	double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * var4;
	// TODO- 1.7.10 fix?
	Vec3 var13 = Vec3.createVectorHelper(var7, var9, var11);
	float var14 = MathHelper.cos(-var6 * 0.017453292F - (float) Math.PI);
	float var15 = MathHelper.sin(-var6 * 0.017453292F - (float) Math.PI);
	float var16 = -MathHelper.cos(-var5 * 0.017453292F);
	float var17 = MathHelper.sin(-var5 * 0.017453292F);
	float var18 = var15 * var16;
	float var20 = var14 * var16;
	double var21 = 5.0D;

	if (par2EntityPlayer instanceof EntityPlayerMP) {
		var21 = ((EntityPlayerMP) par2EntityPlayer).theItemInWorldManager.getBlockReachDistance();
	}

	Vec3 var23 = var13.addVector(var18 * var21, var17 * var21, var20 * var21);
	return par1World.rayTraceBlocks(var13, var23, par3);
}
 
Example 5
Source Project: Chisel   File: General.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3)
{
    float var4 = 1.0F;
    float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4;
    float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4;
    double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * var4;
    double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * var4 + 1.62D - par2EntityPlayer.yOffset;
    double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * var4;
    //TODO- 1.7.10 fix?
    Vec3 var13 = Vec3.createVectorHelper(var7, var9, var11);
    float var14 = MathHelper.cos(-var6 * 0.017453292F - (float) Math.PI);
    float var15 = MathHelper.sin(-var6 * 0.017453292F - (float) Math.PI);
    float var16 = -MathHelper.cos(-var5 * 0.017453292F);
    float var17 = MathHelper.sin(-var5 * 0.017453292F);
    float var18 = var15 * var16;
    float var20 = var14 * var16;
    double var21 = 5.0D;

    if(par2EntityPlayer instanceof EntityPlayerMP)
    {
        var21 = ((EntityPlayerMP) par2EntityPlayer).theItemInWorldManager.getBlockReachDistance();
    }

    Vec3 var23 = var13.addVector(var18 * var21, var17 * var21, var20 * var21);
    return par1World.rayTraceBlocks(var13, var23, par3);
}
 
Example 6
public RayTraceResult getLook(EntityPlayer player, World ws) {

		Vec3d eye = player.getPositionEyes(1.0F).subtract(getPositionVector()).add(getOffset().getX(),
				getOffset().getY(), getOffset().getZ());
		Vec3d look = eye.add(player.getLookVec()
				.scale(player.getAttributeMap().getAttributeInstance(EntityPlayer.REACH_DISTANCE).getAttributeValue()));

		RayTraceResult ray = ws.rayTraceBlocks(eye, look, false);
		return ray;
	}
 
Example 7
/**
 * Returns the first hittable blockpos along an entity's line of sight
 */
public static BlockPos getLineOfSightTargetBlock(World world, Entity ent, double dist)
{
	Vec3d start = ent.getPositionVector().add(0D, ent.getEyeHeight(), 0D);
	Vec3d lookVec = ent.getLookVec().scale(dist);	// look along a distance of 16
	Vec3d end = start.add(lookVec);
	RayTraceResult result = world.rayTraceBlocks(start, end, false, false, true);
	return (result == null) ? null : result.getBlockPos();
}
 
Example 8
/**
 * Returns the first hittable blockpos along a random vector in a cone based
 * on an entity's line of sight
 */
public static BlockPos getConeOfSightTargetBlock(World world, Entity ent, double dist)
{
	Vec3d start = ent.getPositionVector().add(0D, ent.getEyeHeight(), 0D);
	
	Vec3d LOSvec = ent.getLookVec();
	LOSvec = LOSvec.rotatePitch((world.rand.nextFloat()-0.5F)*MathExtender.PI_HALVED);
	LOSvec = LOSvec.rotateYaw((world.rand.nextFloat()-0.5F)*MathExtender.PI_QUARTERED);
	LOSvec = LOSvec.scale(dist);
	Vec3d end = start.add(LOSvec);
	RayTraceResult result = world.rayTraceBlocks(start, end, false, false, true);
	return (result == null) ? null : result.getBlockPos();
}
 
Example 9
/**
 * Returns the first hittable blockpos between an entity and a target position
 */
public static BlockPos getTargetBlockTowards(World world, Entity ent, BlockPos target)
{
	Vec3d start = ent.getPositionVector().add(0D, ent.getEyeHeight(), 0D);
	Vec3d end = new Vec3d(target);
	RayTraceResult result = world.rayTraceBlocks(start, end, false, false, true);
	return (result == null) ? null : result.getBlockPos();
}
 
Example 10
Source Project: MiningGadgets   File: VectorHelper.java    License: MIT License 5 votes vote down vote up
public static BlockRayTraceResult getLookingAt(PlayerEntity player, RayTraceContext.FluidMode rayTraceFluid, int range) {
    World world = player.world;

    Vec3d look = player.getLookVec();
    Vec3d start = new Vec3d(player.getPosX(), player.getPosY() + player.getEyeHeight(), player.getPosZ());

    Vec3d end = new Vec3d(player.getPosX() + look.x * (double) range, player.getPosY() + player.getEyeHeight() + look.y * (double) range, player.getPosZ() + look.z * (double) range);
    RayTraceContext context = new RayTraceContext(start, end, RayTraceContext.BlockMode.COLLIDER, rayTraceFluid, player);
    return world.rayTraceBlocks(context);
}
 
Example 11
public static RayTraceResult getRayTraceFromPlayer(World world, EntityPlayer player, boolean useLiquids)
{
    double range = 5.0D;
    Vec3d eyesVec = getEyesVec(player);
    Vec3d rangedLookRot = player.getLook(1f).scale(range);
    Vec3d lookVec = eyesVec.add(rangedLookRot);

    if (player instanceof EntityPlayer)
    {
        range = ((EntityPlayer) player).getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
    }

    return world.rayTraceBlocks(eyesVec, lookVec, useLiquids, false, false);
}
 
Example 12
@SubscribeEvent
public void onRenderTick(RenderWorldLastEvent event) {

    World world = Minecraft.getMinecraft().theWorld;
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    MovingObjectPosition mop = world.rayTraceBlocks(RayTracer.instance().getStartVector(player).toVec3(), RayTracer.instance()
            .getEndVector(player).toVec3());
    ItemStack item = player.getCurrentEquippedItem();
    if (item == null)
        return;
    if (!(item.getItem() instanceof IFramezWrench))
        return;
    if (Minecraft.getMinecraft().gameSettings.hideGUI && Minecraft.getMinecraft().currentScreen == null)
        return;

    double thickness = 1 / 32D;

    GL11.glPushMatrix();
    {
        GL11.glDisable(GL11.GL_TEXTURE_2D);

        Vec3 playerPos = player.getPosition(event.partialTicks);

        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

        GL11.glColor4d(1, 1, 1, 1);

        List<TileMotor> l = null;

        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te != null && te instanceof TileMotor) {
                l = new ArrayList<TileMotor>();
                l.add((TileMotor) te);
            }
        }

        if (l == null)
            l = MotorCache.getLoadedMotors();

        for (TileMotor m : l) {
            if (m.getWorldObj() == world) {
                List<Vec3i> blocking = m.getBlocking();
                if (blocking == null || blocking.size() == 0)
                    continue;

                for (Vec3i b : blocking) {
                    double x = b.getX() - playerPos.xCoord;
                    double y = b.getY() - playerPos.yCoord;
                    double z = b.getZ() - playerPos.zCoord;

                    GL11.glPushMatrix();
                    {
                        GL11.glTranslated(x - thickness, y - thickness, z - thickness);
                        GL11.glScaled(1 + (thickness * 2), 1 + (thickness * 2), 1 + (thickness * 2));

                        GL11.glColor4d(1, 0, 0, .25);

                        GL11.glBegin(GL11.GL_QUADS);
                        RenderUtils.drawColoredCube();
                        GL11.glEnd();
                    }
                    GL11.glPopMatrix();

                    GL11.glPushMatrix();
                    {
                        GL11.glDisable(GL11.GL_DEPTH_TEST);
                        GL11.glColor4d(.75, 0, 0, .5);

                        GL11.glLineWidth(2);

                        GL11.glBegin(GL11.GL_LINES);
                        GL11.glVertex3d(m.xCoord - playerPos.xCoord + 0.5, m.yCoord - playerPos.yCoord + 0.5, m.zCoord
                                - playerPos.zCoord + 0.5);
                        GL11.glVertex3d(x + 0.5, y + 0.5, z + 0.5);
                        GL11.glEnd();
                        GL11.glEnable(GL11.GL_DEPTH_TEST);
                    }
                    GL11.glPopMatrix();
                }
            }
        }

        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }
    GL11.glPopMatrix();
}