Java Code Examples for net.minecraft.util.math.Vec3d#of()

The following examples show how to use net.minecraft.util.math.Vec3d#of() . 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: AutoBuildHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private void buildInstantly()
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	IClientPlayerInteractionManager im = IMC.getInteractionManager();
	double rangeSq = Math.pow(range.getValue(), 2);
	
	for(BlockPos pos : remainingBlocks)
	{
		if(!BlockUtils.getState(pos).getMaterial().isReplaceable())
			continue;
		
		Vec3d posVec = Vec3d.ofCenter(pos);
		
		for(Direction side : Direction.values())
		{
			BlockPos neighbor = pos.offset(side);
			
			// check if neighbor can be right-clicked
			if(!BlockUtils.canBeClicked(neighbor))
				continue;
			
			Vec3d sideVec = Vec3d.of(side.getVector());
			Vec3d hitVec = posVec.add(sideVec.multiply(0.5));
			
			// check if hitVec is within range
			if(eyesPos.squaredDistanceTo(hitVec) > rangeSq)
				continue;
			
			// place block
			im.rightClickBlock(neighbor, side.getOpposite(), hitVec);
			
			break;
		}
	}
	
	remainingBlocks.clear();
}
 
Example 2
Source File: TunnellerHack.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run()
{
	BlockPos player = new BlockPos(MC.player.getPos());
	KeyBinding forward = MC.options.keyForward;
	
	Vec3d diffVec = Vec3d.of(player.subtract(start));
	Vec3d dirVec = Vec3d.of(direction.getVector());
	double dotProduct = diffVec.dotProduct(dirVec);
	
	BlockPos pos1 = start.offset(direction, (int)dotProduct);
	if(!player.equals(pos1))
	{
		WURST.getRotationFaker()
			.faceVectorClientIgnorePitch(toVec3d(pos1));
		forward.setPressed(true);
		return;
	}
	
	BlockPos pos2 = start.offset(direction, Math.max(0, length - 10));
	if(!player.equals(pos2))
	{
		WURST.getRotationFaker()
			.faceVectorClientIgnorePitch(toVec3d(pos2));
		forward.setPressed(true);
		MC.player.setSprinting(true);
		return;
	}
	
	BlockPos pos3 = start.offset(direction, length + 1);
	WURST.getRotationFaker().faceVectorClientIgnorePitch(toVec3d(pos3));
	forward.setPressed(false);
	MC.player.setSprinting(false);
	
	if(disableTimer > 0)
	{
		disableTimer--;
		return;
	}
	
	setEnabled(false);
}
 
Example 3
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 4
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;
}