net.minecraft.world.RayTraceContext Java Examples

The following examples show how to use net.minecraft.world.RayTraceContext. 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: Nuker.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public boolean canSeeBlock(BlockPos pos) {
	double diffX = pos.getX() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).x;
	double diffY = pos.getY() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).y;
	double diffZ = pos.getZ() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).z;
		
	double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
		
	float yaw = mc.player.yaw + MathHelper.wrapDegrees((float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90 - mc.player.yaw);
	float pitch = mc.player.pitch + MathHelper.wrapDegrees((float)-Math.toDegrees(Math.atan2(diffY, diffXZ)) - mc.player.pitch);
	
	Vec3d rotation = new Vec3d(
			(double)(MathHelper.sin(-yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F)),
			(double)(-MathHelper.sin(pitch * 0.017453292F)),
			(double)(MathHelper.cos(-yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F)));
	
	Vec3d rayVec = mc.player.getCameraPosVec(mc.getTickDelta()).add(rotation.x * 6, rotation.y * 6, rotation.z * 6);
	return mc.world.rayTrace(new RayTraceContext(mc.player.getCameraPosVec(mc.getTickDelta()),
			rayVec, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.NONE, mc.player))
			.getBlockPos().equals(pos);
}
 
Example #2
Source File: Nuker.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public boolean canSeeBlock(BlockPos pos) {
	double diffX = pos.getX() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).x;
	double diffY = pos.getY() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).y;
	double diffZ = pos.getZ() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).z;
		
	double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
		
	float yaw = mc.player.yaw + MathHelper.wrapDegrees((float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90 - mc.player.yaw);
	float pitch = mc.player.pitch + MathHelper.wrapDegrees((float)-Math.toDegrees(Math.atan2(diffY, diffXZ)) - mc.player.pitch);
	
	Vec3d rotation = new Vec3d(
			(double)(MathHelper.sin(-yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F)),
			(double)(-MathHelper.sin(pitch * 0.017453292F)),
			(double)(MathHelper.cos(-yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F)));
	
	Vec3d rayVec = mc.player.getCameraPosVec(mc.getTickDelta()).add(rotation.x * 6, rotation.y * 6, rotation.z * 6);
	return mc.world.rayTrace(new RayTraceContext(mc.player.getCameraPosVec(mc.getTickDelta()),
			rayVec, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.NONE, mc.player))
			.getBlockPos().equals(pos);
}
 
Example #3
Source File: Nuker.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
public boolean canSeeBlock(BlockPos pos) {
	double diffX = pos.getX() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).x;
	double diffY = pos.getY() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).y;
	double diffZ = pos.getZ() + 0.5 - mc.player.getCameraPosVec(mc.getTickDelta()).z;
		
	double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
		
	float yaw = mc.player.yaw + MathHelper.wrapDegrees((float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90 - mc.player.yaw);
	float pitch = mc.player.pitch + MathHelper.wrapDegrees((float)-Math.toDegrees(Math.atan2(diffY, diffXZ)) - mc.player.pitch);
	
	Vec3d rotation = new Vec3d(
			(double)(MathHelper.sin(-yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F)),
			(double)(-MathHelper.sin(pitch * 0.017453292F)),
			(double)(MathHelper.cos(-yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F)));
	
	Vec3d rayVec = mc.player.getCameraPosVec(mc.getTickDelta()).add(rotation.x * 6, rotation.y * 6, rotation.z * 6);
	return mc.world.rayTrace(new RayTraceContext(mc.player.getCameraPosVec(mc.getTickDelta()),
			rayVec, RayTraceContext.ShapeType.OUTLINE, RayTraceContext.FluidHandling.NONE, mc.player))
			.getBlockPos().equals(pos);
}
 
Example #4
Source File: Tracer.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static BlockHitResult rayTraceBlocks(Entity source, float partialTicks, double reach, boolean fluids)
{
    Vec3d pos = source.getCameraPosVec(partialTicks);
    Vec3d rotation = source.getRotationVec(partialTicks);
    Vec3d reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
    return source.world.rayTrace(new RayTraceContext(pos, reachEnd, RayTraceContext.ShapeType.OUTLINE, fluids ? RayTraceContext.FluidHandling.ANY : RayTraceContext.FluidHandling.NONE, source));
}
 
Example #5
Source File: BonemealAuraHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean rightClickBlockLegit(BlockPos pos)
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5));
		double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec);
		
		// check if hitVec is within range (4.25 blocks)
		if(distanceSqHitVec > 18.0625)
			continue;
		
		// check if side is facing towards player
		if(distanceSqHitVec >= distanceSqPosVec)
			continue;
		
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		WURST.getRotationFaker().faceVectorPacket(hitVec);
		
		// place block
		IMC.getInteractionManager().rightClickBlock(pos, side, hitVec);
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
		
		return true;
	}
	
	return false;
}
 
Example #6
Source File: NukerLegitHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean breakBlockExtraLegit(BlockPos pos)
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5));
		double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec);
		
		// check if hitVec is within range (4.25 blocks)
		if(distanceSqHitVec > 18.0625)
			continue;
		
		// check if side is facing towards player
		if(distanceSqHitVec >= distanceSqPosVec)
			continue;
		
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		WURST.getRotationFaker().faceVectorClient(hitVec);
		
		if(currentBlock != null)
			WURST.getHax().autoToolHack.equipIfEnabled(currentBlock);
			
		// if attack key is down but nothing happens, release it for one
		// tick
		if(MC.options.keyAttack.isPressed()
			&& !MC.interactionManager.isBreakingBlock())
		{
			MC.options.keyAttack.setPressed(false);
			return true;
		}
		
		// damage block
		MC.options.keyAttack.setPressed(true);
		
		return true;
	}
	
	return false;
}
 
Example #7
Source File: TunnellerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private boolean breakBlockSimple(BlockPos pos)
{
	Direction side = null;
	Direction[] sides = Direction.values();
	
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d relCenter = BlockUtils.getBoundingBox(pos)
		.offset(-pos.getX(), -pos.getY(), -pos.getZ()).getCenter();
	Vec3d center = Vec3d.of(pos).add(relCenter);
	
	Vec3d[] hitVecs = new Vec3d[sides.length];
	for(int i = 0; i < sides.length; i++)
	{
		Vec3i dirVec = sides[i].getVector();
		Vec3d relHitVec = new Vec3d(relCenter.x * dirVec.getX(),
			relCenter.y * dirVec.getY(), relCenter.z * dirVec.getZ());
		hitVecs[i] = center.add(relHitVec);
	}
	
	for(int i = 0; i < sides.length; i++)
	{
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVecs[i],
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		side = sides[i];
		break;
	}
	
	if(side == null)
	{
		double distanceSqToCenter = eyesPos.squaredDistanceTo(center);
		for(int i = 0; i < sides.length; i++)
		{
			// check if side is facing towards player
			if(eyesPos.squaredDistanceTo(hitVecs[i]) >= distanceSqToCenter)
				continue;
			
			side = sides[i];
			break;
		}
	}
	
	if(side == null)
		throw new RuntimeException(
			"How could none of the sides be facing towards the player?!");
	
	// face block
	WURST.getRotationFaker().faceVectorPacket(hitVecs[side.ordinal()]);
	
	// damage block
	if(!MC.interactionManager.updateBlockBreakingProgress(pos, side))
		return false;
	
	// swing arm
	MC.player.networkHandler
		.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
	
	return true;
}
 
Example #8
Source File: AutoBuildHack.java    From Wurst7 with GNU General Public License v3.0 3 votes vote down vote up
private boolean tryToPlace(BlockPos pos, Vec3d eyesPos, double rangeSq)
{
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		BlockPos neighbor = pos.offset(side);
		
		// check if neighbor can be right clicked
		if(!BlockUtils.canBeClicked(neighbor)
			|| BlockUtils.getState(neighbor).getMaterial().isReplaceable())
			continue;
		
		Vec3d dirVec = Vec3d.of(side.getVector());
		Vec3d hitVec = posVec.add(dirVec.multiply(0.5));
		
		// check if hitVec is within range
		if(eyesPos.squaredDistanceTo(hitVec) > rangeSq)
			continue;
		
		// check if side is visible (facing away from player)
		if(distanceSqPosVec > eyesPos.squaredDistanceTo(posVec.add(dirVec)))
			continue;
		
		// check line of sight
		if(checkLOS.isChecked() && MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		Rotation rotation = RotationUtils.getNeededRotations(hitVec);
		PlayerMoveC2SPacket.LookOnly packet =
			new PlayerMoveC2SPacket.LookOnly(rotation.getYaw(),
				rotation.getPitch(), MC.player.isOnGround());
		MC.player.networkHandler.sendPacket(packet);
		
		// place block
		IMC.getInteractionManager().rightClickBlock(neighbor,
			side.getOpposite(), hitVec);
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
		return true;
	}
	
	return false;
}
 
Example #9
Source File: BuildRandomHack.java    From Wurst7 with GNU General Public License v3.0 3 votes vote down vote up
private boolean placeBlockLegit(BlockPos pos)
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	Vec3d posVec = Vec3d.ofCenter(pos);
	double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
	
	for(Direction side : Direction.values())
	{
		BlockPos neighbor = pos.offset(side);
		
		// check if neighbor can be right clicked
		if(!BlockUtils.canBeClicked(neighbor))
			continue;
		
		Vec3d dirVec = Vec3d.of(side.getVector());
		Vec3d hitVec = posVec.add(dirVec.multiply(0.5));
		
		// check if hitVec is within range (4.25 blocks)
		if(eyesPos.squaredDistanceTo(hitVec) > 18.0625)
			continue;
		
		// check if side is visible (facing away from player)
		if(distanceSqPosVec > eyesPos.squaredDistanceTo(posVec.add(dirVec)))
			continue;
		
		// check line of sight
		if(MC.world
			.rayTrace(new RayTraceContext(eyesPos, hitVec,
				RayTraceContext.ShapeType.COLLIDER,
				RayTraceContext.FluidHandling.NONE, MC.player))
			.getType() != HitResult.Type.MISS)
			continue;
		
		// face block
		Rotation rotation = RotationUtils.getNeededRotations(hitVec);
		PlayerMoveC2SPacket.LookOnly packet =
			new PlayerMoveC2SPacket.LookOnly(rotation.getYaw(),
				rotation.getPitch(), MC.player.isOnGround());
		MC.player.networkHandler.sendPacket(packet);
		
		// place block
		IMC.getInteractionManager().rightClickBlock(neighbor,
			side.getOpposite(), hitVec);
		MC.player.swingHand(Hand.MAIN_HAND);
		IMC.setItemUseCooldown(4);
		
		return true;
	}
	
	return false;
}